Search in sources :

Example 16 with FillMandatoryException

use of org.adempiere.exceptions.FillMandatoryException in project metasfresh-webui-api by metasfresh.

the class MailRestController method sendEmail.

private WebuiEmail sendEmail(final WebuiEmail webuiEmail) {
    final String emailId = webuiEmail.getEmailId();
    // 
    // Create the email object
    final I_AD_Client adClient = Services.get(IClientDAO.class).retriveClient(Env.getCtx(), userSession.getAD_Client_ID());
    final String mailCustomType = null;
    final I_AD_User from = Services.get(IUserDAO.class).retrieveUser(webuiEmail.getFrom().getIdAsInt());
    final List<String> toList = extractEMailAddreses(webuiEmail.getTo()).collect(ImmutableList.toImmutableList());
    if (toList.isEmpty()) {
        throw new FillMandatoryException("To");
    }
    final String to = toList.get(0);
    final String subject = webuiEmail.getSubject();
    final String message = webuiEmail.getMessage();
    final boolean html = false;
    final EMail email = Services.get(IMailBL.class).createEMail(adClient, mailCustomType, from, to, subject, message, html);
    toList.stream().skip(1).forEach(email::addTo);
    webuiEmail.getAttachments().stream().map(webuiAttachment -> {
        final byte[] content = mailAttachmentsRepo.getAttachmentAsByteArray(emailId, webuiAttachment);
        return EMailAttachment.of(webuiAttachment.getDisplayName(), content);
    }).forEach(email::addAttachment);
    // 
    // Actually send the email
    final EMailSentStatus sentStatus = email.send();
    if (!sentStatus.isSentOK()) {
        throw new AdempiereException("Failed sending the email: " + sentStatus.getSentMsg());
    }
    // 
    // Delete temporary attachments
    mailAttachmentsRepo.deleteAttachments(emailId, webuiEmail.getAttachments());
    // Mark the webui email as sent
    return webuiEmail.toBuilder().sent(true).build();
}
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) I_AD_User(org.compiere.model.I_AD_User) EMailSentStatus(de.metas.email.EMailSentStatus) FillMandatoryException(org.adempiere.exceptions.FillMandatoryException) EMail(de.metas.email.EMail) IUserDAO(org.adempiere.user.api.IUserDAO) AdempiereException(org.adempiere.exceptions.AdempiereException) IClientDAO(org.adempiere.service.IClientDAO) I_AD_Client(org.compiere.model.I_AD_Client) IMailBL(de.metas.email.IMailBL)

Example 17 with FillMandatoryException

use of org.adempiere.exceptions.FillMandatoryException in project metasfresh-webui-api by metasfresh.

the class WebuiHUTransformCommand method execute.

public final WebuiHUTransformCommandResult execute() {
    final HUEditorRow row = getSelectedRow();
    final ActionType action = getActionType();
    final WebuiHUTransformParameters parameters = getParameters();
    switch(action) {
        case CU_To_NewCU:
            {
                return action_SplitCU_To_NewCU(row, parameters.getQtyCU());
            }
        case CU_To_ExistingTU:
            {
                return action_SplitCU_To_ExistingTU(row, parameters.getTuHU(), parameters.getQtyCU());
            }
        case CU_To_NewTUs:
            {
                if (parameters.getHuPIItemProduct() == null) {
                    throw new FillMandatoryException(WEBUI_M_HU_Transform.PARAM_M_HU_PI_Item_Product_ID);
                }
                return action_SplitCU_To_NewTUs(row, parameters.getHuPIItemProduct(), parameters.getQtyCU(), parameters.isHuPlanningReceiptOwnerPM_TU());
            }
        case TU_Set_Ownership:
            {
                return action_updatePlanningReceiptOwnerPM(row, parameters.isHuPlanningReceiptOwnerPM_TU());
            }
        case TU_To_NewTUs:
            {
                return action_SplitTU_To_NewTUs(row, parameters.getQtyTU());
            }
        case TU_To_NewLUs:
            {
                if (parameters.getHuPIItem() == null) {
                    throw new FillMandatoryException(WEBUI_M_HU_Transform.PARAM_M_HU_PI_Item_ID);
                }
                return action_SplitTU_To_NewLU(row, parameters.getHuPIItem(), parameters.getQtyTU(), parameters.isHuPlanningReceiptOwnerPM_LU());
            }
        case LU_Set_Ownership:
            {
                return action_updatePlanningReceiptOwnerPM(row, parameters.isHuPlanningReceiptOwnerPM_LU());
            }
        case TU_To_ExistingLU:
            {
                return action_SplitTU_To_ExistingLU(row, parameters.getLuHU(), parameters.getQtyTU());
            }
        // 
        default:
            {
                throw new AdempiereException("@Unknown@ @Action@ " + action);
            }
    }
}
Also used : AdempiereException(org.adempiere.exceptions.AdempiereException) FillMandatoryException(org.adempiere.exceptions.FillMandatoryException) HUEditorRow(de.metas.ui.web.handlingunits.HUEditorRow)

