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;
}
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);
}
}
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));
}
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);
}
}
Aggregations