Search in sources :

Example 11 with RepositoryObjectType

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;
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) RepositoryObjectType(org.pentaho.di.repository.RepositoryObjectType) List(java.util.List) ArrayList(java.util.ArrayList) SharedObjectInterface(org.pentaho.di.shared.SharedObjectInterface) 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)

Example 12 with RepositoryObjectType

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;
}
Also used : Serializable(java.io.Serializable) 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)

Example 13 with RepositoryObjectType

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;
}
Also used : RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) RepositoryDirectory(org.pentaho.di.repository.RepositoryDirectory) RepositoryObject(org.pentaho.di.repository.RepositoryObject) EERepositoryObject(org.pentaho.di.repository.pur.model.EERepositoryObject) ArrayList(java.util.ArrayList) RepositoryObjectType(org.pentaho.di.repository.RepositoryObjectType) RepositoryRequest(org.pentaho.platform.api.repository2.unified.RepositoryRequest) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) RepositoryObjectInterface(org.pentaho.di.repository.RepositoryObjectInterface)

Example 14 with RepositoryObjectType

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

Example 15 with RepositoryObjectType

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);
    }
}
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) RepositoryLock(org.pentaho.di.repository.pur.model.RepositoryLock) StringObjectId(org.pentaho.di.repository.StringObjectId) RepositoryFileTree(org.pentaho.platform.api.repository2.unified.RepositoryFileTree) 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)

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