Search in sources :

Example 31 with Path

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;
}
Also used : Path(org.uberfire.backend.vfs.Path) FileAlreadyExistsException(org.uberfire.java.nio.file.FileAlreadyExistsException) FileAlreadyExistsException(org.uberfire.java.nio.file.FileAlreadyExistsException)

Example 32 with Path

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;
}
Also used : Path(org.uberfire.backend.vfs.Path)

Example 33 with Path

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;
}
Also used : Path(org.uberfire.backend.vfs.Path)

Example 34 with Path

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;
}
Also used : Path(org.uberfire.backend.vfs.Path) FileAlreadyExistsException(org.uberfire.java.nio.file.FileAlreadyExistsException)

Example 35 with Path

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);
}
Also used : Path(org.uberfire.backend.vfs.Path) Branch(org.guvnor.structure.repositories.Branch)

Aggregations

Path (org.uberfire.backend.vfs.Path)607 Test (org.junit.Test)408 URL (java.net.URL)93 Package (org.guvnor.common.services.project.model.Package)87 KieModuleService (org.kie.workbench.common.services.shared.project.KieModuleService)71 CreationalContext (javax.enterprise.context.spi.CreationalContext)66 Bean (javax.enterprise.inject.spi.Bean)66 ArrayList (java.util.ArrayList)63 Metadata (org.guvnor.common.services.shared.metadata.model.Metadata)51 Module (org.guvnor.common.services.project.model.Module)48 WorkspaceProject (org.guvnor.common.services.project.model.WorkspaceProject)41 KieModule (org.kie.workbench.common.services.shared.project.KieModule)38 List (java.util.List)37 NotificationEvent (org.uberfire.workbench.events.NotificationEvent)30 Branch (org.guvnor.structure.repositories.Branch)29 HashMap (java.util.HashMap)28 FileAlreadyExistsException (org.uberfire.java.nio.file.FileAlreadyExistsException)28 ObservablePath (org.uberfire.backend.vfs.ObservablePath)27 GuidedDecisionTable52 (org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52)25 Before (org.junit.Before)25