Search in sources :

Example 16 with IMetaStoreElement

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

the class StarDomainMetaStoreUtil method getStarDomainList.

public static List<IdNameDescription> getStarDomainList(IMetaStore metaStore) throws MetaStoreException {
    IMetaStoreElementType elementType = getStarDomainElementType(metaStore);
    List<IdNameDescription> list = new ArrayList<IdNameDescription>();
    for (IMetaStoreElement element : metaStore.getElements(namespace, elementType)) {
        IdNameDescription nameDescription = new IdNameDescription(element.getId(), element.getName(), getChildString(element, Attribute.ID_STAR_DOMAIN_DESCRIPTION.id));
        list.add(nameDescription);
    }
    return list;
}
Also used : IMetaStoreElementType(org.pentaho.metastore.api.IMetaStoreElementType) ArrayList(java.util.ArrayList) IMetaStoreElement(org.pentaho.metastore.api.IMetaStoreElement)

Example 17 with IMetaStoreElement

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

the class PurRepositoryMetaStore method getElements.

@Override
public List<IMetaStoreElement> getElements(String namespace, IMetaStoreElementType elementType) throws MetaStoreException {
    List<IMetaStoreElement> elements = new ArrayList<IMetaStoreElement>();
    RepositoryFile typeFolder = validateElementTypeRepositoryFolder(namespace, elementType);
    List<RepositoryFile> children = getChildren(typeFolder.getId());
    removeHiddenFilesFromList(children);
    for (RepositoryFile child : children) {
        IMetaStoreElement element = getElement(namespace, elementType, child.getId().toString());
        elements.add(element);
    }
    return elements;
}
Also used : ArrayList(java.util.ArrayList) IMetaStoreElement(org.pentaho.metastore.api.IMetaStoreElement) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile)

Example 18 with IMetaStoreElement

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

the class AbstractMetaTest method testGetSetImportMetaStore.

@Test(expected = KettlePluginException.class)
public void testGetSetImportMetaStore() throws Exception {
    assertNull(meta.getMetaStore());
    meta.importFromMetaStore();
    IMetaStore metastore = mock(IMetaStore.class);
    meta.setMetaStore(metastore);
    assertEquals(metastore, meta.getMetaStore());
    meta.importFromMetaStore();
    IMetaStoreElementType elementType = mock(IMetaStoreElementType.class);
    when(metastore.getElementTypeByName(PentahoDefaults.NAMESPACE, PentahoDefaults.DATABASE_CONNECTION_ELEMENT_TYPE_NAME)).thenReturn(elementType);
    when(metastore.getElements(PentahoDefaults.NAMESPACE, elementType)).thenReturn(new ArrayList<IMetaStoreElement>());
    meta.importFromMetaStore();
    IMetaStoreElement element = mock(IMetaStoreElement.class);
    when(metastore.getElements(PentahoDefaults.NAMESPACE, elementType)).thenReturn(Arrays.asList(element));
    meta.importFromMetaStore();
}
Also used : IMetaStoreElementType(org.pentaho.metastore.api.IMetaStoreElementType) IMetaStoreElement(org.pentaho.metastore.api.IMetaStoreElement) IMetaStore(org.pentaho.metastore.api.IMetaStore) Test(org.junit.Test)

Example 19 with IMetaStoreElement

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

the class KettleDatabaseRepositoryMetaStore method createElement.

@Override
public void createElement(String namespace, IMetaStoreElementType elementType, IMetaStoreElement element) throws MetaStoreException, MetaStoreElementExistException {
    try {
        IMetaStoreElement found = getElementByName(namespace, elementType, element.getName());
        if (found != null) {
            throw new MetaStoreElementExistException(Arrays.asList(found), "The element with name '" + element.getName() + "' already exists");
        }
        delegate.insertElement(elementType, element);
        repository.commit();
    } catch (MetaStoreElementExistException e) {
        throw e;
    } catch (Exception e) {
        repository.rollback();
        throw new MetaStoreException("Unable to create element with name '" + element.getName() + "' of type '" + elementType.getName() + "'", e);
    }
}
Also used : MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) MetaStoreElementExistException(org.pentaho.metastore.api.exceptions.MetaStoreElementExistException) IMetaStoreElement(org.pentaho.metastore.api.IMetaStoreElement) 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 20 with IMetaStoreElement

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

the class KettleDatabaseRepositoryMetaStore method getElementIds.

@Override
public List<String> getElementIds(String namespace, IMetaStoreElementType elementType) throws MetaStoreException {
    List<String> ids = new ArrayList<String>();
    List<IMetaStoreElement> elements = getElements(namespace, elementType);
    for (IMetaStoreElement element : elements) {
        ids.add(element.getId());
    }
    return ids;
}
Also used : ArrayList(java.util.ArrayList) IMetaStoreElement(org.pentaho.metastore.api.IMetaStoreElement)

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