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());
}
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();
}
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));
}
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);
}
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));
}
Aggregations