preparing for sending documents

Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
2025-07-17 20:15:28 +02:00
parent 93449e4bad
commit 6a58087ace
19 changed files with 146 additions and 110 deletions

View File

@@ -5,10 +5,10 @@ dependencies{
implementation(project(":core"))
implementation("de.srsoftware:configuration.json:1.0.3")
implementation("de.srsoftware:document.api:1.0.1")
implementation("de.srsoftware:document.file:1.0.0")
implementation("de.srsoftware:document.processor:1.0.2")
implementation("de.srsoftware:document.zugferd:1.0.3")
implementation("de.srsoftware:document.api:2.0.0")
implementation("de.srsoftware:document.file:1.0.1")
implementation("de.srsoftware:document.processor:1.0.3")
implementation("de.srsoftware:document.zugferd:1.0.4")
implementation("de.srsoftware:tools.mime:1.1.2")
}

View File

@@ -29,7 +29,6 @@ import de.srsoftware.configuration.Configuration;
import de.srsoftware.document.api.Content;
import de.srsoftware.document.api.DocumentRegistry;
import de.srsoftware.document.api.RenderError;
import de.srsoftware.document.api.RenderResult;
import de.srsoftware.document.files.DocumentDirectory;
import de.srsoftware.document.processor.latex.LatexFactory;
import de.srsoftware.document.processor.weasyprint.WeasyFactory;
@@ -42,12 +41,11 @@ import de.srsoftware.tools.SessionToken;
import de.srsoftware.tools.Tuple;
import de.srsoftware.umbrella.core.BaseHandler;
import de.srsoftware.umbrella.core.api.CompanyService;
import de.srsoftware.umbrella.core.api.PostBox;
import de.srsoftware.umbrella.core.api.Translator;
import de.srsoftware.umbrella.core.api.UserService;
import de.srsoftware.umbrella.core.exceptions.UmbrellaException;
import de.srsoftware.umbrella.core.model.Company;
import de.srsoftware.umbrella.core.model.Token;
import de.srsoftware.umbrella.core.model.UmbrellaUser;
import de.srsoftware.umbrella.core.model.*;
import de.srsoftware.umbrella.documents.model.*;
import de.srsoftware.umbrella.documents.model.Customer;
import java.io.File;
@@ -227,7 +225,11 @@ public class DocumentApi extends BaseHandler {
if (!(json.has(SUBJECT) && json.get(SUBJECT) instanceof String subject)) throw missingFieldException(SUBJECT);
if (!(json.has(CONTENT) && json.get(CONTENT) instanceof String content)) throw missingFieldException(CONTENT);
postBox.send()
var attachment = new Attachment(doc.number()+".pdf",rendered.mimeType(),rendered.bytes());
var message = new Message(user,subject,content,null,List.of(attachment));
var envelope = new Envelope(message,new User(doc.customer().name(),new EmailAddress(email),doc.customer().language()));
messages.send(envelope);
// TODO postBox.send(…)
return sendEmptyResponse(HTTP_NOT_IMPLEMENTED,ex);
}

View File

@@ -560,7 +560,7 @@ CREATE TABLE IF NOT EXISTS {0} ( {1} VARCHAR(255) PRIMARY KEY, {2} VARCHAR(255)
var customerId = rs.getString(FIELD_CUSTOMER_NUMBER);
var customerTaxNumber = rs.getString(FIELD_CUSTOMER_TAX_NUMBER);
var customerEmail = rs.getString(FIELD_CUSTOMER_EMAIL);
var customer = new Customer(customerId, customerName, customerEmail, customerTaxNumber);
var customer = new Customer(customerId, customerName, customerEmail, customerTaxNumber,FALLBACK_LANG);
var sender = new Sender(senderName,bankAccount,taxNumber,court);
var template = toTemplate(rs);
return new Document(id,company,number,type,date, Document.State.of(state).orElse(State.ERROR),template,delivery,head,footer,currency, DEFAULT_THOUSANDS_SEPARATOR,sender,customer,new PositionList());

View File

@@ -88,7 +88,7 @@ public abstract class TemplateDoc implements Document {
if (MIME_HTML.equals(mimeType())) value = value.replace("\n","<span class=\"break\"></span>\n");
source = source.replace("<? "+token+" ?>",value);
}
return new StringContent(source);
return new StringContent(source,content.mimeType());
}
return precursor;
}

View File

@@ -18,13 +18,15 @@ public final class Customer implements Mappable {
private String name;
private String email;
private String taxNumber;
private String language;
private final Set<String> dirtyFields = new HashSet<>();
public Customer(String id, String name, String email, String taxNumber) {
public Customer(String id, String name, String email, String taxNumber, String language) {
this.id = id;
this.name = name;
this.email = email;
this.taxNumber = taxNumber;
this.language = language;
}
public void clean() {
@@ -59,6 +61,10 @@ public final class Customer implements Mappable {
return !dirtyFields.isEmpty();
}
public String language(){
return language;
}
public String name() {
return name;
}
@@ -68,7 +74,8 @@ public final class Customer implements Mappable {
if (!json.has(NAME) || !(json.get(NAME) instanceof String name)) throw missingFieldException(NAME);
if (!json.has(EMAIL) || !(json.get(EMAIL) instanceof String email)) throw missingFieldException(EMAIL);
if (!json.has(FIELD_TAX_ID) || !(json.get(FIELD_TAX_ID) instanceof String taxId)) throw missingFieldException(FIELD_TAX_ID);
return new Customer(id,name,email,taxId);
var lang = json.has(LANGUAGE) && json.get(LANGUAGE) instanceof String l ? l : FALLBACK_LANG;
return new Customer(id,name,email,taxId,lang);
}
public void patch(JSONObject json) {

View File

@@ -2,10 +2,9 @@
package de.srsoftware.umbrella.documents.model;
import de.srsoftware.tools.Mappable;
import static de.srsoftware.umbrella.documents.Constants.*;
import de.srsoftware.tools.Mappable;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Map;