Search in sources :

Example 1 with FileProvider

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

Example 2 with FileProvider

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

the class FileControllerTest method setup.

@Before
public void setup() {
    List<FileProvider> fileProviders = new ArrayList<>();
    fileProviders.add(new TestFileProvider());
    ProviderService providerService = new ProviderService(fileProviders);
    fileController = new FileController(new FileCache(), providerService);
}
Also used : ProviderService(org.pentaho.di.plugins.fileopensave.providers.ProviderService) FileProvider(org.pentaho.di.plugins.fileopensave.api.providers.FileProvider) TestFileProvider(org.pentaho.di.plugins.fileopensave.providers.TestFileProvider) TestFileProvider(org.pentaho.di.plugins.fileopensave.providers.TestFileProvider) ArrayList(java.util.ArrayList) FileCache(org.pentaho.di.plugins.fileopensave.cache.FileCache) Before(org.junit.Before)

Example 3 with FileProvider

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

the class FileController method load.

public List<Tree> load(String filter, List<String> connectionTypes) {
    List<Tree> trees = new ArrayList<>();
    List<String> filters = Utils.isEmpty(filter) || filter.equalsIgnoreCase(ProviderFilterType.DEFAULT.toString()) ? Arrays.asList(ProviderFilterType.getDefaults()) : Arrays.asList(filter.split("[,]"));
    // filter
    if (filters.contains(ProviderFilterType.ALL_PROVIDERS.toString())) {
        for (FileProvider fileProvider : providerService.get()) {
            if (fileProvider.isAvailable()) {
                trees.add(fileProvider.getTree(connectionTypes));
            }
        }
    } else {
        for (FileProvider fileProvider : providerService.get()) {
            if (fileProvider.isAvailable() && filters.contains(fileProvider.getType())) {
                trees.add(fileProvider.getTree(connectionTypes));
            }
        }
    }
    return trees;
}
Also used : FileProvider(org.pentaho.di.plugins.fileopensave.api.providers.FileProvider) ArrayList(java.util.ArrayList) Tree(org.pentaho.di.plugins.fileopensave.api.providers.Tree)

Example 4 with FileProvider

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

Example 5 with FileProvider

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

the class FileOpenSaveExtensionPoint method callExtensionPoint.

@Override
public void callExtensionPoint(LogChannelInterface logChannelInterface, Object o) throws KettleException {
    FileDialogOperation fileDialogOperation = (FileDialogOperation) o;
    final FileOpenSaveDialog fileOpenSaveDialog = new FileOpenSaveDialog(spoonSupplier.get().getShell(), WIDTH, HEIGHT, logChannelInterface);
    resolveProvider(fileDialogOperation);
    fileOpenSaveDialog.open(fileDialogOperation);
    fileDialogOperation.setPath(null);
    fileDialogOperation.setFilename(null);
    fileDialogOperation.setConnection(null);
    if (!Utils.isEmpty(fileOpenSaveDialog.getProvider())) {
        try {
            FileProvider fileProvider = providerService.get(fileOpenSaveDialog.getProvider());
            fileProvider.setFileProperties(fileOpenSaveDialog, fileDialogOperation);
        } catch (InvalidFileProviderException e) {
            throw new KettleException(e);
        }
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) FileProvider(org.pentaho.di.plugins.fileopensave.api.providers.FileProvider) RepositoryFileProvider(org.pentaho.di.plugins.fileopensave.providers.repository.RepositoryFileProvider) LocalFileProvider(org.pentaho.di.plugins.fileopensave.providers.local.LocalFileProvider) VFSFileProvider(org.pentaho.di.plugins.fileopensave.providers.vfs.VFSFileProvider) FileOpenSaveDialog(org.pentaho.di.plugins.fileopensave.dialog.FileOpenSaveDialog) InvalidFileProviderException(org.pentaho.di.plugins.fileopensave.api.providers.exception.InvalidFileProviderException) FileDialogOperation(org.pentaho.di.ui.core.FileDialogOperation)

Aggregations

FileProvider (org.pentaho.di.plugins.fileopensave.api.providers.FileProvider)5 InvalidFileProviderException (org.pentaho.di.plugins.fileopensave.api.providers.exception.InvalidFileProviderException)3 ArrayList (java.util.ArrayList)2 File (org.pentaho.di.plugins.fileopensave.api.providers.File)2 FileException (org.pentaho.di.plugins.fileopensave.api.providers.exception.FileException)2 Before (org.junit.Before)1 KettleException (org.pentaho.di.core.exception.KettleException)1 Tree (org.pentaho.di.plugins.fileopensave.api.providers.Tree)1 FileCache (org.pentaho.di.plugins.fileopensave.cache.FileCache)1 FileOpenSaveDialog (org.pentaho.di.plugins.fileopensave.dialog.FileOpenSaveDialog)1 ProviderService (org.pentaho.di.plugins.fileopensave.providers.ProviderService)1 TestFileProvider (org.pentaho.di.plugins.fileopensave.providers.TestFileProvider)1 LocalFileProvider (org.pentaho.di.plugins.fileopensave.providers.local.LocalFileProvider)1 RepositoryFileProvider (org.pentaho.di.plugins.fileopensave.providers.repository.RepositoryFileProvider)1 VFSFileProvider (org.pentaho.di.plugins.fileopensave.providers.vfs.VFSFileProvider)1 FileDialogOperation (org.pentaho.di.ui.core.FileDialogOperation)1