Search in sources :

Example 6 with MigrationContext

use of org.kie.workbench.common.forms.migration.tool.pipelines.MigrationContext in project kie-wb-common by kiegroup.

the class FormDefinitionGeneratorWithUnsupportedFieldsTest method doInit.

@Override
protected void doInit() throws Exception {
    List<FormMigrationSummary> summaries = new ArrayList<>();
    initForm(form -> userForm = form, DATAOBJECTS_RESOURCES, USER_WITH_UNSUPPORTED_FIELDS, userFormPath);
    summaries.add(new FormMigrationSummary(new Resource<>(userForm, userFormPath)));
    context = new MigrationContext(workspaceProject, weldContainer, migrationServicesCDIWrapper, new RealSystemAccess(), summaries);
}
Also used : MigrationContext(org.kie.workbench.common.forms.migration.tool.pipelines.MigrationContext) RealSystemAccess(org.kie.workbench.common.migration.cli.RealSystemAccess) FormMigrationSummary(org.kie.workbench.common.forms.migration.tool.FormMigrationSummary) ArrayList(java.util.ArrayList) Resource(org.kie.workbench.common.forms.migration.tool.Resource)

Example 7 with MigrationContext

use of org.kie.workbench.common.forms.migration.tool.pipelines.MigrationContext 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)

Aggregations

ArrayList (java.util.ArrayList)7 MigrationContext (org.kie.workbench.common.forms.migration.tool.pipelines.MigrationContext)7 FormMigrationSummary (org.kie.workbench.common.forms.migration.tool.FormMigrationSummary)6 Resource (org.kie.workbench.common.forms.migration.tool.Resource)6 RealSystemAccess (org.kie.workbench.common.migration.cli.RealSystemAccess)6 File (java.io.File)1 Path (java.nio.file.Path)1 Form (org.kie.workbench.common.forms.migration.legacy.model.Form)1 IOException (org.uberfire.java.nio.IOException)1 FileVisitResult (org.uberfire.java.nio.file.FileVisitResult)1 BasicFileAttributes (org.uberfire.java.nio.file.attribute.BasicFileAttributes)1