Search in sources :

Example 31 with StringObjectId

use of org.pentaho.di.repository.StringObjectId in project pentaho-kettle by pentaho.

the class PurRepository method loadTransformation.

@Override
public TransMeta loadTransformation(final String transName, final RepositoryDirectoryInterface parentDir, final ProgressMonitorListener monitor, final boolean setInternalVariables, final String versionId) throws KettleException {
    String absPath = null;
    try {
        // by the user
        if (StringUtils.isBlank(transName)) {
            throw new KettleFileException(BaseMessages.getString(PKG, "PurRepository.ERROR_0007_TRANSFORMATION_NAME_MISSING"));
        }
        try {
            absPath = getPath(transName, parentDir, RepositoryObjectType.TRANSFORMATION);
        } catch (Exception e) {
        // ignore and handle null value below
        }
        // variable that is not available at runtime
        if (StringUtils.isBlank(absPath)) {
            // Couldn't resolve path, throw an exception
            throw new KettleFileException(BaseMessages.getString(PKG, "PurRepository.ERROR_0008_TRANSFORMATION_PATH_INVALID", transName));
        }
        RepositoryFile file = pur.getFile(absPath);
        if (versionId != null) {
            // need to go back to server to get versioned info
            file = pur.getFileAtVersion(file.getId(), versionId);
        }
        // valid file
        if (file == null) {
            throw new KettleException(BaseMessages.getString(PKG, "PurRepository.ERROR_0008_TRANSFORMATION_PATH_INVALID", absPath));
        }
        NodeRepositoryFileData data = null;
        ObjectRevision revision = null;
        // Additional obfuscation through obscurity
        data = pur.getDataAtVersionForRead(file.getId(), versionId, NodeRepositoryFileData.class);
        revision = getObjectRevision(new StringObjectId(file.getId().toString()), versionId);
        TransMeta transMeta = buildTransMeta(file, parentDir, data, revision);
        ExtensionPointHandler.callExtensionPoint(log, KettleExtensionPoint.TransformationMetaLoaded.id, transMeta);
        return transMeta;
    } catch (final KettleException ke) {
        // if we have a KettleException, simply re-throw it
        throw ke;
    } catch (Exception e) {
        throw new KettleException("Unable to load transformation from path [" + absPath + "]", e);
    }
}
Also used : ObjectRevision(org.pentaho.di.repository.ObjectRevision) KettleException(org.pentaho.di.core.exception.KettleException) KettleFileException(org.pentaho.di.core.exception.KettleFileException) NodeRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData) TransMeta(org.pentaho.di.trans.TransMeta) EETransMeta(org.pentaho.di.repository.pur.model.EETransMeta) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) StringObjectId(org.pentaho.di.repository.StringObjectId) 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 32 with StringObjectId

use of org.pentaho.di.repository.StringObjectId in project pentaho-kettle by pentaho.

the class PurRepository method getObjectId.

/**
 * Copying the behavior of the original JCRRepository, this implementation returns IDs of deleted objects too.
 */
private ObjectId getObjectId(final String name, final RepositoryDirectoryInterface dir, final RepositoryObjectType objectType, boolean includedDeleteFiles) {
    final String absPath = getPath(name, dir, objectType);
    RepositoryFile file = pur.getFile(absPath);
    if (file != null) {
        // file exists
        return new StringObjectId(file.getId().toString());
    } else if (includedDeleteFiles) {
        switch(objectType) {
            case DATABASE:
                {
                    // file either never existed or has been deleted
                    List<RepositoryFile> deletedChildren = pur.getDeletedFiles(getDatabaseMetaParentFolderPath(), name + RepositoryObjectType.DATABASE.getExtension());
                    if (!deletedChildren.isEmpty()) {
                        return new StringObjectId(deletedChildren.get(0).getId().toString());
                    } else {
                        return null;
                    }
                }
            case TRANSFORMATION:
                {
                    // file either never existed or has been deleted
                    List<RepositoryFile> deletedChildren = pur.getDeletedFiles(dir.getObjectId().getId(), name + RepositoryObjectType.TRANSFORMATION.getExtension());
                    if (!deletedChildren.isEmpty()) {
                        return new StringObjectId(deletedChildren.get(0).getId().toString());
                    } else {
                        return null;
                    }
                }
            case PARTITION_SCHEMA:
                {
                    // file either never existed or has been deleted
                    List<RepositoryFile> deletedChildren = pur.getDeletedFiles(getPartitionSchemaParentFolderPath(), name + RepositoryObjectType.PARTITION_SCHEMA.getExtension());
                    if (!deletedChildren.isEmpty()) {
                        return new StringObjectId(deletedChildren.get(0).getId().toString());
                    } else {
                        return null;
                    }
                }
            case SLAVE_SERVER:
                {
                    // file either never existed or has been deleted
                    List<RepositoryFile> deletedChildren = pur.getDeletedFiles(getSlaveServerParentFolderPath(), name + RepositoryObjectType.SLAVE_SERVER.getExtension());
                    if (!deletedChildren.isEmpty()) {
                        return new StringObjectId(deletedChildren.get(0).getId().toString());
                    } else {
                        return null;
                    }
                }
            case CLUSTER_SCHEMA:
                {
                    // file either never existed or has been deleted
                    List<RepositoryFile> deletedChildren = pur.getDeletedFiles(getClusterSchemaParentFolderPath(), name + RepositoryObjectType.CLUSTER_SCHEMA.getExtension());
                    if (!deletedChildren.isEmpty()) {
                        return new StringObjectId(deletedChildren.get(0).getId().toString());
                    } else {
                        return null;
                    }
                }
            case JOB:
                {
                    // file either never existed or has been deleted
                    List<RepositoryFile> deletedChildren = pur.getDeletedFiles(dir.getObjectId().getId(), name + RepositoryObjectType.JOB.getExtension());
                    if (!deletedChildren.isEmpty()) {
                        return new StringObjectId(deletedChildren.get(0).getId().toString());
                    } else {
                        return null;
                    }
                }
            default:
                {
                    throw new UnsupportedOperationException("not implemented");
                }
        }
    } else {
        return null;
    }
}
Also used : RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) StringObjectId(org.pentaho.di.repository.StringObjectId)

