use of org.pentaho.di.plugins.fileopensave.api.providers.exception.FileExistsException in project pentaho-kettle by pentaho.
the class RepositoryFileProvider method add.
@Override
public RepositoryFile add(RepositoryFile folder) throws FileException {
if (hasDupeFolder(folder.getParent(), folder.getName())) {
throw new FileExistsException();
}
try {
RepositoryDirectoryInterface repositoryDirectoryInterface = getRepository().createRepositoryDirectory(findDirectory(folder.getParent()), folder.getName());
RepositoryDirectory repositoryDirectory = new RepositoryDirectory();
repositoryDirectory.setName(repositoryDirectoryInterface.getName());
repositoryDirectory.setPath(repositoryDirectoryInterface.getPath());
repositoryDirectory.setObjectId(repositoryDirectoryInterface.getObjectId().getId());
repositoryDirectory.setParent(folder.getParent());
return RepositoryDirectory.build(folder.getPath(), repositoryDirectoryInterface);
} catch (Exception e) {
return null;
}
}
use of org.pentaho.di.plugins.fileopensave.api.providers.exception.FileExistsException in project pentaho-kettle by pentaho.
the class FileController method add.
public Result add(File folder) {
try {
FileProvider<File> fileProvider = providerService.get(folder.getProvider());
File newFile = fileProvider.add(folder);
if (newFile != null) {
fileCache.addFile(fileProvider.getParent(folder), newFile);
return Result.success("", newFile);
} else {
return Result.error("Unable to create folder", folder);
}
} catch (FileExistsException fee) {
return Result.fileCollision("", folder);
} catch (FileException | InvalidFileProviderException fe) {
return Result.error("", folder);
}
}
use of org.pentaho.di.plugins.fileopensave.api.providers.exception.FileExistsException 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;
}
}
Aggregations