Search in sources :

Example 21 with RepositoryObjectType

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;
    }
}
Also used : RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) KettleException(org.pentaho.di.core.exception.KettleException) RepositoryObjectType(org.pentaho.di.repository.RepositoryObjectType) LastUsedFile(org.pentaho.di.core.LastUsedFile)

Example 22 with RepositoryObjectType

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;
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) PartitionSchema(org.pentaho.di.partition.PartitionSchema) ArrayList(java.util.ArrayList) SlaveServer(org.pentaho.di.cluster.SlaveServer) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) RepositoryObjectType(org.pentaho.di.repository.RepositoryObjectType) List(java.util.List) ArrayList(java.util.ArrayList) SharedObjectInterface(org.pentaho.di.shared.SharedObjectInterface) EnumMap(java.util.EnumMap) ClusterSchema(org.pentaho.di.cluster.ClusterSchema)

Example 23 with RepositoryObjectType

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);
    }
}
Also used : EERepositoryObject(org.pentaho.di.repository.pur.model.EERepositoryObject) KettleException(org.pentaho.di.core.exception.KettleException) RepositoryDirectory(org.pentaho.di.repository.RepositoryDirectory) ArrayList(java.util.ArrayList) RepositoryObjectType(org.pentaho.di.repository.RepositoryObjectType) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) RepositoryLock(org.pentaho.di.repository.pur.model.RepositoryLock) MetaStoreNamespaceExistsException(org.pentaho.metastore.api.exceptions.MetaStoreNamespaceExistsException) KettleFileException(org.pentaho.di.core.exception.KettleFileException) MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) UnifiedRepositoryCreateFileException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryCreateFileException) UnifiedRepositoryUpdateFileException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryUpdateFileException) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) KettleException(org.pentaho.di.core.exception.KettleException) IdNotFoundException(org.pentaho.di.core.exception.IdNotFoundException) KettleSecurityException(org.pentaho.di.core.exception.KettleSecurityException) RepositoryElementMetaInterface(org.pentaho.di.repository.RepositoryElementMetaInterface)

Example 24 with RepositoryObjectType

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);
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) StringObjectId(org.pentaho.di.repository.StringObjectId) ObjectId(org.pentaho.di.repository.ObjectId) PartitionSchema(org.pentaho.di.partition.PartitionSchema) ArrayList(java.util.ArrayList) SlaveServer(org.pentaho.di.cluster.SlaveServer) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) KettleExtensionPoint(org.pentaho.di.core.extension.KettleExtensionPoint) RepositoryElementInterface(org.pentaho.di.repository.RepositoryElementInterface) RepositoryObjectType(org.pentaho.di.repository.RepositoryObjectType) SharedObjectInterface(org.pentaho.di.shared.SharedObjectInterface)

Example 25 with RepositoryObjectType

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;
}
Also used : ArrayList(java.util.ArrayList) RepositoryObjectType(org.pentaho.di.repository.RepositoryObjectType) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) KettleExtensionPoint(org.pentaho.di.core.extension.KettleExtensionPoint) HashSet(java.util.HashSet)

Aggregations

RepositoryObjectType (org.pentaho.di.repository.RepositoryObjectType)25 ArrayList (java.util.ArrayList)13 KettleException (org.pentaho.di.core.exception.KettleException)13 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)10 List (java.util.List)7 SharedObjectInterface (org.pentaho.di.shared.SharedObjectInterface)7 IdNotFoundException (org.pentaho.di.core.exception.IdNotFoundException)6 RepositoryDirectoryInterface (org.pentaho.di.repository.RepositoryDirectoryInterface)6 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)5 Test (org.junit.Test)5 KettleFileException (org.pentaho.di.core.exception.KettleFileException)5 KettleSecurityException (org.pentaho.di.core.exception.KettleSecurityException)5 RepositoryElementMetaInterface (org.pentaho.di.repository.RepositoryElementMetaInterface)5 StringObjectId (org.pentaho.di.repository.StringObjectId)5 EERepositoryObject (org.pentaho.di.repository.pur.model.EERepositoryObject)5 MetaStoreException (org.pentaho.metastore.api.exceptions.MetaStoreException)5 MetaStoreNamespaceExistsException (org.pentaho.metastore.api.exceptions.MetaStoreNamespaceExistsException)5 RepositoryFileTree (org.pentaho.platform.api.repository2.unified.RepositoryFileTree)5 UnifiedRepositoryCreateFileException (org.pentaho.platform.api.repository2.unified.UnifiedRepositoryCreateFileException)5 UnifiedRepositoryUpdateFileException (org.pentaho.platform.api.repository2.unified.UnifiedRepositoryUpdateFileException)5