Search in sources :

Example 1 with LHSGeneratorContextFactory

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

the class RuleModelDRLPersistenceImpl method marshalRule.

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();
    // Build rule
    this.marshalPackageHeader(model, buf);
    this.marshalRuleHeader(model, buf);
    this.marshalMetadata(buf, model);
    this.marshalAttributes(buf, model);
    buf.append("\twhen\n");
    this.marshalLHS(buf, model, isDSLEnhanced, new LHSGeneratorContextFactory());
    buf.append("\tthen\n");
    this.marshalRHS(buf, model, isDSLEnhanced, new RHSGeneratorContextFactory());
    this.marshalFooter(buf);
    return buf.toString();
}
Also used : LHSGeneratorContextFactory(org.drools.workbench.models.commons.backend.rule.context.LHSGeneratorContextFactory) RHSGeneratorContextFactory(org.drools.workbench.models.commons.backend.rule.context.RHSGeneratorContextFactory) IFactPattern(org.drools.workbench.models.datamodel.rule.IFactPattern) FieldConstraint(org.drools.workbench.models.datamodel.rule.FieldConstraint) CompositeFieldConstraint(org.drools.workbench.models.datamodel.rule.CompositeFieldConstraint) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)

Example 2 with LHSGeneratorContextFactory

use of org.drools.workbench.models.commons.backend.rule.context.LHSGeneratorContextFactory 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

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