Search in sources :

Example 16 with ProjectImports

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;
}
Also used : ProjectImports(org.guvnor.common.services.project.model.ProjectImports)

Example 17 with 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");
    }
}
Also used : Path(org.uberfire.backend.vfs.Path) Import(org.drools.template.model.Import) ArrayList(java.util.ArrayList) Metadata(org.guvnor.common.services.shared.metadata.model.Metadata) ProjectImports(org.guvnor.common.services.project.model.ProjectImports) KieModule(org.kie.workbench.common.services.shared.project.KieModule)

Example 18 with ProjectImports

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), "", "", "", "");
}
Also used : BRLConditionColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLConditionColumn) ConversionMessage(org.drools.workbench.models.guided.dtable.shared.conversion.ConversionMessage) Import(org.kie.soup.project.datamodel.imports.Import) GuidedDecisionTable52(org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) BRLConditionVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLConditionVariableColumn) CompositeColumn(org.drools.workbench.models.guided.dtable.shared.model.CompositeColumn) AttributeCol52(org.drools.workbench.models.guided.dtable.shared.model.AttributeCol52) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BRLActionColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) BaseColumn(org.drools.workbench.models.guided.dtable.shared.model.BaseColumn) List(java.util.List) Path(org.uberfire.backend.vfs.Path) ActionCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionCol52) InputStream(java.io.InputStream) ProjectImports(org.guvnor.common.services.project.model.ProjectImports) ConversionResult(org.drools.workbench.models.guided.dtable.shared.conversion.ConversionResult) FreeFormLine(org.drools.workbench.models.datamodel.rule.FreeFormLine) BRLActionVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionVariableColumn) FieldConstraint(org.drools.workbench.models.datamodel.rule.FieldConstraint) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) Test(org.junit.Test)

Aggregations

ProjectImports (org.guvnor.common.services.project.model.ProjectImports)18 Test (org.junit.Test)12 Import (org.kie.soup.project.datamodel.imports.Import)8 Path (org.uberfire.backend.vfs.Path)8 Metadata (org.guvnor.common.services.shared.metadata.model.Metadata)6 ProjectScreenModel (org.kie.workbench.common.screens.projecteditor.model.ProjectScreenModel)4 InputStream (java.io.InputStream)2 ConversionResult (org.drools.workbench.models.guided.dtable.shared.conversion.ConversionResult)2 GuidedDecisionTable52 (org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52)2 GAV (org.guvnor.common.services.project.model.GAV)2 MavenRepository (org.guvnor.common.services.project.model.MavenRepository)2 POM (org.guvnor.common.services.project.model.POM)2 Imports (org.kie.soup.project.datamodel.imports.Imports)2 KModuleModel (org.kie.workbench.common.services.shared.kmodule.KModuleModel)2 KieModule (org.kie.workbench.common.services.shared.project.KieModule)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 PomModel (org.appformer.maven.support.PomModel)1