use of org.drools.workbench.models.commons.backend.rule.context.RHSGeneratorContext 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();
}
Aggregations