Search in sources :

Example 6 with MetaStoreDependenciesExistsException

use of org.pentaho.metastore.api.exceptions.MetaStoreDependenciesExistsException in project pentaho-kettle by pentaho.

the class PurRepositoryIT method testMetaStoreElements.

@Test
public void testMetaStoreElements() throws MetaStoreException {
    // Set up a namespace
    // 
    String ns = PentahoDefaults.NAMESPACE;
    IMetaStore metaStore = repository.getMetaStore();
    if (!metaStore.namespaceExists(ns)) {
        metaStore.createNamespace(ns);
    }
    // And an element type
    // 
    IMetaStoreElementType elementType = metaStore.newElementType(ns);
    elementType.setName(PentahoDefaults.KETTLE_DATA_SERVICE_ELEMENT_TYPE_NAME);
    elementType.setDescription(PentahoDefaults.KETTLE_DATA_SERVICE_ELEMENT_TYPE_DESCRIPTION);
    metaStore.createElementType(ns, elementType);
    // Now we play with elements...
    // 
    IMetaStoreElement oneElement = populateElement(metaStore, elementType, "Element One");
    metaStore.createElement(ns, elementType, oneElement);
    IMetaStoreElement verifyOneElement = metaStore.getElement(ns, elementType, oneElement.getId());
    assertNotNull(verifyOneElement);
    validateElement(verifyOneElement, "Element One");
    assertEquals(1, metaStore.getElements(ns, elementType).size());
    IMetaStoreElement twoElement = populateElement(metaStore, elementType, "Element Two");
    metaStore.createElement(ns, elementType, twoElement);
    IMetaStoreElement verifyTwoElement = metaStore.getElement(ns, elementType, twoElement.getId());
    assertNotNull(verifyTwoElement);
    assertEquals(2, metaStore.getElements(ns, elementType).size());
    try {
        metaStore.deleteElementType(ns, elementType);
        fail("Delete element type failed to properly detect element dependencies");
    } catch (MetaStoreDependenciesExistsException e) {
        List<String> ids = e.getDependencies();
        assertEquals(2, ids.size());
        assertTrue(ids.contains(oneElement.getId()));
        assertTrue(ids.contains(twoElement.getId()));
    }
    metaStore.deleteElement(ns, elementType, oneElement.getId());
    assertEquals(1, metaStore.getElements(ns, elementType).size());
    metaStore.deleteElement(ns, elementType, twoElement.getId());
    assertEquals(0, metaStore.getElements(ns, elementType).size());
}
Also used : IMetaStoreElementType(org.pentaho.metastore.api.IMetaStoreElementType) IMetaStoreElement(org.pentaho.metastore.api.IMetaStoreElement) ArrayList(java.util.ArrayList) AbstractList(java.util.AbstractList) List(java.util.List) Matchers.anyString(org.mockito.Matchers.anyString) IMetaStore(org.pentaho.metastore.api.IMetaStore) MetaStoreDependenciesExistsException(org.pentaho.metastore.api.exceptions.MetaStoreDependenciesExistsException) Test(org.junit.Test)

Example 7 with MetaStoreDependenciesExistsException

use of org.pentaho.metastore.api.exceptions.MetaStoreDependenciesExistsException in project pentaho-kettle by pentaho.

the class PurRepositoryMetaStore method deleteNamespace.

@Override
public void deleteNamespace(String namespace) throws MetaStoreException {
    RepositoryFile namespaceFile = getNamespaceRepositoryFile(namespace);
    if (namespaceFile == null) {
        // already gone.
        return;
    }
    List<RepositoryFile> children = getChildren(namespaceFile.getId());
    if (children == null || children.isEmpty()) {
        // Delete the file, there are no children.
        // 
        pur.deleteFile(namespaceFile.getId(), true, "Delete namespace");
    } else {
        // Dependencies exists, throw an exception.
        // 
        List<String> elementTypeIds = new ArrayList<String>();
        for (RepositoryFile child : children) {
            elementTypeIds.add(child.getId().toString());
        }
        throw new MetaStoreDependenciesExistsException(elementTypeIds, "Namespace '" + namespace + " can not be deleted because it is not empty");
    }
}
Also used : ArrayList(java.util.ArrayList) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) MetaStoreDependenciesExistsException(org.pentaho.metastore.api.exceptions.MetaStoreDependenciesExistsException)

Example 8 with MetaStoreDependenciesExistsException

use of org.pentaho.metastore.api.exceptions.MetaStoreDependenciesExistsException in project pentaho-kettle by pentaho.

the class KettleMetaStoreTestBase method testFunctionality.

