Search in sources :

Example 1 with IOException

use of org.uberfire.java.nio.IOException 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);
}
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 2 with IOException

use of org.uberfire.java.nio.IOException 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;
        }
    });
}
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 3 with IOException

use of org.uberfire.java.nio.IOException in project kie-wb-common by kiegroup.

the class ServerTemplateMigration method migrate.

public static void migrate(Path dir, IOService ioService, XStream xs, KieServerTemplateStorage templateStorage) {
    logger.debug("Attempting to find and migrate 6.2 type kie server templates inside directory '{}'...", dir);
    try {
        ioService.startBatch(dir.getFileSystem());
        for (final Path path : ioService.newDirectoryStream(dir, new DirectoryStream.Filter<Path>() {

            @Override
            public boolean accept(Path entry) throws IOException {
                return entry.toString().endsWith("-info.xml");
            }
        })) {
            logger.debug("Found 6.2 type kie server template file '{}', migrating it...", path);
            try {
                final KieServerInstance kieServerInstance = (KieServerInstance) xs.fromXML(ioService.readAllString(path));
                logger.debug("Loaded KieServerInstance {}", kieServerInstance);
                ServerTemplate serverTemplate = new ServerTemplate();
                serverTemplate.setId(kieServerInstance.getIdentifier());
                serverTemplate.setName(kieServerInstance.getName());
                KieServerSetup serverSetup = kieServerInstance.getKieServerSetup();
                if (serverSetup != null) {
                    Set<KieContainerResource> containerResources = kieServerInstance.getKieServerSetup().getContainers();
                    logger.debug("Server with id {} has containers {}", kieServerInstance.getIdentifier(), containerResources);
                    if (containerResources != null) {
                        for (KieContainerResource containerRef : containerResources) {
                            ContainerSpec containerSpec = new ContainerSpec(containerRef.getContainerId(), containerRef.getContainerId(), serverTemplate, containerRef.getReleaseId(), containerRef.getStatus(), new HashMap<Capability, ContainerConfig>());
                            logger.debug("Migrating container '{}' to container spec '{}'", containerRef, containerSpec);
                            serverTemplate.addContainerSpec(containerSpec);
                        }
                    }
                }
                Set<KieServerInstanceInfo> instanceInfos = kieServerInstance.getManagedInstances();
                if (instanceInfos != null) {
                    logger.debug("Server with id {} has server instances {}", kieServerInstance.getIdentifier(), instanceInfos);
                    for (KieServerInstanceInfo instanceInfo : instanceInfos) {
                        logger.debug("Migrating server instance '{}'", instanceInfo);
                        serverTemplate.addServerInstance(ModelFactory.newServerInstanceKey(serverTemplate.getId(), instanceInfo.getLocation()));
                        serverTemplate.setCapabilities(instanceInfo.getCapabilities());
                    }
                }
                logger.debug("About to store migrated server template {}", serverTemplate);
                // store migrated information
                templateStorage.store(serverTemplate);
                logger.info("Server template {} migrated successfully, removing old version...", serverTemplate);
                // delete old to do not attempt second time migration
                try {
                    ioService.startBatch(path.getFileSystem());
                    ioService.delete(path);
                } finally {
                    ioService.endBatch();
                }
                logger.debug("Old version of server template '{}' has been removed", kieServerInstance);
            } catch (Exception ex) {
                logger.error("Error while migrating old version (6.2.) of kie server instance from path {}", path, ex);
            }
        }
    } catch (final NotDirectoryException ignore) {
        logger.debug("No directory found, ignoring migration of kie server templates");
    } finally {
        ioService.endBatch();
    }
}
Also used : Path(org.uberfire.java.nio.file.Path) KieServerSetup(org.kie.server.controller.api.model.KieServerSetup) Capability(org.kie.server.controller.api.model.spec.Capability) ContainerSpec(org.kie.server.controller.api.model.spec.ContainerSpec) DirectoryStream(org.uberfire.java.nio.file.DirectoryStream) IOException(org.uberfire.java.nio.IOException) NotDirectoryException(org.uberfire.java.nio.file.NotDirectoryException) IOException(org.uberfire.java.nio.IOException) ContainerConfig(org.kie.server.controller.api.model.spec.ContainerConfig) NotDirectoryException(org.uberfire.java.nio.file.NotDirectoryException) KieServerInstance(org.kie.server.controller.api.model.KieServerInstance) KieServerInstanceInfo(org.kie.server.controller.api.model.KieServerInstanceInfo) ServerTemplate(org.kie.server.controller.api.model.spec.ServerTemplate) KieContainerResource(org.kie.server.api.model.KieContainerResource)

Example 4 with IOException

use of org.uberfire.java.nio.IOException in project kie-wb-common by kiegroup.

the class DataModelerServiceHelper method resolvePackages.

