Search in sources :

Example 1 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 2 with IMetaStoreElement

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

the class KettleDatabaseRepositoryMetaStore method getElements.

@Override
public List<IMetaStoreElement> getElements(String namespace, IMetaStoreElementType elementType) throws MetaStoreException {
    try {
        IMetaStoreElementType type = getElementTypeByName(namespace, elementType.getName());
        if (type == null) {
            return new ArrayList<IMetaStoreElement>();
        }
        Collection<RowMetaAndData> elementRows = delegate.getElements(new LongObjectId(new StringObjectId(type.getId())));
        List<IMetaStoreElement> elements = new ArrayList<IMetaStoreElement>();
        for (RowMetaAndData elementRow : elementRows) {
            IMetaStoreElement element = delegate.parseElement(elementType, elementRow);
            elements.add(element);
        }
        return elements;
    } catch (Exception e) {
        throw new MetaStoreException("Unable to get list of elements from namespace '" + namespace + "' and for element type '" + elementType.getName() + "'", e);
    }
}
Also used : MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) IMetaStoreElementType(org.pentaho.metastore.api.IMetaStoreElementType) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) ArrayList(java.util.ArrayList) IMetaStoreElement(org.pentaho.metastore.api.IMetaStoreElement) LongObjectId(org.pentaho.di.repository.LongObjectId) StringObjectId(org.pentaho.di.repository.StringObjectId) 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 3 with IMetaStoreElement

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

the class DatabaseMetaStoreUtil method populateDatabaseElement.

public static IMetaStoreElement populateDatabaseElement(IMetaStore metaStore, DatabaseMeta databaseMeta) throws MetaStoreException {
    if (!metaStore.namespaceExists(PentahoDefaults.NAMESPACE)) {
        throw new MetaStoreException("Namespace '" + PentahoDefaults.NAMESPACE + "' doesn't exist.");
    }
    // If the data type doesn't exist, error out...
    // 
    IMetaStoreElementType elementType = metaStore.getElementTypeByName(PentahoDefaults.NAMESPACE, PentahoDefaults.DATABASE_CONNECTION_ELEMENT_TYPE_NAME);
    if (elementType == null) {
        throw new MetaStoreException("Unable to find the database connection type");
    }
    elementType = populateDatabaseElementType(metaStore);
    // generate a new database element and populate it with metadata
    // 
    IMetaStoreElement element = metaStore.newElement(elementType, databaseMeta.getName(), null);
    element.addChild(metaStore.newAttribute(MetaStoreConst.DB_ATTR_ID_PLUGIN_ID, databaseMeta.getPluginId()));
    element.setName(databaseMeta.getName());
    element.addChild(metaStore.newAttribute(MetaStoreConst.DB_ATTR_ID_DESCRIPTION, databaseMeta.getDescription()));
    element.addChild(metaStore.newAttribute(MetaStoreConst.DB_ATTR_ID_ACCESS_TYPE, databaseMeta.getAccessTypeDesc()));
    element.addChild(metaStore.newAttribute(MetaStoreConst.DB_ATTR_ID_HOSTNAME, databaseMeta.getHostname()));
    element.addChild(metaStore.newAttribute(MetaStoreConst.DB_ATTR_ID_PORT, databaseMeta.getDatabasePortNumberString()));
    element.addChild(metaStore.newAttribute(MetaStoreConst.DB_ATTR_ID_DATABASE_NAME, databaseMeta.getDatabaseName()));
    element.addChild(metaStore.newAttribute(MetaStoreConst.DB_ATTR_ID_USERNAME, databaseMeta.getUsername()));
    element.addChild(metaStore.newAttribute(MetaStoreConst.DB_ATTR_ID_PASSWORD, metaStore.getTwoWayPasswordEncoder().encode(databaseMeta.getPassword())));
    element.addChild(metaStore.newAttribute(MetaStoreConst.DB_ATTR_ID_SERVERNAME, databaseMeta.getServername()));
    element.addChild(metaStore.newAttribute(MetaStoreConst.DB_ATTR_ID_DATA_TABLESPACE, databaseMeta.getDataTablespace()));
    element.addChild(metaStore.newAttribute(MetaStoreConst.DB_ATTR_ID_INDEX_TABLESPACE, databaseMeta.getIndexTablespace()));
    IMetaStoreAttribute attributesChild = metaStore.newAttribute(MetaStoreConst.DB_ATTR_ID_ATTRIBUTES, null);
    element.addChild(attributesChild);
    // Now add a list of all the attributes set on the database connection...
    // 
    Properties attributes = databaseMeta.getAttributes();
    Enumeration<Object> keys = databaseMeta.getAttributes().keys();
    while (keys.hasMoreElements()) {
        String code = (String) keys.nextElement();
        String attribute = (String) attributes.get(code);
        // Add it to the attributes child
        // 
        attributesChild.addChild(metaStore.newAttribute(code, attribute));
    }
    // Extra information for 3rd-party tools:
    // 
    // The driver class
    // 
    element.addChild(metaStore.newAttribute(MetaStoreConst.DB_ATTR_DRIVER_CLASS, databaseMeta.getDriverClass()));
    // 
    try {
        element.addChild(metaStore.newAttribute(MetaStoreConst.DB_ATTR_JDBC_URL, databaseMeta.getURL()));
    } catch (Exception e) {
        throw new MetaStoreException("Unable to assemble URL from database '" + databaseMeta.getName() + "'", e);
    }
    return element;
}
Also used : MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) IMetaStoreElementType(org.pentaho.metastore.api.IMetaStoreElementType) IMetaStoreAttribute(org.pentaho.metastore.api.IMetaStoreAttribute) IMetaStoreElement(org.pentaho.metastore.api.IMetaStoreElement) Properties(java.util.Properties) MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) KettlePluginException(org.pentaho.di.core.exception.KettlePluginException)

