use of org.drools.workbench.models.guided.dtable.shared.model.BRLActionVariableColumn in project drools-wb by kiegroup.
the class GuidedDecisionTableGeneratorListenerTest method testActions.
@Test
public void testActions() {
final ConversionResult result = new ConversionResult();
final List<DataListener> listeners = new ArrayList<DataListener>();
final GuidedDecisionTableGeneratorListener listener = new GuidedDecisionTableGeneratorListener(result, dmo);
listeners.add(listener);
// Convert
final ExcelParser parser = new ExcelParser(listeners);
final InputStream is = this.getClass().getResourceAsStream("Actions.xls");
try {
parser.parseFile(is);
} finally {
try {
is.close();
} catch (IOException ioe) {
fail(ioe.getMessage());
}
}
// Check conversion results
assertEquals(0, result.getMessages().size());
// Check basics
List<GuidedDecisionTable52> dtables = listener.getGuidedDecisionTables();
assertNotNull(dtables);
assertEquals(1, dtables.size());
GuidedDecisionTable52 dtable = dtables.get(0);
assertEquals("ActionsTest", dtable.getTableName());
assertEquals(GuidedDecisionTable52.TableFormat.EXTENDED_ENTRY, dtable.getTableFormat());
// Check expanded columns
List<BaseColumn> columns = dtable.getExpandedColumns();
assertNotNull(columns);
assertEquals(8, columns.size());
assertTrue(columns.get(0) instanceof RowNumberCol52);
assertTrue(columns.get(1) instanceof RuleNameColumn);
assertTrue(columns.get(2) instanceof DescriptionCol52);
assertTrue(columns.get(3) instanceof BRLActionVariableColumn);
assertTrue(columns.get(4) instanceof BRLActionVariableColumn);
assertTrue(columns.get(5) instanceof BRLActionVariableColumn);
assertTrue(columns.get(6) instanceof BRLActionVariableColumn);
assertTrue(columns.get(7) instanceof BRLActionVariableColumn);
// Check individual action columns
assertEquals(4, dtable.getActionCols().size());
assertTrue(dtable.getActionCols().get(0) instanceof BRLActionColumn);
assertTrue(dtable.getActionCols().get(1) instanceof BRLActionColumn);
assertTrue(dtable.getActionCols().get(2) instanceof BRLActionColumn);
assertTrue(dtable.getActionCols().get(3) instanceof BRLActionColumn);
// Column 1
BRLActionColumn actionCol0 = ((BRLActionColumn) dtable.getActionCols().get(0));
assertEquals("Converted from ['Multi-parameters', 'Multi-parameters']", actionCol0.getHeader());
assertEquals(2, actionCol0.getChildColumns().size());
List<IAction> actionCol0definition = actionCol0.getDefinition();
assertEquals(1, actionCol0definition.size());
assertTrue(actionCol0definition.get(0) instanceof FreeFormLine);
FreeFormLine actionCol0ffl = (FreeFormLine) actionCol0definition.get(0);
assertEquals("policy.setBasePrice(@{param1}, @{param2});", actionCol0ffl.getText());
// Column 1 - Variable 1
BRLActionVariableColumn actionCol0param0 = actionCol0.getChildColumns().get(0);
assertEquals("param1", actionCol0param0.getVarName());
assertEquals("Multi-parameters", actionCol0param0.getHeader());
assertEquals(DataType.TYPE_OBJECT, actionCol0param0.getFieldType());
assertNull(actionCol0param0.getFactType());
assertNull(actionCol0param0.getFactField());
// Column 1 - Variable 2
BRLActionVariableColumn actionCol0param1 = actionCol0.getChildColumns().get(1);
assertEquals("param2", actionCol0param1.getVarName());
assertEquals("Multi-parameters", actionCol0param1.getHeader());
assertEquals(DataType.TYPE_OBJECT, actionCol0param1.getFieldType());
assertNull(actionCol0param1.getFactType());
assertNull(actionCol0param1.getFactField());
// Column 2
BRLActionColumn actionCol1 = ((BRLActionColumn) dtable.getActionCols().get(1));
assertEquals("Converted from ['Single-parameter']", actionCol1.getHeader());
assertEquals(1, actionCol1.getChildColumns().size());
List<IAction> actionCol1definition = actionCol1.getDefinition();
assertEquals(1, actionCol1definition.size());
assertTrue(actionCol1definition.get(0) instanceof FreeFormLine);
FreeFormLine actionCol1ffl = (FreeFormLine) actionCol1definition.get(0);
assertEquals("policy.setSmurf(@{param3});", actionCol1ffl.getText());
// Column 2 - Variable 1
BRLActionVariableColumn actionCol1param0 = actionCol1.getChildColumns().get(0);
assertEquals("param3", actionCol1param0.getVarName());
assertEquals("Single-parameter", actionCol1param0.getHeader());
assertEquals(DataType.TYPE_OBJECT, actionCol1param0.getFieldType());
assertNull(actionCol1param0.getFactType());
assertNull(actionCol1param0.getFactField());
// Column 3
BRLActionColumn actionCol2 = ((BRLActionColumn) dtable.getActionCols().get(2));
assertEquals("Converted from ['Log-single-parameter']", actionCol2.getHeader());
assertEquals(1, actionCol2.getChildColumns().size());
List<IAction> actionCol2definition = actionCol2.getDefinition();
assertEquals(1, actionCol2definition.size());
assertTrue(actionCol2definition.get(0) instanceof FreeFormLine);
FreeFormLine actionCol2ffl = (FreeFormLine) actionCol2definition.get(0);
assertEquals("System.out.println(\"@{param4}\");", actionCol2ffl.getText());
// Column 3 - Variable 1
BRLActionVariableColumn actionCol2param0 = actionCol2.getChildColumns().get(0);
assertEquals("param4", actionCol2param0.getVarName());
assertEquals("Log-single-parameter", actionCol2param0.getHeader());
assertEquals(DataType.TYPE_OBJECT, actionCol2param0.getFieldType());
assertNull(actionCol2param0.getFactType());
assertNull(actionCol2param0.getFactField());
// Column 4
BRLActionColumn actionCol3 = ((BRLActionColumn) dtable.getActionCols().get(3));
assertEquals("Converted from ['Zero-parameters']", actionCol3.getHeader());
assertEquals(1, actionCol3.getChildColumns().size());
List<IAction> actionCol3definition = actionCol3.getDefinition();
assertEquals(1, actionCol3definition.size());
assertTrue(actionCol3definition.get(0) instanceof FreeFormLine);
FreeFormLine actionCol3ffl = (FreeFormLine) actionCol3definition.get(0);
assertEquals("System.out.println(\"Woot\");", actionCol3ffl.getText());
// Column 3 - Variable 1
BRLActionVariableColumn actionCol3param0 = actionCol3.getChildColumns().get(0);
assertEquals("", actionCol3param0.getVarName());
assertEquals("Zero-parameters", actionCol3param0.getHeader());
assertEquals(DataType.TYPE_BOOLEAN, actionCol3param0.getFieldType());
assertNull(actionCol3param0.getFactType());
assertNull(actionCol3param0.getFactField());
// Check data
assertEquals(2, dtable.getData().size());
assertTrue(isRowEquivalent(new Object[] { 1, "", "Row 1", "10", "20", "30", "hello", true }, dtable.getData().get(0)));
assertTrue(isRowEquivalent(new Object[] { 2, "", "Row 2", "50", "60", "70", "goodbye", false }, dtable.getData().get(1)));
}
use of org.drools.workbench.models.guided.dtable.shared.model.BRLActionVariableColumn in project drools-wb by kiegroup.
the class DecisionTableXLSToDecisionTableGuidedConverterTest method checkConversionOfXLSXFilesRHDM1159.
@Test
public void checkConversionOfXLSXFilesRHDM1159() {
final InputStream is = this.getClass().getResourceAsStream("RHDM-1159.xls");
when(ioService.newInputStream(any(org.uberfire.java.nio.file.Path.class))).thenReturn(is);
// Mock imports to match project attached to JIRA
final ProjectImports projectImports = new ProjectImports();
projectImports.getImports().addImport(new Import("com.aia.model.underWriting.Benefit"));
projectImports.getImports().addImport(new Import("com.aia.model.underWriting.Plans"));
projectImports.getImports().addImport(new Import("com.aia.model.underWriting.CaseInfo"));
projectImports.getImports().addImport(new Import("com.aia.model.underWriting.UnderwritingRuleRequest"));
projectImports.getImports().addImport(new Import("com.aia.model.underWriting.UnderwritingRuleResponse"));
doReturn(projectImports).when(converter).loadProjectImports(eq(expectedProjectImportsPath));
final ConversionResult result = converter.convert(path);
assertNotNull(result);
final List<ConversionMessage> messages = result.getMessages();
assertEquals(1, messages.size());
assertTrue(messages.get(0).getMessage().startsWith("Created Guided Decision Table 'SampleAUWRule"));
verify(guidedDecisionTableService, times(1)).create(any(Path.class), any(String.class), decisionTableArgumentCaptor.capture(), any(String.class));
final GuidedDecisionTable52 dtable = decisionTableArgumentCaptor.getValue();
assertNotNull(dtable);
// Check attributes
final List<AttributeCol52> attributes = dtable.getAttributeCols();
assertEquals(1, attributes.size());
assertEquals(Attribute.RULEFLOW_GROUP.getAttributeName(), attributes.get(0).getAttribute());
// Check LHS
final List<CompositeColumn<? extends BaseColumn>> conditions = dtable.getConditions();
assertEquals(3, conditions.size());
assertTrue(conditions.get(0) instanceof BRLConditionColumn);
final BRLConditionColumn condition0 = (BRLConditionColumn) conditions.get(0);
assertEquals(1, condition0.getDefinition().size());
assertTrue(condition0.getDefinition().get(0) instanceof FactPattern);
final FactPattern condition0FactPattern = (FactPattern) condition0.getDefinition().get(0);
assertEquals("UnderwritingRuleRequest", condition0FactPattern.getFactType());
assertEquals(1, condition0FactPattern.getNumberOfConstraints());
final FieldConstraint condition0FactPatternConstraint = condition0FactPattern.getConstraint(0);
assertTrue(condition0FactPatternConstraint instanceof SingleFieldConstraint);
final SingleFieldConstraint condition0FactPatternSingleFieldConstraint = (SingleFieldConstraint) condition0FactPattern.getConstraint(0);
assertEquals("traceId", condition0FactPatternSingleFieldConstraint.getFieldName());
assertEquals("==", condition0FactPatternSingleFieldConstraint.getOperator());
assertEquals(SingleFieldConstraint.TYPE_TEMPLATE, condition0FactPatternSingleFieldConstraint.getConstraintValueType());
assertEquals("param1", condition0FactPatternSingleFieldConstraint.getValue());
assertEquals(1, condition0.getChildColumns().size());
final BRLConditionVariableColumn condition0Variable = condition0.getChildColumns().get(0);
assertEquals("param1", condition0Variable.getVarName());
assertEquals("UnderwritingRuleRequest", condition0Variable.getFactType());
assertEquals("traceId", condition0Variable.getFactField());
assertTrue(conditions.get(1) instanceof BRLConditionColumn);
final BRLConditionColumn condition1 = (BRLConditionColumn) conditions.get(1);
assertEquals(1, condition1.getDefinition().size());
assertTrue(condition1.getDefinition().get(0) instanceof FromCompositeFactPattern);
final FromCompositeFactPattern condition1FromCompositeFactPattern = (FromCompositeFactPattern) condition1.getDefinition().get(0);
final FactPattern condition1FactPattern = condition1FromCompositeFactPattern.getFactPattern();
assertEquals("CaseInfo", condition1FactPattern.getFactType());
assertEquals(1, condition1FactPattern.getNumberOfConstraints());
final FieldConstraint condition1FactPatternConstraint = condition1FactPattern.getConstraint(0);
assertTrue(condition1FactPatternConstraint instanceof SingleFieldConstraint);
final SingleFieldConstraint condition1FactPatternSingleFieldConstraint = (SingleFieldConstraint) condition1FactPattern.getConstraint(0);
assertEquals("channel", condition1FactPatternSingleFieldConstraint.getFieldName());
assertEquals("in", condition1FactPatternSingleFieldConstraint.getOperator());
assertEquals(SingleFieldConstraint.TYPE_TEMPLATE, condition1FactPatternSingleFieldConstraint.getConstraintValueType());
assertEquals("param2", condition1FactPatternSingleFieldConstraint.getValue());
assertEquals(1, condition1.getChildColumns().size());
final BRLConditionVariableColumn condition1Variable = condition1.getChildColumns().get(0);
assertEquals("param2", condition1Variable.getVarName());
assertEquals("CaseInfo", condition1Variable.getFactType());
assertEquals("channel", condition1Variable.getFactField());
assertTrue(conditions.get(2) instanceof BRLConditionColumn);
final BRLConditionColumn condition2 = (BRLConditionColumn) conditions.get(2);
assertEquals(1, condition2.getDefinition().size());
assertTrue(condition2.getDefinition().get(0) instanceof FreeFormLine);
final FreeFormLine condition2FreeFormLine = (FreeFormLine) condition2.getDefinition().get(0);
assertEquals("plan :Plans();bn:Benefit(benefitCode in (\"@{param3}\")) from plan.benefit;\n", condition2FreeFormLine.getText());
assertEquals(1, condition2.getChildColumns().size());
final BRLConditionVariableColumn condition2Variable = condition2.getChildColumns().get(0);
assertEquals("param3", condition2Variable.getVarName());
assertEquals("Benefit", condition2Variable.getFactType());
assertEquals("benefitCode", condition2Variable.getFactField());
// Check RHS
final List<ActionCol52> actions = dtable.getActionCols();
assertEquals(1, actions.size());
assertTrue(actions.get(0) instanceof BRLActionColumn);
final BRLActionColumn action0 = (BRLActionColumn) actions.get(0);
assertTrue(action0.getDefinition().get(0) instanceof FreeFormLine);
final FreeFormLine action0FreeFormLine = (FreeFormLine) action0.getDefinition().get(0);
assertEquals("UnderwritingRuleResponse uwr= new UnderwritingRuleResponse();uwr.setAuwStatus(@{param4});", action0FreeFormLine.getText());
assertEquals(1, action0.getChildColumns().size());
final BRLActionVariableColumn action0Variable = action0.getChildColumns().get(0);
assertEquals("param4", action0Variable.getVarName());
// Check data
final List<List<DTCellValue52>> data = dtable.getData();
assertEquals(5, data.size());
assertRHDM1159RowData(data.get(0), "abc", "AGENT", "RB", "\"FAIL\"");
assertRHDM1159RowData(data.get(1), "sdf", "AGENT", "RB", "\"FAIL\"");
assertRHDM1159RowData(data.get(2), "dsds", "AGENT", "RB", "\"FAIL\"");
assertRHDM1159RowData(data.get(3), "sdddv", "AGENT", "RB", "\"FAIL\"");
assertRHDM1159RowData(data.get(4), "", "", "", "");
}
use of org.drools.workbench.models.guided.dtable.shared.model.BRLActionVariableColumn in project drools-wb by kiegroup.
the class GuidedDecisionTablePopulater method setCompositeColumnHeader.
private void setCompositeColumnHeader(final BRLActionColumn column) {
final List<BRLActionVariableColumn> columnVariableColumns = column.getChildColumns();
final StringBuilder sb = new StringBuilder();
final List<String> variableColumnHeaders = new ArrayList<>();
sb.append("Converted from [");
for (int i = 0; i < columnVariableColumns.size(); i++) {
final BRLActionVariableColumn variableColumn = columnVariableColumns.get(i);
final String header = variableColumn.getHeader();
variableColumnHeaders.add(header);
sb.append("'").append(header).append("'");
sb.append(i < columnVariableColumns.size() - 1 ? ", " : "");
}
sb.append("]");
column.setHeader(sb.toString());
for (int i = 0; i < columnVariableColumns.size(); i++) {
final BRLActionVariableColumn variableColumn = columnVariableColumns.get(i);
variableColumn.setHeader(variableColumnHeaders.get(i));
}
}
use of org.drools.workbench.models.guided.dtable.shared.model.BRLActionVariableColumn in project drools-wb by kiegroup.
the class GuidedDecisionTablePopulater method createRHSChildColumns.
private void createRHSChildColumns(final RuleModel rm, final IAction action, final BRLActionColumn column, final List<BRLVariableColumn> variableColumns) {
final Map<InterpolationVariable, Integer> templateKeys = new HashMap<>();
final RuleModelVisitor rmv = new RuleModelVisitor(rm.lhs, templateKeys);
rmv.visit(action);
final List<InterpolationVariable> ivs = new ArrayList<>(templateKeys.keySet());
for (BRLVariableColumn variableColumn : variableColumns) {
final Iterator<InterpolationVariable> ivsIts = ivs.iterator();
while (ivsIts.hasNext()) {
final InterpolationVariable iv = ivsIts.next();
if (iv.getVarName().equals(variableColumn.getVarName())) {
final BRLActionVariableColumn source = (BRLActionVariableColumn) variableColumn;
final BRLActionVariableColumn target = makeBRLActionVariableColumn(source, iv);
column.getChildColumns().add(target);
ivsIts.remove();
}
}
}
}
use of org.drools.workbench.models.guided.dtable.shared.model.BRLActionVariableColumn in project drools-wb by kiegroup.
the class GuidedDecisionTablePopulater method setZeroParameterActionColumnHeader.
private void setZeroParameterActionColumnHeader(final BRLActionColumn column, final List<BRLVariableColumn> allVariableColumns) {
final BRLActionVariableColumn source = findZeroParameterSourceActionColumn(allVariableColumns);
final BRLActionVariableColumn target = new BRLActionVariableColumn("", DataType.TYPE_BOOLEAN);
column.getChildColumns().add(target);
setZeroParameterColumnHeader(column, source, target);
}
Aggregations