public Set<String> resolvePackages(final KieModule project) {
    final Set<String> packages = new HashSet<String>();
    final Path rootPath = Paths.convert(project.getRootPath());
    final String[] subdirs = ModuleResourcePaths.MAIN_SRC_PATH.split("/");
    Path javaDir = rootPath;
    // ensure rout to java files exists
    for (String subdir : subdirs) {
        javaDir = javaDir.resolve(subdir);
        if (!ioService.exists(javaDir)) {
            javaDir = null;
            break;
        }
    }
    if (javaDir == null) {
        // uncommon case
        return packages;
    }
    final String javaDirURI = javaDir.toUri().toString();
    // path to java directory has been calculated, now visit the subdirectories to get the package names.
    final List<Path> childDirectories = new ArrayList<Path>();
    childDirectories.add(javaDir);
    Path subDir;
    while (childDirectories.size() > 0) {
        final DirectoryStream<Path> dirStream = ioService.newDirectoryStream(childDirectories.remove(0), new DirectoryStream.Filter<Path>() {

            @Override
            public boolean accept(final Path entry) throws IOException {
                return Files.isDirectory(entry);
            }
        });
        Iterator<Path> it = dirStream.iterator();
        while (it != null && it.hasNext()) {
            // visit this directory
            subDir = it.next();
            childDirectories.add(subDir);
            // store this package name
            packages.add(getPackagePart(javaDirURI, subDir));
        }
        dirStream.close();
    }
    return packages;
}
Also used : Path(org.uberfire.java.nio.file.Path) ArrayList(java.util.ArrayList) DirectoryStream(org.uberfire.java.nio.file.DirectoryStream) IOException(org.uberfire.java.nio.IOException) HashSet(java.util.HashSet)

Example 5 with IOException

use of org.uberfire.java.nio.IOException in project kie-wb-common by kiegroup.

the class ExamplesServiceImpl method setupExamples.

@Override
public WorkspaceProjectContextChangeEvent setupExamples(final ExampleOrganizationalUnit exampleTargetOU, final List<ExampleProject> exampleProjects) {
    PortablePreconditions.checkNotNull("exampleTargetOU", exampleTargetOU);
    PortablePreconditions.checkNotNull("exampleProjects", exampleProjects);
    PortablePreconditions.checkCondition("Must have at least one ExampleProject", exampleProjects.size() > 0);
    // Retrieve or create Organizational Unit
    final String targetOUName = exampleTargetOU.getName();
    final OrganizationalUnit targetOU = getOrganizationalUnit(targetOUName);
    WorkspaceProject firstExampleProject = null;
    for (final ExampleProject exampleProject : exampleProjects) {
        try {
            final Repository targetRepository = repositoryCopier.copy(targetOU, exampleProject.getName(), exampleProject.getRoot());
            // Signal creation of new Project (Creation of OU and Repository, if applicable,
            // are already handled in the corresponding services).
            WorkspaceProject project = projectService.resolveProject(targetRepository);
            project = renameIfNecessary(targetOU, project);
            newProjectEvent.fire(new NewProjectEvent(project));
            // Store first new example project
            if (firstExampleProject == null) {
                firstExampleProject = project;
            }
        } catch (IOException ioe) {
            logger.error("Unable to create Example(s).", ioe);
        }
    }
    return new WorkspaceProjectContextChangeEvent(firstExampleProject, firstExampleProject.getMainModule());
}
Also used : NewProjectEvent(org.guvnor.common.services.project.events.NewProjectEvent) ExampleRepository(org.kie.workbench.common.screens.examples.model.ExampleRepository) Repository(org.guvnor.structure.repositories.Repository) GitRepository(org.guvnor.structure.repositories.impl.git.GitRepository) OrganizationalUnit(org.guvnor.structure.organizationalunit.OrganizationalUnit) ExampleOrganizationalUnit(org.kie.workbench.common.screens.examples.model.ExampleOrganizationalUnit) WorkspaceProject(org.guvnor.common.services.project.model.WorkspaceProject) IOException(org.uberfire.java.nio.IOException) WorkspaceProjectContextChangeEvent(org.guvnor.common.services.project.context.WorkspaceProjectContextChangeEvent) ExampleProject(org.kie.workbench.common.screens.examples.model.ExampleProject)

Aggregations

IOException (org.uberfire.java.nio.IOException)7 Path (org.uberfire.java.nio.file.Path)4 DirectoryStream (org.uberfire.java.nio.file.DirectoryStream)3 File (java.io.File)2 ArrayList (java.util.ArrayList)2 FileVisitResult (org.uberfire.java.nio.file.FileVisitResult)2 BasicFileAttributes (org.uberfire.java.nio.file.attribute.BasicFileAttributes)2 Path (java.nio.file.Path)1 HashSet (java.util.HashSet)1 WorkspaceProjectContextChangeEvent (org.guvnor.common.services.project.context.WorkspaceProjectContextChangeEvent)1 NewProjectEvent (org.guvnor.common.services.project.events.NewProjectEvent)1 WorkspaceProject (org.guvnor.common.services.project.model.WorkspaceProject)1 OrganizationalUnit (org.guvnor.structure.organizationalunit.OrganizationalUnit)1 Repository (org.guvnor.structure.repositories.Repository)1 GitRepository (org.guvnor.structure.repositories.impl.git.GitRepository)1 Test (org.junit.Test)1 KieContainerResource (org.kie.server.api.model.KieContainerResource)1 KieServerInstance (org.kie.server.controller.api.model.KieServerInstance)1 KieServerInstanceInfo (org.kie.server.controller.api.model.KieServerInstanceInfo)1 KieServerSetup (org.kie.server.controller.api.model.KieServerSetup)1