Search in sources :

Example 6 with RepositoryElementInterface

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);
}
Also used : RepositoryElementInterface(org.pentaho.di.repository.RepositoryElementInterface) RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) Test(org.junit.Test)

Example 7 with RepositoryElementInterface

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());
}
Also used : RepositoryElementInterface(org.pentaho.di.repository.RepositoryElementInterface) RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) RepositoryObject(org.pentaho.di.repository.RepositoryObject)

Example 8 with RepositoryElementInterface

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);
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) StringObjectId(org.pentaho.di.repository.StringObjectId) ObjectId(org.pentaho.di.repository.ObjectId) PartitionSchema(org.pentaho.di.partition.PartitionSchema) ArrayList(java.util.ArrayList) SlaveServer(org.pentaho.di.cluster.SlaveServer) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) KettleExtensionPoint(org.pentaho.di.core.extension.KettleExtensionPoint) RepositoryElementInterface(org.pentaho.di.repository.RepositoryElementInterface) RepositoryObjectType(org.pentaho.di.repository.RepositoryObjectType) SharedObjectInterface(org.pentaho.di.shared.SharedObjectInterface)

Aggregations

RepositoryElementInterface (org.pentaho.di.repository.RepositoryElementInterface)8 Test (org.junit.Test)5 KettleException (org.pentaho.di.core.exception.KettleException)5 SlaveServer (org.pentaho.di.cluster.SlaveServer)3 PartitionSchema (org.pentaho.di.partition.PartitionSchema)3 MetaStoreDependenciesExistsException (org.pentaho.metastore.api.exceptions.MetaStoreDependenciesExistsException)3 MetaStoreException (org.pentaho.metastore.api.exceptions.MetaStoreException)3 MetaStoreNamespaceExistsException (org.pentaho.metastore.api.exceptions.MetaStoreNamespaceExistsException)3 BeansException (org.springframework.beans.BeansException)3 SAXException (org.xml.sax.SAXException)3 SAXParseException (org.xml.sax.SAXParseException)3 ClusterSchema (org.pentaho.di.cluster.ClusterSchema)2 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)2 RepositoryDirectoryInterface (org.pentaho.di.repository.RepositoryDirectoryInterface)2 RepositoryObjectType (org.pentaho.di.repository.RepositoryObjectType)2 SharedObjectInterface (org.pentaho.di.shared.SharedObjectInterface)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Matchers.anyString (org.mockito.Matchers.anyString)1 KettleExtensionPoint (org.pentaho.di.core.extension.KettleExtensionPoint)1