Search in sources :

Example 1 with VFSDirectory

use of org.pentaho.di.plugins.fileopensave.providers.vfs.model.VFSDirectory in project pentaho-kettle by pentaho.

the class VFSFileProvider method getRoot.

/**
 * @param file
 * @return
 */
private List<VFSFile> getRoot(VFSFile file) throws FileException {
    if (this.roots.containsKey(file.getConnection())) {
        return this.roots.get(file.getConnection());
    }
    List<VFSFile> files = new ArrayList<>();
    VFSConnectionDetails vfsConnectionDetails = (VFSConnectionDetails) ConnectionManager.getInstance().getConnectionDetails(file.getConnection());
    @SuppressWarnings("unchecked") VFSConnectionProvider<VFSConnectionDetails> vfsConnectionProvider = (VFSConnectionProvider<VFSConnectionDetails>) ConnectionManager.getInstance().getConnectionProvider(vfsConnectionDetails.getType());
    List<VFSRoot> vfsRoots = vfsConnectionProvider.getLocations(vfsConnectionDetails);
    if (vfsRoots.isEmpty()) {
        throw new FileNotFoundException(file.getPath(), file.getProvider());
    }
    String scheme = vfsConnectionProvider.getProtocol(vfsConnectionDetails);
    for (VFSRoot root : vfsRoots) {
        VFSDirectory vfsDirectory = new VFSDirectory();
        vfsDirectory.setName(root.getName());
        vfsDirectory.setDate(root.getModifiedDate());
        vfsDirectory.setHasChildren(true);
        vfsDirectory.setCanAddChildren(true);
        vfsDirectory.setParent(scheme + "://");
        vfsDirectory.setDomain(vfsConnectionDetails.getDomain());
        vfsDirectory.setConnection(vfsConnectionDetails.getName());
        vfsDirectory.setPath(scheme + "://" + root.getName());
        vfsDirectory.setRoot(NAME);
        files.add(vfsDirectory);
    }
    this.roots.put(file.getConnection(), files);
    return files;
}
Also used : VFSFile(org.pentaho.di.plugins.fileopensave.providers.vfs.model.VFSFile) VFSDirectory(org.pentaho.di.plugins.fileopensave.providers.vfs.model.VFSDirectory) VFSConnectionProvider(org.pentaho.di.connections.vfs.VFSConnectionProvider) VFSRoot(org.pentaho.di.connections.vfs.VFSRoot) ArrayList(java.util.ArrayList) FileNotFoundException(org.pentaho.di.plugins.fileopensave.api.providers.exception.FileNotFoundException) VFSConnectionDetails(org.pentaho.di.connections.vfs.VFSConnectionDetails)

Example 2 with VFSDirectory

use of org.pentaho.di.plugins.fileopensave.providers.vfs.model.VFSDirectory in project pentaho-kettle by pentaho.

the class VFSFileProvider method doMove.

/**
 * @param file
 * @param newPath
 * @param overwrite
 * @return
 */
private VFSFile doMove(VFSFile file, String newPath, boolean overwrite) {
    try {
        FileObject fileObject = KettleVFS.getFileObject(file.getPath(), new Variables(), VFSHelper.getOpts(file.getPath(), file.getConnection()));
        FileObject renameObject = KettleVFS.getFileObject(newPath, new Variables(), VFSHelper.getOpts(file.getPath(), file.getConnection()));
        if (overwrite && renameObject.exists()) {
            renameObject.delete();
        }
        fileObject.moveTo(renameObject);
        if (file instanceof VFSDirectory) {
            return VFSDirectory.create(renameObject.getParent().getPublicURIString(), renameObject, file.getConnection(), file.getDomain());
        } else {
            return VFSFile.create(renameObject.getParent().getPublicURIString(), renameObject, file.getConnection(), file.getDomain());
        }
    } catch (KettleFileException | FileSystemException e) {
        return null;
    }
}
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) FileObject(org.apache.commons.vfs2.FileObject)

Example 3 with VFSDirectory

use of org.pentaho.di.plugins.fileopensave.providers.vfs.model.VFSDirectory 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)

Aggregations

VFSDirectory (org.pentaho.di.plugins.fileopensave.providers.vfs.model.VFSDirectory)3 FileObject (org.apache.commons.vfs2.FileObject)2 FileSystemException (org.apache.commons.vfs2.FileSystemException)2 KettleFileException (org.pentaho.di.core.exception.KettleFileException)2 Variables (org.pentaho.di.core.variables.Variables)2 ArrayList (java.util.ArrayList)1 VFSConnectionDetails (org.pentaho.di.connections.vfs.VFSConnectionDetails)1 VFSConnectionProvider (org.pentaho.di.connections.vfs.VFSConnectionProvider)1 VFSRoot (org.pentaho.di.connections.vfs.VFSRoot)1 FileException (org.pentaho.di.plugins.fileopensave.api.providers.exception.FileException)1 FileNotFoundException (org.pentaho.di.plugins.fileopensave.api.providers.exception.FileNotFoundException)1 VFSFile (org.pentaho.di.plugins.fileopensave.providers.vfs.model.VFSFile)1