Search in sources :

Example 6 with RuleMetadata

use of org.drools.workbench.models.datamodel.rule.RuleMetadata 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 7 with RuleMetadata

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

the class GuidedRuleAttributeSelectorPopup method handleMetadataAddition.

@Override
protected void handleMetadataAddition(final String metadataName) {
    model.addMetadata(new RuleMetadata(metadataName, ""));
    refresh.execute();
}
Also used : RuleMetadata(org.drools.workbench.models.datamodel.rule.RuleMetadata)

Example 8 with RuleMetadata

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

the class GuidedDTDRLPersistenceTest method testMetaData.

@Test
public void testMetaData() {
    GuidedDTDRLPersistence p = new GuidedDTDRLPersistence();
    String[] row = new String[] { "1", "desc", "bar", "" };
    List<BaseColumn> allColumns = new ArrayList<BaseColumn>();
    allColumns.add(new RowNumberCol52());
    allColumns.add(new DescriptionCol52());
    List<MetadataCol52> metadataCols = new ArrayList<MetadataCol52>();
    RuleModel rm = new RuleModel();
    RuleMetadata[] orig = rm.metadataList;
    // RuleAttribute[] orig = rm.attributes;
    p.doMetadata(allColumns, metadataCols, DataUtilities.makeDataRowList(row), rm);
    assertSame(orig, rm.metadataList);
    MetadataCol52 col1 = new MetadataCol52();
    col1.setMetadata("foo");
    MetadataCol52 col2 = new MetadataCol52();
    col2.setMetadata("foo2");
    metadataCols.add(col1);
    metadataCols.add(col2);
    allColumns.addAll(metadataCols);
    p.doMetadata(allColumns, metadataCols, DataUtilities.makeDataRowList(row), rm);
    assertEquals(1, rm.metadataList.length);
    assertEquals("foo", rm.metadataList[0].getAttributeName());
    assertEquals("bar", rm.metadataList[0].getValue());
    row = new String[] { "1", "desc", "bar1", "bar2" };
    p.doMetadata(allColumns, metadataCols, DataUtilities.makeDataRowList(row), rm);
    assertEquals(2, rm.metadataList.length);
    assertEquals("foo", rm.metadataList[0].getAttributeName());
    assertEquals("bar1", rm.metadataList[0].getValue());
    assertEquals("foo2", rm.metadataList[1].getAttributeName());
    assertEquals("bar2", rm.metadataList[1].getValue());
}
Also used : ArrayList(java.util.ArrayList) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) MetadataCol52(org.drools.workbench.models.guided.dtable.shared.model.MetadataCol52) DescriptionCol52(org.drools.workbench.models.guided.dtable.shared.model.DescriptionCol52) BaseColumn(org.drools.workbench.models.guided.dtable.shared.model.BaseColumn) RuleMetadata(org.drools.workbench.models.datamodel.rule.RuleMetadata) RowNumberCol52(org.drools.workbench.models.guided.dtable.shared.model.RowNumberCol52) Test(org.junit.Test)

Example 9 with RuleMetadata

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

the class GuidedRuleAttributeSelectorPopup method createFreezeButton.

private Button createFreezeButton(final String text, final String metadataName) {
    return new Button(text, (ClickEvent event) -> {
        model.addMetadata(new RuleMetadata(metadataName, "true"));
        refresh.execute();
        hide();
    });
}
Also used : Button(org.gwtbootstrap3.client.ui.Button) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) RuleMetadata(org.drools.workbench.models.datamodel.rule.RuleMetadata)

Aggregations

RuleMetadata (org.drools.workbench.models.datamodel.rule.RuleMetadata)9 RuleModel (org.drools.workbench.models.datamodel.rule.RuleModel)5 SingleFieldConstraint (org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)3 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)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 IAction (org.drools.workbench.models.datamodel.rule.IAction)2 IPattern (org.drools.workbench.models.datamodel.rule.IPattern)2 RuleAttribute (org.drools.workbench.models.datamodel.rule.RuleAttribute)2 MetadataCol52 (org.drools.workbench.models.guided.dtable.shared.model.MetadataCol52)2 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)1 AnnotationDescr (org.drools.compiler.lang.descr.AnnotationDescr)1 RuleDescr (org.drools.compiler.lang.descr.RuleDescr)1 ActionCallMethod (org.drools.workbench.models.datamodel.rule.ActionCallMethod)1 ActionFieldFunction (org.drools.workbench.models.datamodel.rule.ActionFieldFunction)1 ActionGlobalCollectionAdd (org.drools.workbench.models.datamodel.rule.ActionGlobalCollectionAdd)1 ActionInsertFact (org.drools.workbench.models.datamodel.rule.ActionInsertFact)1 ActionRetractFact (org.drools.workbench.models.datamodel.rule.ActionRetractFact)1