use of org.drools.workbench.models.datamodel.rule.FieldConstraint in project drools by kiegroup.
the class RuleModelUpgradeHelper3 method fixConstraints.
private void fixConstraints(FactPattern fp, SingleFieldConstraint sfc) {
final FieldConstraint parent = sfc.getParent();
if (parent == null) {
sfc.setFactType(fp.getFactType());
} else if (parent instanceof SingleFieldConstraint) {
sfc.setFactType(((SingleFieldConstraint) parent).getFieldType());
}
sfc.setFieldName(fixFieldName(sfc.getFieldName()));
if (sfc.getConnectives() == null) {
return;
}
for (ConnectiveConstraint cc : sfc.getConnectives()) {
cc.setFactType(fp.getFactType());
cc.setFieldName(fixFieldName(cc.getFieldName()));
}
}
use of org.drools.workbench.models.datamodel.rule.FieldConstraint in project drools-wb by kiegroup.
the class RuleModelCloneVisitor method visitCompositeFieldConstraint.
private CompositeFieldConstraint visitCompositeFieldConstraint(CompositeFieldConstraint cfc) {
CompositeFieldConstraint clone = new CompositeFieldConstraint();
clone.setCompositeJunctionType(cfc.getCompositeJunctionType());
if (cfc.getConstraints() != null) {
clone.setConstraints(new FieldConstraint[cfc.getConstraints().length]);
for (int i = 0; i < cfc.getConstraints().length; i++) {
FieldConstraint fc = cfc.getConstraints()[i];
clone.getConstraints()[i] = (FieldConstraint) visit(fc);
}
}
return clone;
}
use of org.drools.workbench.models.datamodel.rule.FieldConstraint in project drools-wb by kiegroup.
the class FactPatternWidget method compositeFieldConstraintEditor.
/**
* This will show the constraint editor - allowing field constraints to be
* nested etc.
*/
private Widget compositeFieldConstraintEditor(final CompositeFieldConstraint constraint) {
FlexTable t = new FlexTable();
String desc = null;
ClickHandler click = new ClickHandler() {
public void onClick(ClickEvent event) {
popupCreator.showPatternPopupForComposite(constraint);
}
};
if (constraint.getCompositeJunctionType().equals(CompositeFieldConstraint.COMPOSITE_TYPE_AND)) {
desc = GuidedRuleEditorResources.CONSTANTS.AllOf() + ":";
} else {
desc = GuidedRuleEditorResources.CONSTANTS.AnyOf() + ":";
}
t.setWidget(0, 0, new ClickableLabel(desc, click, !this.readOnly));
t.getFlexCellFormatter().setColSpan(0, 0, 2);
FieldConstraint[] nested = constraint.getConstraints();
FlexTable inner = new FlexTable();
if (nested != null) {
for (int i = 0; i < nested.length; i++) {
this.renderFieldConstraint(inner, i, nested[i], constraint, true, 0);
// add in remove icon here...
final int currentRow = i;
Image clear = GuidedRuleEditorImages508.INSTANCE.DeleteItemSmall();
clear.setTitle(GuidedRuleEditorResources.CONSTANTS.RemoveThisNestedRestriction());
clear.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
if (Window.confirm(GuidedRuleEditorResources.CONSTANTS.RemoveThisItemFromNestedConstraint())) {
setModified(true);
constraint.removeConstraint(currentRow);
getModeller().refreshWidget();
}
}
});
if (!this.readOnly) {
// This used to be 5 and Connectives were not rendered
inner.setWidget(i, 6, clear);
}
}
}
t.setWidget(1, 1, inner);
t.setWidget(1, 0, new HTML(" "));
return t;
}
use of org.drools.workbench.models.datamodel.rule.FieldConstraint in project drools-wb by kiegroup.
the class GuidedRuleTemplateIndexVisitor method visitCompositeFieldConstraint.
private void visitCompositeFieldConstraint(final CompositeFieldConstraint cfc) {
if (cfc.getConstraints() != null) {
for (int i = 0; i < cfc.getConstraints().length; i++) {
FieldConstraint fc = cfc.getConstraints()[i];
visit(fc);
}
}
}
use of org.drools.workbench.models.datamodel.rule.FieldConstraint 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