Search in sources :

Example 1 with FileException

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

the class VFSFileProvider method writeFile.

/**
 * @param inputStream
 * @param destDir
 * @param path
 * @param overwrite
 * @return
 * @throws FileException
 */
@Override
public VFSFile writeFile(InputStream inputStream, VFSFile destDir, String path, boolean overwrite) throws FileException {
    FileObject fileObject = null;
    try {
        fileObject = KettleVFS.getFileObject(path, new Variables(), VFSHelper.getOpts(destDir.getPath(), destDir.getConnection()));
    } catch (KettleException ke) {
        throw new FileException();
    }
    if (fileObject != null) {
        try (OutputStream outputStream = fileObject.getContent().getOutputStream()) {
            IOUtils.copy(inputStream, outputStream);
            outputStream.flush();
            return VFSFile.create(destDir.getPath(), fileObject, destDir.getConnection(), destDir.getDomain());
        } catch (IOException e) {
            return null;
        }
    }
    return null;
}
Also used : Variables(org.pentaho.di.core.variables.Variables) KettleException(org.pentaho.di.core.exception.KettleException) FileException(org.pentaho.di.plugins.fileopensave.api.providers.exception.FileException) KettleFileException(org.pentaho.di.core.exception.KettleFileException) OutputStream(java.io.OutputStream) FileObject(org.apache.commons.vfs2.FileObject) IOException(java.io.IOException)

Example 2 with FileException

use of org.pentaho.di.plugins.fileopensave.api.providers.exception.FileException 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 3 with FileException

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

the class FileController method delete.

public Result delete(List<File> files) {
    try {
        FileProvider<File> fileProvider = providerService.get(files.get(0).getProvider());
        List<File> deletedFiles = fileProvider.delete(files);
        for (File file : deletedFiles) {
            fileCache.removeFile(fileProvider.getParent(file), file);
        }
        return Result.success("", deletedFiles);
    } catch (InvalidFileProviderException | FileException e) {
        return null;
    }
}
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)

Example 4 with FileException

use of org.pentaho.di.plugins.fileopensave.api.providers.exception.FileException 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 5 with FileException

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

the class FileController method copyFile.

public Result copyFile(File file, File destDir, String path, Boolean overwrite) {
    try {
        FileProvider<File> fileProvider = providerService.get(file.getProvider());
        File newFile;
        if (fileProvider.isSame(file, destDir)) {
            newFile = fileProvider.copy(file, path, overwrite);
        } else {
            newFile = copyFileBetweenProviders(file, destDir, path, overwrite);
        }
        if (newFile != null) {
            FileProvider newFileProvider = providerService.get(newFile.getProvider());
            fileCache.addFile(newFileProvider.getParent(newFile), newFile);
            return Result.success("Copy file complete", newFile);
        }
    } catch (InvalidFileProviderException | FileException e) {
        return Result.error("Unable to copy file", file);
    }
    return Result.error("Unable to copy file", file);
}
Also used : FileException(org.pentaho.di.plugins.fileopensave.api.providers.exception.FileException) FileProvider(org.pentaho.di.plugins.fileopensave.api.providers.FileProvider) File(org.pentaho.di.plugins.fileopensave.api.providers.File) InvalidFileProviderException(org.pentaho.di.plugins.fileopensave.api.providers.exception.InvalidFileProviderException)

Aggregations

FileException (org.pentaho.di.plugins.fileopensave.api.providers.exception.FileException)8 File (org.pentaho.di.plugins.fileopensave.api.providers.File)5 InvalidFileProviderException (org.pentaho.di.plugins.fileopensave.api.providers.exception.InvalidFileProviderException)5 FileObject (org.apache.commons.vfs2.FileObject)2 KettleException (org.pentaho.di.core.exception.KettleException)2 KettleFileException (org.pentaho.di.core.exception.KettleFileException)2 Variables (org.pentaho.di.core.variables.Variables)2 FileProvider (org.pentaho.di.plugins.fileopensave.api.providers.FileProvider)2 FileExistsException (org.pentaho.di.plugins.fileopensave.api.providers.exception.FileExistsException)2 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 FileSystemException (org.apache.commons.vfs2.FileSystemException)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 InvalidFileOperationException (org.pentaho.di.plugins.fileopensave.api.providers.exception.InvalidFileOperationException)1 InvalidFileTypeException (org.pentaho.di.plugins.fileopensave.api.providers.exception.InvalidFileTypeException)1 RepositoryDirectory (org.pentaho.di.plugins.fileopensave.providers.repository.model.RepositoryDirectory)1 VFSDirectory (org.pentaho.di.plugins.fileopensave.providers.vfs.model.VFSDirectory)1 RepositoryDirectoryInterface (org.pentaho.di.repository.RepositoryDirectoryInterface)1