Search in sources :

Example 6 with IMetaStoreElement

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

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

the class MetaStoreTestBase method generateCustomerDimensionElement.

private IMetaStoreElement generateCustomerDimensionElement(IMetaStore metaStore, IMetaStoreElementType elementType) throws MetaStoreException {
    IMetaStoreElement element = metaStore.newElement();
    element.setElementType(elementType);
    element.setName(CUSTOMER_DIMENSION_NAME);
    element.addChild(metaStore.newAttribute("description", "This is the shared customer dimension"));
    element.addChild(metaStore.newAttribute("physical_table", "DIM_CUSTOMER"));
    IMetaStoreAttribute fieldsElement = metaStore.newAttribute("fields", null);
    element.addChild(fieldsElement);
    // A technical key
    // 
    IMetaStoreAttribute fieldElement = metaStore.newAttribute("field_0", null);
    fieldsElement.addChild(fieldElement);
    fieldElement.addChild(metaStore.newAttribute("field_name", "Customer TK"));
    fieldElement.addChild(metaStore.newAttribute("field_description", "Customer Technical key"));
    fieldElement.addChild(metaStore.newAttribute("field_phyiscal_name", "customer_tk"));
    fieldElement.addChild(metaStore.newAttribute("field_kettle_type", "Integer"));
    // A version field
    // 
    fieldElement = metaStore.newAttribute("field_1", null);
    fieldsElement.addChild(fieldElement);
    fieldElement.addChild(metaStore.newAttribute("field_name", "version field"));
    fieldElement.addChild(metaStore.newAttribute("field_description", "dimension version field (1..N)"));
    fieldElement.addChild(metaStore.newAttribute("field_phyiscal_name", "version"));
    fieldElement.addChild(metaStore.newAttribute("field_kettle_type", "Integer"));
    // Natural key
    // 
    fieldElement = metaStore.newAttribute("field_2", null);
    fieldsElement.addChild(fieldElement);
    fieldElement.addChild(metaStore.newAttribute("field_name", "Customer ID"));
    fieldElement.addChild(metaStore.newAttribute("field_description", "Customer ID as a natural key of this dimension"));
    fieldElement.addChild(metaStore.newAttribute("field_phyiscal_name", "customer_id"));
    fieldElement.addChild(metaStore.newAttribute("field_kettle_type", "Integer"));
    // Start date
    // 
    fieldElement = metaStore.newAttribute("field_3", null);
    fieldsElement.addChild(fieldElement);
    fieldElement.addChild(metaStore.newAttribute("field_name", "Start date"));
    fieldElement.addChild(metaStore.newAttribute("field_description", "Start of validity of this dimension entry"));
    fieldElement.addChild(metaStore.newAttribute("field_phyiscal_name", "start_date"));
    fieldElement.addChild(metaStore.newAttribute("field_kettle_type", "Date"));
    // End date
    // 
    fieldElement = metaStore.newAttribute("field_4", null);
    fieldsElement.addChild(fieldElement);
    fieldElement.addChild(metaStore.newAttribute("field_name", "End date"));
    fieldElement.addChild(metaStore.newAttribute("field_description", "End of validity of this dimension entry"));
    fieldElement.addChild(metaStore.newAttribute("field_phyiscal_name", "end_date"));
    fieldElement.addChild(metaStore.newAttribute("field_kettle_type", "Date"));
    // 
    for (int i = 5; i <= 10; i++) {
        fieldElement = metaStore.newAttribute("field_" + i, null);
        fieldsElement.addChild(fieldElement);
        fieldElement.addChild(metaStore.newAttribute("field_name", "Field name " + i));
        fieldElement.addChild(metaStore.newAttribute("field_description", "Field description " + i));
        fieldElement.addChild(metaStore.newAttribute("field_phyiscal_name", "physical_name_" + i));
        fieldElement.addChild(metaStore.newAttribute("field_kettle_type", "String"));
    }
    // Some security
    // 
    element.setOwner(metaStore.newElementOwner("joe", MetaStoreElementOwnerType.USER));
    // The "users" role has read/write permissions
    // 
    IMetaStoreElementOwner usersRole = metaStore.newElementOwner("users", MetaStoreElementOwnerType.ROLE);
    MetaStoreOwnerPermissions usersRoleOwnerPermissions = new MetaStoreOwnerPermissions(usersRole, MetaStoreObjectPermission.READ, MetaStoreObjectPermission.UPDATE);
    element.getOwnerPermissionsList().add(usersRoleOwnerPermissions);
    return element;
}
Also used : IMetaStoreElementOwner(org.pentaho.metastore.api.security.IMetaStoreElementOwner) MetaStoreOwnerPermissions(org.pentaho.metastore.api.security.MetaStoreOwnerPermissions) IMetaStoreAttribute(org.pentaho.metastore.api.IMetaStoreAttribute) IMetaStoreElement(org.pentaho.metastore.api.IMetaStoreElement)

