Search in sources :

Example 1 with EERepositoryObject

use of org.pentaho.di.repository.pur.model.EERepositoryObject in project pentaho-kettle by pentaho.

the class LazyUnifiedRepositoryDirectory method getRepositoryObjects.

@Override
public List<RepositoryElementMetaInterface> getRepositoryObjects() {
    if (fileChildren == null) {
        fileChildren = new ArrayList<RepositoryElementMetaInterface>();
        synchronized (fileChildren) {
            UnifiedRepositoryLockService lockService = (UnifiedRepositoryLockService) registry.getService(ILockService.class);
            RepositoryFileTree tree = repository.getTree(new RepositoryRequest(this.self.getPath(), true, 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) RepositoryElementMetaInterface(org.pentaho.di.repository.RepositoryElementMetaInterface)

Example 2 with EERepositoryObject

use of org.pentaho.di.repository.pur.model.EERepositoryObject 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)

Example 3 with EERepositoryObject

use of org.pentaho.di.repository.pur.model.EERepositoryObject in project pentaho-kettle by pentaho.

the class PurRepositoryUnitTest method testRevisionsEnabled.

@Test
public void testRevisionsEnabled() throws KettleException {
    PurRepository purRepository = new PurRepository();
    IUnifiedRepository mockRepo = mock(IUnifiedRepository.class);
    RepositoryConnectResult result = mock(RepositoryConnectResult.class);
    when(result.getUnifiedRepository()).thenReturn(mockRepo);
    IRepositoryConnector connector = mock(IRepositoryConnector.class);
    when(connector.connect(anyString(), anyString())).thenReturn(result);
    RepositoryServiceRegistry registry = mock(RepositoryServiceRegistry.class);
    UnifiedRepositoryLockService lockService = new UnifiedRepositoryLockService(mockRepo);
    when(registry.getService(ILockService.class)).thenReturn(lockService);
    when(result.repositoryServiceRegistry()).thenReturn(registry);
    PurRepositoryMeta mockMeta = mock(PurRepositoryMeta.class);
    purRepository.init(mockMeta);
    purRepository.setPurRepositoryConnector(connector);
    // purRepository.setTest( mockRepo );
    ObjectId objectId = mock(ObjectId.class);
    RepositoryFile mockFileVersioningEnabled = mock(RepositoryFile.class);
    RepositoryFile mockFileVersioningNotEnabled = mock(RepositoryFile.class);
    RepositoryFileTree mockRepositoryTreeChildVersioningEnabled = mock(RepositoryFileTree.class);
    RepositoryFileTree mockRepositoryTreeChildVersioningNotEnabled = mock(RepositoryFileTree.class);
    RepositoryFile publicFolder = mock(RepositoryFile.class);
    RepositoryFileTree publicFolderTree = mock(RepositoryFileTree.class);
    RepositoryFile mockRootFolder = mock(RepositoryFile.class);
    RepositoryObjectType repositoryObjectType = RepositoryObjectType.TRANSFORMATION;
    RepositoryFileTree mockRepositoryTree = mock(RepositoryFileTree.class);
    String testId = "TEST_ID";
    String testFileId = "TEST_FILE_ID";
    List<RepositoryFileTree> children = Arrays.asList(mockRepositoryTreeChildVersioningEnabled, mockRepositoryTreeChildVersioningNotEnabled);
    when(objectId.getId()).thenReturn(testId);
    when(mockRepo.getFileById(testId)).thenReturn(mockFileVersioningEnabled);
    when(mockFileVersioningEnabled.getPath()).thenReturn("/public/path.ktr");
    when(mockFileVersioningEnabled.getId()).thenReturn(testFileId);
    when(mockFileVersioningEnabled.getName()).thenReturn("path.ktr");
    when(mockFileVersioningNotEnabled.getPath()).thenReturn("/public/path2.ktr");
    when(mockFileVersioningNotEnabled.getId()).thenReturn(testFileId + "2");
    when(mockFileVersioningNotEnabled.getName()).thenReturn("path2.ktr");
    when(publicFolder.getPath()).thenReturn("/public");
    when(publicFolder.getName()).thenReturn("public");
    when(publicFolder.getId()).thenReturn(testFileId + "3");
    when(publicFolder.isFolder()).thenReturn(true);
    when(publicFolderTree.getFile()).thenReturn(publicFolder);
    when(mockRepositoryTreeChildVersioningEnabled.getFile()).thenReturn(mockFileVersioningEnabled);
    when(mockRepositoryTreeChildVersioningEnabled.getVersionCommentEnabled()).thenReturn(true);
    when(mockRepositoryTreeChildVersioningEnabled.getVersioningEnabled()).thenReturn(true);
    when(mockRepositoryTreeChildVersioningNotEnabled.getFile()).thenReturn(mockFileVersioningNotEnabled);
    when(mockRepositoryTreeChildVersioningNotEnabled.getVersionCommentEnabled()).thenReturn(false);
    when(mockRepositoryTreeChildVersioningNotEnabled.getVersioningEnabled()).thenReturn(false);
    when(mockRepo.getTree(anyString(), anyInt(), anyString(), anyBoolean())).thenReturn(mockRepositoryTree);
    when(mockRepo.getTree(any(RepositoryRequest.class))).thenReturn(mockRepositoryTree);
    when(mockRepo.getTree(argThat(new ArgumentMatcher<RepositoryRequest>() {

        @Override
        public boolean matches(Object argument) {
            return ((RepositoryRequest) argument).getPath().equals("/public");
        }
    }))).thenReturn(publicFolderTree);
    when(mockRepositoryTree.getFile()).thenReturn(mockRootFolder);
    when(mockRepositoryTree.getChildren()).thenReturn(new ArrayList<>(Arrays.asList(publicFolderTree)));
    when(publicFolderTree.getChildren()).thenReturn(children);
    when(mockRootFolder.getId()).thenReturn("/");
    when(mockRootFolder.getPath()).thenReturn("/");
    when(mockRepo.getFile("/")).thenReturn(mockRootFolder);
    when(mockRepo.getFile("/public")).thenReturn(publicFolder);
    purRepository.connect("TEST_USER", "TEST_PASSWORD");
    List<RepositoryElementMetaInterface> repositoryObjects = purRepository.findDirectory("/public").getRepositoryObjects();
    assertThat(repositoryObjects.size(), is(2));
    // Test Enabled
    RepositoryElementMetaInterface element = repositoryObjects.get(0);
    assertThat(element, is(instanceOf(EERepositoryObject.class)));
    EERepositoryObject eeElement = (EERepositoryObject) element;
    assertThat(eeElement.getVersioningEnabled(), is(true));
    assertThat(eeElement.getVersionCommentEnabled(), is(true));
    // Test Not Enabled
    RepositoryElementMetaInterface element2 = repositoryObjects.get(1);
    assertThat(element2, is(instanceOf(EERepositoryObject.class)));
    EERepositoryObject eeElement2 = (EERepositoryObject) element;
    assertThat(eeElement2.getVersioningEnabled(), is(true));
    assertThat(eeElement2.getVersionCommentEnabled(), is(true));
}
Also used : EERepositoryObject(org.pentaho.di.repository.pur.model.EERepositoryObject) StringObjectId(org.pentaho.di.repository.StringObjectId) ObjectId(org.pentaho.di.repository.ObjectId) Matchers.anyString(org.mockito.Matchers.anyString) RepositoryFileTree(org.pentaho.platform.api.repository2.unified.RepositoryFileTree) ArgumentMatcher(org.mockito.ArgumentMatcher) RepositoryObjectType(org.pentaho.di.repository.RepositoryObjectType) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) RepositoryRequest(org.pentaho.platform.api.repository2.unified.RepositoryRequest) EERepositoryObject(org.pentaho.di.repository.pur.model.EERepositoryObject) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository) RepositoryElementMetaInterface(org.pentaho.di.repository.RepositoryElementMetaInterface) Test(org.junit.Test)

Example 4 with EERepositoryObject

use of org.pentaho.di.repository.pur.model.EERepositoryObject in project pentaho-kettle by pentaho.

the class PurRepository method getPdiObjects.

protected List<RepositoryElementMetaInterface> getPdiObjects(ObjectId dirId, List<RepositoryObjectType> objectTypes, boolean includeDeleted) throws KettleException {
    try {
        // RepositoryDirectoryInterface repDir = getRootDir().findDirectory( dirId );
        RepositoryFile dirFile = pur.getFileById(dirId.getId());
        RepositoryDirectory repDir = new RepositoryDirectory();
        repDir.setObjectId(dirId);
        repDir.setName(dirFile.getName());
        List<RepositoryElementMetaInterface> list = new ArrayList<RepositoryElementMetaInterface>();
        List<RepositoryFile> nonDeletedChildren = getAllFilesOfType(dirId, objectTypes);
        for (RepositoryFile file : nonDeletedChildren) {
            RepositoryLock lock = unifiedRepositoryLockService.getLock(file);
            RepositoryObjectType objectType = getObjectType(file.getName());
            list.add(new EERepositoryObject(file, repDir, null, objectType, null, lock, false));
        }
        if (includeDeleted) {
            String dirPath = null;
            if (dirId != null) {
                // derive path using id
                dirPath = pur.getFileById(dirId.getId()).getPath();
            }
            List<RepositoryFile> deletedChildren = getAllDeletedFilesOfType(dirPath, objectTypes);
            for (RepositoryFile file : deletedChildren) {
                RepositoryLock lock = unifiedRepositoryLockService.getLock(file);
                RepositoryObjectType objectType = getObjectType(file.getName());
                list.add(new EERepositoryObject(file, repDir, null, objectType, null, lock, true));
            }
        }
        return list;
    } catch (Exception e) {
        throw new KettleException("Unable to get list of objects from directory [" + dirId + "]", 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) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) RepositoryLock(org.pentaho.di.repository.pur.model.RepositoryLock) 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

RepositoryElementMetaInterface (org.pentaho.di.repository.RepositoryElementMetaInterface)4 RepositoryObjectType (org.pentaho.di.repository.RepositoryObjectType)4 EERepositoryObject (org.pentaho.di.repository.pur.model.EERepositoryObject)4 KettleException (org.pentaho.di.core.exception.KettleException)3 RepositoryLock (org.pentaho.di.repository.pur.model.RepositoryLock)3 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)3 RepositoryFileTree (org.pentaho.platform.api.repository2.unified.RepositoryFileTree)3 ArrayList (java.util.ArrayList)2 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)2 IdNotFoundException (org.pentaho.di.core.exception.IdNotFoundException)2 KettleFileException (org.pentaho.di.core.exception.KettleFileException)2 KettleSecurityException (org.pentaho.di.core.exception.KettleSecurityException)2 RepositoryDirectory (org.pentaho.di.repository.RepositoryDirectory)2 StringObjectId (org.pentaho.di.repository.StringObjectId)2 MetaStoreException (org.pentaho.metastore.api.exceptions.MetaStoreException)2 MetaStoreNamespaceExistsException (org.pentaho.metastore.api.exceptions.MetaStoreNamespaceExistsException)2 RepositoryRequest (org.pentaho.platform.api.repository2.unified.RepositoryRequest)2 UnifiedRepositoryCreateFileException (org.pentaho.platform.api.repository2.unified.UnifiedRepositoryCreateFileException)2 UnifiedRepositoryUpdateFileException (org.pentaho.platform.api.repository2.unified.UnifiedRepositoryUpdateFileException)2 Test (org.junit.Test)1