Search in sources :

Example 11 with PortableBooleanParameterDefinition

use of org.drools.workbench.models.datamodel.workitems.PortableBooleanParameterDefinition in project drools by kiegroup.

the class RuleModelDRLPersistenceTest method testRHSActionWorkItemInsertFacts.

@Test
public // Test that WorkItem Parameters can be used to set fields on new Fact
void testRHSActionWorkItemInsertFacts() {
    RuleModel m = new RuleModel();
    m.name = "WorkItem";
    ActionExecuteWorkItem awi = new ActionExecuteWorkItem();
    PortableWorkDefinition pwd = new PortableWorkDefinition();
    pwd.setName("WorkItem");
    awi.setWorkDefinition(pwd);
    PortableBooleanParameterDefinition p1 = new PortableBooleanParameterDefinition();
    p1.setName("BooleanResult");
    pwd.addResult(p1);
    PortableFloatParameterDefinition p2 = new PortableFloatParameterDefinition();
    p2.setName("FloatResult");
    pwd.addResult(p2);
    PortableIntegerParameterDefinition p3 = new PortableIntegerParameterDefinition();
    p3.setName("IntegerResult");
    pwd.addResult(p3);
    PortableStringParameterDefinition p4 = new PortableStringParameterDefinition();
    p4.setName("StringResult");
    pwd.addResult(p4);
    m.addRhsItem(awi);
    ActionInsertFact aif = new ActionInsertFact();
    aif.setBoundName("$r");
    aif.setFactType("Results");
    ActionWorkItemFieldValue fv1 = new ActionWorkItemFieldValue("ResultsBooleanResult", DataType.TYPE_BOOLEAN, "WorkItem", "BooleanResult", Boolean.class.getName());
    aif.addFieldValue(fv1);
    ActionWorkItemFieldValue fv2 = new ActionWorkItemFieldValue("ResultsFloatResult", DataType.TYPE_NUMERIC_FLOAT, "WorkItem", "FloatResult", Float.class.getName());
    aif.addFieldValue(fv2);
    ActionWorkItemFieldValue fv3 = new ActionWorkItemFieldValue("ResultsIntegerResult", DataType.TYPE_NUMERIC_INTEGER, "WorkItem", "IntegerResult", Integer.class.getName());
    aif.addFieldValue(fv3);
    ActionWorkItemFieldValue fv4 = new ActionWorkItemFieldValue("ResultsStringResult", DataType.TYPE_STRING, "WorkItem", "StringResult", String.class.getName());
    aif.addFieldValue(fv4);
    m.addRhsItem(aif);
    String result = RuleModelDRLPersistenceImpl.getInstance().marshal(m);
    assertTrue(result.indexOf("org.drools.core.process.instance.WorkItemManager wim = (org.drools.core.process.instance.WorkItemManager) drools.getWorkingMemory().getWorkItemManager();") != -1);
    assertTrue(result.indexOf("org.drools.core.process.instance.impl.WorkItemImpl wiWorkItem = new org.drools.core.process.instance.impl.WorkItemImpl();") != -1);
    assertTrue(result.indexOf("Results $r = new Results();") != -1);
    assertTrue(result.indexOf("$r.setResultsBooleanResult( (java.lang.Boolean) wiWorkItem.getResult( \"BooleanResult\" ) );") != -1);
    assertTrue(result.indexOf("$r.setResultsFloatResult( (java.lang.Float) wiWorkItem.getResult( \"FloatResult\" ) );") != -1);
    assertTrue(result.indexOf("$r.setResultsIntegerResult( (java.lang.Integer) wiWorkItem.getResult( \"IntegerResult\" ) );") != -1);
    assertTrue(result.indexOf("$r.setResultsStringResult( (java.lang.String) wiWorkItem.getResult( \"StringResult\" ) );") != -1);
    assertTrue(result.indexOf("insert( $r );") != -1);
    checkMarshalling(null, m);
}
Also used : PortableIntegerParameterDefinition(org.drools.workbench.models.datamodel.workitems.PortableIntegerParameterDefinition) ActionWorkItemFieldValue(org.drools.workbench.models.datamodel.rule.ActionWorkItemFieldValue) PortableFloatParameterDefinition(org.drools.workbench.models.datamodel.workitems.PortableFloatParameterDefinition) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) PortableStringParameterDefinition(org.drools.workbench.models.datamodel.workitems.PortableStringParameterDefinition) ActionInsertFact(org.drools.workbench.models.datamodel.rule.ActionInsertFact) PortableWorkDefinition(org.drools.workbench.models.datamodel.workitems.PortableWorkDefinition) PortableBooleanParameterDefinition(org.drools.workbench.models.datamodel.workitems.PortableBooleanParameterDefinition) ActionExecuteWorkItem(org.drools.workbench.models.datamodel.rule.ActionExecuteWorkItem) Test(org.junit.Test)