Example 8 with IMetaStoreElement

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

the class PurRepositoryIT method populateElement.

protected IMetaStoreElement populateElement(IMetaStore metaStore, IMetaStoreElementType elementType, String name) throws MetaStoreException {
    IMetaStoreElement element = metaStore.newElement();
    element.setElementType(elementType);
    element.setName(name);
    for (int i = 1; i <= 5; i++) {
        element.addChild(metaStore.newAttribute("id " + i, "value " + i));
    }
    IMetaStoreAttribute subAttr = metaStore.newAttribute("sub-attr", null);
    for (int i = 101; i <= 110; i++) {
        subAttr.addChild(metaStore.newAttribute("sub-id " + i, "sub-value " + i));
    }
    element.addChild(subAttr);
    return element;
}
Also used : IMetaStoreAttribute(org.pentaho.metastore.api.IMetaStoreAttribute) IMetaStoreElement(org.pentaho.metastore.api.IMetaStoreElement)

Example 9 with IMetaStoreElement

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

the class SharedDimensionMetaStoreUtilTest method testSaveSharedDimension.

@Test
public void testSaveSharedDimension() throws Exception {
    final String locale = Locale.US.toString();
    final IMetaStore metaStore = mock(IMetaStore.class);
    final IMetaStoreElementType metaStoreElementType = mock(IMetaStoreElementType.class);
    when(metaStore.newElementType(anyString())).thenReturn(metaStoreElementType);
    final IMetaStoreElement metaStoreElement = mock(IMetaStoreElement.class);
    final String sdId = "sdId";
    when(metaStore.getElement(anyString(), eq(metaStoreElementType), eq(sdId))).thenReturn(metaStoreElement);
    final LogicalTable sharedDimension = mock(LogicalTable.class);
    final String sdName = "sdName";
    when(sharedDimension.getName(eq(locale))).thenReturn(sdName);
    when(sharedDimension.getId()).thenReturn(sdId);
    SharedDimensionMetaStoreUtil.saveSharedDimension(metaStore, sharedDimension, locale);
    verify(metaStoreElement, times(1)).setElementType(eq(metaStoreElementType));
    verify(metaStoreElement, times(1)).setName(eq(sdName));
    verify(metaStoreElement, times(2)).addChild(any(IMetaStoreAttribute.class));
    verify(metaStore, times(1)).updateElement(anyString(), eq(metaStoreElementType), eq(sdId), eq(metaStoreElement));
    verify(sharedDimension, times(1)).setId(anyString());
}
Also used : IMetaStoreElementType(org.pentaho.metastore.api.IMetaStoreElementType) IMetaStoreAttribute(org.pentaho.metastore.api.IMetaStoreAttribute) IMetaStoreElement(org.pentaho.metastore.api.IMetaStoreElement) Matchers.anyString(org.mockito.Matchers.anyString) LogicalTable(org.pentaho.metadata.model.LogicalTable) IMetaStore(org.pentaho.metastore.api.IMetaStore) Test(org.junit.Test)

Example 10 with IMetaStoreElement

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

the class StarDomainMetaStoreUtilTest method testGetStarDomainList.

@Test
public void testGetStarDomainList() throws Exception {
    final IMetaStoreElement metaStoreElement = mock(IMetaStoreElement.class);
    final String id = "id";
    when(metaStoreElement.getId()).thenReturn(id);
    final String name = "name";
    when(metaStoreElement.getName()).thenReturn(name);
    final IMetaStoreAttribute metaStoreAttribute = mock(IMetaStoreAttribute.class);
    when(metaStoreElement.getChild(eq(StarDomainMetaStoreUtil.Attribute.ID_STAR_DOMAIN_DESCRIPTION.id))).thenReturn(metaStoreAttribute);
    when(metaStore.getElements(anyString(), eq(metaStoreElementType))).thenReturn(new LinkedList<IMetaStoreElement>() {

        {
            add(metaStoreElement);
        }
    });
    final List<IdNameDescription> starDomainList = StarDomainMetaStoreUtil.getStarDomainList(metaStore);
    assertNotNull(starDomainList);
    assertEquals(1, starDomainList.size());
    final IdNameDescription result = starDomainList.get(0);
    assertEquals(id, result.getId());
    assertEquals(name, result.getName());
}
Also used : IMetaStoreAttribute(org.pentaho.metastore.api.IMetaStoreAttribute) IMetaStoreElement(org.pentaho.metastore.api.IMetaStoreElement) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

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