Search in sources :

Example 6 with FileException

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

the class VFSFileProvider method copy.

/**
 * @param file
 * @param toPath
 * @param overwrite
 * @return
 * @throws FileException
 */
@Override
public VFSFile copy(VFSFile file, String toPath, boolean overwrite) throws FileException {
    try {
        FileObject fileObject = KettleVFS.getFileObject(file.getPath(), new Variables(), VFSHelper.getOpts(file.getPath(), file.getConnection()));
        FileObject copyObject = KettleVFS.getFileObject(toPath, new Variables(), VFSHelper.getOpts(file.getPath(), file.getConnection()));
        copyObject.copyFrom(fileObject, Selectors.SELECT_SELF);
        if (file instanceof VFSDirectory) {
            return VFSDirectory.create(copyObject.getParent().getPublicURIString(), fileObject, file.getConnection(), file.getDomain());
        } else {
            return VFSFile.create(copyObject.getParent().getPublicURIString(), fileObject, file.getConnection(), file.getDomain());
        }
    } catch (KettleFileException | FileSystemException e) {
        throw new FileException();
    }
}
Also used : Variables(org.pentaho.di.core.variables.Variables) VFSDirectory(org.pentaho.di.plugins.fileopensave.providers.vfs.model.VFSDirectory) KettleFileException(org.pentaho.di.core.exception.KettleFileException) FileSystemException(org.apache.commons.vfs2.FileSystemException) FileException(org.pentaho.di.plugins.fileopensave.api.providers.exception.FileException) KettleFileException(org.pentaho.di.core.exception.KettleFileException) FileObject(org.apache.commons.vfs2.FileObject)

Example 7 with FileException

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

the class FileController method rename.

public Result rename(File file, String newPath, boolean overwrite) {
    try {
        FileProvider<File> fileProvider = providerService.get(file.getProvider());
        File newFile = fileProvider.rename(file, newPath, overwrite);
        if (newFile != null) {
            fileCache.move(fileProvider.getParent(file), file, fileProvider.getParent(newFile), newFile);
        }
        return Result.success("", newFile);
    } 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 8 with FileException

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

the class FileController method moveFile.

public Result moveFile(File file, File destDir, String newPath, boolean overwrite) {
    try {
        FileProvider<File> fileProvider = providerService.get(file.getProvider());
        File newFile;
        if (fileProvider.isSame(file, destDir)) {
            newFile = fileProvider.move(file, newPath, overwrite);
        } else {
            newFile = moveBetweenProviders(file, destDir, newPath, overwrite);
        }
        if (newFile != null) {
            FileProvider newFileProvider = providerService.get(newFile.getProvider());
            fileCache.move(fileProvider.getParent(file), file, newFileProvider.getParent(newFile), newFile);
            return Result.success("Move file complete", newFile);
        }
    } catch (InvalidFileProviderException | FileException e) {
        return Result.error("Unable to move file", file);
    }
    return Result.error("Unable to move 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