Search in sources :

Example 1 with MetaStoreElementTypeExistsException

use of org.pentaho.metastore.api.exceptions.MetaStoreElementTypeExistsException 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 MetaStoreElementTypeExistsException

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

the class PurRepositoryMetaStore method createElementType.

// The element types
@Override
public void createElementType(String namespace, IMetaStoreElementType elementType) throws MetaStoreException {
    RepositoryFile namespaceFile = validateNamespace(namespace);
    IMetaStoreElementType existingType = getElementTypeByName(namespace, elementType.getName());
    if (existingType != null) {
        throw new MetaStoreElementTypeExistsException(Collections.singletonList(existingType), "Can not create element type with id '" + elementType.getId() + "' because it already exists");
    }
    RepositoryFile elementTypeFile = new RepositoryFile.Builder(elementType.getName()).folder(true).versioned(false).build();
    RepositoryFile folder = pur.createFolder(namespaceFile.getId(), elementTypeFile, null);
    elementType.setId(folder.getId().toString());
    // In this folder there is a hidden file which contains the description
    // and the other future properties of the element type
    // 
    RepositoryFile detailsFile = new RepositoryFile.Builder(ELEMENT_TYPE_DETAILS_FILENAME).folder(false).title(ELEMENT_TYPE_DETAILS_FILENAME).description(elementType.getDescription()).hidden(true).build();
    DataNode dataNode = getElementTypeDataNode(elementType);
    pur.createFile(folder.getId(), detailsFile, new NodeRepositoryFileData(dataNode), null);
    elementType.setMetaStoreName(getName());
}
Also used : IMetaStoreElementType(org.pentaho.metastore.api.IMetaStoreElementType) MetaStoreElementTypeExistsException(org.pentaho.metastore.api.exceptions.MetaStoreElementTypeExistsException) DataNode(org.pentaho.platform.api.repository2.unified.data.node.DataNode) NodeRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile)

Example 3 with MetaStoreElementTypeExistsException

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

the class KettleDatabaseRepositoryMetaStore method createElementType.

// Handle the element types
public void createElementType(String namespace, IMetaStoreElementType elementType) throws MetaStoreException, MetaStoreElementTypeExistsException {
    try {
        ObjectId namespaceId = delegate.verifyNamespace(namespace);
        // See if the element already exists in this namespace
        // 
        IMetaStoreElementType existingType = getElementTypeByName(namespace, elementType.getName());
        if (existingType != null) {
            throw new MetaStoreElementTypeExistsException(Arrays.asList(existingType), "Can not create element type with id '" + elementType.getId() + "' because it already exists");
        }
        KDBRMetaStoreElementType newElementType = new KDBRMetaStoreElementType(delegate, namespace, namespaceId, elementType.getName(), elementType.getDescription());
        newElementType.save();
        elementType.setId(newElementType.getId());
        repository.commit();
    } catch (MetaStoreElementTypeExistsException e) {
        throw e;
    } catch (MetaStoreException e) {
        repository.rollback();
        throw e;
    } catch (Exception e) {
        repository.rollback();
        throw new MetaStoreException(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) MetaStoreElementTypeExistsException(org.pentaho.metastore.api.exceptions.MetaStoreElementTypeExistsException) 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 MetaStoreElementTypeExistsException

use of org.pentaho.metastore.api.exceptions.MetaStoreElementTypeExistsException 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

IMetaStoreElementType (org.pentaho.metastore.api.IMetaStoreElementType)4 MetaStoreElementTypeExistsException (org.pentaho.metastore.api.exceptions.MetaStoreElementTypeExistsException)4 MetaStoreDependenciesExistsException (org.pentaho.metastore.api.exceptions.MetaStoreDependenciesExistsException)3 MetaStoreException (org.pentaho.metastore.api.exceptions.MetaStoreException)3 List (java.util.List)2 IMetaStoreElement (org.pentaho.metastore.api.IMetaStoreElement)2 IMetaStoreElementOwner (org.pentaho.metastore.api.security.IMetaStoreElementOwner)2 LongObjectId (org.pentaho.di.repository.LongObjectId)1 ObjectId (org.pentaho.di.repository.ObjectId)1 StringObjectId (org.pentaho.di.repository.StringObjectId)1 MetaStoreElementExistException (org.pentaho.metastore.api.exceptions.MetaStoreElementExistException)1 MetaStoreNamespaceExistsException (org.pentaho.metastore.api.exceptions.MetaStoreNamespaceExistsException)1 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)1 DataNode (org.pentaho.platform.api.repository2.unified.data.node.DataNode)1 NodeRepositoryFileData (org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData)1