use of org.drools.workbench.models.guided.dtable.shared.model.MetadataCol52 in project drools by kiegroup.
the class GuidedDTDRLPersistence method doMetadata.
void doMetadata(List<BaseColumn> allColumns, List<MetadataCol52> metadataCols, List<DTCellValue52> row, RuleModel rm) {
// setup temp list
List<RuleMetadata> metadataList = new ArrayList<RuleMetadata>();
for (int j = 0; j < metadataCols.size(); j++) {
MetadataCol52 meta = metadataCols.get(j);
int index = allColumns.indexOf(meta);
final DTCellValue52 dcv = row.get(index);
String cell = GuidedDTDRLUtilities.convertDTCellValueToString(dcv);
if (validateMetadataCell(cell)) {
metadataList.add(new RuleMetadata(meta.getMetadata(), cell));
}
}
if (metadataList.size() > 0) {
rm.metadataList = metadataList.toArray(new RuleMetadata[metadataList.size()]);
}
}
use of org.drools.workbench.models.guided.dtable.shared.model.MetadataCol52 in project drools by kiegroup.
the class GuidedDecisionTableUpgradeHelper3 method upgrade.
/**
* Convert the Default Values in the Decision Table model
*
* @param source
* @return The new DTModel
*/
public GuidedDecisionTable52 upgrade(GuidedDecisionTable52 source) {
final GuidedDecisionTable52 destination = source;
for (BaseColumn column : source.getExpandedColumns()) {
DTColumnConfig52 dtColumn = null;
if (column instanceof MetadataCol52) {
dtColumn = (DTColumnConfig52) column;
} else if (column instanceof AttributeCol52) {
dtColumn = (DTColumnConfig52) column;
} else if (column instanceof ConditionCol52) {
dtColumn = (DTColumnConfig52) column;
} else if (column instanceof ActionCol52) {
dtColumn = (DTColumnConfig52) column;
}
if (dtColumn instanceof LimitedEntryCol) {
dtColumn = null;
}
if (dtColumn instanceof BRLVariableColumn) {
dtColumn = null;
}
if (dtColumn != null) {
final String legacyDefaultValue = dtColumn.defaultValue;
if (legacyDefaultValue != null) {
dtColumn.setDefaultValue(new DTCellValue52(legacyDefaultValue));
dtColumn.defaultValue = null;
}
}
}
return destination;
}
use of org.drools.workbench.models.guided.dtable.shared.model.MetadataCol52 in project drools by kiegroup.
the class GuidedDTDRLPersistenceTest method testLHSNotPattern.
@Test
public void testLHSNotPattern() {
GuidedDTDRLPersistence p = new GuidedDTDRLPersistence();
String[] row = new String[] { "1", "desc", "a", "mike", "33 + 1", "age > 6", "stilton" };
String[][] data = new String[1][];
data[0] = row;
List<BaseColumn> allColumns = new ArrayList<BaseColumn>();
List<CompositeColumn<? extends BaseColumn>> allPatterns = new ArrayList<CompositeColumn<? extends BaseColumn>>();
allColumns.add(new RowNumberCol52());
allColumns.add(new DescriptionCol52());
allColumns.add(new MetadataCol52());
Pattern52 p1 = new Pattern52();
p1.setNegated(true);
p1.setBoundName("p1");
p1.setFactType("Person");
allPatterns.add(p1);
ConditionCol52 col = new ConditionCol52();
col.setFactField("name");
col.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
col.setOperator("==");
p1.getChildColumns().add(col);
allColumns.add(col);
ConditionCol52 col2 = new ConditionCol52();
col2.setFactField("age");
col2.setConstraintValueType(BaseSingleFieldConstraint.TYPE_RET_VALUE);
col2.setOperator("<");
p1.getChildColumns().add(col2);
allColumns.add(col2);
ConditionCol52 col3 = new ConditionCol52();
col3.setConstraintValueType(BaseSingleFieldConstraint.TYPE_PREDICATE);
p1.getChildColumns().add(col3);
allColumns.add(col3);
Pattern52 p2 = new Pattern52();
p2.setBoundName("c");
p2.setFactType("Cheese");
allPatterns.add(p2);
ConditionCol52 col4 = new ConditionCol52();
col4.setFactField("type");
col4.setOperator("==");
col4.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
p2.getChildColumns().add(col4);
allColumns.add(col4);
List<DTCellValue52> rowData = DataUtilities.makeDataRowList(row);
TemplateDataProvider rowDataProvider = new GuidedDTTemplateDataProvider(allColumns, rowData);
RuleModel rm = new RuleModel();
p.doConditions(allColumns, allPatterns, rowDataProvider, rowData, DataUtilities.makeDataLists(data), rm);
String drl = RuleModelDRLPersistenceImpl.getInstance().marshal(rm);
assertEquals(2, rm.lhs.length);
assertEquals("Person", ((FactPattern) rm.lhs[0]).getFactType());
assertEquals("p1", ((FactPattern) rm.lhs[0]).getBoundName());
assertEquals("Cheese", ((FactPattern) rm.lhs[1]).getFactType());
assertEquals("c", ((FactPattern) rm.lhs[1]).getBoundName());
// examine the first pattern
FactPattern person = (FactPattern) rm.lhs[0];
assertEquals(3, person.getConstraintList().getConstraints().length);
SingleFieldConstraint cons = (SingleFieldConstraint) person.getConstraint(0);
assertEquals(BaseSingleFieldConstraint.TYPE_LITERAL, cons.getConstraintValueType());
assertEquals("name", cons.getFieldName());
assertEquals("==", cons.getOperator());
assertEquals("mike", cons.getValue());
cons = (SingleFieldConstraint) person.getConstraint(1);
assertEquals(BaseSingleFieldConstraint.TYPE_RET_VALUE, cons.getConstraintValueType());
assertEquals("age", cons.getFieldName());
assertEquals("<", cons.getOperator());
assertEquals("33 + 1", cons.getValue());
assertNull(cons.getFieldBinding());
cons = (SingleFieldConstraint) person.getConstraint(2);
assertEquals(BaseSingleFieldConstraint.TYPE_PREDICATE, cons.getConstraintValueType());
assertEquals("age > 6", cons.getValue());
assertEquals(person.isNegated(), true);
assertTrue(drl.indexOf("not Person(") > 0);
// examine the second pattern
FactPattern cheese = (FactPattern) rm.lhs[1];
assertEquals(1, cheese.getConstraintList().getConstraints().length);
cons = (SingleFieldConstraint) cheese.getConstraint(0);
assertEquals("type", cons.getFieldName());
assertEquals("==", cons.getOperator());
assertEquals("stilton", cons.getValue());
assertEquals(BaseSingleFieldConstraint.TYPE_LITERAL, cons.getConstraintValueType());
assertEquals(cheese.isNegated(), false);
assertTrue(drl.indexOf("c : Cheese(") > 0);
}
use of org.drools.workbench.models.guided.dtable.shared.model.MetadataCol52 in project drools by kiegroup.
the class GuidedDTDRLPersistenceTest method testNoOperator.
@Test
public void testNoOperator() {
GuidedDTDRLPersistence p = new GuidedDTDRLPersistence();
String[] row = new String[] { "1", "desc", "a", "> 42" };
String[][] data = new String[1][];
data[0] = row;
List<BaseColumn> allColumns = new ArrayList<BaseColumn>();
List<CompositeColumn<? extends BaseColumn>> allPatterns = new ArrayList<CompositeColumn<? extends BaseColumn>>();
allColumns.add(new RowNumberCol52());
allColumns.add(new DescriptionCol52());
allColumns.add(new MetadataCol52());
Pattern52 p1 = new Pattern52();
p1.setBoundName("p1");
p1.setFactType("Person");
allPatterns.add(p1);
ConditionCol52 col1 = new ConditionCol52();
col1.setFactField("age");
col1.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
col1.setOperator("");
p1.getChildColumns().add(col1);
allColumns.add(col1);
RuleModel rm = new RuleModel();
List<DTCellValue52> rowData = DataUtilities.makeDataRowList(row);
TemplateDataProvider rowDataProvider = new GuidedDTTemplateDataProvider(allColumns, rowData);
p.doConditions(allColumns, allPatterns, rowDataProvider, rowData, DataUtilities.makeDataLists(data), rm);
String drl = RuleModelDRLPersistenceImpl.getInstance().marshal(rm);
assertTrue(drl.indexOf("age > \"42\"") > 0);
}
use of org.drools.workbench.models.guided.dtable.shared.model.MetadataCol52 in project drools by kiegroup.
the class GuidedDTXMLPersistenceTest method testRoundTrip.
@Test
public void testRoundTrip() {
GuidedDecisionTable52 dt = new GuidedDecisionTable52();
dt.getActionCols().add(new ActionInsertFactCol52());
ActionSetFieldCol52 set = new ActionSetFieldCol52();
set.setFactField("foo");
dt.getActionCols().add(set);
dt.getMetadataCols().add(new MetadataCol52());
dt.getAttributeCols().add(new AttributeCol52());
Pattern52 p = new Pattern52();
ConditionCol52 c = new ConditionCol52();
p.getChildColumns().add(c);
dt.getConditions().add(p);
dt.setData(upgrader.makeDataLists(new String[][] { new String[] { "1", "hola" } }));
dt.setTableName("blah");
String xml = GuidedDTXMLPersistence.getInstance().marshal(dt);
System.out.println(xml);
assertNotNull(xml);
assertEquals(-1, xml.indexOf("ActionSetField"));
assertEquals(-1, xml.indexOf("ConditionCol"));
assertEquals(-1, xml.indexOf("GuidedDecisionTable"));
GuidedDecisionTable52 dt_ = GuidedDTXMLPersistence.getInstance().unmarshal(xml);
assertNotNull(dt_);
assertEquals("blah", dt_.getTableName());
assertEquals(1, dt_.getMetadataCols().size());
assertEquals(1, dt_.getAttributeCols().size());
assertEquals(2, dt_.getActionCols().size());
assertEquals(1, dt_.getConditions().size());
assertEquals(1, dt_.getConditions().get(0).getChildColumns().size());
}
Aggregations