Search in sources :

Example 31 with IMetaStoreElementType

use of org.pentaho.metastore.api.IMetaStoreElementType 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 32 with IMetaStoreElementType

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

the class SharedDimensionMetaStoreUtil method getSharedDimensionElementType.

public static IMetaStoreElementType getSharedDimensionElementType(IMetaStore metaStore) throws MetaStoreException {
    verifyNamespaceCreated(metaStore, namespace);
    IMetaStoreElementType elementType = metaStore.getElementTypeByName(namespace, METASTORE_SHARED_DIMENSION_TYPE_NAME);
    if (elementType == null) {
        // create the type
        // 
        elementType = metaStore.newElementType(namespace);
        elementType.setName(METASTORE_SHARED_DIMENSION_TYPE_NAME);
        elementType.setDescription(METASTORE_SHARED_DIMENSION_TYPE_DESCRIPTION);
        metaStore.createElementType(namespace, elementType);
    }
    return elementType;
}
Also used : IMetaStoreElementType(org.pentaho.metastore.api.IMetaStoreElementType)

Example 33 with IMetaStoreElementType

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

the class StarDomainMetaStoreUtil method getStarDomainElementType.

public static IMetaStoreElementType getStarDomainElementType(IMetaStore metaStore) throws MetaStoreException {
    verifyNamespaceCreated(metaStore, namespace);
    IMetaStoreElementType elementType = metaStore.getElementTypeByName(namespace, METASTORE_STAR_DOMAIN_TYPE_NAME);
    if (elementType == null) {
        // create the type
        // 
        elementType = createStarDomainElementType(metaStore);
    }
    return elementType;
}
Also used : IMetaStoreElementType(org.pentaho.metastore.api.IMetaStoreElementType)

Example 34 with IMetaStoreElementType

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

the class StarDomainMetaStoreUtil method saveStarDomain.

public static void saveStarDomain(IMetaStore metaStore, StarDomain starDomain) throws MetaStoreException {
    IMetaStoreElementType elementType = getStarDomainElementType(metaStore);
    IMetaStoreElement element = null;
    if (starDomain.getObjectId() != null) {
        // verify the ID!
        // 
        element = metaStore.getElement(namespace, elementType, starDomain.getObjectId().toString());
    }
    if (element == null) {
        // Create a new element
        // 
        element = metaStore.newElement();
        populateElementWithStarDomain(metaStore, starDomain, element, elementType);
        metaStore.createElement(namespace, elementType, element);
    } else {
        // Update an existing element
        // 
        populateElementWithStarDomain(metaStore, starDomain, element, elementType);
        metaStore.updateElement(namespace, elementType, starDomain.getObjectId().toString(), element);
    }
    starDomain.setObjectId(new StringObjectId(element.getId().toString()));
}
Also used : IMetaStoreElementType(org.pentaho.metastore.api.IMetaStoreElementType) IMetaStoreElement(org.pentaho.metastore.api.IMetaStoreElement) StringObjectId(org.pentaho.di.repository.StringObjectId)

Example 35 with IMetaStoreElementType

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

the class SharedDimensionMetaStoreUtilTest method testGetSharedDimensionElementTypeNew.

@Test
public void testGetSharedDimensionElementTypeNew() throws Exception {
    final IMetaStore metaStore = mock(IMetaStore.class);
    final IMetaStoreElementType metaStoreElementType = mock(IMetaStoreElementType.class);
    when(metaStore.newElementType(anyString())).thenReturn(metaStoreElementType);
    final IMetaStoreElementType sharedDimensionElementType = SharedDimensionMetaStoreUtil.getSharedDimensionElementType(metaStore);
    verify(metaStore, times(1)).createNamespace(anyString());
    assertNotNull(sharedDimensionElementType);
    assertEquals(metaStoreElementType, sharedDimensionElementType);
    verify(sharedDimensionElementType, times(1)).setName(eq(SharedDimensionMetaStoreUtil.METASTORE_SHARED_DIMENSION_TYPE_NAME));
    verify(sharedDimensionElementType, times(1)).setDescription(eq(SharedDimensionMetaStoreUtil.METASTORE_SHARED_DIMENSION_TYPE_DESCRIPTION));
    verify(metaStore, times(1)).createElementType(anyString(), eq(sharedDimensionElementType));
}
Also used : IMetaStoreElementType(org.pentaho.metastore.api.IMetaStoreElementType) IMetaStore(org.pentaho.metastore.api.IMetaStore) Test(org.junit.Test)

Aggregations

IMetaStoreElementType (org.pentaho.metastore.api.IMetaStoreElementType)40 IMetaStoreElement (org.pentaho.metastore.api.IMetaStoreElement)19 MetaStoreException (org.pentaho.metastore.api.exceptions.MetaStoreException)12 MetaStoreDependenciesExistsException (org.pentaho.metastore.api.exceptions.MetaStoreDependenciesExistsException)10 ArrayList (java.util.ArrayList)9 Test (org.junit.Test)9 IMetaStore (org.pentaho.metastore.api.IMetaStore)9 MetaStoreElementTypeExistsException (org.pentaho.metastore.api.exceptions.MetaStoreElementTypeExistsException)9 StringObjectId (org.pentaho.di.repository.StringObjectId)7 MetaStoreElementExistException (org.pentaho.metastore.api.exceptions.MetaStoreElementExistException)7 LongObjectId (org.pentaho.di.repository.LongObjectId)6 MetaStoreNamespaceExistsException (org.pentaho.metastore.api.exceptions.MetaStoreNamespaceExistsException)6 Matchers.anyString (org.mockito.Matchers.anyString)4 List (java.util.List)3 ObjectId (org.pentaho.di.repository.ObjectId)3 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)3 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)2 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)2 KettlePluginException (org.pentaho.di.core.exception.KettlePluginException)2 StarDomain (org.pentaho.di.starmodeler.StarDomain)2