use of org.pentaho.di.repository.RepositoryObjectType in project pentaho-kettle by pentaho.
the class PurRepository method loadAndCacheSharedObjects.
protected Map<RepositoryObjectType, List<? extends SharedObjectInterface>> loadAndCacheSharedObjects(final boolean deepCopy) throws KettleException {
if (sharedObjectsByType == null) {
try {
sharedObjectsByType = new EnumMap<RepositoryObjectType, List<? extends SharedObjectInterface>>(RepositoryObjectType.class);
// Slave Servers are referenced by Cluster Schemas so they must be loaded first
readSharedObjects(sharedObjectsByType, RepositoryObjectType.DATABASE, RepositoryObjectType.PARTITION_SCHEMA, RepositoryObjectType.SLAVE_SERVER, RepositoryObjectType.CLUSTER_SCHEMA);
} catch (Exception e) {
sharedObjectsByType = null;
// $NON-NLS-1$
throw new KettleException("Unable to read shared objects from repository", e);
}
}
return deepCopy ? deepCopy(sharedObjectsByType) : sharedObjectsByType;
}
use of org.pentaho.di.repository.RepositoryObjectType in project pentaho-kettle by pentaho.
the class PurRepository method getAllFilesOfType.
protected List<RepositoryFile> getAllFilesOfType(final ObjectId dirId, final List<RepositoryObjectType> objectTypes) throws KettleException {
Set<Serializable> parentFolderIds = new HashSet<>();
List<String> filters = new ArrayList<>();
for (RepositoryObjectType objectType : objectTypes) {
switch(objectType) {
case DATABASE:
{
parentFolderIds.add(getDatabaseMetaParentFolderId());
// $NON-NLS-1$
filters.add("*" + RepositoryObjectType.DATABASE.getExtension());
break;
}
case TRANSFORMATION:
{
parentFolderIds.add(dirId.getId());
// $NON-NLS-1$
filters.add("*" + RepositoryObjectType.TRANSFORMATION.getExtension());
break;
}
case PARTITION_SCHEMA:
{
parentFolderIds.add(getPartitionSchemaParentFolderId());
// $NON-NLS-1$
filters.add("*" + RepositoryObjectType.PARTITION_SCHEMA.getExtension());
break;
}
case SLAVE_SERVER:
{
parentFolderIds.add(getSlaveServerParentFolderId());
// $NON-NLS-1$
filters.add("*" + RepositoryObjectType.SLAVE_SERVER.getExtension());
break;
}
case CLUSTER_SCHEMA:
{
parentFolderIds.add(getClusterSchemaParentFolderId());
// $NON-NLS-1$
filters.add("*" + RepositoryObjectType.CLUSTER_SCHEMA.getExtension());
break;
}
case JOB:
{
parentFolderIds.add(dirId.getId());
// $NON-NLS-1$
filters.add("*" + RepositoryObjectType.JOB.getExtension());
break;
}
case TRANS_DATA_SERVICE:
{
parentFolderIds.add(dirId.getId());
// $NON-NLS-1$
filters.add("*" + RepositoryObjectType.TRANS_DATA_SERVICE.getExtension());
break;
}
default:
{
throw new UnsupportedOperationException("not implemented");
}
}
}
StringBuilder mergedFilterBuf = new StringBuilder();
// build filter
int i = 0;
for (String filter : filters) {
if (i++ > 0) {
// $NON-NLS-1$
mergedFilterBuf.append(" | ");
}
mergedFilterBuf.append(filter);
}
List<RepositoryFile> allFiles = new ArrayList<>();
for (Serializable parentFolderId : parentFolderIds) {
allFiles.addAll(pur.getChildren(parentFolderId, mergedFilterBuf.toString()));
}
Collections.sort(allFiles);
return allFiles;
}
use of org.pentaho.di.repository.RepositoryObjectType 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;
}
use of org.pentaho.di.repository.RepositoryObjectType in project pentaho-kettle by pentaho.
the class PurRepository method getFilesByType.
/**
* Fetch {@link RepositoryFile}s by {@code RepositoryObjectType}.
*
* @param allFiles
* List to add files into.
* @param types
* Types of files to fetch
* @return Ordered map of object types to list of files.
* @throws KettleException
*/
private LinkedHashMap<RepositoryObjectType, List<RepositoryFile>> getFilesByType(List<RepositoryFile> allFiles, RepositoryObjectType... types) throws KettleException {
// Must be ordered or we can't match up files with data and version summary
LinkedHashMap<RepositoryObjectType, List<RepositoryFile>> filesByType = new LinkedHashMap<RepositoryObjectType, List<RepositoryFile>>();
// Since type is not preserved in the RepositoryFile we must fetch files by type
for (RepositoryObjectType type : types) {
try {
List<RepositoryFile> files = getAllFilesOfType(null, type, false);
filesByType.put(type, files);
allFiles.addAll(files);
} catch (Exception ex) {
// $NON-NLS-1$
throw new KettleException(String.format("Unable to get all files of type [%s]", type), ex);
}
}
return filesByType;
}
use of org.pentaho.di.repository.RepositoryObjectType in project pentaho-kettle by pentaho.
the class PurRepository method fillRepositoryDirectoryFromTree.
private void fillRepositoryDirectoryFromTree(final RepositoryDirectoryInterface parentDir, final RepositoryFileTree treeNode) throws KettleException {
try {
List<RepositoryElementMetaInterface> fileChildren = new ArrayList<RepositoryElementMetaInterface>();
List<RepositoryFileTree> children = treeNode.getChildren();
if (children != null) {
for (RepositoryFileTree child : children) {
if (child.getFile().isFolder()) {
RepositoryDirectory dir = new RepositoryDirectory(parentDir, child.getFile().getName());
dir.setObjectId(new StringObjectId(child.getFile().getId().toString()));
parentDir.addSubdirectory(dir);
fillRepositoryDirectoryFromTree(dir, child);
} else {
// a real file, like a Transformation or Job
RepositoryLock lock = unifiedRepositoryLockService.getLock(child.getFile());
RepositoryObjectType objectType = getObjectType(child.getFile().getName());
fileChildren.add(new EERepositoryObject(child, parentDir, null, objectType, null, lock, false));
}
}
parentDir.setRepositoryObjects(fileChildren);
}
} catch (Exception e) {
throw new KettleException("Unable to load directory structure from repository", e);
}
}
Aggregations