Search in sources :

Example 1 with BoilerPlateContext

use of de.metas.letters.model.MADBoilerPlate.BoilerPlateContext in project metasfresh-webui-api by metasfresh.

the class LetterRestController method applyTemplate.

private void applyTemplate(final WebuiLetter letter, final WebuiLetterBuilder newLetterBuilder, final LookupValue templateLookupValue) {
    final Properties ctx = Env.getCtx();
    final int textTemplateId = templateLookupValue.getIdAsInt();
    final MADBoilerPlate boilerPlate = MADBoilerPlate.get(ctx, textTemplateId);
    // 
    // Attributes
    final BoilerPlateContext context = documentCollection.createBoilerPlateContext(letter.getContextDocumentPath());
    // 
    // Content and subject
    newLetterBuilder.textTemplateId(textTemplateId);
    newLetterBuilder.content(boilerPlate.getTextSnippetParsed(context));
    newLetterBuilder.subject(boilerPlate.getSubject());
}
Also used : MADBoilerPlate(de.metas.letters.model.MADBoilerPlate) BoilerPlateContext(de.metas.letters.model.MADBoilerPlate.BoilerPlateContext) Properties(java.util.Properties)

Example 2 with BoilerPlateContext

use of de.metas.letters.model.MADBoilerPlate.BoilerPlateContext in project metasfresh-webui-api by metasfresh.

the class LetterRestController method complete0.

private final WebuiLetter complete0(final WebuiLetter letter) {
    lettersRepo.createC_Letter(letter);
    // 
    // Create the printable letter
    final byte[] pdfData = createPDFData(letter);
    final File pdfFile = createFile(pdfData);
    // 
    // create the Boilerplate context
    final BoilerPlateContext context = documentCollection.createBoilerPlateContext(letter.getContextDocumentPath());
    // 
    // Create the request
    final TableRecordReference recordRef = documentCollection.getTableRecordReference(letter.getContextDocumentPath());
    MADBoilerPlate.createRequest(pdfFile, recordRef.getAD_Table_ID(), recordRef.getRecord_ID(), context);
    return letter.toBuilder().processed(true).temporaryPDFData(pdfData).build();
}
Also used : TableRecordReference(org.adempiere.util.lang.impl.TableRecordReference) BoilerPlateContext(de.metas.letters.model.MADBoilerPlate.BoilerPlateContext) File(java.io.File)

Example 3 with BoilerPlateContext

use of de.metas.letters.model.MADBoilerPlate.BoilerPlateContext 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 4 with BoilerPlateContext

use of de.metas.letters.model.MADBoilerPlate.BoilerPlateContext in project metasfresh-webui-api by metasfresh.

the class LetterRestController method createNewLetter.

@PostMapping
@ApiOperation("Creates a new letter")
public JSONLetter createNewLetter(@RequestBody final JSONLetterRequest request) {
    userSession.assertLoggedIn();
    final DocumentPath contextDocumentPath = JSONDocumentPath.toDocumentPathOrNull(request.getDocumentPath());
    // 
    // Extract context BPartner, Location and Contact
    final BoilerPlateContext context = documentCollection.createBoilerPlateContext(contextDocumentPath);
    final int bpartnerId = context.getC_BPartner_ID(-1);
    final int bpartnerLocationId = context.getC_BPartner_Location_ID(-1);
    final int contactId = context.getAD_User_ID(-1);
    // 
    // Build BPartnerAddress
    final PlainDocumentLocation documentLocation = new PlainDocumentLocation(Env.getCtx(), bpartnerId, bpartnerLocationId, contactId, ITrx.TRXNAME_None);
    Services.get(IDocumentLocationBL.class).setBPartnerAddress(documentLocation);
    final String bpartnerAddress = documentLocation.getBPartnerAddress();
    final WebuiLetter letter = lettersRepo.createNewLetter(WebuiLetter.builder().contextDocumentPath(contextDocumentPath).ownerUserId(userSession.getAD_User_ID()).adOrgId(context.getAD_Org_ID(userSession.getAD_Org_ID())).bpartnerId(bpartnerId).bpartnerLocationId(bpartnerLocationId).bpartnerAddress(bpartnerAddress).bpartnerContactId(contactId));
    return JSONLetter.of(letter);
}
Also used : DocumentPath(de.metas.ui.web.window.datatypes.DocumentPath) JSONDocumentPath(de.metas.ui.web.window.datatypes.json.JSONDocumentPath) BoilerPlateContext(de.metas.letters.model.MADBoilerPlate.BoilerPlateContext) PlainDocumentLocation(de.metas.document.model.impl.PlainDocumentLocation) IDocumentLocationBL(de.metas.document.IDocumentLocationBL) PostMapping(org.springframework.web.bind.annotation.PostMapping) ApiOperation(io.swagger.annotations.ApiOperation)

Example 5 with BoilerPlateContext

use of de.metas.letters.model.MADBoilerPlate.BoilerPlateContext in project metasfresh-webui-api by metasfresh.

the class MailRestController method applyTemplate.

private void applyTemplate(final WebuiEmail email, final WebuiEmailBuilder newEmailBuilder, final LookupValue templateId) {
    final Properties ctx = Env.getCtx();
    final MADBoilerPlate boilerPlate = MADBoilerPlate.get(ctx, templateId.getIdAsInt());
    // 
    // Attributes
    final BoilerPlateContext attributes = documentCollection.createBoilerPlateContext(email.getContextDocumentPath());
    // 
    // Subject
    final String subject = MADBoilerPlate.parseText(ctx, boilerPlate.getSubject(), true, attributes, ITrx.TRXNAME_None);
    newEmailBuilder.subject(subject);
    // Message
    newEmailBuilder.message(boilerPlate.getTextSnippetParsed(attributes));
}
Also used : MADBoilerPlate(de.metas.letters.model.MADBoilerPlate) BoilerPlateContext(de.metas.letters.model.MADBoilerPlate.BoilerPlateContext) Properties(java.util.Properties)

Aggregations

BoilerPlateContext (de.metas.letters.model.MADBoilerPlate.BoilerPlateContext)5 MADBoilerPlate (de.metas.letters.model.MADBoilerPlate)2 DocumentPath (de.metas.ui.web.window.datatypes.DocumentPath)2 JSONDocumentPath (de.metas.ui.web.window.datatypes.json.JSONDocumentPath)2 ApiOperation (io.swagger.annotations.ApiOperation)2 Properties (java.util.Properties)2 PostMapping (org.springframework.web.bind.annotation.PostMapping)2 IDocumentLocationBL (de.metas.document.IDocumentLocationBL)1 PlainDocumentLocation (de.metas.document.model.impl.PlainDocumentLocation)1 LookupValue (de.metas.ui.web.window.datatypes.LookupValue)1 IntegerLookupValue (de.metas.ui.web.window.datatypes.LookupValue.IntegerLookupValue)1 JSONLookupValue (de.metas.ui.web.window.datatypes.json.JSONLookupValue)1 DocumentPrint (de.metas.ui.web.window.model.DocumentCollection.DocumentPrint)1 File (java.io.File)1 IOException (java.io.IOException)1 AdempiereException (org.adempiere.exceptions.AdempiereException)1 FillMandatoryException (org.adempiere.exceptions.FillMandatoryException)1 IUserBL (org.adempiere.user.api.IUserBL)1 TableRecordReference (org.adempiere.util.lang.impl.TableRecordReference)1