use of de.metas.ui.web.mail.WebuiEmail.WebuiEmailBuilder in project metasfresh-webui-api by metasfresh.
the class MailRestController method changeEmail.
private void changeEmail(final WebuiEmail email, final WebuiEmailBuilder newEmailBuilder, final JSONDocumentChangedEvent event) {
if (!event.isReplace()) {
throw new AdempiereException("Unsupported event").setParameter("event", event);
}
final String fieldName = event.getPath();
if (PATCH_FIELD_To.equals(fieldName)) {
@SuppressWarnings("unchecked") final List<Object> jsonTo = (List<Object>) event.getValue();
@SuppressWarnings("unchecked") final LookupValuesList to = jsonTo.stream().map(mapObj -> (Map<String, Object>) mapObj).map(map -> JSONLookupValue.integerLookupValueFromJsonMap(map)).collect(LookupValuesList.collect());
newEmailBuilder.to(to);
} else if (PATCH_FIELD_Subject.equals(fieldName)) {
final String subject = (String) event.getValue();
newEmailBuilder.subject(subject);
} else if (PATCH_FIELD_Message.equals(fieldName)) {
final String message = (String) event.getValue();
newEmailBuilder.message(message);
} else if (PATCH_FIELD_Attachments.equals(fieldName)) {
@SuppressWarnings("unchecked") final List<Object> jsonAttachments = (List<Object>) event.getValue();
@SuppressWarnings("unchecked") final LookupValuesList attachments = jsonAttachments.stream().map(mapObj -> (Map<String, Object>) mapObj).map(map -> JSONLookupValue.stringLookupValueFromJsonMap(map)).collect(LookupValuesList.collect());
newEmailBuilder.attachments(attachments);
} else if (PATCH_FIELD_TemplateId.equals(fieldName)) {
@SuppressWarnings("unchecked") final LookupValue templateId = JSONLookupValue.integerLookupValueFromJsonMap((Map<String, Object>) event.getValue());
applyTemplate(email, newEmailBuilder, templateId);
} else {
throw new AdempiereException("Unsupported event path").setParameter("event", event).setParameter("fieldName", fieldName).setParameter("availablePaths", PATCH_FIELD_ALL);
}
}
use of de.metas.ui.web.mail.WebuiEmail.WebuiEmailBuilder in project metasfresh-webui-api by metasfresh.
the class MailRestController method changeEmail.
private WebuiEmail changeEmail(final WebuiEmail email, final List<JSONDocumentChangedEvent> events) {
final WebuiEmailBuilder emailBuilder = email.toBuilder();
events.forEach(event -> changeEmail(email, emailBuilder, event));
return emailBuilder.build();
}
Aggregations