Search in sources :

Example 6 with LookupValue

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);
    }
}
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 7 with LookupValue

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));
}
Also used : IUserBL(org.adempiere.user.api.IUserBL) DocumentPath(de.metas.ui.web.window.datatypes.DocumentPath) JSONDocumentPath(de.metas.ui.web.window.datatypes.json.JSONDocumentPath) IntegerLookupValue(de.metas.ui.web.window.datatypes.LookupValue.IntegerLookupValue) BoilerPlateContext(de.metas.letters.model.MADBoilerPlate.BoilerPlateContext) DocumentPrint(de.metas.ui.web.window.model.DocumentCollection.DocumentPrint) DocumentPrint(de.metas.ui.web.window.model.DocumentCollection.DocumentPrint) FillMandatoryException(org.adempiere.exceptions.FillMandatoryException) IOException(java.io.IOException) AdempiereException(org.adempiere.exceptions.AdempiereException) 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) PostMapping(org.springframework.web.bind.annotation.PostMapping) ApiOperation(io.swagger.annotations.ApiOperation)

Example 8 with LookupValue

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());
}
Also used : LookupValue(de.metas.ui.web.window.datatypes.LookupValue) IntegerLookupValue(de.metas.ui.web.window.datatypes.LookupValue.IntegerLookupValue)

Example 9 with LookupValue

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());
}
Also used : LookupValue(de.metas.ui.web.window.datatypes.LookupValue) IntegerLookupValue(de.metas.ui.web.window.datatypes.LookupValue.IntegerLookupValue)

Example 10 with LookupValue

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()));
}
Also used : LookupValue(de.metas.ui.web.window.datatypes.LookupValue) IntegerLookupValue(de.metas.ui.web.window.datatypes.LookupValue.IntegerLookupValue)

Aggregations

LookupValue (de.metas.ui.web.window.datatypes.LookupValue)31 IntegerLookupValue (de.metas.ui.web.window.datatypes.LookupValue.IntegerLookupValue)25 LookupValuesList (de.metas.ui.web.window.datatypes.LookupValuesList)7 JSONLookupValue (de.metas.ui.web.window.datatypes.json.JSONLookupValue)6 ITranslatableString (de.metas.i18n.ITranslatableString)5 AdempiereException (org.adempiere.exceptions.AdempiereException)4 Map (java.util.Map)3 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 IHUOrderBL (de.metas.handlingunits.order.api.IHUOrderBL)2 NumberTranslatableString (de.metas.i18n.NumberTranslatableString)2 BoilerPlateContext (de.metas.letters.model.MADBoilerPlate.BoilerPlateContext)2 ProcessInfoParameter (de.metas.process.ProcessInfoParameter)2 QuickInput (de.metas.ui.web.quickinput.QuickInput)2 DocumentPath (de.metas.ui.web.window.datatypes.DocumentPath)2 StringLookupValue (de.metas.ui.web.window.datatypes.LookupValue.StringLookupValue)2 Password (de.metas.ui.web.window.datatypes.Password)2 JSONDate (de.metas.ui.web.window.datatypes.json.JSONDate)2 JSONDocumentPath (de.metas.ui.web.window.datatypes.json.JSONDocumentPath)2 JSONLookupValuesList (de.metas.ui.web.window.datatypes.json.JSONLookupValuesList)2