Search in sources :

Example 6 with FileAlreadyExistsException

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

the class DRLTextEditorServiceImpl method create.

@Override
public Path create(final Path context, final String fileName, final String content, final String comment) {
    try {
        final String drl = assertPackageName(content, context);
        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, drl, 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 7 with FileAlreadyExistsException

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

the class GuidedDecisionTreeEditorServiceImpl method create.

@Override
public Path create(final Path context, final String fileName, final GuidedDecisionTree 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, GuidedDecisionTreeDRLPersistence.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 8 with FileAlreadyExistsException

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

the class GuidedRuleEditorServiceImpl method create.

@Override
public Path create(final Path context, final String fileName, final RuleModel model, final String comment) {
    try {
        final Package pkg = moduleService.resolvePackage(context);
        final String packageName = (pkg == null ? null : pkg.getPackageName());
        model.setPackageName(packageName);
        // Temporal fix for https://bugzilla.redhat.com/show_bug.cgi?id=998922
        model.getImports().addImport(new Import("java.lang.Number"));
        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, toSource(newPath, model), 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) Import(org.kie.soup.project.datamodel.imports.Import) Package(org.guvnor.common.services.project.model.Package) FileAlreadyExistsException(org.uberfire.java.nio.file.FileAlreadyExistsException)

Example 9 with FileAlreadyExistsException

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

the class GuidedScoreCardEditorServiceImpl method create.

@Override
public Path create(final Path context, final String fileName, final ScoreCardModel 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, GuidedScoreCardXMLPersistence.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) SourceGenerationFailedException(org.kie.workbench.common.services.shared.source.SourceGenerationFailedException) FileAlreadyExistsException(org.uberfire.java.nio.file.FileAlreadyExistsException)

Example 10 with FileAlreadyExistsException

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

the class GuidedDecisionTableEditorServiceImpl method create.

@Override
public Path create(final Path context, final String fileName, final GuidedDecisionTable52 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, GuidedDTXMLPersistence.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)

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