Example 12 with PortableBooleanParameterDefinition

use of org.drools.workbench.models.datamodel.workitems.PortableBooleanParameterDefinition in project drools by kiegroup.

the class GuidedDTDRLPersistenceTest method testRHSActionWorkItemInsertFacts1.

@Test
public // Test all Actions inserting Facts are correctly converted to RuleModel
void testRHSActionWorkItemInsertFacts1() {
    GuidedDTDRLPersistence p = new GuidedDTDRLPersistence();
    String[] row = new String[] { "1", "desc", "true", "true", "true", "true", "true" };
    List<BaseColumn> allColumns = new ArrayList<BaseColumn>();
    allColumns.add(new RowNumberCol52());
    allColumns.add(new DescriptionCol52());
    List<ActionCol52> cols = new ArrayList<ActionCol52>();
    ActionWorkItemCol52 awi = new ActionWorkItemCol52();
    PortableWorkDefinition pwd = new PortableWorkDefinition();
    pwd.setName("WorkItem");
    awi.setWorkItemDefinition(pwd);
    PortableBooleanParameterDefinition p1 = new PortableBooleanParameterDefinition();
    p1.setName("BooleanResult");
    pwd.addResult(p1);
    PortableFloatParameterDefinition p2 = new PortableFloatParameterDefinition();
    p2.setName("FloatResult");
    pwd.addResult(p2);
    PortableIntegerParameterDefinition p3 = new PortableIntegerParameterDefinition();
    p3.setName("IntegerResult");
    pwd.addResult(p3);
    PortableStringParameterDefinition p4 = new PortableStringParameterDefinition();
    p4.setName("StringResult");
    pwd.addResult(p4);
    cols.add(awi);
    ActionWorkItemInsertFactCol52 asf1 = new ActionWorkItemInsertFactCol52();
    asf1.setBoundName("$r");
    asf1.setFactField("ResultBooleanField");
    asf1.setType(DataType.TYPE_BOOLEAN);
    asf1.setWorkItemName("WorkItem");
    asf1.setWorkItemResultParameterName("BooleanResult");
    asf1.setParameterClassName(Boolean.class.getName());
    cols.add(asf1);
    ActionWorkItemInsertFactCol52 asf2 = new ActionWorkItemInsertFactCol52();
    asf2.setBoundName("$r");
    asf2.setFactField("ResultFloatField");
    asf2.setType(DataType.TYPE_NUMERIC_FLOAT);
    asf2.setWorkItemName("WorkItem");
    asf2.setWorkItemResultParameterName("FloatResult");
    asf2.setParameterClassName(Float.class.getName());
    cols.add(asf2);
    ActionWorkItemInsertFactCol52 asf3 = new ActionWorkItemInsertFactCol52();
    asf3.setBoundName("$r");
    asf3.setFactField("ResultIntegerField");
    asf3.setType(DataType.TYPE_NUMERIC_INTEGER);
    asf3.setWorkItemName("WorkItem");
    asf3.setWorkItemResultParameterName("IntegerResult");
    asf3.setParameterClassName(Integer.class.getName());
    cols.add(asf3);
    ActionWorkItemInsertFactCol52 asf4 = new ActionWorkItemInsertFactCol52();
    asf4.setBoundName("$r");
    asf4.setFactField("ResultStringField");
    asf4.setType(DataType.TYPE_STRING);
    asf4.setWorkItemName("WorkItem");
    asf4.setWorkItemResultParameterName("StringResult");
    asf4.setParameterClassName(String.class.getName());
    cols.add(asf4);
    RuleModel rm = new RuleModel();
    allColumns.addAll(cols);
    List<DTCellValue52> rowData = DataUtilities.makeDataRowList(row);
    TemplateDataProvider rowDataProvider = new GuidedDTTemplateDataProvider(allColumns, rowData);
    p.doActions(allColumns, cols, rowDataProvider, rowData, rm);
    assertEquals(2, rm.rhs.length);
    // Examine RuleModel actions
    ActionExecuteWorkItem aw = (ActionExecuteWorkItem) rm.rhs[0];
    assertNotNull(aw);
    ActionInsertFact aif = (ActionInsertFact) rm.rhs[1];
    assertNotNull(aif);
    // Check ActionExecuteWorkItem
    PortableWorkDefinition mpwd = aw.getWorkDefinition();
    assertNotNull(mpwd);
    assertEquals(4, mpwd.getResults().size());
    PortableBooleanParameterDefinition mp1 = (PortableBooleanParameterDefinition) mpwd.getResult("BooleanResult");
    assertNotNull(mp1);
    PortableFloatParameterDefinition mp2 = (PortableFloatParameterDefinition) mpwd.getResult("FloatResult");
    assertNotNull(mp2);
    PortableIntegerParameterDefinition mp3 = (PortableIntegerParameterDefinition) mpwd.getResult("IntegerResult");
    assertNotNull(mp3);
    PortableStringParameterDefinition mp4 = (PortableStringParameterDefinition) mpwd.getResult("StringResult");
    assertNotNull(mp4);
    // Check ActionInsertFact
    assertEquals(aif.getBoundName(), "$r");
    assertEquals(4, aif.getFieldValues().length);
    ActionFieldValue fv1 = aif.getFieldValues()[0];
    assertNotNull(fv1);
    assertTrue(fv1 instanceof ActionWorkItemFieldValue);
    ActionWorkItemFieldValue wifv1 = (ActionWorkItemFieldValue) fv1;
    assertEquals("ResultBooleanField", wifv1.getField());
    assertEquals(DataType.TYPE_BOOLEAN, wifv1.getType());
    assertEquals("WorkItem", wifv1.getWorkItemName());
    assertEquals("BooleanResult", wifv1.getWorkItemParameterName());
    assertEquals(Boolean.class.getName(), wifv1.getWorkItemParameterClassName());
    ActionFieldValue fv2 = aif.getFieldValues()[1];
    assertNotNull(fv2);
    assertTrue(fv2 instanceof ActionWorkItemFieldValue);
    ActionWorkItemFieldValue wifv2 = (ActionWorkItemFieldValue) fv2;
    assertEquals("ResultFloatField", wifv2.getField());
    assertEquals(DataType.TYPE_NUMERIC_FLOAT, wifv2.getType());
    assertEquals("WorkItem", wifv2.getWorkItemName());
    assertEquals("FloatResult", wifv2.getWorkItemParameterName());
    assertEquals(Float.class.getName(), wifv2.getWorkItemParameterClassName());
    ActionFieldValue fv3 = aif.getFieldValues()[2];
    assertNotNull(fv3);
    assertTrue(fv3 instanceof ActionWorkItemFieldValue);
    ActionWorkItemFieldValue wifv3 = (ActionWorkItemFieldValue) fv3;
    assertEquals("ResultIntegerField", wifv3.getField());
    assertEquals(DataType.TYPE_NUMERIC_INTEGER, wifv3.getType());
    assertEquals("WorkItem", wifv3.getWorkItemName());
    assertEquals("IntegerResult", wifv3.getWorkItemParameterName());
    assertEquals(Integer.class.getName(), wifv3.getWorkItemParameterClassName());
    ActionFieldValue fv4 = aif.getFieldValues()[3];
    assertNotNull(fv4);
    assertTrue(fv4 instanceof ActionWorkItemFieldValue);
    ActionWorkItemFieldValue wifv4 = (ActionWorkItemFieldValue) fv4;
    assertEquals("ResultStringField", wifv4.getField());
    assertEquals(DataType.TYPE_STRING, wifv4.getType());
    assertEquals("WorkItem", wifv4.getWorkItemName());
    assertEquals("StringResult", wifv4.getWorkItemParameterName());
    assertEquals(String.class.getName(), wifv4.getWorkItemParameterClassName());
}
Also used : PortableIntegerParameterDefinition(org.drools.workbench.models.datamodel.workitems.PortableIntegerParameterDefinition) ActionWorkItemFieldValue(org.drools.workbench.models.datamodel.rule.ActionWorkItemFieldValue) PortableFloatParameterDefinition(org.drools.workbench.models.datamodel.workitems.PortableFloatParameterDefinition) ActionWorkItemCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionWorkItemCol52) ArrayList(java.util.ArrayList) DTCellValue52(org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52) DescriptionCol52(org.drools.workbench.models.guided.dtable.shared.model.DescriptionCol52) ActionFieldValue(org.drools.workbench.models.datamodel.rule.ActionFieldValue) PortableWorkDefinition(org.drools.workbench.models.datamodel.workitems.PortableWorkDefinition) BaseColumn(org.drools.workbench.models.guided.dtable.shared.model.BaseColumn) PortableBooleanParameterDefinition(org.drools.workbench.models.datamodel.workitems.PortableBooleanParameterDefinition) ActionExecuteWorkItem(org.drools.workbench.models.datamodel.rule.ActionExecuteWorkItem) GuidedDTTemplateDataProvider(org.drools.workbench.models.guided.dtable.backend.util.GuidedDTTemplateDataProvider) TemplateDataProvider(org.drools.workbench.models.guided.dtable.backend.util.TemplateDataProvider) ActionWorkItemInsertFactCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionWorkItemInsertFactCol52) ActionCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionCol52) GuidedDTTemplateDataProvider(org.drools.workbench.models.guided.dtable.backend.util.GuidedDTTemplateDataProvider) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) PortableStringParameterDefinition(org.drools.workbench.models.datamodel.workitems.PortableStringParameterDefinition) ActionInsertFact(org.drools.workbench.models.datamodel.rule.ActionInsertFact) RowNumberCol52(org.drools.workbench.models.guided.dtable.shared.model.RowNumberCol52) Test(org.junit.Test)

