use of de.metas.ui.web.window.datatypes.LookupValue 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.window.datatypes.LookupValue in project metasfresh-webui-api by metasfresh.
the class MailRestController method createNewEmail.
@PostMapping()
@ApiOperation("Creates a new email")
public JSONEmail createNewEmail(@RequestBody final JSONEmailRequest request) {
userSession.assertLoggedIn();
final int adUserId = userSession.getAD_User_ID();
Services.get(IUserBL.class).assertCanSendEMail(adUserId);
final IntegerLookupValue from = IntegerLookupValue.of(adUserId, userSession.getUserFullname() + " <" + userSession.getUserEmail() + "> ");
final DocumentPath contextDocumentPath = JSONDocumentPath.toDocumentPathOrNull(request.getDocumentPath());
final BoilerPlateContext attributes = documentCollection.createBoilerPlateContext(contextDocumentPath);
final Integer toUserId = attributes.getAD_User_ID();
final LookupValue to = mailRepo.getToByUserId(toUserId);
final String emailId = mailRepo.createNewEmail(adUserId, from, to, contextDocumentPath).getEmailId();
if (contextDocumentPath != null) {
try {
final DocumentPrint contextDocumentPrint = documentCollection.createDocumentPrint(contextDocumentPath);
attachFile(emailId, () -> mailAttachmentsRepo.createAttachment(emailId, contextDocumentPrint.getFilename(), contextDocumentPrint.getReportData()));
} catch (final Exception ex) {
logger.debug("Failed creating attachment from document print of {}", contextDocumentPath, ex);
}
}
return JSONEmail.of(mailRepo.getEmail(emailId));
}
use of de.metas.ui.web.window.datatypes.LookupValue in project metasfresh-webui-api by metasfresh.
the class HuTraceQueryCreator method updatePpOrderIdFromParameter.
private static HUTraceEventQuery updatePpOrderIdFromParameter(@NonNull final HUTraceEventQuery query, @NonNull final DocumentFilterParam parameter) {
errorIfQueryValueGreaterThanZero("PpOrderId", query.getPpOrderId(), query);
final LookupValue value = (LookupValue) parameter.getValue();
return query.withPpOrderId(value.getIdAsInt());
}
use of de.metas.ui.web.window.datatypes.LookupValue in project metasfresh-webui-api by metasfresh.
the class HuTraceQueryCreator method updateInOutIdFromParameter.
private static HUTraceEventQuery updateInOutIdFromParameter(@NonNull final HUTraceEventQuery query, @NonNull final DocumentFilterParam parameter) {
errorIfQueryValueGreaterThanZero("InOutId", query.getInOutId(), query);
final LookupValue value = (LookupValue) parameter.getValue();
return query.withInOutId(value.getIdAsInt());
}
use of de.metas.ui.web.window.datatypes.LookupValue in project metasfresh-webui-api by metasfresh.
the class HuTraceQueryCreator method updateTypeFromParameter.
private static HUTraceEventQuery updateTypeFromParameter(@NonNull final HUTraceEventQuery query, @NonNull final DocumentFilterParam parameter) {
errorIfQueryValueNotNull("Type", query.getType(), query);
final LookupValue value = (LookupValue) parameter.getValue();
return query.withType(HUTraceType.valueOf(value.getIdAsString()));
}
Aggregations