use of org.pentaho.platform.api.repository2.unified.RepositoryFile 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.RepositoryFile 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.RepositoryFile 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.RepositoryFile in project pentaho-kettle by pentaho.
the class LazyUnifiedRepositoryDirectory method findDirectory.
@Override
public RepositoryDirectory findDirectory(ObjectId id_directory) {
RepositoryFile file = repository.getFileById(id_directory.getId());
if (file == null || !file.isFolder()) {
return null;
}
if (isRoot() && RepositoryDirectory.DIRECTORY_SEPARATOR.equals(file.getPath())) {
return this;
}
// Verifies if this is the parent directory of file and if so passes this as parent argument
String parentPath = getParentPath(file.getPath());
if (self.getPath().endsWith(RepositoryDirectory.DIRECTORY_SEPARATOR)) {
if (parentPath.equals(self.getPath().substring(0, self.getPath().length() - 1))) {
return new LazyUnifiedRepositoryDirectory(file, this, repository, registry);
}
} else {
if (parentPath.equals(self.getPath())) {
return new LazyUnifiedRepositoryDirectory(file, this, repository, registry);
}
}
return new LazyUnifiedRepositoryDirectory(file, findDirectory(parentPath), repository, registry);
}
use of org.pentaho.platform.api.repository2.unified.RepositoryFile in project pentaho-kettle by pentaho.
the class LazyUnifiedRepositoryDirectory method getChildren.
@Override
public List<RepositoryDirectoryInterface> getChildren() {
if (subdirectories == null) {
subdirectories = new ArrayList<>();
synchronized (subdirectories) {
List<RepositoryFile> children = getAllURChildrenFiles();
for (RepositoryFile child : children) {
LazyUnifiedRepositoryDirectory dir = new LazyUnifiedRepositoryDirectory(child, this, repository, registry);
dir.setObjectId(new StringObjectId(child.getId().toString()));
this.addSubdirectory(dir);
}
}
}
return subdirectories;
}
Aggregations