Example 13 with PortableBooleanParameterDefinition

use of org.drools.workbench.models.datamodel.workitems.PortableBooleanParameterDefinition in project drools by kiegroup.

the class GuidedDTDRLPersistenceTest method testRHSActionWorkItemInsertFacts2.

@Test
public // Test only Actions set to "true" are correctly converted to RuleModel
void testRHSActionWorkItemInsertFacts2() {
    GuidedDTDRLPersistence p = new GuidedDTDRLPersistence();
    String[] row = new String[] { "1", "desc", "true", "true", "false" };
    List<BaseColumn> allColumns = new ArrayList<BaseColumn>();
    allColumns.add(new RowNumberCol52());
    allColumns.add(new DescriptionCol52());
    List<ActionCol52> cols = new ArrayList<ActionCol52>();
    ActionWorkItemCol52 awi = new ActionWorkItemCol52();
    PortableWorkDefinition pwd = new PortableWorkDefinition();
    pwd.setName("WorkItem");
    awi.setWorkItemDefinition(pwd);
    PortableBooleanParameterDefinition p1 = new PortableBooleanParameterDefinition();
    p1.setName("BooleanResult");
    pwd.addResult(p1);
    PortableFloatParameterDefinition p2 = new PortableFloatParameterDefinition();
    p2.setName("FloatResult");
    pwd.addResult(p2);
    cols.add(awi);
    ActionWorkItemInsertFactCol52 asf1 = new ActionWorkItemInsertFactCol52();
    asf1.setBoundName("$r");
    asf1.setFactField("ResultBooleanField");
    asf1.setType(DataType.TYPE_BOOLEAN);
    asf1.setWorkItemName("WorkItem");
    asf1.setWorkItemResultParameterName("BooleanResult");
    asf1.setParameterClassName(Boolean.class.getName());
    cols.add(asf1);
    ActionWorkItemInsertFactCol52 asf2 = new ActionWorkItemInsertFactCol52();
    asf2.setBoundName("$r");
    asf2.setFactField("ResultFloatField");
    asf2.setType(DataType.TYPE_NUMERIC_FLOAT);
    asf2.setWorkItemName("WorkItem");
    asf2.setWorkItemResultParameterName("FloatResult");
    asf2.setParameterClassName(Float.class.getName());
    cols.add(asf2);
    RuleModel rm = new RuleModel();
    allColumns.addAll(cols);
    List<DTCellValue52> rowData = DataUtilities.makeDataRowList(row);
    TemplateDataProvider rowDataProvider = new GuidedDTTemplateDataProvider(allColumns, rowData);
    p.doActions(allColumns, cols, rowDataProvider, rowData, rm);
    assertEquals(2, rm.rhs.length);
    // Examine RuleModel actions
    ActionExecuteWorkItem aw = (ActionExecuteWorkItem) rm.rhs[0];
    assertNotNull(aw);
    ActionInsertFact aif = (ActionInsertFact) rm.rhs[1];
    assertNotNull(aif);
    // Check ActionExecuteWorkItem
    PortableWorkDefinition mpwd = aw.getWorkDefinition();
    assertNotNull(mpwd);
    assertEquals(2, mpwd.getResults().size());
    PortableBooleanParameterDefinition mp1 = (PortableBooleanParameterDefinition) mpwd.getResult("BooleanResult");
    assertNotNull(mp1);
    PortableFloatParameterDefinition mp2 = (PortableFloatParameterDefinition) mpwd.getResult("FloatResult");
    assertNotNull(mp2);
    // Check ActionInsertFact
    assertEquals(aif.getBoundName(), "$r");
    assertEquals(1, aif.getFieldValues().length);
    ActionFieldValue fv1 = aif.getFieldValues()[0];
    assertNotNull(fv1);
    assertTrue(fv1 instanceof ActionWorkItemFieldValue);
    ActionWorkItemFieldValue wifv1 = (ActionWorkItemFieldValue) fv1;
    assertEquals("ResultBooleanField", wifv1.getField());
    assertEquals(DataType.TYPE_BOOLEAN, wifv1.getType());
    assertEquals("WorkItem", wifv1.getWorkItemName());
    assertEquals("BooleanResult", wifv1.getWorkItemParameterName());
    assertEquals(Boolean.class.getName(), wifv1.getWorkItemParameterClassName());
}
Also used : ActionWorkItemFieldValue(org.drools.workbench.models.datamodel.rule.ActionWorkItemFieldValue) PortableFloatParameterDefinition(org.drools.workbench.models.datamodel.workitems.PortableFloatParameterDefinition) ActionWorkItemCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionWorkItemCol52) ArrayList(java.util.ArrayList) DTCellValue52(org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52) DescriptionCol52(org.drools.workbench.models.guided.dtable.shared.model.DescriptionCol52) ActionFieldValue(org.drools.workbench.models.datamodel.rule.ActionFieldValue) PortableWorkDefinition(org.drools.workbench.models.datamodel.workitems.PortableWorkDefinition) BaseColumn(org.drools.workbench.models.guided.dtable.shared.model.BaseColumn) PortableBooleanParameterDefinition(org.drools.workbench.models.datamodel.workitems.PortableBooleanParameterDefinition) ActionExecuteWorkItem(org.drools.workbench.models.datamodel.rule.ActionExecuteWorkItem) GuidedDTTemplateDataProvider(org.drools.workbench.models.guided.dtable.backend.util.GuidedDTTemplateDataProvider) TemplateDataProvider(org.drools.workbench.models.guided.dtable.backend.util.TemplateDataProvider) ActionWorkItemInsertFactCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionWorkItemInsertFactCol52) ActionCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionCol52) GuidedDTTemplateDataProvider(org.drools.workbench.models.guided.dtable.backend.util.GuidedDTTemplateDataProvider) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) ActionInsertFact(org.drools.workbench.models.datamodel.rule.ActionInsertFact) RowNumberCol52(org.drools.workbench.models.guided.dtable.shared.model.RowNumberCol52) Test(org.junit.Test)

