Search in sources :

Example 11 with IMetaStoreElement

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

the class StarDomainMetaStoreUtilTest method testLoadStarDomain.

@Test
public void testLoadStarDomain() throws Exception {
    final String id = "id";
    final String msName = "MSName";
    when(metaStore.getName()).thenReturn(msName);
    final DelegatingMetaStore delegatingMetaStore = spy(new DelegatingMetaStore(metaStore));
    delegatingMetaStore.setActiveMetaStoreName(msName);
    doAnswer(new Answer<IMetaStoreElementType>() {

        @Override
        public IMetaStoreElementType answer(InvocationOnMock invocationOnMock) throws Throwable {
            return metaStore.getElementTypeByName((String) invocationOnMock.getArguments()[0], (String) invocationOnMock.getArguments()[1]);
        }
    }).when(delegatingMetaStore).getElementTypeByName(anyString(), anyString());
    assertNull(StarDomainMetaStoreUtil.loadStarDomain(delegatingMetaStore, id));
    final IMetaStoreElement metaStoreElement = mock(IMetaStoreElement.class);
    final String name = "name";
    when(metaStoreElement.getName()).thenReturn(name);
    doReturn(metaStoreElement).when(delegatingMetaStore).getElement(anyString(), eq(metaStoreElementType), eq(id));
    final StarDomain starDomain = StarDomainMetaStoreUtil.loadStarDomain(delegatingMetaStore, id);
    assertEquals(id, starDomain.getObjectId().getId());
    assertEquals(name, starDomain.getName());
}
Also used : IMetaStoreElementType(org.pentaho.metastore.api.IMetaStoreElementType) StarDomain(org.pentaho.di.starmodeler.StarDomain) InvocationOnMock(org.mockito.invocation.InvocationOnMock) IMetaStoreElement(org.pentaho.metastore.api.IMetaStoreElement) Matchers.anyString(org.mockito.Matchers.anyString) DelegatingMetaStore(org.pentaho.metastore.stores.delegate.DelegatingMetaStore) Test(org.junit.Test)

Example 12 with IMetaStoreElement

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

the class StarModelerPerspective method testMetaStore.

protected void testMetaStore() {
    try {
        // Force repository meta store
        IMetaStore metaStore = Spoon.getInstance().getRepository().getMetaStore();
        LogChannel.GENERAL.logBasic("Active metastore: " + metaStore.getName());
        StarDomainMetaStoreUtil.verifyNamespaceCreated(metaStore, "pentaho");
        IMetaStoreElementType elementType = StarDomainMetaStoreUtil.getStarDomainElementType(metaStore);
        if (elementType == null) {
            throw new KettleException("Unable to find star domain element type");
        }
        LogChannel.GENERAL.logBasic("Found star domain element type: " + elementType.getName() + " : " + elementType.getDescription());
        elementType = metaStore.getElementTypeByName(PentahoDefaults.NAMESPACE, elementType.getName());
        if (elementType == null) {
            throw new KettleException("Unable to find star domain element type by name");
        }
        LogChannel.GENERAL.logBasic("Found element type by name");
        List<IdNameDescription> list = new ArrayList<IdNameDescription>();
        for (IMetaStoreElement element : metaStore.getElements(PentahoDefaults.NAMESPACE, elementType)) {
            IdNameDescription nameDescription = new IdNameDescription(element.getId(), element.getName(), null);
            list.add(nameDescription);
        }
        LogChannel.GENERAL.logBasic("Found " + list.size() + " star domain elements.");
        StarDomainMetaStoreUtil.getStarDomainList(metaStore);
    } catch (Exception e) {
        new ErrorDialog(Spoon.getInstance().getShell(), "ERROR", "Error testing meta store: ", e);
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) IMetaStoreElementType(org.pentaho.metastore.api.IMetaStoreElementType) ArrayList(java.util.ArrayList) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) IMetaStoreElement(org.pentaho.metastore.api.IMetaStoreElement) IdNameDescription(org.pentaho.di.starmodeler.metastore.IdNameDescription) IMetaStore(org.pentaho.metastore.api.IMetaStore) XulException(org.pentaho.ui.xul.XulException) MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) KettleException(org.pentaho.di.core.exception.KettleException) MetaStoreElementExistException(org.pentaho.metastore.api.exceptions.MetaStoreElementExistException)

Example 13 with IMetaStoreElement

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

the class ModelMetaStoreUtil method saveLogicalModel.

public static IMetaStoreElement saveLogicalModel(IMetaStore metaStore, LogicalModel model) throws MetaStoreException {
    IMetaStoreElementType elementType = getLogicalModelElementType(metaStore);
    IMetaStoreElement oldElement = metaStore.getElementByName(PentahoDefaults.NAMESPACE, elementType, model.getName(defaultLocale));
    if (oldElement == null) {
        // populate and create...
        // 
        IMetaStoreElement newElement = populateElement(metaStore, model);
        metaStore.createElement(PentahoDefaults.NAMESPACE, elementType, newElement);
        return newElement;
    } else {
        // The element exists, update...
        // 
        IMetaStoreElement newElement = populateElement(metaStore, model);
        metaStore.updateElement(PentahoDefaults.NAMESPACE, elementType, oldElement.getId(), newElement);
        return newElement;
    }
}
Also used : IMetaStoreElementType(org.pentaho.metastore.api.IMetaStoreElementType) IMetaStoreElement(org.pentaho.metastore.api.IMetaStoreElement)

Example 14 with IMetaStoreElement

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

the class SharedDimensionMetaStoreUtil method saveSharedDimension.

public static void saveSharedDimension(IMetaStore metaStore, LogicalTable sharedDimension, String locale) throws MetaStoreException {
    IMetaStoreElementType elementType = getSharedDimensionElementType(metaStore);
    IMetaStoreElement element = null;
    if (sharedDimension.getId() != null) {
        element = metaStore.getElement(namespace, elementType, sharedDimension.getId());
    }
    if (element != null) {
        // Update the shared dimension!
        // 
        populateElementWithSharedDimension(metaStore, sharedDimension, locale, elementType, element);
        metaStore.updateElement(namespace, elementType, sharedDimension.getId(), element);
    } else {
        // New shared dimension
        // 
        element = metaStore.newElement();
        populateElementWithSharedDimension(metaStore, sharedDimension, locale, elementType, element);
        metaStore.createElement(namespace, elementType, element);
    }
    sharedDimension.setId(element.getId());
}
Also used : IMetaStoreElementType(org.pentaho.metastore.api.IMetaStoreElementType) IMetaStoreElement(org.pentaho.metastore.api.IMetaStoreElement)

Example 15 with IMetaStoreElement

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

the class StarDomainMetaStoreUtil method loadStarDomain.

public static StarDomain loadStarDomain(DelegatingMetaStore metaStore, String id) throws MetaStoreException {
    IMetaStoreElementType elementType = getStarDomainElementType(metaStore);
    IMetaStoreElement element = metaStore.getElement(namespace, elementType, id);
    if (element == null) {
        return null;
    }
    StarDomain starDomain = new StarDomain();
    starDomain.setObjectId(new StringObjectId(id));
    starDomain.setName(element.getName());
    starDomain.setDescription(getChildString(element, Attribute.ID_STAR_DOMAIN_DESCRIPTION.id));
    return starDomain;
}
Also used : IMetaStoreElementType(org.pentaho.metastore.api.IMetaStoreElementType) StarDomain(org.pentaho.di.starmodeler.StarDomain) IMetaStoreElement(org.pentaho.metastore.api.IMetaStoreElement) StringObjectId(org.pentaho.di.repository.StringObjectId)

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