Search in sources :

Example 1 with ActionBuilderLine

use of com.axelor.studio.db.ActionBuilderLine in project axelor-open-suite by axelor.

the class ActionViewBuilderService method appendParams.

private void appendParams(List<ActionBuilderLine> params, StringBuilder xml) {
    if (params == null) {
        return;
    }
    for (ActionBuilderLine param : params) {
        xml.append("\n" + INDENT + "<view-param name=\"" + param.getName() + "\" ");
        xml.append("value=\"" + StringEscapeUtils.escapeXml(param.getValue()) + "\" />");
    }
}
Also used : ActionBuilderLine(com.axelor.studio.db.ActionBuilderLine)

Example 2 with ActionBuilderLine

use of com.axelor.studio.db.ActionBuilderLine in project axelor-open-suite by axelor.

the class ActionViewBuilderService method appendContext.

private void appendContext(ActionBuilder builder, StringBuilder xml) {
    boolean addJsonCtx = true;
    if (builder.getLines() != null) {
        for (ActionBuilderLine context : builder.getLines()) {
            if (context.getName().contentEquals("jsonModel")) {
                addJsonCtx = false;
            }
            xml.append("\n" + INDENT + "<context name=\"" + context.getName() + "\" ");
            xml.append("expr=\"eval:" + StringEscapeUtils.escapeXml(context.getValue()) + "\" />");
        }
    }
    if (addJsonCtx && builder.getIsJson() && builder.getModel() != null) {
        xml.append("\n" + INDENT + "<context name=\"jsonModel\" ");
        xml.append("expr=\"" + builder.getModel() + "\" />");
    }
}
Also used : ActionBuilderLine(com.axelor.studio.db.ActionBuilderLine)

Example 3 with ActionBuilderLine

use of com.axelor.studio.db.ActionBuilderLine in project axelor-open-suite by axelor.

the class ExportService method exportActionBuilderLines.

@SuppressWarnings("deprecation")
public static String exportActionBuilderLines(List<ActionBuilderLine> lines, int count) {
    String xml = "";
    String indent = "\n" + Strings.repeat("\t", count);
    String indentPlus = "\n" + Strings.repeat("\t", count + 1);
    for (ActionBuilderLine line : lines) {
        String source = "";
        String target = "";
        if (line.getParent() == null) {
            ActionBuilder builder = line.getActionBuilder();
            if (builder != null) {
                target = builder.getTargetModel();
                source = builder.getModel();
                if (builder.getTypeSelect() == ActionBuilderRepository.TYPE_SELECT_UPDATE) {
                    target = builder.getModel();
                }
            }
        } else {
            ActionBuilderLine parent = line.getParent();
            if (parent.getMetaField() != null)
                target = parent.getMetaField().getTypeName();
            if (parent.getMetaJsonField() != null && parent.getMetaJsonField().getTargetModel() != null)
                target = parent.getMetaJsonField().getTargetModel();
            if (parent.getMetaJsonField() != null && parent.getMetaJsonField().getTargetJsonModel() != null)
                target = parent.getMetaJsonField().getTargetJsonModel().getName();
            if (parent.getValueField() != null)
                source = parent.getValueField().getMetaModel().getFullName();
            if (parent.getValueJson() != null && parent.getValueJson().getTargetModel() != null)
                source = parent.getValueJson().getTargetModel();
            if (parent.getValueJson() != null && parent.getValueJson().getTargetJsonModel() != null)
                source = parent.getValueJson().getTargetJsonModel().getName();
        }
        xml += indent + "<line>" + indentPlus + "<target>" + target + "</target>" + indentPlus + "<source>" + source + "</source>" + indentPlus + "<metaJsonField>" + (line.getMetaJsonField() != null ? line.getMetaJsonField().getName() : "") + "</metaJsonField>" + indentPlus + "<metaField>" + (line.getMetaField() != null ? line.getMetaField().getName() : "") + "</metaField>" + indentPlus + "<valueJson>" + (line.getValueJson() != null ? line.getValueJson().getName() : "") + "</valueJson>" + indentPlus + "<valueField>" + (line.getValueField() != null ? line.getValueField().getName() : "") + "</valueField>" + indentPlus + "<value>" + (line.getValue() != null ? line.getValue() : "") + "</value>" + indentPlus + "<conditionText>" + (line.getConditionText() != null ? StringEscapeUtils.escapeXml(StringEscapeUtils.escapeXml(line.getConditionText())) : "") + "</conditionText>" + indentPlus + "<filter>" + (line.getFilter() != null ? line.getFilter() : "") + "</filter>" + indentPlus + "<validationTypeSelect>" + (line.getValidationTypeSelect() != null ? line.getValidationTypeSelect() : "") + "</validationTypeSelect>" + indentPlus + "<validationMsg>" + (line.getValidationMsg() != null ? line.getValidationMsg() : "") + "</validationMsg>" + indentPlus + "<name>" + (line.getName() != null ? line.getName() : "") + "</name>" + indentPlus + "<dummy>" + (line.getDummy() != null ? line.getDummy() : "") + "</dummy>" + indentPlus + "<subLines>" + exportActionBuilderLines(line.getSubLines(), count + 2) + indentPlus + "</subLines>" + indent + "</line>";
    }
    return StringEscapeUtils.unescapeXml(xml);
}
Also used : ActionBuilderLine(com.axelor.studio.db.ActionBuilderLine) ActionBuilder(com.axelor.studio.db.ActionBuilder)

Example 4 with ActionBuilderLine