Example 14 with PortableBooleanParameterDefinition

use of org.drools.workbench.models.datamodel.workitems.PortableBooleanParameterDefinition in project drools by kiegroup.

the class GuidedDTDRLPersistenceTest method testRHSActionWorkItemSetFields1.

@Test
public // Test all Actions setting fields are correctly converted to RuleModel
void testRHSActionWorkItemSetFields1() {
    GuidedDTDRLPersistence p = new GuidedDTDRLPersistence();
    String[] row = new String[] { "1", "desc", "true", "true", "true", "true", "true" };
    List<BaseColumn> allColumns = new ArrayList<BaseColumn>();
    allColumns.add(new RowNumberCol52());
    allColumns.add(new DescriptionCol52());
    List<ActionCol52> cols = new ArrayList<ActionCol52>();
    ActionWorkItemCol52 awi = new ActionWorkItemCol52();
    PortableWorkDefinition pwd = new PortableWorkDefinition();
    pwd.setName("WorkItem");
    awi.setWorkItemDefinition(pwd);
    PortableBooleanParameterDefinition p1 = new PortableBooleanParameterDefinition();
    p1.setName("BooleanResult");
    pwd.addResult(p1);
    PortableFloatParameterDefinition p2 = new PortableFloatParameterDefinition();
    p2.setName("FloatResult");
    pwd.addResult(p2);
    PortableIntegerParameterDefinition p3 = new PortableIntegerParameterDefinition();
    p3.setName("IntegerResult");
    pwd.addResult(p3);
    PortableStringParameterDefinition p4 = new PortableStringParameterDefinition();
    p4.setName("StringResult");
    pwd.addResult(p4);
    cols.add(awi);
    ActionWorkItemSetFieldCol52 asf1 = new ActionWorkItemSetFieldCol52();
    asf1.setBoundName("$r");
    asf1.setFactField("ResultBooleanField");
    asf1.setType(DataType.TYPE_BOOLEAN);
    asf1.setWorkItemName("WorkItem");
    asf1.setWorkItemResultParameterName("BooleanResult");
    asf1.setParameterClassName(Boolean.class.getName());
    cols.add(asf1);
    ActionWorkItemSetFieldCol52 asf2 = new ActionWorkItemSetFieldCol52();
    asf2.setBoundName("$r");
    asf2.setFactField("ResultFloatField");
    asf2.setType(DataType.TYPE_NUMERIC_FLOAT);
    asf2.setWorkItemName("WorkItem");
    asf2.setWorkItemResultParameterName("FloatResult");
    asf2.setParameterClassName(Float.class.getName());
    cols.add(asf2);
    ActionWorkItemSetFieldCol52 asf3 = new ActionWorkItemSetFieldCol52();
    asf3.setBoundName("$r");
    asf3.setFactField("ResultIntegerField");
    asf3.setType(DataType.TYPE_NUMERIC_INTEGER);
    asf3.setWorkItemName("WorkItem");
    asf3.setWorkItemResultParameterName("IntegerResult");
    asf3.setParameterClassName(Integer.class.getName());
    cols.add(asf3);
    ActionWorkItemSetFieldCol52 asf4 = new ActionWorkItemSetFieldCol52();
    asf4.setBoundName("$r");
    asf4.setFactField("ResultStringField");
    asf4.setType(DataType.TYPE_STRING);
    asf4.setWorkItemName("WorkItem");
    asf4.setWorkItemResultParameterName("StringResult");
    asf4.setParameterClassName(String.class.getName());
    cols.add(asf4);
    RuleModel rm = new RuleModel();
    allColumns.addAll(cols);
    List<DTCellValue52> rowData = DataUtilities.makeDataRowList(row);
    TemplateDataProvider rowDataProvider = new GuidedDTTemplateDataProvider(allColumns, rowData);
    p.doActions(allColumns, cols, rowDataProvider, rowData, rm);
    assertEquals(2, rm.rhs.length);
    // Examine RuleModel actions
    ActionExecuteWorkItem aw = (ActionExecuteWorkItem) rm.rhs[0];
    assertNotNull(aw);
    ActionSetField asf = (ActionSetField) rm.rhs[1];
    assertNotNull(asf);
    // Check ActionExecuteWorkItem
    PortableWorkDefinition mpwd = aw.getWorkDefinition();
    assertNotNull(mpwd);
    assertEquals(4, mpwd.getResults().size());
    PortableBooleanParameterDefinition mp1 = (PortableBooleanParameterDefinition) mpwd.getResult("BooleanResult");
    assertNotNull(mp1);
    PortableFloatParameterDefinition mp2 = (PortableFloatParameterDefinition) mpwd.getResult("FloatResult");
    assertNotNull(mp2);
    PortableIntegerParameterDefinition mp3 = (PortableIntegerParameterDefinition) mpwd.getResult("IntegerResult");
    assertNotNull(mp3);
    PortableStringParameterDefinition mp4 = (PortableStringParameterDefinition) mpwd.getResult("StringResult");
    assertNotNull(mp4);
    // Check ActionSetField
    assertEquals(asf.getVariable(), "$r");
    assertEquals(4, asf.getFieldValues().length);
    ActionFieldValue fv1 = asf.getFieldValues()[0];
    assertNotNull(fv1);
    assertTrue(fv1 instanceof ActionWorkItemFieldValue);
    ActionWorkItemFieldValue wifv1 = (ActionWorkItemFieldValue) fv1;
    assertEquals("ResultBooleanField", wifv1.getField());
    assertEquals(DataType.TYPE_BOOLEAN, wifv1.getType());
    assertEquals("WorkItem", wifv1.getWorkItemName());
    assertEquals("BooleanResult", wifv1.getWorkItemParameterName());
    assertEquals(Boolean.class.getName(), wifv1.getWorkItemParameterClassName());
    ActionFieldValue fv2 = asf.getFieldValues()[1];
    assertNotNull(fv2);
    assertTrue(fv2 instanceof ActionWorkItemFieldValue);
    ActionWorkItemFieldValue wifv2 = (ActionWorkItemFieldValue) fv2;
    assertEquals("ResultFloatField", wifv2.getField());
    assertEquals(DataType.TYPE_NUMERIC_FLOAT, wifv2.getType());
    assertEquals("WorkItem", wifv2.getWorkItemName());
    assertEquals("FloatResult", wifv2.getWorkItemParameterName());
    assertEquals(Float.class.getName(), wifv2.getWorkItemParameterClassName());
    ActionFieldValue fv3 = asf.getFieldValues()[2];
    assertNotNull(fv3);
    assertTrue(fv3 instanceof ActionWorkItemFieldValue);
    ActionWorkItemFieldValue wifv3 = (ActionWorkItemFieldValue) fv3;
    assertEquals("ResultIntegerField", wifv3.getField());
    assertEquals(DataType.TYPE_NUMERIC_INTEGER, wifv3.getType());
    assertEquals("WorkItem", wifv3.getWorkItemName());
    assertEquals("IntegerResult", wifv3.getWorkItemParameterName());
    assertEquals(Integer.class.getName(), wifv3.getWorkItemParameterClassName());
    ActionFieldValue fv4 = asf.getFieldValues()[3];
    assertNotNull(fv4);
    assertTrue(fv4 instanceof ActionWorkItemFieldValue);
    ActionWorkItemFieldValue wifv4 = (ActionWorkItemFieldValue) fv4;
    assertEquals("ResultStringField", wifv4.getField());
    assertEquals(DataType.TYPE_STRING, wifv4.getType());
    assertEquals("WorkItem", wifv4.getWorkItemName());
    assertEquals("StringResult", wifv4.getWorkItemParameterName());
    assertEquals(String.class.getName(), wifv4.getWorkItemParameterClassName());
}
Also used : PortableIntegerParameterDefinition(org.drools.workbench.models.datamodel.workitems.PortableIntegerParameterDefinition) ActionWorkItemFieldValue(org.drools.workbench.models.datamodel.rule.ActionWorkItemFieldValue) PortableFloatParameterDefinition(org.drools.workbench.models.datamodel.workitems.PortableFloatParameterDefinition) ActionWorkItemCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionWorkItemCol52) ArrayList(java.util.ArrayList) DTCellValue52(org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52) DescriptionCol52(org.drools.workbench.models.guided.dtable.shared.model.DescriptionCol52) ActionFieldValue(org.drools.workbench.models.datamodel.rule.ActionFieldValue) PortableWorkDefinition(org.drools.workbench.models.datamodel.workitems.PortableWorkDefinition) BaseColumn(org.drools.workbench.models.guided.dtable.shared.model.BaseColumn) PortableBooleanParameterDefinition(org.drools.workbench.models.datamodel.workitems.PortableBooleanParameterDefinition) ActionExecuteWorkItem(org.drools.workbench.models.datamodel.rule.ActionExecuteWorkItem) GuidedDTTemplateDataProvider(org.drools.workbench.models.guided.dtable.backend.util.GuidedDTTemplateDataProvider) TemplateDataProvider(org.drools.workbench.models.guided.dtable.backend.util.TemplateDataProvider) ActionCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionCol52) GuidedDTTemplateDataProvider(org.drools.workbench.models.guided.dtable.backend.util.GuidedDTTemplateDataProvider) ActionWorkItemSetFieldCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionWorkItemSetFieldCol52) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) PortableStringParameterDefinition(org.drools.workbench.models.datamodel.workitems.PortableStringParameterDefinition) ActionSetField(org.drools.workbench.models.datamodel.rule.ActionSetField) RowNumberCol52(org.drools.workbench.models.guided.dtable.shared.model.RowNumberCol52) Test(org.junit.Test)

