Search in sources :

Example 6 with FieldConstraint

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()));
    }
}
Also used : SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) ConnectiveConstraint(org.drools.workbench.models.datamodel.rule.ConnectiveConstraint) CompositeFieldConstraint(org.drools.workbench.models.datamodel.rule.CompositeFieldConstraint) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) FieldConstraint(org.drools.workbench.models.datamodel.rule.FieldConstraint)

Example 7 with FieldConstraint

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;
}
Also used : ConnectiveConstraint(org.drools.workbench.models.datamodel.rule.ConnectiveConstraint) CompositeFieldConstraint(org.drools.workbench.models.datamodel.rule.CompositeFieldConstraint) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) FieldConstraint(org.drools.workbench.models.datamodel.rule.FieldConstraint) CompositeFieldConstraint(org.drools.workbench.models.datamodel.rule.CompositeFieldConstraint) CompositeFieldConstraint(org.drools.workbench.models.datamodel.rule.CompositeFieldConstraint) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) FieldConstraint(org.drools.workbench.models.datamodel.rule.FieldConstraint)

Example 8 with FieldConstraint

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("&nbsp;&nbsp;&nbsp;&nbsp;"));
    return t;
}
Also used : ClickHandler(com.google.gwt.event.dom.client.ClickHandler) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) FlexTable(com.google.gwt.user.client.ui.FlexTable) ClickableLabel(org.uberfire.ext.widgets.common.client.common.ClickableLabel) HTML(com.google.gwt.user.client.ui.HTML) Image(com.google.gwt.user.client.ui.Image) CompositeFieldConstraint(org.drools.workbench.models.datamodel.rule.CompositeFieldConstraint) FieldConstraint(org.drools.workbench.models.datamodel.rule.FieldConstraint) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) CompositeFieldConstraint(org.drools.workbench.models.datamodel.rule.CompositeFieldConstraint) FieldConstraint(org.drools.workbench.models.datamodel.rule.FieldConstraint) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)

Example 9 with FieldConstraint

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);
        }
    }
}
Also used : ConnectiveConstraint(org.drools.workbench.models.datamodel.rule.ConnectiveConstraint) CompositeFieldConstraint(org.drools.workbench.models.datamodel.rule.CompositeFieldConstraint) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) FieldConstraint(org.drools.workbench.models.datamodel.rule.FieldConstraint) CompositeFieldConstraint(org.drools.workbench.models.datamodel.rule.CompositeFieldConstraint) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) FieldConstraint(org.drools.workbench.models.datamodel.rule.FieldConstraint)

Example 10 with FieldConstraint

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();
}
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

FieldConstraint (org.drools.workbench.models.datamodel.rule.FieldConstraint)23 SingleFieldConstraint (org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)23 CompositeFieldConstraint (org.drools.workbench.models.datamodel.rule.CompositeFieldConstraint)18 BaseSingleFieldConstraint (org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)10 FactPattern (org.drools.workbench.models.datamodel.rule.FactPattern)7 ConnectiveConstraint (org.drools.workbench.models.datamodel.rule.ConnectiveConstraint)5 ArrayList (java.util.ArrayList)4 Test (org.junit.Test)4 CompositeFactPattern (org.drools.workbench.models.datamodel.rule.CompositeFactPattern)3 FromAccumulateCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern)3 FromCollectCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern)3 FromCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern)3 IFactPattern (org.drools.workbench.models.datamodel.rule.IFactPattern)3 ConditionCol52 (org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52)3 FlexTable (com.google.gwt.user.client.ui.FlexTable)2 Image (com.google.gwt.user.client.ui.Image)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 LHSGeneratorContextFactory (org.drools.workbench.models.commons.backend.rule.context.LHSGeneratorContextFactory)2 RHSGeneratorContextFactory (org.drools.workbench.models.commons.backend.rule.context.RHSGeneratorContextFactory)2