Search in sources :

Example 1 with VfsDateRangeFilter

use of org.pentaho.metaverse.util.VfsDateRangeFilter in project pentaho-metaverse by pentaho.

the class VfsLineageCollector method listArtifacts.

@Override
public List<String> listArtifacts(final String startingDate, final String endingDate) throws IllegalArgumentException {
    List<String> paths = new ArrayList<>();
    try {
        FileSystemOptions opts = new FileSystemOptions();
        FileObject lineageRootFolder = KettleVFS.getFileObject(getOutputFolder(), opts);
        FileSelector dateRangeFilter = new VfsDateRangeFilter(format, startingDate, endingDate);
        FileSelector depthFilter = new FileDepthSelector(1, 256);
        if (lineageRootFolder.exists() && lineageRootFolder.getType() == FileType.FOLDER) {
            // get the folders that come on or after the startingDate
            FileObject[] dayFolders = lineageRootFolder.findFiles(dateRangeFilter);
            for (FileObject dayFolder : dayFolders) {
                FileObject[] listThisFolder = dayFolder.findFiles(depthFilter);
                for (FileObject currentFile : listThisFolder) {
                    if (currentFile.getType() == FileType.FILE) {
                        paths.add(currentFile.getName().getPath());
                    }
                }
            }
        }
        return paths;
    } catch (Exception e) {
        throw new IllegalArgumentException(e);
    }
}
Also used : VfsDateRangeFilter(org.pentaho.metaverse.util.VfsDateRangeFilter) FileSelector(org.apache.commons.vfs2.FileSelector) ArrayList(java.util.ArrayList) FileDepthSelector(org.apache.commons.vfs2.FileDepthSelector) FileObject(org.apache.commons.vfs2.FileObject) IOException(java.io.IOException) KettleFileException(org.pentaho.di.core.exception.KettleFileException) FileSystemOptions(org.apache.commons.vfs2.FileSystemOptions)

Example 2 with VfsDateRangeFilter

use of org.pentaho.metaverse.util.VfsDateRangeFilter in project pentaho-metaverse by pentaho.

the class VfsLineageCollector method listArtifactsForFile.

@Override
public List<String> listArtifactsForFile(String pathToArtifact, String startingDate, String endingDate) throws IllegalArgumentException {
    List<String> paths = new ArrayList<>();
    try {
        FileSystemOptions opts = new FileSystemOptions();
        FileObject lineageRootFolder = KettleVFS.getFileObject(getOutputFolder(), opts);
        FileSelector dateRangeFilter = new VfsDateRangeFilter(format, startingDate, endingDate);
        FileSelector depthFilter = new FileDepthSelector(1, 256);
        if (lineageRootFolder.exists() && lineageRootFolder.getType() == FileType.FOLDER) {
            // get all of the date folders of lineage we have
            FileObject[] dayFolders = lineageRootFolder.findFiles(dateRangeFilter);
            for (FileObject dayFolder : dayFolders) {
                FileObject[] listThisFolder = dayFolder.findFiles(depthFilter);
                for (FileObject currentFile : listThisFolder) {
                    FileObject requested = currentFile.resolveFile(pathToArtifact);
                    if (requested.exists() && requested.getType() == FileType.FOLDER) {
                        FileObject[] requestedChildren = requested.getChildren();
                        for (FileObject requestedChild : requestedChildren) {
                            if (requestedChild.getType() == FileType.FILE) {
                                paths.add(requestedChild.getName().getPath());
                            }
                        }
                    }
                }
            }
        }
        return paths;
    } catch (Exception e) {
        throw new IllegalArgumentException(e);
    }
}
Also used : VfsDateRangeFilter(org.pentaho.metaverse.util.VfsDateRangeFilter) FileSelector(org.apache.commons.vfs2.FileSelector) ArrayList(java.util.ArrayList) FileDepthSelector(org.apache.commons.vfs2.FileDepthSelector) FileObject(org.apache.commons.vfs2.FileObject) IOException(java.io.IOException) KettleFileException(org.pentaho.di.core.exception.KettleFileException) FileSystemOptions(org.apache.commons.vfs2.FileSystemOptions)

Aggregations

IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 FileDepthSelector (org.apache.commons.vfs2.FileDepthSelector)2 FileObject (org.apache.commons.vfs2.FileObject)2 FileSelector (org.apache.commons.vfs2.FileSelector)2 FileSystemOptions (org.apache.commons.vfs2.FileSystemOptions)2 KettleFileException (org.pentaho.di.core.exception.KettleFileException)2 VfsDateRangeFilter (org.pentaho.metaverse.util.VfsDateRangeFilter)2