use of com.axelor.studio.db.ActionBuilderLine in project axelor-open-suite by axelor.

the class MenuBuilderService method createActionBuilder.

@SuppressWarnings("unchecked")
public Optional<ActionBuilder> createActionBuilder(MetaAction metaAction) {
    try {
        ObjectViews objectViews = XMLViews.fromXML(metaAction.getXml());
        List<Action> actions = objectViews.getActions();
        if (actions != null && !actions.isEmpty()) {
            ActionView action = (ActionView) actions.get(0);
            if (action.getModel() != null && action.getModel().contentEquals(MetaJsonRecord.class.getName())) {
                return Optional.empty();
            }
            ActionBuilder actionBuilder = new ActionBuilder(action.getName());
            actionBuilder.setTitle(action.getTitle());
            actionBuilder.setModel(action.getModel());
            actionBuilder.setTypeSelect(ActionBuilderRepository.TYPE_SELECT_VIEW);
            String domain = action.getDomain();
            actionBuilder.setDomainCondition(domain);
            for (ActionView.View view : action.getViews()) {
                ActionBuilderView builderView = new ActionBuilderView();
                builderView.setViewType(view.getType());
                builderView.setViewName(view.getName());
                actionBuilder.addActionBuilderView(builderView);
            }
            if (action.getParams() != null) {
                for (ActionView.Param param : action.getParams()) {
                    ActionBuilderLine paramLine = new ActionBuilderLine();
                    paramLine.setName(param.getName());
                    paramLine.setValue(param.getValue());
                    actionBuilder.addViewParam(paramLine);
                }
            }
            if (action.getContext() != null) {
                for (ActionView.Context ctx : (List<ActionView.Context>) action.getContext()) {
                    ActionBuilderLine ctxLine = new ActionBuilderLine();
                    ctxLine.setName(ctx.getName());
                    if (ctx.getName().contentEquals("jsonModel") && domain != null && domain.contains("self.jsonModel = :jsonModel")) {
                        actionBuilder.setIsJson(true);
                        actionBuilder.setModel(ctx.getExpression());
                    }
                    ctxLine.setValue(ctx.getExpression());
                    actionBuilder.addLine(ctxLine);
                }
            }
            return Optional.of(actionBuilder);
        }
    } catch (JAXBException e) {
        TraceBackService.trace(e);
    }
    return Optional.empty();
}
Also used : MetaAction(com.axelor.meta.db.MetaAction) Action(com.axelor.meta.schema.actions.Action) ActionBuilder(com.axelor.studio.db.ActionBuilder) ActionBuilderLine(com.axelor.studio.db.ActionBuilderLine) JAXBException(javax.xml.bind.JAXBException) ActionView(com.axelor.meta.schema.actions.ActionView) ObjectViews(com.axelor.meta.schema.ObjectViews) ActionBuilderView(com.axelor.studio.db.ActionBuilderView) ArrayList(java.util.ArrayList) List(java.util.List)

Example 5 with ActionBuilderLine

use of com.axelor.studio.db.ActionBuilderLine in project axelor-open-suite by axelor.

the class ActionScriptBuilderService method addFieldsBinding.

private String addFieldsBinding(String target, List<ActionBuilderLine> lines, int level) {
    StringBuilder stb = new StringBuilder();
    lines.sort((l1, l2) -> {
        if (l1.getDummy() && !l2.getDummy()) {
            return -1;
        }
        if (!l1.getDummy() && l2.getDummy()) {
            return 1;
        }
        return 0;
    });
    for (ActionBuilderLine line : lines) {
        String name = line.getName();
        String value = line.getValue();
        if (value != null && value.contains(".sum(")) {
            value = getSum(value, line.getFilter());
        }
        if (line.getDummy()) {
            stb.append(format("_$." + name + " = " + value + ";", level));
            continue;
        }
        MetaJsonField jsonField = line.getMetaJsonField();
        MetaField metaField = line.getMetaField();
        if (jsonField != null && (jsonField.getTargetJsonModel() != null || jsonField.getTargetModel() != null)) {
            value = addRelationalBinding(line, target, true);
        } else if (metaField != null && metaField.getRelationship() != null) {
            value = addRelationalBinding(line, target, false);
        }
        if (value != null && metaField != null && metaField.getTypeName().equals(BigDecimal.class.getSimpleName())) {
            value = "new BigDecimal(" + value + ")";
        }
        String condition = line.getConditionText();
        if (condition != null) {
            stb.append(format("if(" + condition + "){" + target + "." + name + " = " + value + ";}", level));
        } else {
            stb.append(format(target + "." + name + " = " + value + ";", level));
        }
    }
    return stb.toString();
}
Also used : ActionBuilderLine(com.axelor.studio.db.ActionBuilderLine) MetaField(com.axelor.meta.db.MetaField) MetaJsonField(com.axelor.meta.db.MetaJsonField)

Aggregations

ActionBuilderLine (com.axelor.studio.db.ActionBuilderLine)5 ActionBuilder (com.axelor.studio.db.ActionBuilder)2 MetaAction (com.axelor.meta.db.MetaAction)1 MetaField (com.axelor.meta.db.MetaField)1 MetaJsonField (com.axelor.meta.db.MetaJsonField)1 ObjectViews (com.axelor.meta.schema.ObjectViews)1 Action (com.axelor.meta.schema.actions.Action)1 ActionView (com.axelor.meta.schema.actions.ActionView)1 ActionBuilderView (com.axelor.studio.db.ActionBuilderView)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 JAXBException (javax.xml.bind.JAXBException)1