use of org.pentaho.di.plugins.fileopensave.providers.repository.model.RepositoryFile in project pentaho-kettle by pentaho.
the class RepositoryFileProvider method loadDirectoryTree.
public RepositoryTree loadDirectoryTree() {
if (getRepository() != null) {
try {
if (getRepository() instanceof RepositoryExtended) {
rootDirectory = ((RepositoryExtended) getRepository()).loadRepositoryDirectoryTree(false);
} else {
rootDirectory = getRepository().loadRepositoryDirectoryTree();
}
RepositoryTree repositoryTree = new RepositoryTree(null);
RepositoryDirectory repositoryDirectory = RepositoryDirectory.build(null, rootDirectory);
populateFolders(repositoryDirectory, rootDirectory);
boolean isPentahoRepository = getRepository().getRepositoryMeta().getId().equals(PENTAHO_ENTERPRISE_REPOSITORY);
if (!isPentahoRepository) {
populateFiles(repositoryDirectory, rootDirectory, FILTER);
}
for (RepositoryFile child : repositoryDirectory.getChildren()) {
repositoryTree.addChild(child);
}
return repositoryTree;
} catch (Exception e) {
return null;
}
}
return null;
}
use of org.pentaho.di.plugins.fileopensave.providers.repository.model.RepositoryFile in project pentaho-kettle by pentaho.
the class RepositoryFileProvider method doRename.
// TODO: Make this actually work
public RepositoryFile doRename(RepositoryFile file, String newName) throws KettleException {
RepositoryDirectoryInterface repositoryDirectoryInterface = findDirectory(file.getParent());
ObjectId objectId = null;
switch(file.getType()) {
case JOB:
if (getRepository().exists(newName, repositoryDirectoryInterface, RepositoryObjectType.JOB)) {
throw new KettleObjectExistsException();
}
if (isJobOpened(file.getObjectId(), file.getParent(), file.getName())) {
throw new KettleJobException();
}
objectId = getRepository().renameJob(file::getObjectId, repositoryDirectoryInterface, newName);
break;
case TRANSFORMATION:
if (getRepository().exists(newName, repositoryDirectoryInterface, RepositoryObjectType.TRANSFORMATION)) {
throw new KettleObjectExistsException();
}
if (isTransOpened(file.getObjectId(), file.getParent(), file.getName())) {
throw new KettleJobException();
}
objectId = getRepository().renameTransformation(file::getObjectId, repositoryDirectoryInterface, newName);
break;
case FOLDER:
isFileOpenedInFolder(file.getPath());
RepositoryDirectoryInterface parent = findDirectory(file.getPath()).getParent();
if (parent == null) {
parent = findDirectory(file.getPath());
}
RepositoryDirectoryInterface child = parent.findChild(newName);
if (child != null) {
throw new KettleObjectExistsException();
}
if (getRepository() instanceof RepositoryExtended) {
objectId = ((RepositoryExtended) getRepository()).renameRepositoryDirectory(file::getObjectId, null, newName, true);
} else {
objectId = getRepository().renameRepositoryDirectory(file::getObjectId, null, newName);
}
break;
}
RepositoryFile repositoryFile = new RepositoryFile();
return repositoryFile;
}
use of org.pentaho.di.plugins.fileopensave.providers.repository.model.RepositoryFile in project pentaho-kettle by pentaho.
the class RepositoryFileProvider method populateFiles.
private void populateFiles(RepositoryDirectory repositoryDirectory, RepositoryDirectoryInterface repositoryDirectoryInterface, String filter) throws KettleException {
if (getRepository() instanceof RepositoryExtended && !repositoryDirectory.getPath().equals("/")) {
populateFilesLazy(repositoryDirectory, filter);
} else {
Date latestDate = null;
for (RepositoryObjectInterface repositoryObject : getRepositoryElements(repositoryDirectoryInterface)) {
org.pentaho.di.repository.RepositoryObject ro = (org.pentaho.di.repository.RepositoryObject) repositoryObject;
String extension = ro.getObjectType().getExtension();
if (!Util.isFiltered(extension, filter)) {
RepositoryFile repositoryFile = RepositoryFile.build(ro);
repositoryDirectory.addChild(repositoryFile);
}
if (latestDate == null || ro.getModifiedDate().after(latestDate)) {
latestDate = ro.getModifiedDate();
}
}
repositoryDirectory.setDate(latestDate);
}
}
use of org.pentaho.di.plugins.fileopensave.providers.repository.model.RepositoryFile in project pentaho-kettle by pentaho.
the class RepositoryFileProvider method populateFilesLazy.
public void populateFilesLazy(RepositoryDirectory repositoryDirectory, String filter) {
RepositoryRequest repositoryRequest = new RepositoryRequest();
repositoryRequest.setPath(repositoryDirectory.getPath());
repositoryRequest.setDepth(1);
repositoryRequest.setShowHidden(true);
repositoryRequest.setTypes(RepositoryRequest.FILES_TYPE_FILTER.FILES);
repositoryRequest.setChildNodeFilter(filter);
RepositoryFileTree tree = getRepository().getUnderlyingRepository().getTree(repositoryRequest);
for (RepositoryFileTree repositoryFileTree : tree.getChildren()) {
org.pentaho.platform.api.repository2.unified.RepositoryFile repositoryFile = repositoryFileTree.getFile();
RepositoryFile repositoryFile1 = RepositoryFile.build(repositoryDirectory.getPath(), repositoryFile, isAdmin());
repositoryDirectory.addChild(repositoryFile1);
}
}
use of org.pentaho.di.plugins.fileopensave.providers.repository.model.RepositoryFile in project pentaho-kettle by pentaho.
the class RepositoryFileProvider method copy.
@Override
public RepositoryFile copy(RepositoryFile file, String toPath, boolean overwrite) throws FileException {
RepositoryElementInterface repositoryElementInterface = getObject(file.getObjectId(), file.getType());
if (repositoryElementInterface != null) {
repositoryElementInterface.setName(Util.getName(toPath));
repositoryElementInterface.setObjectId(null);
try {
getRepository().save(repositoryElementInterface, null, null);
} catch (KettleException e) {
}
} else {
throw new InvalidFileOperationException();
}
RepositoryFile repositoryFile = new RepositoryFile();
return repositoryFile;
}
Aggregations