use of org.uberfire.java.nio.file.FileVisitResult in project kie-wb-common by kiegroup.
the class FormsMigrationTool method processWorkspaceProject.
private void processWorkspaceProject(WorkspaceProject workspaceProject) {
List<FormMigrationSummary> summaries = new ArrayList<>();
Files.walkFileTree(Paths.convert(workspaceProject.getRootPath()), new SimpleFileVisitor<org.uberfire.java.nio.file.Path>() {
@Override
public FileVisitResult visitFile(org.uberfire.java.nio.file.Path visitedPath, BasicFileAttributes attrs) throws IOException {
org.uberfire.backend.vfs.Path visitedVFSPath = Paths.convert(visitedPath);
String fileName = visitedVFSPath.getFileName();
File file = visitedPath.toFile();
if (file.isFile()) {
if (fileName.endsWith("." + FormsMigrationConstants.LEGACY_FOMRS_EXTENSION)) {
try {
Form legacyForm = legacyFormSerializer.loadFormFromXML(cdiWrapper.getIOService().readAllString(visitedPath));
FormMigrationSummary summary = new FormMigrationSummary(new Resource<>(legacyForm, visitedVFSPath));
// Trying to lookup new form with same name!
String newFormFileName = fileName.substring(0, fileName.lastIndexOf(".") - 1) + FormsMigrationConstants.NEW_FOMRS_EXTENSION;
org.uberfire.java.nio.file.Path newFormPath = visitedPath.getParent().resolve(newFormFileName);
if (cdiWrapper.getIOService().exists(newFormPath)) {
Resource<FormDefinition> newFormResource = new Resource<>(cdiWrapper.getFormDefinitionSerializer().deserialize(cdiWrapper.getIOService().readAllString(newFormPath)), Paths.convert(newFormPath));
summary.setNewFormResource(newFormResource);
}
summaries.add(summary);
} catch (Exception e) {
system.err().println("Error reading form: " + fileName + ":\n");
e.printStackTrace(system.err());
}
}
}
return FileVisitResult.CONTINUE;
}
});
system.console().format("\nProcessing module %s: %s forms found\n", workspaceProject.getName(), summaries.size());
MigrationContext context = new MigrationContext(workspaceProject, weldContainer, cdiWrapper, system, summaries);
pipeline.migrate(context);
}
use of org.uberfire.java.nio.file.FileVisitResult in project kie-wb-common by kiegroup.
the class BPMNFormAdapter method readWorkspaceBPMNModels.
protected void readWorkspaceBPMNModels() {
BPMNAnalyzer analyzer = new BPMNAnalyzer();
Files.walkFileTree(Paths.convert(migrationContext.getWorkspaceProject().getRootPath()), new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(org.uberfire.java.nio.file.Path visitedPath, BasicFileAttributes attrs) throws IOException {
org.uberfire.backend.vfs.Path visitedVFSPath = Paths.convert(visitedPath);
String fileName = visitedVFSPath.getFileName();
File file = visitedPath.toFile();
if (file.isFile()) {
if (fileName.endsWith("." + FormsMigrationConstants.BPMN_EXTENSION) || fileName.endsWith("." + FormsMigrationConstants.BPMN2_EXTENSION)) {
try {
BPMNProcess process = analyzer.read(migrationContext.getCDIWrapper().getIOService().newInputStream(visitedPath));
if (process != null) {
workspaceBPMNFormModels.addAll(process.getFormModels());
} else {
migrationContext.getSystem().console().format(FormsMigrationConstants.BPMN_PARSING_ERROR, FormsMigrationConstants.WARNING, fileName);
}
} catch (Exception ex) {
migrationContext.getSystem().console().format(FormsMigrationConstants.BPMN_PARSING_ERROR, FormsMigrationConstants.WARNING, fileName);
}
}
}
return FileVisitResult.CONTINUE;
}
});
}
Aggregations