|
|
|
@ -19,6 +19,7 @@ import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.forbidden |
|
|
|
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.missingFieldException; |
|
|
|
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.missingFieldException; |
|
|
|
import static de.srsoftware.umbrella.documents.Constants.*; |
|
|
|
import static de.srsoftware.umbrella.documents.Constants.*; |
|
|
|
import static de.srsoftware.umbrella.documents.model.Document.State.NEW; |
|
|
|
import static de.srsoftware.umbrella.documents.model.Document.State.NEW; |
|
|
|
|
|
|
|
import static de.srsoftware.umbrella.documents.model.Document.State.SENT; |
|
|
|
import static java.lang.System.Logger.Level.DEBUG; |
|
|
|
import static java.lang.System.Logger.Level.DEBUG; |
|
|
|
import static java.lang.System.Logger.Level.WARNING; |
|
|
|
import static java.lang.System.Logger.Level.WARNING; |
|
|
|
import static java.net.HttpURLConnection.*; |
|
|
|
import static java.net.HttpURLConnection.*; |
|
|
|
@ -218,20 +219,19 @@ public class DocumentApi extends BaseHandler { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private boolean sendDocument(HttpExchange ex, Path path, UmbrellaUser user, long docId) throws IOException, UmbrellaException { |
|
|
|
private boolean sendDocument(HttpExchange ex, Path path, UmbrellaUser user, long docId) throws IOException, UmbrellaException { |
|
|
|
var doc = getDocument(docId,user).a; |
|
|
|
var doc = getDocumentWithCompanyData(docId,user); |
|
|
|
var rendered = renderDocument(doc,user); |
|
|
|
var rendered = renderDocument(doc,user); |
|
|
|
var json = json(ex); |
|
|
|
var json = json(ex); |
|
|
|
if (!(json.has(EMAIL) && json.get(EMAIL) instanceof String email)) throw missingFieldException(EMAIL); |
|
|
|
if (!(json.has(EMAIL) && json.get(EMAIL) instanceof String email)) throw missingFieldException(EMAIL); |
|
|
|
if (!(json.has(SUBJECT) && json.get(SUBJECT) instanceof String subject)) throw missingFieldException(SUBJECT); |
|
|
|
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); |
|
|
|
if (!(json.has(CONTENT) && json.get(CONTENT) instanceof String content)) throw missingFieldException(CONTENT); |
|
|
|
|
|
|
|
LOG.log(WARNING,"Updating settings of company-customer-document combination not implemented!"); |
|
|
|
var attachment = new Attachment(doc.number()+".pdf",rendered.mimeType(),rendered.bytes()); |
|
|
|
var attachment = new Attachment(doc.number()+".pdf",rendered.mimeType(),rendered.bytes()); |
|
|
|
var message = new Message(user,subject,content,null,List.of(attachment)); |
|
|
|
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())); |
|
|
|
var envelope = new Envelope(message,new User(doc.customer().shortName(),new EmailAddress(email),doc.customer().language())); |
|
|
|
messages.send(envelope); |
|
|
|
messages.send(envelope); |
|
|
|
// TODO postBox.send(…)
|
|
|
|
db.save(doc.set(SENT)); |
|
|
|
|
|
|
|
return ok(ex); |
|
|
|
return sendEmptyResponse(HTTP_NOT_IMPLEMENTED,ex); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private boolean getCompanies(HttpExchange ex, UmbrellaUser user, Token token) throws IOException, UmbrellaException { |
|
|
|
private boolean getCompanies(HttpExchange ex, UmbrellaUser user, Token token) throws IOException, UmbrellaException { |
|
|
|
|