Search in sources :

Example 1 with PrintTemplateLine

use of com.axelor.apps.base.db.PrintTemplateLine in project axelor-open-suite by axelor.

the class PrintTemplateServiceImpl method processPrintTemplateLineList.

private void processPrintTemplateLineList(List<PrintTemplateLine> templateLineList, Print print, PrintLine parent, Context scriptContext, TemplateMaker maker, int level) throws AxelorException {
    int seq = 1;
    if (ObjectUtils.notEmpty(templateLineList.get(0)) && ObjectUtils.notEmpty(templateLineList.get(0).getSequence())) {
        seq = templateLineList.get(0).getSequence().intValue();
    }
    for (PrintTemplateLine printTemplateLine : templateLineList) {
        if (printTemplateLine.getIgnoreTheLine()) {
            continue;
        }
        try {
            boolean present = true;
            if (StringUtils.notEmpty(printTemplateLine.getConditions())) {
                Object evaluation = templateContextService.computeTemplateContext(printTemplateLine.getConditions(), scriptContext);
                if (evaluation instanceof Boolean) {
                    present = (Boolean) evaluation;
                } else {
                    throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.PRINT_TEMPLATE_CONDITION_MUST_BE_BOOLEAN));
                }
            }
            if (present) {
                ++rank;
                String title = null;
                String content = null;
                if (StringUtils.notEmpty(printTemplateLine.getTitle())) {
                    maker.setTemplate(printTemplateLine.getTitle());
                    addSequencesInContext(maker, level, seq, parent);
                    title = maker.make();
                }
                if (StringUtils.notEmpty(printTemplateLine.getContent())) {
                    maker.setTemplate(printTemplateLine.getContent());
                    addSequencesInContext(maker, level, seq, parent);
                    if (CollectionUtils.isNotEmpty(printTemplateLine.getTemplateContextList())) {
                        for (TemplateContext templateContext : printTemplateLine.getTemplateContextList()) {
                            Object result = templateContextService.computeTemplateContext(templateContext, scriptContext);
                            maker.addContext(templateContext.getName(), result);
                        }
                    }
                    content = maker.make();
                }
                PrintLine printLine = new PrintLine();
                printLine.setRank(rank);
                printLine.setSequence(seq);
                printLine.setTitle(title);
                printLine.setContent(content);
                printLine.setIsEditable(printTemplateLine.getIsEditable());
                printLine.setIsSignature(printTemplateLine.getIsSignature());
                printLine.setNbColumns(printTemplateLine.getNbColumns());
                printLine.setParent(parent);
                printLine.setIsWithPageBreakAfter(printTemplateLine.getIsWithPageBreakAfter());
                if (CollectionUtils.isNotEmpty(printTemplateLine.getPrintTemplateLineList())) {
                    processPrintTemplateLineList(printTemplateLine.getPrintTemplateLineList(), print, printLine, scriptContext, maker, level + 1);
                }
                print.addPrintLineListItem(printLine);
                seq++;
            }
        } catch (Exception e) {
            throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.PRINT_TEMPLATE_ERROR_ON_LINE_WITH_SEQUENCE_AND_TITLE), printTemplateLine.getSequence(), printTemplateLine.getTitle());
        }
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) PrintLine(com.axelor.apps.base.db.PrintLine) PrintTemplateLine(com.axelor.apps.base.db.PrintTemplateLine) TemplateContext(com.axelor.apps.message.db.TemplateContext) Print(com.axelor.apps.base.db.Print) AxelorException(com.axelor.exception.AxelorException) IOException(java.io.IOException)

Aggregations

Print (com.axelor.apps.base.db.Print)1 PrintLine (com.axelor.apps.base.db.PrintLine)1 PrintTemplateLine (com.axelor.apps.base.db.PrintTemplateLine)1 TemplateContext (com.axelor.apps.message.db.TemplateContext)1 AxelorException (com.axelor.exception.AxelorException)1 IOException (java.io.IOException)1