Search in sources :

Example 1 with MetaStoreDependenciesExistsException

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

the class MetaStoreTestBase 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)

Example 2 with MetaStoreDependenciesExistsException

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

the class PurRepositoryMetaStore method deleteElementType.

@Override
public void deleteElementType(String namespace, IMetaStoreElementType elementType) throws MetaStoreException {
    RepositoryFile namespaceRepositoryFile = validateNamespace(namespace);
    RepositoryFile elementTypeFile = findChildByName(namespaceRepositoryFile.getId(), elementType.getName());
    List<RepositoryFile> children = getChildren(elementTypeFile.getId());
    removeHiddenFilesFromList(children);
    if (children.isEmpty()) {
        pur.deleteFile(elementTypeFile.getId(), true, null);
    } else {
        List<String> ids = getElementIds(namespace, elementType);
        throw new MetaStoreDependenciesExistsException(ids, "Can't delete element type with name '" + elementType.getName() + "' because it is not empty");
    }
}
Also used : RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) MetaStoreDependenciesExistsException(org.pentaho.metastore.api.exceptions.MetaStoreDependenciesExistsException)

Example 3 with MetaStoreDependenciesExistsException

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

the class KettleDatabaseRepositoryMetaStore method deleteNamespace.

@Override
public void deleteNamespace(String namespace) throws MetaStoreException, MetaStoreDependenciesExistsException {
    try {
        ObjectId namespaceId = delegate.verifyNamespace(namespace);
        List<IMetaStoreElementType> elementTypes = getElementTypes(namespace);
        if (!elementTypes.isEmpty()) {
            List<String> dependencies = new ArrayList<String>();
            for (IMetaStoreElementType elementType : elementTypes) {
                dependencies.add(elementType.getId());
            }
            throw new MetaStoreDependenciesExistsException(dependencies, "The namespace to delete, '" + namespace + "' is not empty");
        }
        // Now delete the namespace
        // 
        delegate.deleteNamespace(namespaceId);
        repository.commit();
    } catch (MetaStoreDependenciesExistsException e) {
        throw e;
    } catch (MetaStoreException e) {
        repository.rollback();
        throw e;
    } catch (Exception e) {
        repository.rollback();
        throw new MetaStoreException("Unable to delete namespace '" + namespace + "'", e);
    }
}
Also used : MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) IMetaStoreElementType(org.pentaho.metastore.api.IMetaStoreElementType) LongObjectId(org.pentaho.di.repository.LongObjectId) ObjectId(org.pentaho.di.repository.ObjectId) StringObjectId(org.pentaho.di.repository.StringObjectId) ArrayList(java.util.ArrayList) MetaStoreDependenciesExistsException(org.pentaho.metastore.api.exceptions.MetaStoreDependenciesExistsException) MetaStoreNamespaceExistsException(org.pentaho.metastore.api.exceptions.MetaStoreNamespaceExistsException) MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) MetaStoreDependenciesExistsException(org.pentaho.metastore.api.exceptions.MetaStoreDependenciesExistsException) MetaStoreElementExistException(org.pentaho.metastore.api.exceptions.MetaStoreElementExistException) MetaStoreElementTypeExistsException(org.pentaho.metastore.api.exceptions.MetaStoreElementTypeExistsException)

Example 4 with MetaStoreDependenciesExistsException

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

the class KettleDatabaseRepositoryMetaStore method deleteElementType.

