Search in sources :

Example 26 with ConversionResult

use of org.drools.workbench.models.guided.dtable.shared.conversion.ConversionResult in project drools-wb by kiegroup.

the class DecisionTableXLSEditorPresenter method convert.

private void convert() {
    busyIndicatorView.showBusyIndicator(DecisionTableXLSEditorConstants.INSTANCE.Converting());
    decisionTableXLSService.call(new RemoteCallback<ConversionResult>() {

        @Override
        public void callback(final ConversionResult response) {
            busyIndicatorView.hideBusyIndicator();
            if (response.getMessages().size() > 0) {
                final PopupListWidget popup = new PopupListWidget();
                for (ConversionMessage message : response.getMessages()) {
                    popup.addListItem(new ConversionMessageWidget(message));
                }
                popup.show();
            }
        }
    }).convert(versionRecordManager.getCurrentPath());
}
Also used : ConversionMessage(org.drools.workbench.models.guided.dtable.shared.conversion.ConversionMessage) ConversionResult(org.drools.workbench.models.guided.dtable.shared.conversion.ConversionResult) ConversionMessageWidget(org.drools.workbench.screens.dtablexls.client.widgets.ConversionMessageWidget) PopupListWidget(org.drools.workbench.screens.dtablexls.client.widgets.PopupListWidget) RemoteCallback(org.jboss.errai.common.client.api.RemoteCallback)

Example 27 with ConversionResult

use of org.drools.workbench.models.guided.dtable.shared.conversion.ConversionResult in project drools-wb by kiegroup.

the class DecisionTableXLSToDecisionTableGuidedConverter method convert.

@Override
public ConversionResult convert(final Path path) {
    ConversionResult result = new ConversionResult();
    // Check Asset is of the correct format
    if (!(xlsDTableType.accept(path) || xlsxDTableType.accept(path))) {
        result.addMessage("Source Asset must be either a XLS or XLSX Decision Table file.", ConversionMessageType.ERROR);
        return result;
    }
    final PackageDataModelOracle dmo = dataModelService.getDataModel(path);
    // Perform conversion!
    final GuidedDecisionTableGeneratorListener listener = parseAssets(path, result, dmo);
    // Root path for new resources is the same folder as the XLS file
    final Path context = Paths.convert(Paths.convert(path).getParent());
    // Add Ancillary resources
    createNewImports(context, listener.getImports(), result);
    createNewFunctions(context, listener.getImports(), listener.getFunctions(), result);
    createNewQueries(context, listener.getImports(), listener.getQueries(), result);
    makeNewJavaTypes(context, listener.getTypeDeclarations(), result);
    createNewGlobals(context, listener.getImports(), listener.getGlobals(), result);
    // Add Web Guided Decision Tables
    createNewDecisionTables(context, listener.getImports(), listener.getGuidedDecisionTables(), result);
    return result;
}
Also used : Path(org.uberfire.backend.vfs.Path) ConversionResult(org.drools.workbench.models.guided.dtable.shared.conversion.ConversionResult) PackageDataModelOracle(org.kie.soup.project.datamodel.oracle.PackageDataModelOracle)

Example 28 with ConversionResult

use of org.drools.workbench.models.guided.dtable.shared.conversion.ConversionResult in project drools-wb by kiegroup.

the class DecisionTableXLSServiceImplCDITest method testConvertFunctionAndBigDecimal.

/**
 * Covers RHBA-48 - BigDecimal fields in table
 */
@Test
public void testConvertFunctionAndBigDecimal() throws Exception {
    final String resourcePath = "dtables/src/main/resources/guvnor/feature/dtables/FunctionAndBigDecimalTable.xls";
    final ConversionResult conversionResult = convertResource(resourcePath);
    final List<ConversionMessage> messages = conversionResult.getMessages();
    Assertions.assertThat(messages).hasSize(1);
    final String message = messages.get(0).getMessage();
    SoftAssertions.assertSoftly(softly -> {
        softly.assertThat(message).startsWith("Created Guided Decision Table 'FunctionAndBigDecimalTable (converted on");
        softly.assertThat(message).endsWith(").gdst'");
    });
}
Also used : ConversionMessage(org.drools.workbench.models.guided.dtable.shared.conversion.ConversionMessage) ConversionResult(org.drools.workbench.models.guided.dtable.shared.conversion.ConversionResult) Test(org.junit.Test)

Example 29 with ConversionResult

