Search in sources :

Example 1 with VFSConnectionDetails

use of org.pentaho.di.connections.vfs.VFSConnectionDetails in project pentaho-kettle by pentaho.

the class ConnectionFileSystem method getUrl.

/**
 * Creates a url for {@link ConnectionFileName}
 *
 * @param abstractFileName  File name
 * @param connectionDetails Connection details for the file name
 * @return created url otherwise null
 */
public static String getUrl(AbstractFileName abstractFileName, ConnectionDetails connectionDetails) {
    VFSConnectionDetails vfsConnectionDetails = (VFSConnectionDetails) connectionDetails;
    String url = null;
    if (vfsConnectionDetails != null) {
        String domain = vfsConnectionDetails.getDomain();
        if (!domain.equals("")) {
            domain = "/" + domain;
        }
        url = vfsConnectionDetails.getType() + ":/" + domain + abstractFileName.getPath();
        if (url.matches(DOMAIN_ROOT)) {
            url += vfsConnectionDetails.getName();
        }
    }
    return url;
}
Also used : VFSConnectionDetails(org.pentaho.di.connections.vfs.VFSConnectionDetails)

Example 2 with VFSConnectionDetails

use of org.pentaho.di.connections.vfs.VFSConnectionDetails in project pentaho-kettle by pentaho.

the class VFSFileProvider method getTree.

/**
 * Filtered implementation
 *
 * @return Filter Tree
 */
@Override
public VFSTree getTree(List<String> connectionTypes) {
    VFSTree vfsTree = new VFSTree(NAME);
    List<ConnectionProvider<? extends ConnectionDetails>> providers = connectionManagerSupplier.get().getProvidersByType(VFSConnectionProvider.class);
    for (ConnectionProvider<? extends ConnectionDetails> provider : providers) {
        for (ConnectionDetails connectionDetails : provider.getConnectionDetails()) {
            VFSConnectionDetails vfsConnectionDetails = (VFSConnectionDetails) connectionDetails;
            VFSLocation vfsLocation = new VFSLocation();
            vfsLocation.setName(connectionDetails.getName());
            vfsLocation.setRoot(NAME);
            vfsLocation.setHasChildren(true);
            vfsLocation.setCanDelete(false);
            vfsLocation.setPath(vfsConnectionDetails.getType() + "://" + vfsConnectionDetails.getDomain());
            vfsLocation.setDomain(vfsConnectionDetails.getDomain());
            vfsLocation.setConnection(connectionDetails.getName());
            if (connectionTypes.isEmpty() || connectionTypes.contains(connectionDetails.getType())) {
                vfsTree.addChild(vfsLocation);
            }
        }
    }
    return vfsTree;
}
Also used : VFSTree(org.pentaho.di.plugins.fileopensave.providers.vfs.model.VFSTree) VFSConnectionDetails(org.pentaho.di.connections.vfs.VFSConnectionDetails) ConnectionDetails(org.pentaho.di.connections.ConnectionDetails) VFSLocation(org.pentaho.di.plugins.fileopensave.providers.vfs.model.VFSLocation) VFSConnectionDetails(org.pentaho.di.connections.vfs.VFSConnectionDetails) ConnectionProvider(org.pentaho.di.connections.ConnectionProvider) VFSConnectionProvider(org.pentaho.di.connections.vfs.VFSConnectionProvider)

Example 3 with VFSConnectionDetails

use of org.pentaho.di.connections.vfs.VFSConnectionDetails 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 4 with VFSConnectionDetails

use of org.pentaho.di.connections.vfs.VFSConnectionDetails in project pentaho-kettle by pentaho.

the class ConnectionFileSystem method createFile.

@Override
protected FileObject createFile(AbstractFileName abstractFileName) throws Exception {
    String connectionName = ((ConnectionFileName) abstractFileName).getConnection();
    VFSConnectionDetails connectionDetails = (VFSConnectionDetails) connectionManager.get().getConnectionDetails(connectionName);
    String url = getUrl(abstractFileName, connectionDetails);
    AbstractFileObject fileObject = null;
    String domain = null;
    if (url != null) {
        domain = connectionDetails.getDomain();
        Variables variables = new Variables();
        variables.setVariable(CONNECTION, connectionName);
        fileObject = (AbstractFileObject) KettleVFS.getFileObject(url, variables);
    }
    return new ConnectionFileObject(abstractFileName, this, fileObject, domain);
}
Also used : Variables(org.pentaho.di.core.variables.Variables) VFSConnectionDetails(org.pentaho.di.connections.vfs.VFSConnectionDetails) AbstractFileObject(org.apache.commons.vfs2.provider.AbstractFileObject)

Aggregations

VFSConnectionDetails (org.pentaho.di.connections.vfs.VFSConnectionDetails)4 VFSConnectionProvider (org.pentaho.di.connections.vfs.VFSConnectionProvider)2 ArrayList (java.util.ArrayList)1 AbstractFileObject (org.apache.commons.vfs2.provider.AbstractFileObject)1 ConnectionDetails (org.pentaho.di.connections.ConnectionDetails)1 ConnectionProvider (org.pentaho.di.connections.ConnectionProvider)1 VFSRoot (org.pentaho.di.connections.vfs.VFSRoot)1 Variables (org.pentaho.di.core.variables.Variables)1 FileNotFoundException (org.pentaho.di.plugins.fileopensave.api.providers.exception.FileNotFoundException)1 VFSDirectory (org.pentaho.di.plugins.fileopensave.providers.vfs.model.VFSDirectory)1 VFSFile (org.pentaho.di.plugins.fileopensave.providers.vfs.model.VFSFile)1 VFSLocation (org.pentaho.di.plugins.fileopensave.providers.vfs.model.VFSLocation)1 VFSTree (org.pentaho.di.plugins.fileopensave.providers.vfs.model.VFSTree)1