Example 15 with PortableBooleanParameterDefinition

use of org.drools.workbench.models.datamodel.workitems.PortableBooleanParameterDefinition in project drools by kiegroup.

the class GuidedDTDRLPersistenceTest method testRHSActionWorkItemSetFields2.

@Test
public // Test only Actions set to "true" are correctly converted to RuleModel
void testRHSActionWorkItemSetFields2() {
    GuidedDTDRLPersistence p = new GuidedDTDRLPersistence();
    String[] row = new String[] { "1", "desc", "true", "true", "false" };
    List<BaseColumn> allColumns = new ArrayList<BaseColumn>();
    allColumns.add(new RowNumberCol52());
    allColumns.add(new DescriptionCol52());
    List<ActionCol52> cols = new ArrayList<ActionCol52>();
    ActionWorkItemCol52 awi = new ActionWorkItemCol52();
    PortableWorkDefinition pwd = new PortableWorkDefinition();
    pwd.setName("WorkItem");
    awi.setWorkItemDefinition(pwd);
    PortableBooleanParameterDefinition p1 = new PortableBooleanParameterDefinition();
    p1.setName("BooleanResult");
    pwd.addResult(p1);
    PortableFloatParameterDefinition p2 = new PortableFloatParameterDefinition();
    p2.setName("FloatResult");
    pwd.addResult(p2);
    cols.add(awi);
    ActionWorkItemSetFieldCol52 asf1 = new ActionWorkItemSetFieldCol52();
    asf1.setBoundName("$r");
    asf1.setFactField("ResultBooleanField");
    asf1.setType(DataType.TYPE_BOOLEAN);
    asf1.setWorkItemName("WorkItem");
    asf1.setWorkItemResultParameterName("BooleanResult");
    asf1.setParameterClassName(Boolean.class.getName());
    cols.add(asf1);
    ActionWorkItemSetFieldCol52 asf2 = new ActionWorkItemSetFieldCol52();
    asf2.setBoundName("$r");
    asf2.setFactField("ResultFloatField");
    asf2.setType(DataType.TYPE_NUMERIC_FLOAT);
    asf2.setWorkItemName("WorkItem");
    asf2.setWorkItemResultParameterName("FloatResult");
    asf2.setParameterClassName(Float.class.getName());
    cols.add(asf2);
    RuleModel rm = new RuleModel();
    allColumns.addAll(cols);
    List<DTCellValue52> rowData = DataUtilities.makeDataRowList(row);
    TemplateDataProvider rowDataProvider = new GuidedDTTemplateDataProvider(allColumns, rowData);
    p.doActions(allColumns, cols, rowDataProvider, rowData, rm);
    assertEquals(2, rm.rhs.length);
    // Examine RuleModel actions
    ActionExecuteWorkItem aw = (ActionExecuteWorkItem) rm.rhs[0];
    assertNotNull(aw);
    ActionSetField asf = (ActionSetField) rm.rhs[1];
    assertNotNull(asf);
    // Check ActionExecuteWorkItem
    PortableWorkDefinition mpwd = aw.getWorkDefinition();
    assertNotNull(mpwd);
    assertEquals(2, mpwd.getResults().size());
    PortableBooleanParameterDefinition mp1 = (PortableBooleanParameterDefinition) mpwd.getResult("BooleanResult");
    assertNotNull(mp1);
    PortableFloatParameterDefinition mp2 = (PortableFloatParameterDefinition) mpwd.getResult("FloatResult");
    assertNotNull(mp2);
    // Check ActionSetField
    assertEquals(asf.getVariable(), "$r");
    assertEquals(1, asf.getFieldValues().length);
    ActionFieldValue fv1 = asf.getFieldValues()[0];
    assertNotNull(fv1);
    assertTrue(fv1 instanceof ActionWorkItemFieldValue);
    ActionWorkItemFieldValue wifv1 = (ActionWorkItemFieldValue) fv1;
    assertEquals("ResultBooleanField", wifv1.getField());
    assertEquals(DataType.TYPE_BOOLEAN, wifv1.getType());
    assertEquals("WorkItem", wifv1.getWorkItemName());
    assertEquals("BooleanResult", wifv1.getWorkItemParameterName());
    assertEquals(Boolean.class.getName(), wifv1.getWorkItemParameterClassName());
}
Also used : ActionWorkItemFieldValue(org.drools.workbench.models.datamodel.rule.ActionWorkItemFieldValue) PortableFloatParameterDefinition(org.drools.workbench.models.datamodel.workitems.PortableFloatParameterDefinition) ActionWorkItemCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionWorkItemCol52) ArrayList(java.util.ArrayList) DTCellValue52(org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52) DescriptionCol52(org.drools.workbench.models.guided.dtable.shared.model.DescriptionCol52) ActionFieldValue(org.drools.workbench.models.datamodel.rule.ActionFieldValue) PortableWorkDefinition(org.drools.workbench.models.datamodel.workitems.PortableWorkDefinition) BaseColumn(org.drools.workbench.models.guided.dtable.shared.model.BaseColumn) PortableBooleanParameterDefinition(org.drools.workbench.models.datamodel.workitems.PortableBooleanParameterDefinition) ActionExecuteWorkItem(org.drools.workbench.models.datamodel.rule.ActionExecuteWorkItem) GuidedDTTemplateDataProvider(org.drools.workbench.models.guided.dtable.backend.util.GuidedDTTemplateDataProvider) TemplateDataProvider(org.drools.workbench.models.guided.dtable.backend.util.TemplateDataProvider) ActionCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionCol52) GuidedDTTemplateDataProvider(org.drools.workbench.models.guided.dtable.backend.util.GuidedDTTemplateDataProvider) ActionWorkItemSetFieldCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionWorkItemSetFieldCol52) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) ActionSetField(org.drools.workbench.models.datamodel.rule.ActionSetField) RowNumberCol52(org.drools.workbench.models.guided.dtable.shared.model.RowNumberCol52) Test(org.junit.Test)