use of org.drools.workbench.models.guided.dtable.shared.conversion.ConversionResult in project drools-wb by kiegroup.

the class DecisionTableXLSToDecisionTableGuidedConverterTest method testGlobalGeneration.

@Test
public // https://bugzilla.redhat.com/show_bug.cgi?id=1310208
void testGlobalGeneration() {
    final InputStream is = this.getClass().getResourceAsStream("BZ1310208.xls");
    when(ioService.newInputStream(any(org.uberfire.java.nio.file.Path.class))).thenReturn(is);
    final ConversionResult result = converter.convert(path);
    assertNotNull(result);
    final ArgumentCaptor<GlobalsModel> globalsModelArgumentCaptor = ArgumentCaptor.forClass(GlobalsModel.class);
    verify(globalsService, times(1)).create(any(Path.class), any(String.class), globalsModelArgumentCaptor.capture(), any(String.class));
    assertNotNull(globalsModelArgumentCaptor.getValue());
    final GlobalsModel globalsModel = globalsModelArgumentCaptor.getValue();
    assertEquals(1, globalsModel.getGlobals().size());
    assertEquals("list", globalsModel.getGlobals().get(0).getAlias());
    assertEquals("java.util.List", globalsModel.getGlobals().get(0).getClassName());
    verify(guidedDecisionTableService, times(1)).create(any(Path.class), any(String.class), any(GuidedDecisionTable52.class), any(String.class));
    verify(drlService, never()).create(any(Path.class), any(String.class), any(String.class), any(String.class));
}
Also used : Path(org.uberfire.backend.vfs.Path) ConversionResult(org.drools.workbench.models.guided.dtable.shared.conversion.ConversionResult) GuidedDecisionTable52(org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52) GlobalsModel(org.drools.workbench.screens.globals.model.GlobalsModel) InputStream(java.io.InputStream) Test(org.junit.Test)

Example 30 with ConversionResult

use of org.drools.workbench.models.guided.dtable.shared.conversion.ConversionResult in project drools-wb by kiegroup.

the class DecisionTableXLSToDecisionTableGuidedConverterTest method checkConversionOfXLSXFiles.

@Test
public // https://issues.jboss.org/browse/GUVNOR-2696
void checkConversionOfXLSXFiles() {
    final InputStream is = this.getClass().getResourceAsStream("GUVNOR-2696.xlsx");
    when(ioService.newInputStream(any(org.uberfire.java.nio.file.Path.class))).thenReturn(is);
    final ConversionResult result = converter.convert(path);
    assertNotNull(result);
    assertEquals(1, result.getMessages().size());
    assertTrue(result.getMessages().get(0).getMessage().startsWith("Created Guided Decision Table 'Weather"));
    verify(guidedDecisionTableService, times(1)).create(any(Path.class), any(String.class), any(GuidedDecisionTable52.class), any(String.class));
}
Also used : Path(org.uberfire.backend.vfs.Path) ConversionResult(org.drools.workbench.models.guided.dtable.shared.conversion.ConversionResult) GuidedDecisionTable52(org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52) InputStream(java.io.InputStream) Test(org.junit.Test)

Aggregations

ConversionResult (org.drools.workbench.models.guided.dtable.shared.conversion.ConversionResult)30 Test (org.junit.Test)27 InputStream (java.io.InputStream)26 IOException (java.io.IOException)23 ArrayList (java.util.ArrayList)23 ExcelParser (org.drools.decisiontable.parser.xls.ExcelParser)23 DataListener (org.drools.template.parser.DataListener)23 GuidedDecisionTable52 (org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52)21 BaseColumn (org.drools.workbench.models.guided.dtable.shared.model.BaseColumn)17 DescriptionCol52 (org.drools.workbench.models.guided.dtable.shared.model.DescriptionCol52)17 RowNumberCol52 (org.drools.workbench.models.guided.dtable.shared.model.RowNumberCol52)17 BRLConditionVariableColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLConditionVariableColumn)11 IPattern (org.drools.workbench.models.datamodel.rule.IPattern)10 BRLActionVariableColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLActionVariableColumn)10 BRLConditionColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLConditionColumn)10 CompositeFactPattern (org.drools.workbench.models.datamodel.rule.CompositeFactPattern)9 FactPattern (org.drools.workbench.models.datamodel.rule.FactPattern)9 IAction (org.drools.workbench.models.datamodel.rule.IAction)9 SingleFieldConstraint (org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)9 BRLActionColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn)9