use of org.pentaho.di.repository.RepositoryObjectType in project pentaho-kettle by pentaho.
the class Spoon method recentRepoFileExists.
/**
* Returns true if the {@link LastUsedFile} at the given {@code index} within the {@link
* PropsUI#getLastUsedRepoFiles()} collection exists within the given {@code repo} {@link Repository},
* and false otherwise.
*
* @param repo the {@link Repository} containing the file
* @param indexStr the String index of the file within the last used repo file collection
* @return true if the {@link LastUsedFile} at the given {@code index} within the {@link
* PropsUI#getLastUsedRepoFiles()} collection exists within the given {@code repo} {@link Repository},
* and false otherwise
* @throws KettleException
*/
public boolean recentRepoFileExists(String repo, String indexStr) {
final LastUsedFile lastUsedFile = getLastUsedRepoFile(repo, indexStr);
// this should never happen when used on a repo file, but we check just to be safe
if (lastUsedFile == null) {
return false;
}
// again, should never happen, since the file being selected is a valid repo file in this repo
if (!lastUsedFile.isSourceRepository() || !rep.getName().equalsIgnoreCase(lastUsedFile.getRepositoryName())) {
return false;
}
try {
final RepositoryDirectoryInterface rdi = rep.findDirectory(lastUsedFile.getDirectory());
if (rdi == null) {
return false;
}
final RepositoryObjectType fileType = lastUsedFile.isJob() ? RepositoryObjectType.JOB : RepositoryObjectType.TRANSFORMATION;
return rep.exists(lastUsedFile.getFilename(), rdi, fileType);
} catch (final KettleException ke) {
// log
return false;
}
}
use of org.pentaho.di.repository.RepositoryObjectType in project pentaho-kettle by pentaho.
the class PurRepository method deepCopy.
private Map<RepositoryObjectType, List<? extends SharedObjectInterface>> deepCopy(Map<RepositoryObjectType, List<? extends SharedObjectInterface>> orig) throws KettleException {
Map<RepositoryObjectType, List<? extends SharedObjectInterface>> copy = new EnumMap<RepositoryObjectType, List<? extends SharedObjectInterface>>(RepositoryObjectType.class);
for (Entry<RepositoryObjectType, List<? extends SharedObjectInterface>> entry : orig.entrySet()) {
RepositoryObjectType type = entry.getKey();
List<? extends SharedObjectInterface> value = entry.getValue();
List<SharedObjectInterface> newValue = new ArrayList<SharedObjectInterface>(value.size());
for (SharedObjectInterface obj : value) {
SharedObjectInterface newValueItem;
if (obj instanceof DatabaseMeta) {
DatabaseMeta databaseMeta = (DatabaseMeta) ((DatabaseMeta) obj).clone();
databaseMeta.setObjectId(((DatabaseMeta) obj).getObjectId());
databaseMeta.clearChanged();
newValueItem = databaseMeta;
} else if (obj instanceof SlaveServer) {
SlaveServer slaveServer = (SlaveServer) ((SlaveServer) obj).clone();
slaveServer.setObjectId(((SlaveServer) obj).getObjectId());
slaveServer.clearChanged();
newValueItem = slaveServer;
} else if (obj instanceof PartitionSchema) {
PartitionSchema partitionSchema = (PartitionSchema) ((PartitionSchema) obj).clone();
partitionSchema.setObjectId(((PartitionSchema) obj).getObjectId());
partitionSchema.clearChanged();
newValueItem = partitionSchema;
} else if (obj instanceof ClusterSchema) {
ClusterSchema clusterSchema = ((ClusterSchema) obj).clone();
clusterSchema.setObjectId(((ClusterSchema) obj).getObjectId());
clusterSchema.clearChanged();
newValueItem = clusterSchema;
} else {
throw new KettleException("unknown shared object class");
}
newValue.add(newValueItem);
}
copy.put(type, newValue);
}
return copy;
}
use of org.pentaho.di.repository.RepositoryObjectType in project pentaho-kettle by pentaho.
the class PurRepository method getPdiObjects.
protected List<RepositoryElementMetaInterface> getPdiObjects(ObjectId dirId, List<RepositoryObjectType> objectTypes, boolean includeDeleted) throws KettleException {
try {
// RepositoryDirectoryInterface repDir = getRootDir().findDirectory( dirId );
RepositoryFile dirFile = pur.getFileById(dirId.getId());
RepositoryDirectory repDir = new RepositoryDirectory();
repDir.setObjectId(dirId);
repDir.setName(dirFile.getName());
List<RepositoryElementMetaInterface> list = new ArrayList<RepositoryElementMetaInterface>();
List<RepositoryFile> nonDeletedChildren = getAllFilesOfType(dirId, objectTypes);
for (RepositoryFile file : nonDeletedChildren) {
RepositoryLock lock = unifiedRepositoryLockService.getLock(file);
RepositoryObjectType objectType = getObjectType(file.getName());
list.add(new EERepositoryObject(file, repDir, null, objectType, null, lock, false));
}
if (includeDeleted) {
String dirPath = null;
if (dirId != null) {
// derive path using id
dirPath = pur.getFileById(dirId.getId()).getPath();
}
List<RepositoryFile> deletedChildren = getAllDeletedFilesOfType(dirPath, objectTypes);
for (RepositoryFile file : deletedChildren) {
RepositoryLock lock = unifiedRepositoryLockService.getLock(file);
RepositoryObjectType objectType = getObjectType(file.getName());
list.add(new EERepositoryObject(file, repDir, null, objectType, null, lock, true));
}
}
return list;
} catch (Exception e) {
throw new KettleException("Unable to get list of objects from directory [" + dirId + "]", e);
}
}
use of org.pentaho.di.repository.RepositoryObjectType in project pentaho-kettle by pentaho.
the class PurRepository method updateSharedObjectCache.
/**
* Do not call this method directly. Instead call updateSharedObjectCache or removeFromSharedObjectCache.
*/
private void updateSharedObjectCache(final RepositoryElementInterface element, final RepositoryObjectType type, final ObjectId id) throws KettleException {
if (element != null && (element.getObjectId() == null || element.getObjectId().getId() == null)) {
throw new IllegalArgumentException(element.getName() + " has a null id");
}
loadAndCacheSharedObjects(false);
boolean remove = element == null;
ObjectId idToFind = element != null ? element.getObjectId() : id;
RepositoryObjectType typeToUpdate = element != null ? element.getRepositoryElementType() : type;
RepositoryElementInterface elementToUpdate = null;
List<? extends SharedObjectInterface> origSharedObjects = null;
switch(typeToUpdate) {
case DATABASE:
origSharedObjects = sharedObjectsByType.get(RepositoryObjectType.DATABASE);
if (!remove) {
elementToUpdate = (RepositoryElementInterface) ((DatabaseMeta) element).clone();
}
break;
case SLAVE_SERVER:
origSharedObjects = sharedObjectsByType.get(RepositoryObjectType.SLAVE_SERVER);
if (!remove) {
elementToUpdate = (RepositoryElementInterface) ((SlaveServer) element).clone();
}
break;
case CLUSTER_SCHEMA:
origSharedObjects = sharedObjectsByType.get(RepositoryObjectType.CLUSTER_SCHEMA);
if (!remove) {
elementToUpdate = ((ClusterSchema) element).clone();
}
break;
case PARTITION_SCHEMA:
origSharedObjects = sharedObjectsByType.get(RepositoryObjectType.PARTITION_SCHEMA);
if (!remove) {
elementToUpdate = (RepositoryElementInterface) ((PartitionSchema) element).clone();
}
break;
default:
throw new KettleException("unknown type [" + typeToUpdate + "]");
}
List<SharedObjectInterface> newSharedObjects = new ArrayList<SharedObjectInterface>(origSharedObjects);
// if there's a match on id, replace the element
boolean found = false;
for (int i = 0; i < origSharedObjects.size(); i++) {
RepositoryElementInterface repositoryElementInterface = (RepositoryElementInterface) origSharedObjects.get(i);
if (repositoryElementInterface == null) {
continue;
}
ObjectId objectId = repositoryElementInterface.getObjectId();
if (objectId != null && objectId.equals(idToFind)) {
if (remove) {
newSharedObjects.remove(i);
} else {
// because some clones don't clone the ID!!!
elementToUpdate.setObjectId(idToFind);
newSharedObjects.set(i, (SharedObjectInterface) elementToUpdate);
}
found = true;
}
}
// otherwise, add it
if (!remove && !found) {
// because some clones don't clone the ID!!!
elementToUpdate.setObjectId(idToFind);
newSharedObjects.add((SharedObjectInterface) elementToUpdate);
}
sharedObjectsByType.put(typeToUpdate, newSharedObjects);
}
use of org.pentaho.di.repository.RepositoryObjectType in project pentaho-kettle by pentaho.
the class PurRepository method getAllDeletedFilesOfType.
protected List<RepositoryFile> getAllDeletedFilesOfType(final String dirPath, final List<RepositoryObjectType> objectTypes) throws KettleException {
Set<String> parentFolderPaths = new HashSet<>();
List<String> filters = new ArrayList<>();
for (RepositoryObjectType objectType : objectTypes) {
switch(objectType) {
case DATABASE:
{
parentFolderPaths.add(getDatabaseMetaParentFolderPath());
// $NON-NLS-1$
filters.add("*" + RepositoryObjectType.DATABASE.getExtension());
break;
}
case TRANSFORMATION:
{
parentFolderPaths.add(dirPath);
// $NON-NLS-1$
filters.add("*" + RepositoryObjectType.TRANSFORMATION.getExtension());
break;
}
case PARTITION_SCHEMA:
{
parentFolderPaths.add(getPartitionSchemaParentFolderPath());
// $NON-NLS-1$
filters.add("*" + RepositoryObjectType.PARTITION_SCHEMA.getExtension());
break;
}
case SLAVE_SERVER:
{
parentFolderPaths.add(getSlaveServerParentFolderPath());
// $NON-NLS-1$
filters.add("*" + RepositoryObjectType.SLAVE_SERVER.getExtension());
break;
}
case CLUSTER_SCHEMA:
{
parentFolderPaths.add(getClusterSchemaParentFolderPath());
// $NON-NLS-1$
filters.add("*" + RepositoryObjectType.CLUSTER_SCHEMA.getExtension());
break;
}
case JOB:
{
parentFolderPaths.add(dirPath);
// $NON-NLS-1$
filters.add("*" + RepositoryObjectType.JOB.getExtension());
break;
}
default:
{
throw new UnsupportedOperationException();
}
}
}
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<RepositoryFile>();
for (String parentFolderPath : parentFolderPaths) {
allFiles.addAll(pur.getDeletedFiles(parentFolderPath, mergedFilterBuf.toString()));
}
Collections.sort(allFiles);
return allFiles;
}
Aggregations