Search in sources :

Example 1 with LocalDirectory

use of org.pentaho.di.plugins.fileopensave.providers.local.model.LocalDirectory in project pentaho-kettle by pentaho.

the class LocalFileProvider method getTree.

/**
 * @return
 */
@Override
public Tree getTree() {
    LocalTree localTree = new LocalTree(NAME);
    List<LocalFile> rootFiles = new ArrayList<>();
    ArrayList<Path> paths = new ArrayList<>();
    if (Const.isRunningOnWebspoonMode()) {
        Path kettleUserDataDirectoryPath = Paths.get(Const.getUserDataDirectory());
        paths.add(kettleUserDataDirectoryPath);
    } else {
        FileSystems.getDefault().getRootDirectories().forEach(paths::add);
    }
    paths.forEach(path -> {
        LocalDirectory localDirectory = new LocalDirectory();
        localDirectory.setPath(path.toString());
        localDirectory.setName(path.toString());
        localDirectory.setRoot(NAME);
        localDirectory.setHasChildren(true);
        rootFiles.add(localDirectory);
    });
    localTree.setFiles(rootFiles);
    return localTree;
}
Also used : Path(java.nio.file.Path) LocalFile(org.pentaho.di.plugins.fileopensave.providers.local.model.LocalFile) LocalDirectory(org.pentaho.di.plugins.fileopensave.providers.local.model.LocalDirectory) LocalTree(org.pentaho.di.plugins.fileopensave.providers.local.model.LocalTree) ArrayList(java.util.ArrayList)

Example 2 with LocalDirectory

use of org.pentaho.di.plugins.fileopensave.providers.local.model.LocalDirectory in project pentaho-kettle by pentaho.

the class LocalFileProvider method add.

/**
 * @param folder
 * @return
 */
@Override
public LocalFile add(LocalFile folder) throws FileException {
    Path folderPath = Paths.get(folder.getPath());
    if (folderPath.toFile().exists()) {
        throw new FileExistsException();
    }
    try {
        Path newPath = Files.createDirectories(Paths.get(folder.getPath()));
        LocalDirectory localDirectory = new LocalDirectory();
        localDirectory.setName(newPath.getFileName().toString());
        localDirectory.setPath(newPath.getFileName().toString());
        localDirectory.setDate(new Date(Files.getLastModifiedTime(newPath).toMillis()));
        localDirectory.setRoot(NAME);
        localDirectory.setCanAddChildren(true);
        localDirectory.setCanEdit(true);
        return localDirectory;
    } catch (IOException e) {
        return null;
    }
}
Also used : Path(java.nio.file.Path) LocalDirectory(org.pentaho.di.plugins.fileopensave.providers.local.model.LocalDirectory) IOException(java.io.IOException) Date(java.util.Date) FileExistsException(org.pentaho.di.plugins.fileopensave.api.providers.exception.FileExistsException)

Aggregations

Path (java.nio.file.Path)2 LocalDirectory (org.pentaho.di.plugins.fileopensave.providers.local.model.LocalDirectory)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 FileExistsException (org.pentaho.di.plugins.fileopensave.api.providers.exception.FileExistsException)1 LocalFile (org.pentaho.di.plugins.fileopensave.providers.local.model.LocalFile)1 LocalTree (org.pentaho.di.plugins.fileopensave.providers.local.model.LocalTree)1