use of org.uberfire.backend.vfs.Path in project kie-wb-common by kiegroup.
the class AbstractDefEditorService method create.
protected Path create(final D def, final Path context) {
checkNotNull("def", def);
checkNotNull("context", context);
if (def.getUuid() == null) {
def.setUuid(UUIDGenerator.generateUUID());
}
String fileName = buildFileName(def);
String content = serializeDef(def);
final org.uberfire.java.nio.file.Path nioPath = Paths.convert(context).resolve(fileName);
final Path newPath = Paths.convert(nioPath);
if (ioService.exists(nioPath)) {
throw new FileAlreadyExistsException(nioPath.toString());
}
try {
ioService.startBatch(nioPath.getFileSystem());
// create the file.
ioService.write(nioPath, content, optionsFactory.makeCommentedOption(""));
serviceHelper.getDefRegistry().setEntry(newPath, def);
} catch (Exception e) {
logger.error("It was not possible to create: " + def.getName(), e);
ioService.endBatch();
throw ExceptionUtilities.handleException(e);
}
try {
// proceed with the deployment
deploy(def, DeploymentOptions.create());
} catch (Exception e1) {
logger.error("It was not possible to create: " + def.getName(), e1);
serviceHelper.getDefRegistry().invalidateCache(newPath);
// the file was created, but the deployment failed.
try {
ioService.delete(nioPath);
} catch (Exception e2) {
logger.warn("Removal of orphan definition file failed: " + newPath, e2);
}
throw ExceptionUtilities.handleException(e1);
} finally {
ioService.endBatch();
}
return newPath;
}
use of org.uberfire.backend.vfs.Path in project kie-wb-common by kiegroup.
the class AbstractDefEditorService method createGlobal.
public Path createGlobal(final D def) {
checkNotNull("def", def);
Path context = serviceHelper.getGlobalDataSourcesContext();
Path newPath = create(def, context);
fireCreateEvent(def);
return newPath;
}
use of org.uberfire.backend.vfs.Path in project kie-wb-common by kiegroup.
the class AbstractDefEditorService method create.
public Path create(final D def, final Module module) {
checkNotNull("def", def);
checkNotNull("module", module);
Path context = serviceHelper.getModuleDataSourcesContext(module);
Path newPath = create(def, context);
fireCreateEvent(def, module);
return newPath;
}
use of org.uberfire.backend.vfs.Path in project kie-wb-common by kiegroup.
the class AbstractDefEditorService method save.
public Path save(final Path path, final C editorContent, final String comment) {
checkNotNull("path", path);
checkNotNull("content", editorContent);
Path newPath = path;
boolean onBatch = false;
try {
final D originalDef = deserializeDef(ioService.readAllString(Paths.convert(path)));
final String content = serializeDef(editorContent.getDef());
I deploymentInfo = readDeploymentInfo(editorContent.getDef().getUuid());
if (deploymentInfo != null) {
unDeploy(deploymentInfo, UnDeploymentOptions.forcedUnDeployment());
}
deploy(editorContent.getDef(), DeploymentOptions.create());
final org.uberfire.java.nio.file.Path _path = Paths.convert(path);
ioService.startBatch(_path.getFileSystem());
onBatch = true;
serviceHelper.getDefRegistry().invalidateCache(path);
ioService.write(_path, content, optionsFactory.makeCommentedOption(comment));
if (originalDef.getName() != null && !originalDef.getName().equals(editorContent.getDef().getName())) {
final org.uberfire.java.nio.file.Path _target = Paths.convert(pathNamingService.buildTargetPath(path, editorContent.getDef().getName()));
ioService.move(_path, _target, optionsFactory.makeCommentedOption(comment));
newPath = Paths.convert(_target);
}
serviceHelper.getDefRegistry().setEntry(newPath, editorContent.getDef());
fireUpdateEvent(editorContent.getDef(), editorContent.getModule(), originalDef);
} catch (Exception e) {
throw ExceptionUtilities.handleException(e);
} finally {
if (onBatch) {
ioService.endBatch();
}
}
return newPath;
}
use of org.uberfire.backend.vfs.Path in project kie-wb-common by kiegroup.
the class AddBranchPopUpPresenterTest method makeBranch.
private Branch makeBranch(final String branchName, final String repoName) {
final Path path = mock(Path.class);
doReturn("default://" + branchName + "@" + repoName + "/").when(path).toURI();
return new Branch(branchName, path);
}
Aggregations