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