Search in sources :

Example 1 with LHSGeneratorContext

use of org.drools.workbench.models.commons.backend.rule.context.LHSGeneratorContext in project drools by kiegroup.

the class RuleTemplateModelDRLPersistenceImpl method marshalRule.

@Override
protected String marshalRule(final RuleModel model) {
    boolean isDSLEnhanced = model.hasDSLSentences();
    bindingsPatterns = new HashMap<String, IFactPattern>();
    bindingsFields = new HashMap<String, FieldConstraint>();
    fixActionInsertFactBindings(model.rhs);
    StringBuilder buf = new StringBuilder();
    StringBuilder header = new StringBuilder();
    LHSGeneratorContextFactory lhsGeneratorContextFactory = new LHSGeneratorContextFactory();
    RHSGeneratorContextFactory rhsGeneratorContextFactory = new RHSGeneratorContextFactory();
    // Build rule
    this.marshalRuleHeader(model, header);
    super.marshalMetadata(buf, model);
    super.marshalAttributes(buf, model);
    buf.append("\twhen\n");
    super.marshalLHS(buf, model, isDSLEnhanced, lhsGeneratorContextFactory);
    buf.append("\tthen\n");
    super.marshalRHS(buf, model, isDSLEnhanced, rhsGeneratorContextFactory);
    this.marshalFooter(buf);
    for (LHSGeneratorContext gc : lhsGeneratorContextFactory.getGeneratorContexts()) {
        header.append("@code{hasLHSOutput" + gc.getDepth() + "_" + gc.getOffset() + " = false}");
        header.append("@code{hasLHSNonTemplateOutput" + gc.getDepth() + "_" + gc.getOffset() + " = " + gc.hasNonTemplateOutput() + "}");
    }
    for (RHSGeneratorContext gc : rhsGeneratorContextFactory.getGeneratorContexts()) {
        header.append("@code{hasRHSOutput" + gc.getDepth() + "_" + gc.getOffset() + " = false}");
        header.append("@code{hasRHSNonTemplateOutput" + gc.getDepth() + "_" + gc.getOffset() + " = " + gc.hasNonTemplateOutput() + "}");
    }
    header.append("@code{\n" + "  def removeDelimitingQuotes(value) {\n" + "    if(value.startsWith('\"') && value.endsWith('\"')) {\n" + "      return value.substring(1, value.length() - 1);\n" + "    }\n" + "  value;\n" + "  }\n" + "}");
    header.append("@code{\n" + "def capitals(value) {\n" + "  value.toUpperCase();\n" + "}}");
    header.append("@code{\n" + " def makeValueList(value) {\n" + "    if(value.startsWith('\"') && value.endsWith('\"')) {\n" + "      value = value.substring(1, value.length() - 1);\n" + "    }\n" + "	workingValue = value.trim();\n" + "	if ( workingValue.startsWith('(') ) {\n" + "		workingValue = workingValue.substring( 1 );\n" + "	}\n" + "	if ( workingValue.endsWith(')') ) {\n" + "		workingValue = workingValue.substring( 0," + "				workingValue.length() - 1 );\n" + "	}\n" + "	values = workingValue.split( ',' );\n" + "	output = ' (';\n" + "	for (v : values ) {\n" + "		v = v.trim();\n" + "		if ( v.startsWith( '\"' ) ) {\n" + "			v = v.substring( 1 );\n" + "		}\n" + "		if ( v.endsWith( '\"' ) ) {\n" + "   		v = v.substring( 0,v.length() - 1 );\n" + "		}\n" + "		output+='\"'+v+'\", ';\n" + "	}" + "	output=output.substring(0,output.length()-2)+')';\n" + "	output;\n" + "	}\n" + "}");
    return header.append(buf).toString();
}
Also used : LHSGeneratorContextFactory(org.drools.workbench.models.commons.backend.rule.context.LHSGeneratorContextFactory) RHSGeneratorContext(org.drools.workbench.models.commons.backend.rule.context.RHSGeneratorContext) RHSGeneratorContextFactory(org.drools.workbench.models.commons.backend.rule.context.RHSGeneratorContextFactory) LHSGeneratorContext(org.drools.workbench.models.commons.backend.rule.context.LHSGeneratorContext) IFactPattern(org.drools.workbench.models.datamodel.rule.IFactPattern) CompositeFieldConstraint(org.drools.workbench.models.datamodel.rule.CompositeFieldConstraint) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) FieldConstraint(org.drools.workbench.models.datamodel.rule.FieldConstraint) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)

Aggregations

LHSGeneratorContext (org.drools.workbench.models.commons.backend.rule.context.LHSGeneratorContext)1 LHSGeneratorContextFactory (org.drools.workbench.models.commons.backend.rule.context.LHSGeneratorContextFactory)1 RHSGeneratorContext (org.drools.workbench.models.commons.backend.rule.context.RHSGeneratorContext)1 RHSGeneratorContextFactory (org.drools.workbench.models.commons.backend.rule.context.RHSGeneratorContextFactory)1 BaseSingleFieldConstraint (org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)1 CompositeFieldConstraint (org.drools.workbench.models.datamodel.rule.CompositeFieldConstraint)1 FieldConstraint (org.drools.workbench.models.datamodel.rule.FieldConstraint)1 IFactPattern (org.drools.workbench.models.datamodel.rule.IFactPattern)1 SingleFieldConstraint (org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)1