Search in sources :

Example 21 with RepositoryFile

use of org.pentaho.platform.api.repository2.unified.RepositoryFile in project pentaho-kettle by pentaho.

the class PurRepositoryMetaStore method getElementType.

@Override
public IMetaStoreElementType getElementType(String namespace, String elementTypeId) throws MetaStoreException {
    RepositoryFile elementTypeFolder = pur.getFileById(elementTypeId);
    if (elementTypeFolder == null) {
        return null;
    }
    IMetaStoreElementType elementType = newElementType(namespace);
    elementType.setId(elementTypeFolder.getId().toString());
    elementType.setName(elementTypeFolder.getName());
    RepositoryFile detailsFile = findChildByName(elementTypeFolder.getId(), ELEMENT_TYPE_DETAILS_FILENAME, true);
    if (detailsFile != null) {
        NodeRepositoryFileData data = pur.getDataForRead(detailsFile.getId(), NodeRepositoryFileData.class);
        DataProperty property = data.getNode().getProperty("element_type_description");
        if (property != null) {
            elementType.setDescription(property.getString());
        }
    }
    return elementType;
}
Also used : IMetaStoreElementType(org.pentaho.metastore.api.IMetaStoreElementType) NodeRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) DataProperty(org.pentaho.platform.api.repository2.unified.data.node.DataProperty)

Example 22 with RepositoryFile

use of org.pentaho.platform.api.repository2.unified.RepositoryFile in project pentaho-kettle by pentaho.

the class PurRepositoryMetaStore method getNamespaces.

@Override
public List<String> getNamespaces() throws MetaStoreException {
    List<String> namespaces = new ArrayList<String>();
    List<RepositoryFile> children = getChildren(namespacesFolder.getId());
    for (RepositoryFile child : children) {
        namespaces.add(child.getName());
    }
    return namespaces;
}
Also used : ArrayList(java.util.ArrayList) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile)

Example 23 with RepositoryFile

use of org.pentaho.platform.api.repository2.unified.RepositoryFile in project pentaho-kettle by pentaho.

the class PurRepositoryMetaStore method deleteElementType.

@Override
public void deleteElementType(String namespace, IMetaStoreElementType elementType) throws MetaStoreException {
    RepositoryFile namespaceRepositoryFile = validateNamespace(namespace);
    RepositoryFile elementTypeFile = findChildByName(namespaceRepositoryFile.getId(), elementType.getName());
    List<RepositoryFile> children = getChildren(elementTypeFile.getId());
    removeHiddenFilesFromList(children);
    if (children.isEmpty()) {
        pur.deleteFile(elementTypeFile.getId(), true, null);
    } else {
        List<String> ids = getElementIds(namespace, elementType);
        throw new MetaStoreDependenciesExistsException(ids, "Can't delete element type with name '" + elementType.getName() + "' because it is not empty");
    }
}
Also used : RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) MetaStoreDependenciesExistsException(org.pentaho.metastore.api.exceptions.MetaStoreDependenciesExistsException)

Example 24 with RepositoryFile

use of org.pentaho.platform.api.repository2.unified.RepositoryFile 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 25 with RepositoryFile

use of org.pentaho.platform.api.repository2.unified.RepositoryFile 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)

Aggregations

RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)455 Test (org.junit.Test)183 ITenant (org.pentaho.platform.api.mt.ITenant)87 Matchers.anyString (org.mockito.Matchers.anyString)86 ArrayList (java.util.ArrayList)85 RepositoryFileAcl (org.pentaho.platform.api.repository2.unified.RepositoryFileAcl)83 Serializable (java.io.Serializable)56 IUnifiedRepository (org.pentaho.platform.api.repository2.unified.IUnifiedRepository)53 SimpleRepositoryFileData (org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData)49 KettleException (org.pentaho.di.core.exception.KettleException)40 NodeRepositoryFileData (org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData)40 ByteArrayInputStream (java.io.ByteArrayInputStream)39 UnifiedRepositoryException (org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException)39 IOException (java.io.IOException)37 File (java.io.File)34 MetaStoreException (org.pentaho.metastore.api.exceptions.MetaStoreException)34 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)33 MetaStoreNamespaceExistsException (org.pentaho.metastore.api.exceptions.MetaStoreNamespaceExistsException)33 IdNotFoundException (org.pentaho.di.core.exception.IdNotFoundException)32 KettleFileException (org.pentaho.di.core.exception.KettleFileException)32