use of org.pentaho.di.repository.RepositoryElementInterface in project pentaho-kettle by pentaho.
the class PurRepositoryUnitTest method testSaveTransOrJob.
@Test(expected = KettleException.class)
public void testSaveTransOrJob() throws KettleException {
PurRepository purRepository = new PurRepository();
RepositoryElementInterface element = Mockito.mock(RepositoryElementInterface.class);
RepositoryDirectoryInterface directoryInterface = Mockito.mock(RepositoryDirectoryInterface.class);
Mockito.when(element.getRepositoryDirectory()).thenReturn(directoryInterface);
Mockito.when(element.getRepositoryElementType()).thenReturn(RepositoryObjectType.TRANSFORMATION);
Mockito.when(directoryInterface.toString()).thenReturn(Import.ROOT_DIRECTORY);
purRepository.saveTransOrJob(null, element, null, null, false, false, false, false, false);
}
use of org.pentaho.di.repository.RepositoryElementInterface in project pentaho-kettle by pentaho.
the class PurRepository_GetObjectInformation_IT method testDeletedFlagForObject.
private void testDeletedFlagForObject(Callable<RepositoryElementInterface> elementProvider) throws Exception {
TransDelegate transDelegate = new TransDelegate(purRepository, unifiedRepository);
JobDelegate jobDelegate = new JobDelegate(purRepository, unifiedRepository);
FieldUtils.writeField(purRepository, "transDelegate", transDelegate, true);
FieldUtils.writeField(purRepository, "jobDelegate", jobDelegate, true);
RepositoryElementInterface element = elementProvider.call();
RepositoryDirectoryInterface directory = purRepository.findDirectory(element.getRepositoryDirectory().getPath());
element.setRepositoryDirectory(directory);
purRepository.save(element, null, null);
assertNotNull("Element was saved", element.getObjectId());
RepositoryObject information;
information = purRepository.getObjectInformation(element.getObjectId(), element.getRepositoryElementType());
assertNotNull(information);
assertFalse(information.isDeleted());
purRepository.deleteTransformation(element.getObjectId());
assertNotNull("Element was moved to Trash", unifiedRepository.getFileById(element.getObjectId().getId()));
information = purRepository.getObjectInformation(element.getObjectId(), element.getRepositoryElementType());
assertNotNull(information);
assertTrue(information.isDeleted());
}
use of org.pentaho.di.repository.RepositoryElementInterface in project pentaho-kettle by pentaho.
the class PurRepository method updateSharedObjectCache.
/**
* Do not call this method directly. Instead call updateSharedObjectCache or removeFromSharedObjectCache.
*/
private void updateSharedObjectCache(final RepositoryElementInterface element, final RepositoryObjectType type, final ObjectId id) throws KettleException {
if (element != null && (element.getObjectId() == null || element.getObjectId().getId() == null)) {
throw new IllegalArgumentException(element.getName() + " has a null id");
}
loadAndCacheSharedObjects(false);
boolean remove = element == null;
ObjectId idToFind = element != null ? element.getObjectId() : id;
RepositoryObjectType typeToUpdate = element != null ? element.getRepositoryElementType() : type;
RepositoryElementInterface elementToUpdate = null;
List<? extends SharedObjectInterface> origSharedObjects = null;
switch(typeToUpdate) {
case DATABASE:
origSharedObjects = sharedObjectsByType.get(RepositoryObjectType.DATABASE);
if (!remove) {
elementToUpdate = (RepositoryElementInterface) ((DatabaseMeta) element).clone();
}
break;
case SLAVE_SERVER:
origSharedObjects = sharedObjectsByType.get(RepositoryObjectType.SLAVE_SERVER);
if (!remove) {
elementToUpdate = (RepositoryElementInterface) ((SlaveServer) element).clone();
}
break;
case CLUSTER_SCHEMA:
origSharedObjects = sharedObjectsByType.get(RepositoryObjectType.CLUSTER_SCHEMA);
if (!remove) {
elementToUpdate = ((ClusterSchema) element).clone();
}
break;
case PARTITION_SCHEMA:
origSharedObjects = sharedObjectsByType.get(RepositoryObjectType.PARTITION_SCHEMA);
if (!remove) {
elementToUpdate = (RepositoryElementInterface) ((PartitionSchema) element).clone();
}
break;
default:
throw new KettleException("unknown type [" + typeToUpdate + "]");
}
List<SharedObjectInterface> newSharedObjects = new ArrayList<SharedObjectInterface>(origSharedObjects);
// if there's a match on id, replace the element
boolean found = false;
for (int i = 0; i < origSharedObjects.size(); i++) {
RepositoryElementInterface repositoryElementInterface = (RepositoryElementInterface) origSharedObjects.get(i);
if (repositoryElementInterface == null) {
continue;
}
ObjectId objectId = repositoryElementInterface.getObjectId();
if (objectId != null && objectId.equals(idToFind)) {
if (remove) {
newSharedObjects.remove(i);
} else {
// because some clones don't clone the ID!!!
elementToUpdate.setObjectId(idToFind);
newSharedObjects.set(i, (SharedObjectInterface) elementToUpdate);
}
found = true;
}
}
// otherwise, add it
if (!remove && !found) {
// because some clones don't clone the ID!!!
elementToUpdate.setObjectId(idToFind);
newSharedObjects.add((SharedObjectInterface) elementToUpdate);
}
sharedObjectsByType.put(typeToUpdate, newSharedObjects);
}
Aggregations