Search in sources :

Example 26 with IMetaStoreElement

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

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

the class StarDomainMetaStoreUtilTest method testSaveStarDomain.

@Test
public void testSaveStarDomain() throws Exception {
    final StarDomain starDomain = mock(StarDomain.class);
    final ObjectId objectId = mock(ObjectId.class);
    final String objectIdStr = "objectIdStr";
    when(objectId.toString()).thenReturn(objectIdStr);
    when(starDomain.getObjectId()).thenReturn(objectId);
    final String starDomainName = "starDomainName";
    when(starDomain.getName()).thenReturn(starDomainName);
    final IMetaStoreElement metaStoreElement = mock(IMetaStoreElement.class);
    when(metaStoreElement.getId()).thenReturn("id");
    when(metaStore.getElement(anyString(), eq(metaStoreElementType), eq(objectIdStr))).thenReturn(metaStoreElement);
    StarDomainMetaStoreUtil.saveStarDomain(metaStore, starDomain);
    verify(metaStoreElement, times(1)).setElementType(eq(metaStoreElementType));
    verify(metaStoreElement, times(1)).setName(eq(starDomainName));
    verify(metaStoreElement, times(1)).addChild(any(IMetaStoreAttribute.class));
    verify(metaStore, times(1)).updateElement(anyString(), eq(metaStoreElementType), eq(objectIdStr), eq(metaStoreElement));
    verify(starDomain, times(1)).setObjectId(any(ObjectId.class));
}
Also used : StarDomain(org.pentaho.di.starmodeler.StarDomain) ObjectId(org.pentaho.di.repository.ObjectId) IMetaStoreAttribute(org.pentaho.metastore.api.IMetaStoreAttribute) IMetaStoreElement(org.pentaho.metastore.api.IMetaStoreElement) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 28 with IMetaStoreElement

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

the class PurRepositoryMetaStoreTest method testDataNodeConversion.

@Test
public void testDataNodeConversion() throws Exception {
    IMetaStoreElement expected = new MemoryMetaStoreElement();
    expected.setName("parent");
    expected.addChild(new MemoryMetaStoreAttribute("date", new Date()));
    expected.addChild(new MemoryMetaStoreAttribute("long", 32L));
    expected.addChild(new MemoryMetaStoreAttribute("double", 3.2));
    expected.addChild(new MemoryMetaStoreAttribute("string", "value"));
    MemoryMetaStoreAttribute collection = new MemoryMetaStoreAttribute("collection", "collection-value");
    for (int i = 0; i < 10; i++) {
        collection.addChild(new MemoryMetaStoreAttribute("key-" + i, "value-" + i));
    }
    expected.addChild(collection);
    DataNode dataNode = new DataNode("test");
    metaStore.elementToDataNode(expected, dataNode);
    IMetaStoreElement verify = new MemoryMetaStoreElement();
    metaStore.dataNodeToElement(dataNode, verify);
    assertEquals(expected.getName(), verify.getName());
    validate(expected, verify);
}
Also used : MemoryMetaStoreAttribute(org.pentaho.metastore.stores.memory.MemoryMetaStoreAttribute) DataNode(org.pentaho.platform.api.repository2.unified.data.node.DataNode) IMetaStoreElement(org.pentaho.metastore.api.IMetaStoreElement) Date(java.util.Date) MemoryMetaStoreElement(org.pentaho.metastore.stores.memory.MemoryMetaStoreElement) Test(org.junit.Test)

Example 29 with IMetaStoreElement

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

the class PurRepositoryMetaStore method getElement.

@Override
public IMetaStoreElement getElement(String namespace, IMetaStoreElementType elementType, String elementId) throws MetaStoreException {
    NodeRepositoryFileData data = pur.getDataForRead(elementId, NodeRepositoryFileData.class);
    if (data == null) {
        return null;
    }
    IMetaStoreElement element = newElement();
    element.setId(elementId);
    element.setElementType(elementType);
    DataNode dataNode = data.getNode();
    dataNodeToElement(dataNode, element);
    return element;
}
Also used : NodeRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData) DataNode(org.pentaho.platform.api.repository2.unified.data.node.DataNode) IMetaStoreElement(org.pentaho.metastore.api.IMetaStoreElement)

Example 30 with IMetaStoreElement

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

IMetaStoreElement (org.pentaho.metastore.api.IMetaStoreElement)31 IMetaStoreElementType (org.pentaho.metastore.api.IMetaStoreElementType)19 MetaStoreException (org.pentaho.metastore.api.exceptions.MetaStoreException)10 IMetaStoreAttribute (org.pentaho.metastore.api.IMetaStoreAttribute)8 ArrayList (java.util.ArrayList)7 Test (org.junit.Test)7 IMetaStore (org.pentaho.metastore.api.IMetaStore)6 MetaStoreDependenciesExistsException (org.pentaho.metastore.api.exceptions.MetaStoreDependenciesExistsException)6 Matchers.anyString (org.mockito.Matchers.anyString)5 MetaStoreElementTypeExistsException (org.pentaho.metastore.api.exceptions.MetaStoreElementTypeExistsException)5 MetaStoreElementExistException (org.pentaho.metastore.api.exceptions.MetaStoreElementExistException)4 IMetaStoreElementOwner (org.pentaho.metastore.api.security.IMetaStoreElementOwner)4 List (java.util.List)3 StringObjectId (org.pentaho.di.repository.StringObjectId)3 StarDomain (org.pentaho.di.starmodeler.StarDomain)3 MetaStoreNamespaceExistsException (org.pentaho.metastore.api.exceptions.MetaStoreNamespaceExistsException)3 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)2 KettlePluginException (org.pentaho.di.core.exception.KettlePluginException)2 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)2 LogicalTable (org.pentaho.metadata.model.LogicalTable)2