Search in sources :

Example 1 with BasicFileAttributes

use of org.uberfire.java.nio.file.attribute.BasicFileAttributes 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() && isBPMNFile(fileName)) {
                try {
                    BPMNProcess process = analyzer.read(migrationContext.getMigrationServicesCDIWrapper().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;
        }
    });
}
Also used : Path(org.uberfire.java.nio.file.Path) BPMNProcess(org.kie.workbench.common.forms.migration.tool.bpmn.BPMNProcess) Path(org.uberfire.java.nio.file.Path) FileVisitResult(org.uberfire.java.nio.file.FileVisitResult) IOException(org.uberfire.java.nio.IOException) IOException(org.uberfire.java.nio.IOException) BPMNAnalyzer(org.kie.workbench.common.forms.migration.tool.bpmn.BPMNAnalyzer) File(java.io.File) BasicFileAttributes(org.uberfire.java.nio.file.attribute.BasicFileAttributes)

Example 2 with BasicFileAttributes

use of org.uberfire.java.nio.file.attribute.BasicFileAttributes 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(migrationServicesCDIWrapper.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 (migrationServicesCDIWrapper.getIOService().exists(newFormPath)) {
                            Resource<FormDefinition> newFormResource = new Resource<>(formMigrationServicesCDIWrapper.getFormDefinitionSerializer().deserialize(migrationServicesCDIWrapper.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());
    if (summaries.size() > 0) {
        MigrationContext context = new MigrationContext(workspaceProject, weldContainer, formMigrationServicesCDIWrapper, system, summaries, migrationServicesCDIWrapper);
        pipeline.migrate(context);
    }
}
Also used : Path(java.nio.file.Path) MigrationContext(org.kie.workbench.common.forms.migration.tool.pipelines.MigrationContext) Form(org.kie.workbench.common.forms.migration.legacy.model.Form) ArrayList(java.util.ArrayList) FileVisitResult(org.uberfire.java.nio.file.FileVisitResult) IOException(org.uberfire.java.nio.IOException) IOException(org.uberfire.java.nio.IOException) File(java.io.File) BasicFileAttributes(org.uberfire.java.nio.file.attribute.BasicFileAttributes)

Example 3 with BasicFileAttributes

use of org.uberfire.java.nio.file.attribute.BasicFileAttributes in project kie-wb-common by kiegroup.

the class PomMigrationTool method processWorkspaceProject.

private void processWorkspaceProject(WorkspaceProject workspaceProject, String jsonPath, MigrationServicesCDIWrapper cdiWrapper) {
    if (systemMigrationWasExecuted(cdiWrapper)) {
        PomMigrationEditor editor = new PomMigrationEditor();
        final int[] counter = { 0 };
        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() && fileName.equals(POM_DOT_XML)) {
                    try {
                        Model model;
                        if (jsonPath.isEmpty()) {
                            model = editor.updatePom(visitedPath, cdiWrapper);
                        } else {
                            model = editor.updatePom(visitedPath, jsonPath, cdiWrapper);
                        }
                        if (!model.getBuild().getPlugins().isEmpty()) {
                            counter[0]++;
                        }
                    } catch (Exception e) {
                        system.err().println("Error reading from filename [" + fileName + "] (error below).");
                        e.printStackTrace(system.err());
                    }
                }
                return FileVisitResult.CONTINUE;
            }
        });
        system.out().println("Migrated " + counter[0] + " POMs for project: " + workspaceProject.getName());
    }
}
Also used : PomMigrationEditor(org.kie.workbench.common.project.migration.cli.maven.PomMigrationEditor) FileVisitResult(org.uberfire.java.nio.file.FileVisitResult) IOException(org.uberfire.java.nio.IOException) IOException(org.uberfire.java.nio.IOException) Model(org.apache.maven.model.Model) File(java.io.File) BasicFileAttributes(org.uberfire.java.nio.file.attribute.BasicFileAttributes)

Example 4 with BasicFileAttributes

use of org.uberfire.java.nio.file.attribute.BasicFileAttributes in project kie-wb-common by kiegroup.

the class AbstractVFSDiagramServiceTest method testGetAll.

@Test
public void testGetAll() {
    ArgumentCaptor<SimpleFileVisitor> visitorArgumentCaptor = ArgumentCaptor.forClass(SimpleFileVisitor.class);
    org.uberfire.java.nio.file.Path root = mock(org.uberfire.java.nio.file.Path.class);
    D diagram = mockDiagram();
    List<Pair<Path, org.uberfire.java.nio.file.Path>> visitedPaths = new ArrayList<>();
    for (int i = 0; i < 10; i++) {
        Path diagramPath = mock(Path.class);
        org.uberfire.java.nio.file.Path nioDiagramPath = mock(org.uberfire.java.nio.file.Path.class);
        doReturn(nioDiagramPath).when(diagramService).convertToNioPath(diagramPath);
        doReturn(diagramPath).when(diagramService).convertToBackendPath(nioDiagramPath);
        visitedPaths.add(new Pair<>(diagramPath, nioDiagramPath));
        when(resourceType.accept(diagramPath)).thenReturn(true);
        doReturn(diagram).when(diagramService).getDiagramByPath(diagramPath);
    }
    BasicFileAttributes attrs = mock(BasicFileAttributes.class);
    when(ioService.exists(root)).thenReturn(true);
    doNothing().when(diagramService).walkFileTree(eq(root), visitorArgumentCaptor.capture());
    diagramService.getDiagramsByPath(root);
    visitedPaths.forEach(pair -> {
        visitorArgumentCaptor.getValue().visitFile(pair.getK2(), attrs);
        verify(diagramService, times(1)).getDiagramByPath(pair.getK1());
    });
}
Also used : Path(org.uberfire.backend.vfs.Path) SimpleFileVisitor(org.uberfire.java.nio.file.SimpleFileVisitor) UUID(org.kie.workbench.common.stunner.core.util.UUID) ArrayList(java.util.ArrayList) BasicFileAttributes(org.uberfire.java.nio.file.attribute.BasicFileAttributes) Pair(org.uberfire.commons.data.Pair) Test(org.junit.Test)

Aggregations

BasicFileAttributes (org.uberfire.java.nio.file.attribute.BasicFileAttributes)4 File (java.io.File)3 IOException (org.uberfire.java.nio.IOException)3 FileVisitResult (org.uberfire.java.nio.file.FileVisitResult)3 ArrayList (java.util.ArrayList)2 Path (java.nio.file.Path)1 Model (org.apache.maven.model.Model)1 Test (org.junit.Test)1 Form (org.kie.workbench.common.forms.migration.legacy.model.Form)1 BPMNAnalyzer (org.kie.workbench.common.forms.migration.tool.bpmn.BPMNAnalyzer)1 BPMNProcess (org.kie.workbench.common.forms.migration.tool.bpmn.BPMNProcess)1 MigrationContext (org.kie.workbench.common.forms.migration.tool.pipelines.MigrationContext)1 PomMigrationEditor (org.kie.workbench.common.project.migration.cli.maven.PomMigrationEditor)1 UUID (org.kie.workbench.common.stunner.core.util.UUID)1 Path (org.uberfire.backend.vfs.Path)1 Pair (org.uberfire.commons.data.Pair)1 Path (org.uberfire.java.nio.file.Path)1 SimpleFileVisitor (org.uberfire.java.nio.file.SimpleFileVisitor)1