Search in sources :

Example 16 with RepositoryRequest

use of org.pentaho.platform.api.repository2.unified.RepositoryRequest 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);
    readWriteLock.readLock().lock();
    List<RepositoryFile> repositoryFiles;
    try {
        repositoryFiles = pur.getChildren(repoRequest);
    } finally {
        readWriteLock.readLock().unlock();
    }
    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 17 with RepositoryRequest

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

the class LazyUnifiedRepositoryDirectory method getAllURChildrenFiles.

private List<RepositoryFile> getAllURChildrenFiles() {
    RepositoryRequest repositoryRequest = new RepositoryRequest();
    repositoryRequest.setShowHidden(showHidden);
    repositoryRequest.setTypes(RepositoryRequest.FILES_TYPE_FILTER.FOLDERS);
    repositoryRequest.setPath(this.self.getId().toString());
    List<RepositoryFile> children = repository.getChildren(repositoryRequest);
    // Special case: /etc should not be returned from a directory listing.
    RepositoryFile etcFile = null;
    if (this.isRoot()) {
        etcFile = repository.getFile(ClientRepositoryPaths.getEtcFolderPath());
    }
    // Filter for Folders only doesn't appear to work
    Iterator<RepositoryFile> iterator = children.iterator();
    while (iterator.hasNext()) {
        RepositoryFile next = iterator.next();
        if (!next.isFolder()) {
            iterator.remove();
        }
        // Special case: /etc should not be returned from a directory listing.
        if (this.isRoot() && next.equals(etcFile)) {
            iterator.remove();
        }
    }
    return children;
}
Also used : RepositoryRequest(org.pentaho.platform.api.repository2.unified.RepositoryRequest) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile)

Example 18 with RepositoryRequest

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

the class LazyUnifiedRepositoryDirectory method getRepositoryObjects.

@Override
public List<RepositoryElementMetaInterface> getRepositoryObjects() {
    if (fileChildren == null) {
        fileChildren = new ArrayList<>();
        synchronized (fileChildren) {
            UnifiedRepositoryLockService lockService = (UnifiedRepositoryLockService) registry.getService(ILockService.class);
            RepositoryFileTree tree = repository.getTree(new RepositoryRequest(this.self.getPath(), showHidden, 1, null));
            for (RepositoryFileTree tchild : tree.getChildren()) {
                RepositoryFile child = tchild.getFile();
                if (!child.isFolder()) {
                    RepositoryLock lock = null;
                    try {
                        lock = lockService.getLock(child);
                        RepositoryObjectType objectType = PurRepository.getObjectType(child.getName());
                        EERepositoryObject repositoryObject = new EERepositoryObject(child, this, null, objectType, null, lock, false);
                        repositoryObject.setVersioningEnabled(tchild.getVersioningEnabled());
                        repositoryObject.setVersionCommentEnabled(tchild.getVersionCommentEnabled());
                        fileChildren.add(repositoryObject);
                    } catch (KettleException e) {
                        logger.error("Error converting Unified Repository file to PDI RepositoryObject: " + child.getPath() + ". File will be skipped", e);
                    }
                }
            }
        }
    }
    return fileChildren;
}
Also used : EERepositoryObject(org.pentaho.di.repository.pur.model.EERepositoryObject) KettleException(org.pentaho.di.core.exception.KettleException) ILockService(org.pentaho.di.ui.repository.pur.services.ILockService) RepositoryObjectType(org.pentaho.di.repository.RepositoryObjectType) RepositoryRequest(org.pentaho.platform.api.repository2.unified.RepositoryRequest) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) RepositoryLock(org.pentaho.di.repository.pur.model.RepositoryLock) RepositoryFileTree(org.pentaho.platform.api.repository2.unified.RepositoryFileTree)

Example 19 with RepositoryRequest

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

the class UnifiedRepositoryPurgeService method processRevisionDeletion.

private void processRevisionDeletion(PurgeUtilitySpecification purgeSpecification) throws PurgeDeletionException {
    RepositoryRequest repositoryRequest = new RepositoryRequest(purgeSpecification.getPath(), true, -1, purgeSpecification.getFileFilter());
    repositoryRequest.setTypes(FILES_TYPE_FILTER.FILES_FOLDERS);
    repositoryRequest.setIncludeMemberSet(new HashSet<String>(Arrays.asList(new String[] { "name", "id", "folder", "path", "versioned", "versionId", "locked" })));
    getLogger().debug("Creating file list");
    RepositoryFileTreeDto tree = getRepoWs().getTreeFromRequest(repositoryRequest);
    processPurgeForTree(tree, purgeSpecification);
}
Also used : RepositoryFileTreeDto(org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileTreeDto) RepositoryRequest(org.pentaho.platform.api.repository2.unified.RepositoryRequest)

Example 20 with RepositoryRequest

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

the class PurRepository method loadRepositoryFileTree.

private RepositoryFileTree loadRepositoryFileTree(String path, String filter, int depth, boolean showHidden, boolean includeAcls, FILES_TYPE_FILTER types) {
    RepositoryRequest repoRequest = new RepositoryRequest();
    repoRequest.setPath(Utils.isEmpty(path) ? "/" : path);
    repoRequest.setChildNodeFilter(filter == null ? "*" : filter);
    repoRequest.setDepth(depth);
    repoRequest.setShowHidden(showHidden);
    repoRequest.setIncludeAcls(includeAcls);
    repoRequest.setTypes(types == null ? FILES_TYPE_FILTER.FILES_FOLDERS : types);
    readWriteLock.readLock().lock();
    RepositoryFileTree fileTree;
    try {
        fileTree = pur.getTree(repoRequest);
    } finally {
        readWriteLock.readLock().unlock();
    }
    return fileTree;
}
Also used : RepositoryRequest(org.pentaho.platform.api.repository2.unified.RepositoryRequest) RepositoryFileTree(org.pentaho.platform.api.repository2.unified.RepositoryFileTree)

Aggregations

RepositoryRequest (org.pentaho.platform.api.repository2.unified.RepositoryRequest)31 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)19 RepositoryFileTree (org.pentaho.platform.api.repository2.unified.RepositoryFileTree)19 ArrayList (java.util.ArrayList)11 Test (org.junit.Test)11 Matchers.anyString (org.mockito.Matchers.anyString)8 ITenant (org.pentaho.platform.api.mt.ITenant)7 IUnifiedRepository (org.pentaho.platform.api.repository2.unified.IUnifiedRepository)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 Collator (java.text.Collator)4 SimpleRepositoryFileData (org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData)4 File (java.io.File)3 Serializable (java.io.Serializable)3 ObjectId (org.pentaho.di.repository.ObjectId)3 EERepositoryObject (org.pentaho.di.repository.pur.model.EERepositoryObject)3 RepositoryFileAcl (org.pentaho.platform.api.repository2.unified.RepositoryFileAcl)3 RepositoryFileDto (org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto)3 HashMap (java.util.HashMap)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 RepositoryDirectoryInterface (org.pentaho.di.repository.RepositoryDirectoryInterface)2