Aggregations

PortableBooleanParameterDefinition (org.drools.workbench.models.datamodel.workitems.PortableBooleanParameterDefinition)15 PortableFloatParameterDefinition (org.drools.workbench.models.datamodel.workitems.PortableFloatParameterDefinition)15 ActionExecuteWorkItem (org.drools.workbench.models.datamodel.rule.ActionExecuteWorkItem)13 RuleModel (org.drools.workbench.models.datamodel.rule.RuleModel)13 PortableIntegerParameterDefinition (org.drools.workbench.models.datamodel.workitems.PortableIntegerParameterDefinition)13 PortableStringParameterDefinition (org.drools.workbench.models.datamodel.workitems.PortableStringParameterDefinition)13 PortableWorkDefinition (org.drools.workbench.models.datamodel.workitems.PortableWorkDefinition)13 Test (org.junit.Test)13 ArrayList (java.util.ArrayList)6 ActionWorkItemFieldValue (org.drools.workbench.models.datamodel.rule.ActionWorkItemFieldValue)6 CompositeFactPattern (org.drools.workbench.models.datamodel.rule.CompositeFactPattern)6 FactPattern (org.drools.workbench.models.datamodel.rule.FactPattern)6 FromAccumulateCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern)6 FromCollectCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern)6 FromCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern)6 FromEntryPointFactPattern (org.drools.workbench.models.datamodel.rule.FromEntryPointFactPattern)6 GuidedDTTemplateDataProvider (org.drools.workbench.models.guided.dtable.backend.util.GuidedDTTemplateDataProvider)6 TemplateDataProvider (org.drools.workbench.models.guided.dtable.backend.util.TemplateDataProvider)6 ActionCol52 (org.drools.workbench.models.guided.dtable.shared.model.ActionCol52)6 ActionWorkItemCol52 (org.drools.workbench.models.guided.dtable.shared.model.ActionWorkItemCol52)6