Example 4 with IMetaStoreElement

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

the class DatabaseMetaStoreUtil method getDatabaseElements.

public static List<DatabaseMeta> getDatabaseElements(IMetaStore metaStore) throws MetaStoreException {
    List<DatabaseMeta> databases = new ArrayList<DatabaseMeta>();
    // If the data type doesn't exist, it's an empty list...
    // 
    IMetaStoreElementType elementType = metaStore.getElementTypeByName(PentahoDefaults.NAMESPACE, PentahoDefaults.DATABASE_CONNECTION_ELEMENT_TYPE_NAME);
    if (elementType == null) {
        return databases;
    }
    List<IMetaStoreElement> elements = metaStore.getElements(PentahoDefaults.NAMESPACE, elementType);
    for (IMetaStoreElement element : elements) {
        try {
            DatabaseMeta databaseMeta = loadDatabaseMetaFromDatabaseElement(metaStore, element);
            databases.add(databaseMeta);
        } catch (Exception e) {
            throw new MetaStoreException("Unable to load database from element with name '" + element.getName() + "' and type '" + elementType.getName() + "'", e);
        }
    }
    return databases;
}
Also used : MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) IMetaStoreElementType(org.pentaho.metastore.api.IMetaStoreElementType) ArrayList(java.util.ArrayList) IMetaStoreElement(org.pentaho.metastore.api.IMetaStoreElement) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) KettlePluginException(org.pentaho.di.core.exception.KettlePluginException)

Example 5 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)

Aggregations

IMetaStoreElement (org.pentaho.metastore.api.IMetaStoreElement)32 IMetaStoreElementType (org.pentaho.metastore.api.IMetaStoreElementType)19 MetaStoreException (org.pentaho.metastore.api.exceptions.MetaStoreException)11 ArrayList (java.util.ArrayList)8 IMetaStoreAttribute (org.pentaho.metastore.api.IMetaStoreAttribute)8 Test (org.junit.Test)7 MetaStoreDependenciesExistsException (org.pentaho.metastore.api.exceptions.MetaStoreDependenciesExistsException)7 IMetaStore (org.pentaho.metastore.api.IMetaStore)6 MetaStoreElementTypeExistsException (org.pentaho.metastore.api.exceptions.MetaStoreElementTypeExistsException)6 Matchers.anyString (org.mockito.Matchers.anyString)5 MetaStoreElementExistException (org.pentaho.metastore.api.exceptions.MetaStoreElementExistException)4 MetaStoreNamespaceExistsException (org.pentaho.metastore.api.exceptions.MetaStoreNamespaceExistsException)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 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)2 KettleException (org.pentaho.di.core.exception.KettleException)2 KettlePluginException (org.pentaho.di.core.exception.KettlePluginException)2 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)2