Search in sources :

Example 31 with ActionUpdateField

use of org.drools.workbench.models.datamodel.rule.ActionUpdateField in project drools-wb by kiegroup.

the class RuleModelCloneVisitor method visitActionFieldList.

private ActionUpdateField visitActionFieldList(ActionUpdateField auf) {
    ActionUpdateField clone = new ActionUpdateField();
    clone.setVariable(auf.getVariable());
    for (ActionFieldValue afv : auf.getFieldValues()) {
        clone.addFieldValue(cloneActionFieldValue(afv));
    }
    return clone;
}
Also used : ActionUpdateField(org.drools.workbench.models.datamodel.rule.ActionUpdateField) ActionFieldValue(org.drools.workbench.models.datamodel.rule.ActionFieldValue)

Example 32 with ActionUpdateField

use of org.drools.workbench.models.datamodel.rule.ActionUpdateField in project drools-wb by kiegroup.

the class RuleModelCloneVisitorTest method testRuleModelCloning.

@Test
public void testRuleModelCloning() {
    RuleModel model = new RuleModel();
    // --------------------------------------------------------------------------------------------------------------
    // LHS
    // --------------------------------------------------------------------------------------------------------------
    // 
    RuleAttribute attribute = new RuleAttribute("att1_name", "att1_val");
    model.addAttribute(attribute);
    RuleMetadata metadata = new RuleMetadata("meta1_name", "meta1_val");
    model.addMetadata(metadata);
    FactPattern f1 = buildFactPattern();
    FactPattern f2 = new FactPattern();
    f2.setBoundName("$f2");
    f2.setFactType("Fact2");
    f2.addConstraint(buildCompositeFieldConstraint());
    CompositeFactPattern composite = new CompositeFactPattern();
    composite.setType(CompositeFactPattern.COMPOSITE_TYPE_EXISTS);
    composite.addFactPattern(f1);
    composite.addFactPattern(f2);
    model.addLhsItem(composite);
    model.addLhsItem(buildFromAccumulateCompositeFactPattern());
    model.addLhsItem(buildFromCollectCompositeFactPattern());
    model.addLhsItem(buildFromCompositeFactPattern());
    model.addLhsItem(buildFreeFormLine());
    model.addLhsItem(buildDslSentence());
    ActionGlobalCollectionAdd addGlobal = new ActionGlobalCollectionAdd();
    addGlobal.setFactName("MyFact");
    addGlobal.setGlobalName("glist");
    model.addRhsItem(addGlobal);
    // --------------------------------------------------------------------------------------------------------------
    // RHS
    // --------------------------------------------------------------------------------------------------------------
    // 
    ActionInsertFact aif = new ActionInsertFact();
    aif.setBoundName("$f");
    aif.setFactType("FactType");
    aif.addFieldValue(buildActionFieldValue());
    aif.addFieldValue(buildActionFieldValue());
    model.addRhsItem(aif);
    ActionUpdateField auf = new ActionUpdateField();
    auf.setVariable("$var");
    auf.addFieldValue(buildActionFieldValue());
    auf.addFieldValue(buildActionFieldValue());
    model.addRhsItem(auf);
    ActionSetField asf = new ActionSetField();
    asf.setVariable("$var");
    asf.addFieldValue(buildActionFieldValue());
    asf.addFieldValue(buildActionFieldValue());
    model.addRhsItem(asf);
    ActionRetractFact arf = new ActionRetractFact();
    arf.setVariableName("$f");
    model.addRhsItem(arf);
    ActionCallMethod callMethod1 = new ActionCallMethod();
    callMethod1.setVariable("var1");
    callMethod1.setMethodName("testMethod1 ");
    callMethod1.setState(ActionCallMethod.TYPE_DEFINED);
    callMethod1.addFieldValue(new ActionFieldFunction("field1", "value1", "type1"));
    model.addRhsItem(callMethod1);
    ActionCallMethod callMethod2 = new ActionCallMethod();
    callMethod2.setVariable("var2");
    callMethod2.setMethodName("testMethod2 ");
    callMethod2.setState(ActionCallMethod.TYPE_UNDEFINED);
    callMethod2.addFieldValue(new ActionFieldFunction("field2", "value2", "type2"));
    model.addRhsItem(callMethod2);
    model.addRhsItem(buildFreeFormLine());
    // --------------------------------------------------------------------------------------------------------------
    // Clone and verify
    // --------------------------------------------------------------------------------------------------------------
    // 
    RuleModel clone = new RuleModelCloneVisitor().visitRuleModel(model);
    assertArrayEquals(model.attributes, clone.attributes);
    int attIndex = 0;
    for (RuleAttribute att : model.attributes) {
        assertNotSame(att, clone.attributes[attIndex++]);
    }
    assertArrayEquals(model.metadataList, clone.metadataList);
    int metIndex = 0;
    for (RuleMetadata met : model.metadataList) {
        assertNotSame(met, clone.metadataList[metIndex++]);
    }
    assertArrayEquals(model.lhs, clone.lhs);
    int lhsIndex = 0;
    for (IPattern pattern : model.lhs) {
        assertNotSame(pattern, clone.lhs[lhsIndex++]);
    }
    assertArrayEquals(model.rhs, clone.rhs);
    int rhsIndex = 0;
    for (IAction action : model.rhs) {
        assertNotSame(action, clone.rhs[rhsIndex++]);
    }
}
Also used : IPattern(org.drools.workbench.models.datamodel.rule.IPattern) IAction(org.drools.workbench.models.datamodel.rule.IAction) ActionCallMethod(org.drools.workbench.models.datamodel.rule.ActionCallMethod) IFactPattern(org.drools.workbench.models.datamodel.rule.IFactPattern) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) FromAccumulateCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) FromAccumulateCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) ActionFieldFunction(org.drools.workbench.models.datamodel.rule.ActionFieldFunction) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) CompositeFieldConstraint(org.drools.workbench.models.datamodel.rule.CompositeFieldConstraint) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) ActionRetractFact(org.drools.workbench.models.datamodel.rule.ActionRetractFact) ActionUpdateField(org.drools.workbench.models.datamodel.rule.ActionUpdateField) ActionSetField(org.drools.workbench.models.datamodel.rule.ActionSetField) ActionInsertFact(org.drools.workbench.models.datamodel.rule.ActionInsertFact) RuleAttribute(org.drools.workbench.models.datamodel.rule.RuleAttribute) RuleMetadata(org.drools.workbench.models.datamodel.rule.RuleMetadata) ActionGlobalCollectionAdd(org.drools.workbench.models.datamodel.rule.ActionGlobalCollectionAdd) Test(org.junit.Test)

