Search in sources :

Example 1 with WebuiEmailBuilder

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);
    }
}
Also used : FillMandatoryException(org.adempiere.exceptions.FillMandatoryException) PathVariable(org.springframework.web.bind.annotation.PathVariable) RequestParam(org.springframework.web.bind.annotation.RequestParam) WebuiEmailRemovedEvent(de.metas.ui.web.mail.WebuiMailRepository.WebuiEmailRemovedEvent) IntegerLookupValue(de.metas.ui.web.window.datatypes.LookupValue.IntegerLookupValue) ITrx(org.adempiere.ad.trx.api.ITrx) Env(org.compiere.util.Env) Autowired(org.springframework.beans.factory.annotation.Autowired) UnaryOperator(java.util.function.UnaryOperator) DocumentCollection(de.metas.ui.web.window.model.DocumentCollection) ApiOperation(io.swagger.annotations.ApiOperation) Map(java.util.Map) JSONEmail(de.metas.ui.web.mail.json.JSONEmail) PostMapping(org.springframework.web.bind.annotation.PostMapping) ImmutableSet(com.google.common.collect.ImmutableSet) EMail(de.metas.email.EMail) NonNull(lombok.NonNull) Set(java.util.Set) EventListener(org.springframework.context.event.EventListener) RestController(org.springframework.web.bind.annotation.RestController) JSONLookupValuesList(de.metas.ui.web.window.datatypes.json.JSONLookupValuesList) UserSession(de.metas.ui.web.session.UserSession) Services(org.adempiere.util.Services) List(java.util.List) I_AD_Client(org.compiere.model.I_AD_Client) Stream(java.util.stream.Stream) DocumentPrint(de.metas.ui.web.window.model.DocumentCollection.DocumentPrint) IMailBL(de.metas.email.IMailBL) ApiModel(io.swagger.annotations.ApiModel) LogManager(de.metas.logging.LogManager) EMailSentStatus(de.metas.email.EMailSentStatus) WebConfig(de.metas.ui.web.config.WebConfig) DocumentPath(de.metas.ui.web.window.datatypes.DocumentPath) JSONDocumentChangedEvent(de.metas.ui.web.window.datatypes.json.JSONDocumentChangedEvent) Supplier(com.google.common.base.Supplier) IUserBL(org.adempiere.user.api.IUserBL) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) IUserDAO(org.adempiere.user.api.IUserDAO) PatchMapping(org.springframework.web.bind.annotation.PatchMapping) RequestBody(org.springframework.web.bind.annotation.RequestBody) ImmutableList(com.google.common.collect.ImmutableList) GetMapping(org.springframework.web.bind.annotation.GetMapping) LookupValuesList(de.metas.ui.web.window.datatypes.LookupValuesList) I_AD_User(org.compiere.model.I_AD_User) JSONLookupValue(de.metas.ui.web.window.datatypes.json.JSONLookupValue) LookupValue(de.metas.ui.web.window.datatypes.LookupValue) MADBoilerPlate(de.metas.letters.model.MADBoilerPlate) Properties(java.util.Properties) Logger(org.slf4j.Logger) JSONDocumentPath(de.metas.ui.web.window.datatypes.json.JSONDocumentPath) IOException(java.io.IOException) WebuiEmailBuilder(de.metas.ui.web.mail.WebuiEmail.WebuiEmailBuilder) BoilerPlateContext(de.metas.letters.model.MADBoilerPlate.BoilerPlateContext) AdempiereException(org.adempiere.exceptions.AdempiereException) IClientDAO(org.adempiere.service.IClientDAO) Check(de.metas.printing.esb.base.util.Check) EMailAttachment(de.metas.email.EMailAttachment) JSONEmailRequest(de.metas.ui.web.mail.json.JSONEmailRequest) MultipartFile(org.springframework.web.multipart.MultipartFile) AdempiereException(org.adempiere.exceptions.AdempiereException) JSONLookupValuesList(de.metas.ui.web.window.datatypes.json.JSONLookupValuesList) LookupValuesList(de.metas.ui.web.window.datatypes.LookupValuesList) JSONLookupValuesList(de.metas.ui.web.window.datatypes.json.JSONLookupValuesList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) LookupValuesList(de.metas.ui.web.window.datatypes.LookupValuesList) Map(java.util.Map) IntegerLookupValue(de.metas.ui.web.window.datatypes.LookupValue.IntegerLookupValue) JSONLookupValue(de.metas.ui.web.window.datatypes.json.JSONLookupValue) LookupValue(de.metas.ui.web.window.datatypes.LookupValue)

Example 2 with WebuiEmailBuilder

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();
}
Also used : WebuiEmailBuilder(de.metas.ui.web.mail.WebuiEmail.WebuiEmailBuilder)

Aggregations

WebuiEmailBuilder (de.metas.ui.web.mail.WebuiEmail.WebuiEmailBuilder)2 Supplier (com.google.common.base.Supplier)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 EMail (de.metas.email.EMail)1 EMailAttachment (de.metas.email.EMailAttachment)1 EMailSentStatus (de.metas.email.EMailSentStatus)1 IMailBL (de.metas.email.IMailBL)1 MADBoilerPlate (de.metas.letters.model.MADBoilerPlate)1 BoilerPlateContext (de.metas.letters.model.MADBoilerPlate.BoilerPlateContext)1 LogManager (de.metas.logging.LogManager)1 Check (de.metas.printing.esb.base.util.Check)1 WebConfig (de.metas.ui.web.config.WebConfig)1 WebuiEmailRemovedEvent (de.metas.ui.web.mail.WebuiMailRepository.WebuiEmailRemovedEvent)1 JSONEmail (de.metas.ui.web.mail.json.JSONEmail)1 JSONEmailRequest (de.metas.ui.web.mail.json.JSONEmailRequest)1 UserSession (de.metas.ui.web.session.UserSession)1 DocumentPath (de.metas.ui.web.window.datatypes.DocumentPath)1 LookupValue (de.metas.ui.web.window.datatypes.LookupValue)1 IntegerLookupValue (de.metas.ui.web.window.datatypes.LookupValue.IntegerLookupValue)1