Search in sources :

Example 1 with FileAlreadyExistsException

use of org.uberfire.java.nio.file.FileAlreadyExistsException in project drools-wb by kiegroup.

the class GuidedRuleTemplateEditorServiceImpl method create.

public Path create(final Path context, final String fileName, final TemplateModel content, final String comment) {
    try {
        final Package pkg = moduleService.resolvePackage(context);
        final String packageName = (pkg == null ? null : pkg.getPackageName());
        content.setPackageName(packageName);
        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());
        }
        ioService.write(nioPath, RuleTemplateModelXMLPersistenceImpl.getInstance().marshal(content), commentedOptionFactory.makeCommentedOption(comment));
        return newPath;
    } catch (Exception e) {
        throw ExceptionUtilities.handleException(e);
    }
}
Also used : Path(org.uberfire.backend.vfs.Path) FileAlreadyExistsException(org.uberfire.java.nio.file.FileAlreadyExistsException) Package(org.guvnor.common.services.project.model.Package) FileAlreadyExistsException(org.uberfire.java.nio.file.FileAlreadyExistsException)

Example 2 with FileAlreadyExistsException

use of org.uberfire.java.nio.file.FileAlreadyExistsException in project drools-wb by kiegroup.

the class WorkItemsEditorServiceImpl method create.

@Override
public Path create(final Path context, final String fileName, final String content, final String comment) {
    try {
        // Get the template for new Work Item Definitions, stored as a configuration item
        String defaultDefinition = workItemDefinitionElements.getDefinitionElements().get(WORK_ITEMS_EDITOR_SETTINGS_DEFINITION);
        if (defaultDefinition == null) {
            defaultDefinition = "";
        }
        defaultDefinition = defaultDefinition.replaceAll("\\|", "");
        // Write file to VFS
        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());
        }
        ioService.write(nioPath, defaultDefinition, commentedOptionFactory.makeCommentedOption(comment));
        return newPath;
    } catch (Exception e) {
        throw ExceptionUtilities.handleException(e);
    }
}
Also used : Path(org.uberfire.backend.vfs.Path) FileAlreadyExistsException(org.uberfire.java.nio.file.FileAlreadyExistsException) FileAlreadyExistsException(org.uberfire.java.nio.file.FileAlreadyExistsException)

Example 3 with FileAlreadyExistsException

use of org.uberfire.java.nio.file.FileAlreadyExistsException in project drools-wb by kiegroup.

the class ScenarioTestEditorServiceImplTest method testCreateAlreadyExists.

@Test
public void testCreateAlreadyExists() throws Exception {
    final Path scenarioPath = getEmptyScenarioPath();
    doReturn(true).when(ioService).exists(Paths.convert(scenarioPath).resolve(EMPTY_SCENARIO_FILENAME));
    try {
        testEditorService.create(scenarioPath, EMPTY_SCENARIO_FILENAME, scenario, COMMENT);
    } catch (FileAlreadyExistsException e) {
        // ok
        verify(ioService, never()).write(any(), anyString(), any());
    }
}
Also used : Path(org.uberfire.backend.vfs.Path) FileAlreadyExistsException(org.uberfire.java.nio.file.FileAlreadyExistsException) Test(org.junit.Test)

Example 4 with FileAlreadyExistsException

use of org.uberfire.java.nio.file.FileAlreadyExistsException in project drools-wb by kiegroup.

the class GuidedDecisionTableGraphEditorServiceImpl method create.

@Override
public Path create(final Path context, final String fileName, final GuidedDecisionTableEditorGraphModel model, final String comment) {
    try {
        final org.uberfire.java.nio.file.Path nioPath = Paths.convert(context).resolve(fileName);
        if (ioService.exists(nioPath)) {
            throw new FileAlreadyExistsException(nioPath.toString());
        }
        final Set<Path> paths = getLinkedDecisionTablesInPackage(context);
        paths.forEach((path) -> model.getEntries().add(new GuidedDecisionTableEditorGraphModel.GuidedDecisionTableGraphEntry(path, getLatestVersionPath(path))));
        ioService.write(nioPath, GuidedDTGraphXMLPersistence.getInstance().marshal(model), commentedOptionFactory.makeCommentedOption(comment));
        final Path newPath = Paths.convert(nioPath);
        return newPath;
    } catch (Exception e) {
        throw ExceptionUtilities.handleException(e);
    }
}
Also used : Path(org.uberfire.backend.vfs.Path) FileAlreadyExistsException(org.uberfire.java.nio.file.FileAlreadyExistsException) FileAlreadyExistsException(org.uberfire.java.nio.file.FileAlreadyExistsException)

Example 5 with FileAlreadyExistsException

use of org.uberfire.java.nio.file.FileAlreadyExistsException in project drools-wb by kiegroup.

the class EnumServiceImpl method create.

@Override
public Path create(final Path context, final String fileName, final String content, final String comment) {
    try {
        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());
        }
        ioService.write(nioPath, content, commentedOptionFactory.makeCommentedOption(comment));
        return newPath;
    } catch (Exception e) {
        throw ExceptionUtilities.handleException(e);
    }
}
Also used : Path(org.uberfire.backend.vfs.Path) FileAlreadyExistsException(org.uberfire.java.nio.file.FileAlreadyExistsException) FileAlreadyExistsException(org.uberfire.java.nio.file.FileAlreadyExistsException)

Aggregations

Path (org.uberfire.backend.vfs.Path)13 FileAlreadyExistsException (org.uberfire.java.nio.file.FileAlreadyExistsException)13 Package (org.guvnor.common.services.project.model.Package)6 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 DSLMappingParseException (org.drools.compiler.lang.dsl.DSLMappingParseException)1 Metadata (org.guvnor.common.services.shared.metadata.model.Metadata)1 Test (org.junit.Test)1 Import (org.kie.soup.project.datamodel.imports.Import)1 SourceGenerationFailedException (org.kie.workbench.common.services.shared.source.SourceGenerationFailedException)1