Search in sources :

Example 1 with FileExistsException

use of org.pentaho.di.plugins.fileopensave.api.providers.exception.FileExistsException in project pentaho-kettle by pentaho.

the class RepositoryFileProvider method add.

@Override
public RepositoryFile add(RepositoryFile folder) throws FileException {
    if (hasDupeFolder(folder.getParent(), folder.getName())) {
        throw new FileExistsException();
    }
    try {
        RepositoryDirectoryInterface repositoryDirectoryInterface = getRepository().createRepositoryDirectory(findDirectory(folder.getParent()), folder.getName());
        RepositoryDirectory repositoryDirectory = new RepositoryDirectory();
        repositoryDirectory.setName(repositoryDirectoryInterface.getName());
        repositoryDirectory.setPath(repositoryDirectoryInterface.getPath());
        repositoryDirectory.setObjectId(repositoryDirectoryInterface.getObjectId().getId());
        repositoryDirectory.setParent(folder.getParent());
        return RepositoryDirectory.build(folder.getPath(), repositoryDirectoryInterface);
    } catch (Exception e) {
        return null;
    }
}
Also used : RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) RepositoryDirectory(org.pentaho.di.plugins.fileopensave.providers.repository.model.RepositoryDirectory) KettleException(org.pentaho.di.core.exception.KettleException) InvalidFileTypeException(org.pentaho.di.plugins.fileopensave.api.providers.exception.InvalidFileTypeException) FileException(org.pentaho.di.plugins.fileopensave.api.providers.exception.FileException) KettleObjectExistsException(org.pentaho.di.core.exception.KettleObjectExistsException) KettleTransException(org.pentaho.di.core.exception.KettleTransException) KettleJobException(org.pentaho.di.core.exception.KettleJobException) InvalidFileOperationException(org.pentaho.di.plugins.fileopensave.api.providers.exception.InvalidFileOperationException) FileExistsException(org.pentaho.di.plugins.fileopensave.api.providers.exception.FileExistsException) FileExistsException(org.pentaho.di.plugins.fileopensave.api.providers.exception.FileExistsException)

Example 2 with FileExistsException

use of org.pentaho.di.plugins.fileopensave.api.providers.exception.FileExistsException in project pentaho-kettle by pentaho.

the class FileController method add.

public Result add(File folder) {
    try {
        FileProvider<File> fileProvider = providerService.get(folder.getProvider());
        File newFile = fileProvider.add(folder);
        if (newFile != null) {
            fileCache.addFile(fileProvider.getParent(folder), newFile);
            return Result.success("", newFile);
        } else {
            return Result.error("Unable to create folder", folder);
        }
    } catch (FileExistsException fee) {
        return Result.fileCollision("", folder);
    } catch (FileException | InvalidFileProviderException fe) {
        return Result.error("", folder);
    }
}
Also used : FileException(org.pentaho.di.plugins.fileopensave.api.providers.exception.FileException) File(org.pentaho.di.plugins.fileopensave.api.providers.File) InvalidFileProviderException(org.pentaho.di.plugins.fileopensave.api.providers.exception.InvalidFileProviderException) FileExistsException(org.pentaho.di.plugins.fileopensave.api.providers.exception.FileExistsException)

Example 3 with FileExistsException

use of org.pentaho.di.plugins.fileopensave.api.providers.exception.FileExistsException in project pentaho-kettle by pentaho.

the class LocalFileProvider method add.

/**
 * @param folder
 * @return
 */
@Override
public LocalFile add(LocalFile folder) throws FileException {
    Path folderPath = Paths.get(folder.getPath());
    if (folderPath.toFile().exists()) {
        throw new FileExistsException();
    }
    try {
        Path newPath = Files.createDirectories(Paths.get(folder.getPath()));
        LocalDirectory localDirectory = new LocalDirectory();
        localDirectory.setName(newPath.getFileName().toString());
        localDirectory.setPath(newPath.getFileName().toString());
        localDirectory.setDate(new Date(Files.getLastModifiedTime(newPath).toMillis()));
        localDirectory.setRoot(NAME);
        localDirectory.setCanAddChildren(true);
        localDirectory.setCanEdit(true);
        return localDirectory;
    } catch (IOException e) {
        return null;
    }
}
Also used : Path(java.nio.file.Path) LocalDirectory(org.pentaho.di.plugins.fileopensave.providers.local.model.LocalDirectory) IOException(java.io.IOException) Date(java.util.Date) FileExistsException(org.pentaho.di.plugins.fileopensave.api.providers.exception.FileExistsException)

Aggregations

FileExistsException (org.pentaho.di.plugins.fileopensave.api.providers.exception.FileExistsException)3 FileException (org.pentaho.di.plugins.fileopensave.api.providers.exception.FileException)2 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 Date (java.util.Date)1 KettleException (org.pentaho.di.core.exception.KettleException)1 KettleJobException (org.pentaho.di.core.exception.KettleJobException)1 KettleObjectExistsException (org.pentaho.di.core.exception.KettleObjectExistsException)1 KettleTransException (org.pentaho.di.core.exception.KettleTransException)1 File (org.pentaho.di.plugins.fileopensave.api.providers.File)1 InvalidFileOperationException (org.pentaho.di.plugins.fileopensave.api.providers.exception.InvalidFileOperationException)1 InvalidFileProviderException (org.pentaho.di.plugins.fileopensave.api.providers.exception.InvalidFileProviderException)1 InvalidFileTypeException (org.pentaho.di.plugins.fileopensave.api.providers.exception.InvalidFileTypeException)1 LocalDirectory (org.pentaho.di.plugins.fileopensave.providers.local.model.LocalDirectory)1 RepositoryDirectory (org.pentaho.di.plugins.fileopensave.providers.repository.model.RepositoryDirectory)1 RepositoryDirectoryInterface (org.pentaho.di.repository.RepositoryDirectoryInterface)1