Example 33 with ActionUpdateField

use of org.drools.workbench.models.datamodel.rule.ActionUpdateField in project drools-wb by kiegroup.

the class ActionSetFieldWidget method getSetterLabel.

private Widget getSetterLabel() {
    ClickHandler clk = new ClickHandler() {

        public void onClick(ClickEvent event) {
            // Widget w = (Widget)event.getSource();
            showAddFieldPopup(event);
        }
    };
    String modifyType = "set";
    if (this.model instanceof ActionUpdateField) {
        modifyType = "modify";
    }
    String type = this.getModeller().getModel().getLHSBindingType(model.getVariable());
    String descFact = (type != null) ? type + " <b>[" + model.getVariable() + "]</b>" : model.getVariable();
    String sl = GuidedRuleEditorResources.CONSTANTS.setterLabel(HumanReadable.getActionDisplayName(modifyType), descFact);
    return new ClickableLabel(sl, clk, // HumanReadable.getActionDisplayName(modifyType) + " value of <b>[" + model.variable + "]</b>", clk);
    !this.readOnly);
}
Also used : ActionUpdateField(org.drools.workbench.models.datamodel.rule.ActionUpdateField) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ClickableLabel(org.uberfire.ext.widgets.common.client.common.ClickableLabel)

Example 34 with ActionUpdateField

use of org.drools.workbench.models.datamodel.rule.ActionUpdateField in project drools by kiegroup.

the class RuleTemplateModelDRLPersistenceTest method testUpdateModifyMultipleFieldsWithMultipleSkipped1.

