document db no longer storing complete template information in separate table:
- dropped table templates - altered table documents: template_id (ref into templates) → template (name of template) - templates are now picked up by the document registry Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
/* © SRSoftware 2025 */
|
||||
package de.srsoftware.umbrella.core.model;
|
||||
|
||||
import static de.srsoftware.tools.Optionals.emptyIfNull;
|
||||
import static de.srsoftware.umbrella.core.Constants.*;
|
||||
import static de.srsoftware.umbrella.core.Field.*;
|
||||
import static de.srsoftware.umbrella.core.Field.COMPANY;
|
||||
@@ -57,14 +58,14 @@ public final class Document implements Mappable {
|
||||
private final Type type;
|
||||
private LocalDate date;
|
||||
private State state;
|
||||
private Template template;
|
||||
private String template;
|
||||
private final Sender sender;
|
||||
private final Customer customer;
|
||||
private final PositionList positions;
|
||||
private final Set<String> dirtyFields = new HashSet<>();
|
||||
|
||||
|
||||
public Document(long id, long companyId, String number, Type type, LocalDate date, State state, Template template, String delivery, String head, String footer, String currency, String decimalSeparator, Sender sender, Customer customer, PositionList positions) {
|
||||
public Document(long id, long companyId, String number, Type type, LocalDate date, State state, String template, String delivery, String head, String footer, String currency, String decimalSeparator, Sender sender, Customer customer, PositionList positions) {
|
||||
this.id = id;
|
||||
this.companyId = companyId;
|
||||
this.number = number;
|
||||
@@ -206,7 +207,7 @@ public final class Document implements Mappable {
|
||||
case SENDER: if (json.get(key) instanceof JSONObject nested) sender.patch(nested); break;
|
||||
case STATE: state = State.of(json.getInt(key)).orElseThrow(() -> new UmbrellaException(HTTP_UNPROCESSABLE,"Invalid state")); break;
|
||||
case POS: if (json.get(key) instanceof JSONObject nested) positions.patch(nested); break;
|
||||
case TEMPLATE_ID: if (json.get(key) instanceof Number num) template = new Template(num.longValue(),companyId,null,null); break;
|
||||
case TEMPLATE_ID: if (json.get(key) instanceof String templateId) template = templateId; break;
|
||||
default: key = null;
|
||||
}
|
||||
if (key != null) dirtyFields.add(key);
|
||||
@@ -225,7 +226,7 @@ public final class Document implements Mappable {
|
||||
map.put(TYPE, type.name());
|
||||
map.put(DATE, date);
|
||||
map.put(STATE, state.code);
|
||||
map.put(DELIVERY, delivery == null ? "" : delivery);
|
||||
map.put(DELIVERY, emptyIfNull(delivery));
|
||||
map.put(HEAD, mapMarkdown(head));
|
||||
map.put(FOOTER, mapMarkdown(footer));
|
||||
map.put(CURRENCY, currency);
|
||||
@@ -235,7 +236,7 @@ public final class Document implements Mappable {
|
||||
map.put("taxes",positions.taxNetSums(true));
|
||||
map.put(NET_SUM, netSum());
|
||||
map.put(GROSS_SUM, grossSum());
|
||||
if (template != null) map.put("template", template.toMap());
|
||||
map.put("template", emptyIfNull(template));
|
||||
return map;
|
||||
}
|
||||
|
||||
@@ -286,7 +287,7 @@ public final class Document implements Mappable {
|
||||
);
|
||||
}
|
||||
|
||||
public Template template() {
|
||||
public String template() {
|
||||
return template;
|
||||
}
|
||||
|
||||
@@ -309,7 +310,7 @@ public final class Document implements Mappable {
|
||||
map.put("taxes",positions.taxNetSums(true));
|
||||
map.put(NET_SUM, netSum());
|
||||
map.put(GROSS_SUM, grossSum());
|
||||
if (template != null) map.put("template", template.toMap());
|
||||
if (template != null) map.put("template", template);
|
||||
return map;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
/* © SRSoftware 2025 */
|
||||
package de.srsoftware.umbrella.core.model;
|
||||
|
||||
import static de.srsoftware.umbrella.core.Constants.*;
|
||||
import static de.srsoftware.umbrella.core.Field.COMPANY;
|
||||
import static de.srsoftware.umbrella.core.Field.COMPANY_ID;
|
||||
|
||||
import de.srsoftware.tools.Mappable;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Map;
|
||||
|
||||
public record Template(long id, long company, String name, byte[] data) implements Mappable {
|
||||
|
||||
public static Template of(ResultSet rs) throws SQLException {
|
||||
return new Template(rs.getLong(ID),rs.getLong(COMPANY_ID),rs.getString(NAME),rs.getBytes(TEMPLATE));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> toMap() {
|
||||
return Map.of(ID,id, COMPANY,company, NAME,name);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user