use of org.guvnor.common.services.project.model.ProjectImports in project drools-wb by kiegroup.
the class DecisionTableXLSToDecisionTableGuidedConverter method loadProjectImports.
ProjectImports loadProjectImports(final Path externalImportsPath) {
final org.uberfire.java.nio.file.Path nioExternalImportsPath = Paths.convert(externalImportsPath);
ProjectImports projectImports = new ProjectImports();
if (Files.exists(nioExternalImportsPath)) {
projectImports = importsService.load(externalImportsPath);
}
return projectImports;
}
use of org.guvnor.common.services.project.model.ProjectImports in project drools-wb by kiegroup.
the class DecisionTableXLSToDecisionTableGuidedConverter method createNewImports.
private void createNewImports(final Path context, final List<Import> imports, final ConversionResult result) {
if (imports == null || imports.isEmpty()) {
return;
}
// Get Module's project.imports path
final KieModule module = moduleService.resolveModule(context);
final Path externalImportsPath = module.getImportsPath();
// Load existing PackageImports
final ProjectImports projectImports = loadProjectImports(externalImportsPath);
// Make collections of existing Imports so we don't duplicate them when adding the new
List<String> existingImports = new ArrayList<>();
for (org.kie.soup.project.datamodel.imports.Import item : projectImports.getImports().getImports()) {
existingImports.add(item.getType());
}
// Add imports
boolean isModified = false;
for (Import item : imports) {
if (!existingImports.contains(item.getClassName())) {
isModified = true;
result.addMessage("Created Import for '" + item.getClassName() + "'.", ConversionMessageType.INFO);
projectImports.getImports().addImport(new org.kie.soup.project.datamodel.imports.Import(item.getClassName()));
}
}
// Save update
if (isModified) {
final Metadata metadata = metadataService.getMetadata(context);
importsService.save(externalImportsPath, projectImports, metadata, "Imports added during XLS conversion");
}
}
use of org.guvnor.common.services.project.model.ProjectImports 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), "", "", "", "");
}
Aggregations