Search in sources :

Example 6 with File

use of org.pentaho.di.plugins.fileopensave.api.providers.File 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

File (org.pentaho.di.plugins.fileopensave.api.providers.File)6 FileException (org.pentaho.di.plugins.fileopensave.api.providers.exception.FileException)5 InvalidFileProviderException (org.pentaho.di.plugins.fileopensave.api.providers.exception.InvalidFileProviderException)5 FileProvider (org.pentaho.di.plugins.fileopensave.api.providers.FileProvider)2 Test (org.junit.Test)1 FileExistsException (org.pentaho.di.plugins.fileopensave.api.providers.exception.FileExistsException)1 TestDirectory (org.pentaho.di.plugins.fileopensave.providers.model.TestDirectory)1 TestFile (org.pentaho.di.plugins.fileopensave.providers.model.TestFile)1