Search in sources :

Example 6 with KieModule

use of org.kie.workbench.common.services.shared.project.KieModule 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();
    final org.uberfire.java.nio.file.Path nioExternalImportsPath = Paths.convert(externalImportsPath);
    // Load existing PackageImports
    ProjectImports projectImports = new ProjectImports();
    if (Files.exists(nioExternalImportsPath)) {
        projectImports = importsService.load(externalImportsPath);
    }
    // Make collections of existing Imports so we don't duplicate them when adding the new
    List<String> existingImports = new ArrayList<String>();
    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)

Aggregations

KieModule (org.kie.workbench.common.services.shared.project.KieModule)6 ArrayList (java.util.ArrayList)2 TestScenarioResult (org.drools.workbench.screens.testscenario.model.TestScenarioResult)2 TestResultMessage (org.guvnor.common.services.shared.test.TestResultMessage)2 Test (org.junit.Test)2 Path (org.uberfire.backend.vfs.Path)2 URL (java.net.URL)1 Import (org.drools.template.model.Import)1 Scenario (org.drools.workbench.models.testscenarios.shared.Scenario)1 AnnotationMetaModel (org.drools.workbench.screens.factmodel.model.AnnotationMetaModel)1 FactMetaModel (org.drools.workbench.screens.factmodel.model.FactMetaModel)1 FactModels (org.drools.workbench.screens.factmodel.model.FactModels)1 FieldMetaModel (org.drools.workbench.screens.factmodel.model.FieldMetaModel)1 ProjectImports (org.guvnor.common.services.project.model.ProjectImports)1 Metadata (org.guvnor.common.services.shared.metadata.model.Metadata)1 ValidationMessage (org.guvnor.common.services.shared.validation.model.ValidationMessage)1 Import (org.kie.soup.project.datamodel.imports.Import)1 Imports (org.kie.soup.project.datamodel.imports.Imports)1 DataEnumLoader (org.kie.workbench.common.services.datamodel.backend.server.builder.util.DataEnumLoader)1 DataModel (org.kie.workbench.common.services.datamodeller.core.DataModel)1