use of org.pentaho.platform.api.repository2.unified.RepositoryFileTree in project pentaho-kettle by pentaho.
the class PurRepositoryUnitTest method testGetObjectInformationGetsAclByFileId.
@Test
public void testGetObjectInformationGetsAclByFileId() throws KettleException {
PurRepository purRepository = new PurRepository();
IUnifiedRepository mockRepo = mock(IUnifiedRepository.class);
RepositoryConnectResult result = mock(RepositoryConnectResult.class);
when(result.getUnifiedRepository()).thenReturn(mockRepo);
RepositoryServiceRegistry registry = mock(RepositoryServiceRegistry.class);
UnifiedRepositoryLockService lockService = new UnifiedRepositoryLockService(mockRepo);
when(registry.getService(ILockService.class)).thenReturn(lockService);
when(result.repositoryServiceRegistry()).thenReturn(registry);
IRepositoryConnector connector = mock(IRepositoryConnector.class);
when(connector.connect(anyString(), anyString())).thenReturn(result);
PurRepositoryMeta mockMeta = mock(PurRepositoryMeta.class);
purRepository.init(mockMeta);
purRepository.setPurRepositoryConnector(connector);
// purRepository.setTest( mockRepo );
ObjectId objectId = mock(ObjectId.class);
RepositoryFile mockFile = mock(RepositoryFile.class);
RepositoryFile mockRootFolder = mock(RepositoryFile.class);
RepositoryObjectType repositoryObjectType = RepositoryObjectType.TRANSFORMATION;
RepositoryFileTree mockRepositoryTree = mock(RepositoryFileTree.class);
String testId = "TEST_ID";
String testFileId = "TEST_FILE_ID";
when(objectId.getId()).thenReturn(testId);
when(mockRepo.getFileById(testId)).thenReturn(mockFile);
when(mockFile.getPath()).thenReturn("/home/testuser/path.ktr");
when(mockFile.isLocked()).thenReturn(false);
when(mockFile.getId()).thenReturn(testFileId);
when(mockRepo.getTree(anyString(), anyInt(), anyString(), anyBoolean())).thenReturn(mockRepositoryTree);
when(mockRepositoryTree.getFile()).thenReturn(mockRootFolder);
when(mockRootFolder.getId()).thenReturn("/");
when(mockRootFolder.getPath()).thenReturn("/");
when(mockRepo.getFile("/")).thenReturn(mockRootFolder);
purRepository.connect("TEST_USER", "TEST_PASSWORD");
purRepository.getObjectInformation(objectId, repositoryObjectType);
verify(mockRepo).getAcl(testFileId);
}
use of org.pentaho.platform.api.repository2.unified.RepositoryFileTree in project pentaho-kettle by pentaho.
the class PurRepositoryUnitTest method testEtcIsNotThereInGetNrDirectories.
@Test
public void testEtcIsNotThereInGetNrDirectories() 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);
PurRepositoryMeta mockMeta = mock(PurRepositoryMeta.class);
purRepository.init(mockMeta);
purRepository.setPurRepositoryConnector(connector);
ObjectId objectId = mock(ObjectId.class);
RepositoryFile mockEtcFolder = mock(RepositoryFile.class);
RepositoryFile mockFolderVisible = mock(RepositoryFile.class);
RepositoryFile mockRootFolder = mock(RepositoryFile.class);
RepositoryFileTree mockRepositoryTree = mock(RepositoryFileTree.class);
String testId = "TEST_ID";
String visibleFolderId = testId + "2";
when(objectId.getId()).thenReturn(testId);
when(mockRepo.getFileById(testId)).thenReturn(mockEtcFolder);
when(mockRepo.getFile(ClientRepositoryPaths.getEtcFolderPath())).thenReturn(mockEtcFolder);
when(mockRepo.getFileById(visibleFolderId)).thenReturn(mockFolderVisible);
when(mockEtcFolder.getPath()).thenReturn("/etc");
when(mockEtcFolder.getName()).thenReturn("etc");
when(mockEtcFolder.isFolder()).thenReturn(true);
when(mockEtcFolder.getId()).thenReturn(testId);
when(mockFolderVisible.getPath()).thenReturn("/visible");
when(mockFolderVisible.getName()).thenReturn("visible");
when(mockFolderVisible.isFolder()).thenReturn(true);
when(mockFolderVisible.getId()).thenReturn(visibleFolderId);
when(mockRepositoryTree.getFile()).thenReturn(mockRootFolder);
when(mockRootFolder.getId()).thenReturn("/");
when(mockRootFolder.getPath()).thenReturn("/");
List<RepositoryFile> rootChildren = new ArrayList<>(Arrays.asList(mockEtcFolder, mockFolderVisible));
when(mockRepo.getChildren(argThat(IsInstanceOf.<RepositoryRequest>instanceOf(RepositoryRequest.class)))).thenReturn(rootChildren);
// for Lazy Repo
when(mockRepo.getFile("/")).thenReturn(mockRootFolder);
// for Eager Repo
RepositoryFileTree repositoryFileTree = mock(RepositoryFileTree.class);
when(mockRepo.getTree("/", -1, null, true)).thenReturn(repositoryFileTree);
when(repositoryFileTree.getFile()).thenReturn(mockRootFolder);
RepositoryFileTree mockEtcFolderTree = mock(RepositoryFileTree.class);
when(mockEtcFolderTree.getFile()).thenReturn(mockEtcFolder);
RepositoryFileTree mockFolderVisibleTree = mock(RepositoryFileTree.class);
when(mockFolderVisibleTree.getFile()).thenReturn(mockFolderVisible);
when(repositoryFileTree.getChildren()).thenReturn(new ArrayList<RepositoryFileTree>(Arrays.asList(mockEtcFolderTree, mockFolderVisibleTree)));
purRepository.connect("TEST_USER", "TEST_PASSWORD");
int children = purRepository.getRootDir().getNrSubdirectories();
assertThat(children, equalTo(1));
}
use of org.pentaho.platform.api.repository2.unified.RepositoryFileTree 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;
}
use of org.pentaho.platform.api.repository2.unified.RepositoryFileTree 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);
RepositoryFileTree fileTree = pur.getTree(repoRequest);
return fileTree;
}
use of org.pentaho.platform.api.repository2.unified.RepositoryFileTree in project pentaho-kettle by pentaho.
the class PurRepository method loadRepositoryFileTreeFolders.
private RepositoryFileTree loadRepositoryFileTreeFolders(String path, int depth, boolean includeAcls, boolean showHidden) {
RepositoryRequest repoRequest = new RepositoryRequest();
repoRequest.setDepth(depth);
repoRequest.setIncludeAcls(includeAcls);
repoRequest.setChildNodeFilter("*");
repoRequest.setTypes(FILES_TYPE_FILTER.FOLDERS);
repoRequest.setPath(path);
repoRequest.setShowHidden(showHidden);
return pur.getTree(repoRequest);
}
Aggregations