@Test
public void testUpdateModifyMultipleFieldsWithMultipleSkipped1() {
    TemplateModel m = new TemplateModel();
    m.name = "r1";
    FactPattern fp = new FactPattern("Person");
    fp.setBoundName("$p");
    m.addLhsItem(fp);
    ActionUpdateField auf1 = new ActionUpdateField("$p");
    ActionFieldValue afv0 = new ActionFieldValue();
    afv0.setNature(FieldNatureType.TYPE_TEMPLATE);
    afv0.setField("field1");
    afv0.setValue("$f1");
    auf1.addFieldValue(afv0);
    ActionFieldValue afv1 = new ActionFieldValue();
    afv1.setNature(FieldNatureType.TYPE_TEMPLATE);
    afv1.setField("field2");
    afv1.setValue("$f2");
    auf1.addFieldValue(afv1);
    ActionFieldValue afv2 = new ActionFieldValue();
    afv2.setNature(FieldNatureType.TYPE_TEMPLATE);
    afv2.setField("field3");
    afv2.setValue("$f3");
    auf1.addFieldValue(afv2);
    m.addRhsItem(auf1);
    String expected = "rule \"r1_0\"\n" + "dialect \"mvel\"\n" + "when\n" + "  $p : Person()\n" + "then\n" + "  modify( $p ) {\n" + "    setField1(\"v1\"),\n" + "    setField2(\"v2\"),\n" + "    setField3(\"v3\")\n" + "  }\n" + "end";
    m.addRow(new String[] { "v1", "v2", "v3" });
    checkMarshall(expected, m);
}
Also used : ActionUpdateField(org.drools.workbench.models.datamodel.rule.ActionUpdateField) ActionFieldValue(org.drools.workbench.models.datamodel.rule.ActionFieldValue) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) TemplateModel(org.drools.workbench.models.guided.template.shared.TemplateModel) Test(org.junit.Test)

Example 35 with ActionUpdateField

use of org.drools.workbench.models.datamodel.rule.ActionUpdateField in project drools by kiegroup.

the class RuleTemplateModelDRLPersistenceTest method testUpdateModifyMultipleFieldsWithMultipleSkipped2.

@Test
public void testUpdateModifyMultipleFieldsWithMultipleSkipped2() {
    TemplateModel m = new TemplateModel();
    m.name = "r1";
    FactPattern fp = new FactPattern("Person");
    fp.setBoundName("$p");
    m.addLhsItem(fp);
    ActionUpdateField auf1 = new ActionUpdateField("$p");
    ActionFieldValue afv0 = new ActionFieldValue();
    afv0.setNature(FieldNatureType.TYPE_TEMPLATE);
    afv0.setField("field1");
    afv0.setValue("$f1");
    auf1.addFieldValue(afv0);
    ActionFieldValue afv1 = new ActionFieldValue();
    afv1.setNature(FieldNatureType.TYPE_TEMPLATE);
    afv1.setField("field2");
    afv1.setValue("$f2");
    auf1.addFieldValue(afv1);
    ActionFieldValue afv2 = new ActionFieldValue();
    afv2.setNature(FieldNatureType.TYPE_TEMPLATE);
    afv2.setField("field3");
    afv2.setValue("$f3");
    auf1.addFieldValue(afv2);
    m.addRhsItem(auf1);
    String expected = "rule \"r1_0\"\n" + "dialect \"mvel\"\n" + "when\n" + "  $p : Person()\n" + "then\n" + "  modify( $p ) {\n" + "    setField2(\"v2\"),\n" + "    setField3(\"v3\")\n" + "  }\n" + "end";
    m.addRow(new String[] { null, "v2", "v3" });
    checkMarshall(expected, m);
}
Also used : ActionUpdateField(org.drools.workbench.models.datamodel.rule.ActionUpdateField) ActionFieldValue(org.drools.workbench.models.datamodel.rule.ActionFieldValue) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) TemplateModel(org.drools.workbench.models.guided.template.shared.TemplateModel) Test(org.junit.Test)

Aggregations

ActionUpdateField (org.drools.workbench.models.datamodel.rule.ActionUpdateField)58 ActionFieldValue (org.drools.workbench.models.datamodel.rule.ActionFieldValue)53 Test (org.junit.Test)47 CompositeFactPattern (org.drools.workbench.models.datamodel.rule.CompositeFactPattern)37 FactPattern (org.drools.workbench.models.datamodel.rule.FactPattern)37 FromCollectCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern)36 RuleModel (org.drools.workbench.models.datamodel.rule.RuleModel)27 FromAccumulateCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern)22 FromCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern)22 IPattern (org.drools.workbench.models.datamodel.rule.IPattern)16 TemplateModel (org.drools.workbench.models.guided.template.shared.TemplateModel)16 BaseSingleFieldConstraint (org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)11 SingleFieldConstraint (org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)11 ActionSetField (org.drools.workbench.models.datamodel.rule.ActionSetField)10 IAction (org.drools.workbench.models.datamodel.rule.IAction)8 BRLActionColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn)8 BRLActionVariableColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLActionVariableColumn)8 GuidedDecisionTable52 (org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52)8 Pattern52 (org.drools.workbench.models.guided.dtable.shared.model.Pattern52)7 ActionInsertFact (org.drools.workbench.models.datamodel.rule.ActionInsertFact)6