public void testFunctionality(IMetaStore metaStore) throws MetaStoreException {
    if (!metaStore.namespaceExists(namespace)) {
        metaStore.createNamespace(namespace);
    }
    List<String> namespaces = metaStore.getNamespaces();
    assertEquals(1, namespaces.size());
    IMetaStoreElementType elementType = metaStore.newElementType(namespace);
    elementType.setName(SHARED_DIMENSION_NAME);
    elementType.setDescription(SHARED_DIMENSION_DESCRIPTION);
    metaStore.createElementType(namespace, elementType);
    assertNotNull(elementType.getId());
    List<IMetaStoreElementType> elementTypes = metaStore.getElementTypes(namespace);
    assertEquals(1, elementTypes.size());
    try {
        metaStore.createElementType(namespace, elementType);
        fail("Duplicate creation error expected!");
    } catch (MetaStoreElementTypeExistsException e) {
    // OK!
    } catch (MetaStoreException e) {
        e.printStackTrace();
        fail("Create exception needs to be MetaStoreDataTypesExistException");
    }
    // 
    try {
        metaStore.deleteNamespace(namespace);
        fail("Expected error while deleting namespace with content!");
    } catch (MetaStoreDependenciesExistsException e) {
        // OK!
        List<String> dependencies = e.getDependencies();
        assertNotNull(dependencies);
        assertEquals(1, dependencies.size());
        assertEquals(elementType.getId(), dependencies.get(0));
    }
    IMetaStoreElement customerDimension = generateCustomerDimensionElement(metaStore, elementType);
    IMetaStoreElementOwner elementOwner = customerDimension.getOwner();
    assertNotNull(elementOwner);
    assertEquals("joe", elementOwner.getName());
    assertEquals(MetaStoreElementOwnerType.USER, elementOwner.getOwnerType());
    metaStore.createElement(namespace, elementType, customerDimension);
    assertNotNull(customerDimension.getId());
    List<IMetaStoreElement> elements = metaStore.getElements(namespace, elementType);
    assertEquals(1, elements.size());
    assertNotNull(elements.get(0));
    assertEquals(CUSTOMER_DIMENSION_NAME, elements.get(0).getName());
    // 
    try {
        metaStore.deleteElementType(namespace, elementType);
        fail("Expected error while deleting data type with content!");
    } catch (MetaStoreDependenciesExistsException e) {
        // OK!
        List<String> dependencies = e.getDependencies();
        assertNotNull(dependencies);
        assertEquals(1, dependencies.size());
        assertEquals(customerDimension.getId(), dependencies.get(0));
    }
    // Some lookup-by-name tests...
    // 
    assertNotNull(metaStore.getElementTypeByName(namespace, SHARED_DIMENSION_NAME));
    assertNotNull(metaStore.getElementByName(namespace, elementType, CUSTOMER_DIMENSION_NAME));
    // Clean up shop!
    // 
    metaStore.deleteElement(namespace, elementType, customerDimension.getId());
    elements = metaStore.getElements(namespace, elementType);
    assertEquals(0, elements.size());
    metaStore.deleteElementType(namespace, elementType);
    elementTypes = metaStore.getElementTypes(namespace);
    assertEquals(0, elementTypes.size());
    metaStore.deleteNamespace(namespace);
    namespaces = metaStore.getNamespaces();
    assertEquals(0, namespaces.size());
}
Also used : MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) IMetaStoreElementType(org.pentaho.metastore.api.IMetaStoreElementType) MetaStoreElementTypeExistsException(org.pentaho.metastore.api.exceptions.MetaStoreElementTypeExistsException) IMetaStoreElementOwner(org.pentaho.metastore.api.security.IMetaStoreElementOwner) List(java.util.List) IMetaStoreElement(org.pentaho.metastore.api.IMetaStoreElement) MetaStoreDependenciesExistsException(org.pentaho.metastore.api.exceptions.MetaStoreDependenciesExistsException)

Aggregations

MetaStoreDependenciesExistsException (org.pentaho.metastore.api.exceptions.MetaStoreDependenciesExistsException)8 IMetaStoreElementType (org.pentaho.metastore.api.IMetaStoreElementType)5 ArrayList (java.util.ArrayList)4 MetaStoreElementTypeExistsException (org.pentaho.metastore.api.exceptions.MetaStoreElementTypeExistsException)4 MetaStoreException (org.pentaho.metastore.api.exceptions.MetaStoreException)4 List (java.util.List)3 IMetaStoreElement (org.pentaho.metastore.api.IMetaStoreElement)3 Test (org.junit.Test)2 Matchers.anyString (org.mockito.Matchers.anyString)2 LongObjectId (org.pentaho.di.repository.LongObjectId)2 StringObjectId (org.pentaho.di.repository.StringObjectId)2 IMetaStore (org.pentaho.metastore.api.IMetaStore)2 MetaStoreElementExistException (org.pentaho.metastore.api.exceptions.MetaStoreElementExistException)2 MetaStoreNamespaceExistsException (org.pentaho.metastore.api.exceptions.MetaStoreNamespaceExistsException)2 IMetaStoreElementOwner (org.pentaho.metastore.api.security.IMetaStoreElementOwner)2 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)2 AbstractList (java.util.AbstractList)1 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)1 ObjectId (org.pentaho.di.repository.ObjectId)1