Example 18 with FillMandatoryException

use of org.adempiere.exceptions.FillMandatoryException in project metasfresh-webui-api by metasfresh.

the class WEBUI_M_HU_ReturnTUsToVendor method doIt.

@Override
protected String doIt() throws Exception {
    if (p_QtyTU <= 0) {
        throw new FillMandatoryException("QtyTU");
    }
    topLevelHU = getRecord(I_M_HU.class);
    // 
    // Get the original receipt line
    final List<I_M_InOutLine> receiptLines = huAssignmentDAO.retrieveModelsForHU(topLevelHU, I_M_InOutLine.class).stream().filter(// material receipt
    inoutLine -> !inoutLine.getM_InOut().isSOTrx()).collect(ImmutableList.toImmutableList());
    final I_M_InOutLine receiptLine = ListUtils.singleElement(receiptLines);
    // 
    // Split out the TUs we need to return
    final HUsToNewTUsRequest request = HUsToNewTUsRequest.forSourceHuAndQty(topLevelHU, p_QtyTU);
    tusToReturn = HUTransformService.newInstance().husToNewTUs(request);
    if (tusToReturn.size() != p_QtyTU) {
        throw new AdempiereException(WEBUI_HU_Constants.MSG_NotEnoughTUsFound, new Object[] { p_QtyTU, tusToReturn.size() });
    }
    // 
    // Assign the split TUs to the receipt line
    // FIXME: this is a workaround until https://github.com/metasfresh/metasfresh/issues/2392 is implemented
    tusToReturn.forEach(tu -> huAssignmentBL.createHUAssignmentBuilder().initializeAssignment(getCtx(), ITrx.TRXNAME_ThreadInherited).setM_LU_HU(null).setM_TU_HU(tu).setTopLevelHU(tu).setModel(receiptLine).build());
    // 
    // Actually create the vendor return
    final Timestamp movementDate = Env.getDate(getCtx());
    huInOutBL.createVendorReturnInOutForHUs(tusToReturn, movementDate);
    // 
    return MSG_OK;
}
Also used : FillMandatoryException(org.adempiere.exceptions.FillMandatoryException) IHUInOutBL(de.metas.handlingunits.inout.IHUInOutBL) HUEditorRow(de.metas.ui.web.handlingunits.HUEditorRow) IHUAssignmentDAO(de.metas.handlingunits.IHUAssignmentDAO) HUsToNewTUsRequest(de.metas.handlingunits.allocation.transfer.HUTransformService.HUsToNewTUsRequest) Timestamp(java.sql.Timestamp) DocumentId(de.metas.ui.web.window.datatypes.DocumentId) ITrx(org.adempiere.ad.trx.api.ITrx) Env(org.compiere.util.Env) HUEditorProcessTemplate(de.metas.ui.web.handlingunits.HUEditorProcessTemplate) I_M_InOutLine(de.metas.edi.model.I_M_InOutLine) HUTransformService(de.metas.handlingunits.allocation.transfer.HUTransformService) ProcessPreconditionsResolution(de.metas.process.ProcessPreconditionsResolution) Services(org.adempiere.util.Services) List(java.util.List) Param(de.metas.process.Param) ImmutableList(com.google.common.collect.ImmutableList) AdempiereException(org.adempiere.exceptions.AdempiereException) ListUtils(org.adempiere.util.collections.ListUtils) IHUAssignmentBL(de.metas.handlingunits.IHUAssignmentBL) I_M_HU(de.metas.handlingunits.model.I_M_HU) IProcessPrecondition(de.metas.process.IProcessPrecondition) WEBUI_HU_Constants(de.metas.ui.web.handlingunits.WEBUI_HU_Constants) DocumentIdsSelection(de.metas.ui.web.window.datatypes.DocumentIdsSelection) I_M_HU(de.metas.handlingunits.model.I_M_HU) AdempiereException(org.adempiere.exceptions.AdempiereException) I_M_InOutLine(de.metas.edi.model.I_M_InOutLine) FillMandatoryException(org.adempiere.exceptions.FillMandatoryException) HUsToNewTUsRequest(de.metas.handlingunits.allocation.transfer.HUTransformService.HUsToNewTUsRequest) Timestamp(java.sql.Timestamp)

Example 19 with FillMandatoryException

use of org.adempiere.exceptions.FillMandatoryException in project metasfresh-webui-api by metasfresh.

the class PackingInfoProcessParams method createAndSaveNewLUTUConfig.

