use of org.pentaho.di.repository.RepositoryObjectType 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.di.repository.RepositoryObjectType in project pentaho-kettle by pentaho.
the class RepositoryDirectoryUI method loadRepositoryObjects.
protected static List<RepositoryElementMetaInterface> loadRepositoryObjects(RepositoryDirectoryInterface dir, boolean getTransformations, boolean getJobs, Repository rep) throws KettleDatabaseException {
// Then show the transformations & jobs in that directory...
List<RepositoryElementMetaInterface> repositoryObjects = new ArrayList<RepositoryElementMetaInterface>();
if (dir.getRepositoryObjects() == null) {
try {
dir.setRepositoryObjects(rep.getJobAndTransformationObjects(dir.getObjectId(), false));
} catch (KettleException e) {
throw new KettleDatabaseException(e);
}
}
List<RepositoryObjectType> allowedTypes = new ArrayList<>(2);
if (getTransformations) {
allowedTypes.add(RepositoryObjectType.TRANSFORMATION);
}
if (getJobs) {
allowedTypes.add(RepositoryObjectType.JOB);
}
for (RepositoryElementMetaInterface repoObject : dir.getRepositoryObjects()) {
if (allowedTypes.contains(repoObject.getObjectType())) {
repositoryObjects.add(repoObject);
}
}
return repositoryObjects;
}
use of org.pentaho.di.repository.RepositoryObjectType in project pentaho-kettle by pentaho.
the class SelectObjectDialog method ok.
private void ok() {
// Something has to be selected!
if (wTree.getSelectionCount() > 0) {
TreeItem ti = wTree.getSelection()[0];
// No directory!
if (!Boolean.TRUE.equals(wTree.getSelection()[0].getData("isFolder"))) {
int level = ConstUI.getTreeLevel(ti);
if (level > 0) {
repositoryObject = (RepositoryElementMetaInterface) ti.getData();
if (repositoryObject != null) {
objectName = repositoryObject.getName();
objectDirectory = repositoryObject.getRepositoryDirectory();
objectId = repositoryObject.getObjectId();
objectType = repositoryObject.getObjectType();
} else {
// For backward compatibility, we should rarely end up here...
//
String[] path = ConstUI.getTreeStrings(ti.getParentItem());
objectName = ti.getText(0);
objectType = null;
for (RepositoryObjectType type : RepositoryObjectType.values()) {
if (type.getTypeDescription().equalsIgnoreCase(ti.getText(1))) {
objectType = type;
break;
}
}
objectDirectory = directoryTree.findDirectory(path);
}
if (objectDirectory != null) {
dispose();
} else {
MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
mb.setMessage(BaseMessages.getString(PKG, "SelectObjectDialog.Dialog.DirectoryNotFound.Message"));
mb.setText(BaseMessages.getString(PKG, "SelectObjectDialog.Dialog.DirectoryNotFound.Title"));
mb.open();
}
}
}
}
}
use of org.pentaho.di.repository.RepositoryObjectType 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.RepositoryObjectType in project pentaho-kettle by pentaho.
the class PurRepository method readSharedObjects.
/**
* Read shared objects of the types provided from the repository. Every {@link SharedObjectInterface} that is read
* will be fully loaded as if it has been loaded through {@link #loadDatabaseMeta(ObjectId, String)},
* {@link #loadClusterSchema(ObjectId, List, String)}, etc.
* <p>
* This method was introduced to reduce the number of server calls for loading shared objects to a constant number:
* {@code 2 + n, where n is the number of types requested}.
* </p>
*
* @param sharedObjectsByType
* Map of type to shared objects. Each map entry will contain a non-null {@link List} of
* {@link RepositoryObjectType}s for every type provided. Only entries for types provided will be altered.
* @param types
* Types of repository objects to read from the repository
* @throws KettleException
*/
protected void readSharedObjects(Map<RepositoryObjectType, List<? extends SharedObjectInterface>> sharedObjectsByType, RepositoryObjectType... types) throws KettleException {
// Overview:
// 1) We will fetch RepositoryFile, NodeRepositoryFileData, and VersionSummary for all types provided.
// 2) We assume that unless an exception is thrown every RepositoryFile returned by getFilesByType(..) have a
// matching NodeRepositoryFileData and VersionSummary.
// 3) With all files, node data, and versions in hand we will iterate over them, merging them back into usable
// shared objects
List<RepositoryFile> allFiles = new ArrayList<RepositoryFile>();
// Since type is not preserved in the RepositoryFile we fetch files by type so we don't rely on parsing the name to
// determine type afterward
// Map must be ordered or we can't match up files with data and version summary
LinkedHashMap<RepositoryObjectType, List<RepositoryFile>> filesByType = getFilesByType(allFiles, types);
try {
List<NodeRepositoryFileData> data = pur.getDataForReadInBatch(allFiles, NodeRepositoryFileData.class);
List<VersionSummary> versions = pur.getVersionSummaryInBatch(allFiles);
// Only need one iterator for all data and versions. We will work through them as we process the files by type, in
// order.
Iterator<NodeRepositoryFileData> dataIter = data.iterator();
Iterator<VersionSummary> versionsIter = versions.iterator();
// Assemble into completely loaded SharedObjectInterfaces by type
for (Entry<RepositoryObjectType, List<RepositoryFile>> entry : filesByType.entrySet()) {
SharedObjectAssembler<?> assembler = sharedObjectAssemblerMap.get(entry.getKey());
if (assembler == null) {
throw new UnsupportedOperationException(// $NON-NLS-1$
String.format("Cannot assemble shared object of type [%s]", entry.getKey()));
}
// For all files of this type, assemble them from the pieces of data pulled from the repository
Iterator<RepositoryFile> filesIter = entry.getValue().iterator();
List<SharedObjectInterface> sharedObjects = new ArrayList<SharedObjectInterface>(entry.getValue().size());
// (no need to check for next on all iterators)
while (filesIter.hasNext()) {
RepositoryFile file = filesIter.next();
NodeRepositoryFileData repoData = dataIter.next();
VersionSummary version = versionsIter.next();
// TODO: inexistent db types can cause exceptions assembling; prevent total failure
try {
sharedObjects.add(assembler.assemble(file, repoData, version));
} catch (Exception ex) {
// TODO i18n
getLog().logError("Unable to load shared objects", ex);
}
}
sharedObjectsByType.put(entry.getKey(), sharedObjects);
}
} catch (Exception ex) {
// $NON-NLS-1$
throw new KettleException("Unable to load shared objects", ex);
}
}
Aggregations