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");
}
}
Aggregations