Search in sources :

Example 31 with RepositoryFile

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

the class PurRepository method getClusterSchemaParentFolderId.

private Serializable getClusterSchemaParentFolderId() {
    if (cachedClusterSchemaParentFolderId == null) {
        RepositoryFile f = pur.getFile(getClusterSchemaParentFolderPath());
        cachedClusterSchemaParentFolderId = f.getId();
    }
    return cachedClusterSchemaParentFolderId;
}
Also used : RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile)

Example 32 with RepositoryFile

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

the class PurRepository method loadSlaveServer.

@Override
public SlaveServer loadSlaveServer(ObjectId idSlaveServer, String versionId) throws KettleException {
    try {
        NodeRepositoryFileData data = pur.getDataAtVersionForRead(idSlaveServer.getId(), versionId, NodeRepositoryFileData.class);
        RepositoryFile file = null;
        if (versionId != null) {
            file = pur.getFileAtVersion(idSlaveServer.getId(), versionId);
        } else {
            file = pur.getFileById(idSlaveServer.getId());
        }
        return slaveTransformer.assemble(file, data, pur.getVersionSummary(idSlaveServer.getId(), versionId));
    } catch (Exception e) {
        throw new KettleException("Unable to load slave server with id [" + idSlaveServer + "]", e);
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) NodeRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData) 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)

Example 33 with RepositoryFile

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

the class PurRepository method isUserHomeDirectory.

/**
 * Test to see if the folder is a user's home directory If it is an ancestor to a user's home directory, false will be
 * returned. (It is not actually a user's home directory)
 *
 * @param folder
 *          The folder to test; Must not be null
 * @return True if the directory is a users home directory and False if it is not; False if folder is null
 */
protected boolean isUserHomeDirectory(RepositoryFile folder) {
    if (folder != null) {
        // Get the root of all home folders
        RepositoryFile homeRootFolder = pur.getFile(ClientRepositoryPaths.getHomeFolderPath());
        if (homeRootFolder != null) {
            // Strip the final RepositoryDirectory.DIRECTORY_SEPARATOR from the paths
            String temp = homeRootFolder.getPath();
            String homeRootPath = temp.endsWith(RepositoryDirectory.DIRECTORY_SEPARATOR) && temp.length() > RepositoryDirectory.DIRECTORY_SEPARATOR.length() ? temp.substring(0, temp.length() - RepositoryDirectory.DIRECTORY_SEPARATOR.length()) : temp;
            temp = folder.getPath();
            String folderPath = temp.endsWith(RepositoryDirectory.DIRECTORY_SEPARATOR) && temp.length() > RepositoryDirectory.DIRECTORY_SEPARATOR.length() ? temp.substring(0, temp.length() - RepositoryDirectory.DIRECTORY_SEPARATOR.length()) : temp;
            // Is the folder in a user's home directory?
            if (folderPath.startsWith(homeRootPath)) {
                if (folderPath.equals(homeRootPath)) {
                    return false;
                }
                // If there is exactly one more RepositoryDirectory.DIRECTORY_SEPARATOR in folderPath than homeRootFolder,
                // then the user is trying to delete another user's home directory
                int folderPathDirCount = 0;
                int homeRootPathDirCount = 0;
                for (int x = 0; x >= 0; folderPathDirCount++) {
                    x = folderPath.indexOf(RepositoryDirectory.DIRECTORY_SEPARATOR, x + 1);
                }
                for (int x = 0; x >= 0; homeRootPathDirCount++) {
                    x = homeRootPath.indexOf(RepositoryDirectory.DIRECTORY_SEPARATOR, x + 1);
                }
                if (folderPathDirCount == (homeRootPathDirCount + 1)) {
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) KettleExtensionPoint(org.pentaho.di.core.extension.KettleExtensionPoint)

Example 34 with RepositoryFile

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

the class PurRepository method loadDatabaseMeta.

@Override
public DatabaseMeta loadDatabaseMeta(final ObjectId databaseId, final String versionId) throws KettleException {
    try {
        NodeRepositoryFileData data = pur.getDataAtVersionForRead(databaseId.getId(), versionId, NodeRepositoryFileData.class);
        RepositoryFile file = null;
        if (versionId != null) {
            file = pur.getFileAtVersion(databaseId.getId(), versionId);
        } else {
            file = pur.getFileById(databaseId.getId());
        }
        return databaseMetaTransformer.assemble(file, data, pur.getVersionSummary(databaseId.getId(), versionId));
    } catch (Exception e) {
        throw new KettleException("Unable to load database with id [" + databaseId + "]", e);
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) NodeRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData) 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)

Example 35 with RepositoryFile

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

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