use of org.pentaho.platform.api.repository2.unified.RepositoryFile in project pentaho-kettle by pentaho.
the class PurRepository method getClusterSchemaParentFolderId.
private Serializable getClusterSchemaParentFolderId() {
if (cachedClusterSchemaParentFolderId == null) {
RepositoryFile f = pur.getFile(getClusterSchemaParentFolderPath());
cachedClusterSchemaParentFolderId = f.getId();
}
return cachedClusterSchemaParentFolderId;
}
use of org.pentaho.platform.api.repository2.unified.RepositoryFile in project pentaho-kettle by pentaho.
the class PurRepository method loadSlaveServer.
@Override
public SlaveServer loadSlaveServer(ObjectId idSlaveServer, String versionId) throws KettleException {
try {
NodeRepositoryFileData data = pur.getDataAtVersionForRead(idSlaveServer.getId(), versionId, NodeRepositoryFileData.class);
RepositoryFile file = null;
if (versionId != null) {
file = pur.getFileAtVersion(idSlaveServer.getId(), versionId);
} else {
file = pur.getFileById(idSlaveServer.getId());
}
return slaveTransformer.assemble(file, data, pur.getVersionSummary(idSlaveServer.getId(), versionId));
} catch (Exception e) {
throw new KettleException("Unable to load slave server with id [" + idSlaveServer + "]", e);
}
}
use of org.pentaho.platform.api.repository2.unified.RepositoryFile in project pentaho-kettle by pentaho.
the class PurRepository method isUserHomeDirectory.
/**
* Test to see if the folder is a user's home directory If it is an ancestor to a user's home directory, false will be
* returned. (It is not actually a user's home directory)
*
* @param folder
* The folder to test; Must not be null
* @return True if the directory is a users home directory and False if it is not; False if folder is null
*/
protected boolean isUserHomeDirectory(RepositoryFile folder) {
if (folder != null) {
// Get the root of all home folders
RepositoryFile homeRootFolder = pur.getFile(ClientRepositoryPaths.getHomeFolderPath());
if (homeRootFolder != null) {
// Strip the final RepositoryDirectory.DIRECTORY_SEPARATOR from the paths
String temp = homeRootFolder.getPath();
String homeRootPath = temp.endsWith(RepositoryDirectory.DIRECTORY_SEPARATOR) && temp.length() > RepositoryDirectory.DIRECTORY_SEPARATOR.length() ? temp.substring(0, temp.length() - RepositoryDirectory.DIRECTORY_SEPARATOR.length()) : temp;
temp = folder.getPath();
String folderPath = temp.endsWith(RepositoryDirectory.DIRECTORY_SEPARATOR) && temp.length() > RepositoryDirectory.DIRECTORY_SEPARATOR.length() ? temp.substring(0, temp.length() - RepositoryDirectory.DIRECTORY_SEPARATOR.length()) : temp;
// Is the folder in a user's home directory?
if (folderPath.startsWith(homeRootPath)) {
if (folderPath.equals(homeRootPath)) {
return false;
}
// If there is exactly one more RepositoryDirectory.DIRECTORY_SEPARATOR in folderPath than homeRootFolder,
// then the user is trying to delete another user's home directory
int folderPathDirCount = 0;
int homeRootPathDirCount = 0;
for (int x = 0; x >= 0; folderPathDirCount++) {
x = folderPath.indexOf(RepositoryDirectory.DIRECTORY_SEPARATOR, x + 1);
}
for (int x = 0; x >= 0; homeRootPathDirCount++) {
x = homeRootPath.indexOf(RepositoryDirectory.DIRECTORY_SEPARATOR, x + 1);
}
if (folderPathDirCount == (homeRootPathDirCount + 1)) {
return true;
}
}
}
}
return false;
}
use of org.pentaho.platform.api.repository2.unified.RepositoryFile in project pentaho-kettle by pentaho.
the class PurRepository method loadDatabaseMeta.
@Override
public DatabaseMeta loadDatabaseMeta(final ObjectId databaseId, final String versionId) throws KettleException {
try {
NodeRepositoryFileData data = pur.getDataAtVersionForRead(databaseId.getId(), versionId, NodeRepositoryFileData.class);
RepositoryFile file = null;
if (versionId != null) {
file = pur.getFileAtVersion(databaseId.getId(), versionId);
} else {
file = pur.getFileById(databaseId.getId());
}
return databaseMetaTransformer.assemble(file, data, pur.getVersionSummary(databaseId.getId(), versionId));
} catch (Exception e) {
throw new KettleException("Unable to load database with id [" + databaseId + "]", e);
}
}
use of org.pentaho.platform.api.repository2.unified.RepositoryFile in project pentaho-kettle by pentaho.
the class PurRepository method getChildren.
@Override
public List<RepositoryObjectInterface> getChildren(String path, String filter) {
RepositoryRequest repoRequest = new RepositoryRequest();
repoRequest.setDepth(-1);
repoRequest.setChildNodeFilter("*" + filter + "*");
repoRequest.setIncludeAcls(false);
repoRequest.setTypes(FILES_TYPE_FILTER.FILES_FOLDERS);
repoRequest.setPath(path);
repoRequest.setShowHidden(false);
List<RepositoryFile> repositoryFiles = pur.getChildren(repoRequest);
List<RepositoryObjectInterface> repositoryElementInterfaces = new ArrayList<>();
for (RepositoryFile repositoryFile : repositoryFiles) {
if (repositoryFile.isFolder()) {
RepositoryDirectoryInterface repositoryDirectory = new RepositoryDirectory();
repositoryDirectory.setName(repositoryFile.getName());
repositoryDirectory.setObjectId(() -> repositoryFile.getId().toString());
repositoryElementInterfaces.add(repositoryDirectory);
} else {
RepositoryObject repositoryObject = new RepositoryObject();
repositoryObject.setName(repositoryFile.getName());
repositoryObject.setObjectId(() -> repositoryFile.getId().toString());
RepositoryObjectType repositoryObjectType = RepositoryObjectType.UNKNOWN;
if (repositoryFile.getName().endsWith(".ktr")) {
repositoryObjectType = RepositoryObjectType.TRANSFORMATION;
}
if (repositoryFile.getName().endsWith(".kjb")) {
repositoryObjectType = RepositoryObjectType.JOB;
}
repositoryObject.setObjectType(repositoryObjectType);
repositoryElementInterfaces.add(repositoryObject);
}
}
return repositoryElementInterfaces;
}
Aggregations