Example 33 with StringObjectId

use of org.pentaho.di.repository.StringObjectId in project pentaho-kettle by pentaho.

the class PurRepository method deleteDatabaseMeta.

@Override
public void deleteDatabaseMeta(final String databaseName) throws KettleException {
    RepositoryFile fileToDelete = null;
    try {
        fileToDelete = pur.getFile(getPath(databaseName, null, RepositoryObjectType.DATABASE));
    } catch (Exception e) {
        throw new KettleException("Unable to delete database with name [" + databaseName + "]", e);
    }
    ObjectId idDatabase = new StringObjectId(fileToDelete.getId().toString());
    permanentlyDeleteSharedObject(idDatabase);
    removeFromSharedObjectCache(RepositoryObjectType.DATABASE, idDatabase);
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) StringObjectId(org.pentaho.di.repository.StringObjectId) ObjectId(org.pentaho.di.repository.ObjectId) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) StringObjectId(org.pentaho.di.repository.StringObjectId) 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 34 with StringObjectId

use of org.pentaho.di.repository.StringObjectId in project pentaho-kettle by pentaho.

the class PurRepository method getClusterIDs.

@Override
public ObjectId[] getClusterIDs(boolean includeDeleted) throws KettleException {
    try {
        List<RepositoryFile> children = getAllFilesOfType(null, RepositoryObjectType.CLUSTER_SCHEMA, includeDeleted);
        List<ObjectId> ids = new ArrayList<ObjectId>();
        for (RepositoryFile file : children) {
            ids.add(new StringObjectId(file.getId().toString()));
        }
        return ids.toArray(new ObjectId[0]);
    } catch (Exception e) {
        throw new KettleException("Unable to get all cluster schema IDs", e);
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) StringObjectId(org.pentaho.di.repository.StringObjectId) ObjectId(org.pentaho.di.repository.ObjectId) ArrayList(java.util.ArrayList) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) StringObjectId(org.pentaho.di.repository.StringObjectId) 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 35 with StringObjectId

use of org.pentaho.di.repository.StringObjectId 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

StringObjectId (org.pentaho.di.repository.StringObjectId)123 KettleException (org.pentaho.di.core.exception.KettleException)49 ObjectId (org.pentaho.di.repository.ObjectId)38 Test (org.junit.Test)34 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)25 KettleFileException (org.pentaho.di.core.exception.KettleFileException)21 MetaStoreException (org.pentaho.metastore.api.exceptions.MetaStoreException)18 MetaStoreNamespaceExistsException (org.pentaho.metastore.api.exceptions.MetaStoreNamespaceExistsException)18 ArrayList (java.util.ArrayList)16 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)15 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)14 RepositoryObject (org.pentaho.di.repository.RepositoryObject)14 TransMeta (org.pentaho.di.trans.TransMeta)14 IdNotFoundException (org.pentaho.di.core.exception.IdNotFoundException)13 KettleSecurityException (org.pentaho.di.core.exception.KettleSecurityException)13 UnifiedRepositoryCreateFileException (org.pentaho.platform.api.repository2.unified.UnifiedRepositoryCreateFileException)13 UnifiedRepositoryUpdateFileException (org.pentaho.platform.api.repository2.unified.UnifiedRepositoryUpdateFileException)13 Repository (org.pentaho.di.repository.Repository)11 IOException (java.io.IOException)10 FileObject (org.apache.commons.vfs2.FileObject)10