public I_M_HU_LUTU_Configuration createAndSaveNewLUTUConfig() {
    final I_M_HU_LUTU_Configuration defaultLUTUConfig = getDefaultLUTUConfig();
    // Validate parameters
    // not mandatory
    final int lu_PI_Item_ID = getLuPiItemId();
    final int M_HU_PI_Item_Product_ID = getTU_HU_PI_Item_Product_ID();
    final BigDecimal qtyCU = getQtyCU();
    final boolean isVirtualHU = M_HU_PI_Item_Product_ID == IHUPIItemProductDAO.VIRTUAL_HU_PI_Item_Product_ID;
    final BigDecimal qtyTU = isVirtualHU ? BigDecimal.ONE : this.qtyTU;
    if (M_HU_PI_Item_Product_ID <= 0) {
        throw new FillMandatoryException(PARAM_M_HU_PI_Item_Product_ID);
    }
    if (qtyCU == null || qtyCU.signum() <= 0) {
        throw new FillMandatoryException(PARAM_QtyCU);
    }
    if (qtyTU == null || qtyTU.signum() <= 0) {
        throw new FillMandatoryException(PARAM_QtyTU);
    }
    final I_M_HU_LUTU_Configuration lutuConfigNew = InterfaceWrapperHelper.copy().setFrom(defaultLUTUConfig).copyToNew(I_M_HU_LUTU_Configuration.class);
    // CU
    lutuConfigNew.setQtyCU(qtyCU);
    lutuConfigNew.setIsInfiniteQtyCU(false);
    // TU
    configureLUTUConfigTU(lutuConfigNew, M_HU_PI_Item_Product_ID, qtyTU);
    // LU
    configureLUTUConfigLU(lutuConfigNew, lu_PI_Item_ID);
    lutuConfigurationFactory.save(lutuConfigNew);
    return lutuConfigNew;
}
Also used : I_M_HU_LUTU_Configuration(de.metas.handlingunits.model.I_M_HU_LUTU_Configuration) FillMandatoryException(org.adempiere.exceptions.FillMandatoryException) BigDecimal(java.math.BigDecimal)

Example 20 with FillMandatoryException

use of org.adempiere.exceptions.FillMandatoryException in project metasfresh-webui-api by metasfresh.

the class WEBUI_PickingSlotsClearingView_TakeOutHUAndAddToNewHU method doIt.

@Override
protected String doIt() throws Exception {
    if (qtyCU == null || qtyCU.signum() <= 0) {
        throw new FillMandatoryException(PARAM_QtyCU);
    }
    final I_M_HU fromHU = getSingleSelectedPickingSlotTopLevelHU();
    final IAllocationSource source = HUListAllocationSourceDestination.of(fromHU).setDestroyEmptyHUs(true);
    final IHUProducerAllocationDestination destination = createHUProducer(fromHU);
    HULoader.of(source, destination).setAllowPartialUnloads(false).setAllowPartialLoads(false).load(prepareUnloadRequest(fromHU, qtyCU).setForceQtyAllocation(true).create());
    // If the source HU was destroyed, then "remove" it from picking slots
    if (handlingUnitsBL.isDestroyedRefreshFirst(fromHU)) {
        pickingCandidateService.inactivateForHUId(fromHU.getM_HU_ID());
    }
    return MSG_OK;
}
Also used : IAllocationSource(de.metas.handlingunits.allocation.IAllocationSource) I_M_HU(de.metas.handlingunits.model.I_M_HU) IHUProducerAllocationDestination(de.metas.handlingunits.allocation.IHUProducerAllocationDestination) FillMandatoryException(org.adempiere.exceptions.FillMandatoryException)

Aggregations

FillMandatoryException (org.adempiere.exceptions.FillMandatoryException)20 AdempiereException (org.adempiere.exceptions.AdempiereException)11 I_M_HU (de.metas.handlingunits.model.I_M_HU)3 BigDecimal (java.math.BigDecimal)3 Timestamp (java.sql.Timestamp)3 MProduct (org.compiere.model.MProduct)3 ImmutableList (com.google.common.collect.ImmutableList)2 HUsToNewTUsRequest (de.metas.handlingunits.allocation.transfer.HUTransformService.HUsToNewTUsRequest)2 I_M_HU_LUTU_Configuration (de.metas.handlingunits.model.I_M_HU_LUTU_Configuration)2 I_M_HU_PI_Item (de.metas.handlingunits.model.I_M_HU_PI_Item)2 HUEditorRow (de.metas.ui.web.handlingunits.HUEditorRow)2 List (java.util.List)2 ITrx (org.adempiere.ad.trx.api.ITrx)2 Services (org.adempiere.util.Services)2 Query (org.compiere.model.Query)2 Env (org.compiere.util.Env)2 Supplier (com.google.common.base.Supplier)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 I_M_InOutLine (de.metas.edi.model.I_M_InOutLine)1 EMail (de.metas.email.EMail)1