@Override
public void deleteElementType(String namespace, IMetaStoreElementType elementType) throws MetaStoreException, MetaStoreDependenciesExistsException {
    try {
        Collection<RowMetaAndData> elementTypeRows = delegate.getElements(new LongObjectId(new StringObjectId(elementType.getId())));
        if (!elementTypeRows.isEmpty()) {
            List<String> dependencies = new ArrayList<String>();
            for (RowMetaAndData elementTypeRow : elementTypeRows) {
                Long elementTypeId = elementTypeRow.getInteger(KettleDatabaseRepository.FIELD_ELEMENT_TYPE_ID_ELEMENT_TYPE);
                dependencies.add(Long.toString(elementTypeId));
            }
            throw new MetaStoreDependenciesExistsException(dependencies, "The namespace to delete, '" + namespace + "' is not empty");
        }
        delegate.deleteElementType(new LongObjectId(new StringObjectId(elementType.getId())));
        repository.commit();
    } catch (MetaStoreDependenciesExistsException e) {
        throw e;
    } catch (Exception e) {
        repository.rollback();
        throw new MetaStoreException(e);
    }
}
Also used : MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) ArrayList(java.util.ArrayList) LongObjectId(org.pentaho.di.repository.LongObjectId) StringObjectId(org.pentaho.di.repository.StringObjectId) MetaStoreDependenciesExistsException(org.pentaho.metastore.api.exceptions.MetaStoreDependenciesExistsException) MetaStoreNamespaceExistsException(org.pentaho.metastore.api.exceptions.MetaStoreNamespaceExistsException) MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) MetaStoreDependenciesExistsException(org.pentaho.metastore.api.exceptions.MetaStoreDependenciesExistsException) MetaStoreElementExistException(org.pentaho.metastore.api.exceptions.MetaStoreElementExistException) MetaStoreElementTypeExistsException(org.pentaho.metastore.api.exceptions.MetaStoreElementTypeExistsException)

Example 5 with MetaStoreDependenciesExistsException

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

the class PurRepositoryIT method testMetaStoreElementTypes.

@Test
public void testMetaStoreElementTypes() throws MetaStoreException {
    IMetaStore metaStore = repository.getMetaStore();
    assertNotNull(metaStore);
    String ns = PentahoDefaults.NAMESPACE;
    // We start with a clean slate...
    // 
    assertEquals(1, metaStore.getNamespaces().size());
    assertEquals(true, metaStore.namespaceExists(ns));
    // Now create 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);
    IMetaStoreElementType verifyElementType = metaStore.getElementType(ns, elementType.getId());
    assertEquals(PentahoDefaults.KETTLE_DATA_SERVICE_ELEMENT_TYPE_NAME, verifyElementType.getName());
    assertEquals(PentahoDefaults.KETTLE_DATA_SERVICE_ELEMENT_TYPE_DESCRIPTION, verifyElementType.getDescription());
    verifyElementType = metaStore.getElementTypeByName(ns, PentahoDefaults.KETTLE_DATA_SERVICE_ELEMENT_TYPE_NAME);
    assertEquals(PentahoDefaults.KETTLE_DATA_SERVICE_ELEMENT_TYPE_NAME, verifyElementType.getName());
    assertEquals(PentahoDefaults.KETTLE_DATA_SERVICE_ELEMENT_TYPE_DESCRIPTION, verifyElementType.getDescription());
    // Get the list of element type ids.
    // 
    List<String> ids = metaStore.getElementTypeIds(ns);
    assertNotNull(ids);
    assertEquals(1, ids.size());
    assertEquals(elementType.getId(), ids.get(0));
    // 
    try {
        metaStore.deleteNamespace(ns);
        fail("The namespace deletion didn't cause an exception because there are still an element type in it");
    } catch (MetaStoreDependenciesExistsException e) {
        assertNotNull(e.getDependencies());
        assertEquals(1, e.getDependencies().size());
        assertEquals(elementType.getId(), e.getDependencies().get(0));
    }
    metaStore.deleteElementType(ns, elementType);
    assertEquals(0, metaStore.getElementTypes(ns).size());
    metaStore.deleteNamespace(ns);
}
Also used : IMetaStoreElementType(org.pentaho.metastore.api.IMetaStoreElementType) Matchers.anyString(org.mockito.Matchers.anyString) IMetaStore(org.pentaho.metastore.api.IMetaStore) MetaStoreDependenciesExistsException(org.pentaho.metastore.api.exceptions.MetaStoreDependenciesExistsException) Test(org.junit.Test)

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