Search in sources :

Example 26 with IMetaStoreElementType

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

the class KettleDatabaseRepositoryMetaStore method getElementTypes.

@Override
public List<IMetaStoreElementType> getElementTypes(String namespace) throws MetaStoreException {
    try {
        LongObjectId namespaceId = delegate.getNamespaceId(namespace);
        if (namespaceId == null) {
            return new ArrayList<IMetaStoreElementType>();
        }
        Collection<RowMetaAndData> elementTypeRows = delegate.getElementTypes(namespaceId);
        List<IMetaStoreElementType> list = new ArrayList<IMetaStoreElementType>();
        for (RowMetaAndData elementTypeRow : elementTypeRows) {
            KDBRMetaStoreElementType elementType = delegate.parseElementType(namespace, namespaceId, elementTypeRow);
            list.add(elementType);
        }
        return list;
    } catch (Exception e) {
        throw new MetaStoreException("Unable to get list of element types for namespace '" + namespace + "'", 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) LongObjectId(org.pentaho.di.repository.LongObjectId) 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 27 with IMetaStoreElementType

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

the class DatabaseMetaStoreUtil method createDatabaseElement.

public static void createDatabaseElement(IMetaStore metaStore, DatabaseMeta databaseMeta) throws MetaStoreException {
    // 
    if (!metaStore.namespaceExists(PentahoDefaults.NAMESPACE)) {
        metaStore.createNamespace(PentahoDefaults.NAMESPACE);
    }
    // If the database connection element type doesn't exist, create it
    // 
    IMetaStoreElementType elementType = metaStore.getElementTypeByName(PentahoDefaults.NAMESPACE, PentahoDefaults.DATABASE_CONNECTION_ELEMENT_TYPE_NAME);
    if (elementType == null) {
        elementType = populateDatabaseElementType(metaStore);
        metaStore.createElementType(PentahoDefaults.NAMESPACE, elementType);
    }
    // populate an element, store it.
    // 
    IMetaStoreElement databaseElement = populateDatabaseElement(metaStore, databaseMeta);
    // Store the element physically
    // 
    metaStore.createElement(PentahoDefaults.NAMESPACE, databaseElement.getElementType(), databaseElement);
}
Also used : IMetaStoreElementType(org.pentaho.metastore.api.IMetaStoreElementType) IMetaStoreElement(org.pentaho.metastore.api.IMetaStoreElement)

Example 28 with IMetaStoreElementType

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

the class DatabaseMetaStoreUtil method populateDatabaseElementType.

public static IMetaStoreElementType populateDatabaseElementType(IMetaStore metaStore) throws MetaStoreException {
    // The new type will typically have an ID so all we need to do is give the type a name and a description.
    // 
    IMetaStoreElementType elementType = metaStore.newElementType(PentahoDefaults.NAMESPACE);
    // Name and description...
    // 
    elementType.setName(PentahoDefaults.DATABASE_CONNECTION_ELEMENT_TYPE_NAME);
    elementType.setDescription(PentahoDefaults.DATABASE_CONNECTION_ELEMENT_TYPE_DESCRIPTION);
    return elementType;
}
Also used : IMetaStoreElementType(org.pentaho.metastore.api.IMetaStoreElementType)

Example 29 with IMetaStoreElementType

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

the class TestSharedObjectsMetaStore method testSharedObjectsMetaStore.

public void testSharedObjectsMetaStore() throws Exception {
    KettleEnvironment.init();
    File sharedObjectsFile = File.createTempFile("shared-objects", ".xml");
    String sharedObjectsFilename = sharedObjectsFile.toString();
    sharedObjectsFile.delete();
    SharedObjects sharedObjects = new SharedObjects(sharedObjectsFilename);
    SharedObjectsMetaStore metaStore = new SharedObjectsMetaStore(sharedObjects);
    List<IMetaStoreElementType> elementTypes = metaStore.getElementTypes(namespace);
    assertEquals(1, elementTypes.size());
    IMetaStoreElementType databaseElementType = metaStore.getElementType(namespace, PentahoDefaults.DATABASE_CONNECTION_ELEMENT_TYPE_NAME);
    assertNotNull(databaseElementType);
    List<IMetaStoreElement> elements = metaStore.getElements(namespace, databaseElementType);
    assertEquals(0, elements.size());
    DatabaseMeta databaseMeta = new DatabaseMeta(databaseMetaXml);
    // add it to shared objects, see if we find the element (SharedObjects --> MetaStore)
    // 
    sharedObjects.storeObject(databaseMeta);
    elements = metaStore.getElements(namespace, databaseElementType);
    assertEquals(1, elements.size());
    IMetaStoreElement databaseElement = elements.get(0);
    // Remove it again...
    sharedObjects.removeObject(databaseMeta);
    elements = metaStore.getElements(namespace, databaseElementType);
    assertEquals(0, elements.size());
    // Add it to the meta store, see if it shows in the shared objects (MetaStore --> SharedObjects)
    // 
    metaStore.createElement(namespace, databaseElementType, databaseElement);
    elements = metaStore.getElements(namespace, databaseElementType);
    assertEquals(1, elements.size());
    assertNotNull(sharedObjects.getSharedDatabase(databaseMeta.getName()));
}
Also used : IMetaStoreElementType(org.pentaho.metastore.api.IMetaStoreElementType) IMetaStoreElement(org.pentaho.metastore.api.IMetaStoreElement) File(java.io.File) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta)

Example 30 with IMetaStoreElementType

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

the class PurRepositoryIT method testMetaStoreElementTypes.

@Test
public void testMetaStoreElementTypes() throws MetaStoreException {
    IMetaStore metaStore = repository.getMetaStore();
    assertNotNull(metaStore);
    String ns = PentahoDefaults.NAMESPACE;
    // We start with a clean slate...
    // 
    assertEquals(1, metaStore.getNamespaces().size());
    assertEquals(true, metaStore.namespaceExists(ns));
    // Now create an element type
    // 
    IMetaStoreElementType elementType = metaStore.newElementType(ns);
    elementType.setName(PentahoDefaults.KETTLE_DATA_SERVICE_ELEMENT_TYPE_NAME);
    elementType.setDescription(PentahoDefaults.KETTLE_DATA_SERVICE_ELEMENT_TYPE_DESCRIPTION);
    metaStore.createElementType(ns, elementType);
    IMetaStoreElementType verifyElementType = metaStore.getElementType(ns, elementType.getId());
    assertEquals(PentahoDefaults.KETTLE_DATA_SERVICE_ELEMENT_TYPE_NAME, verifyElementType.getName());
    assertEquals(PentahoDefaults.KETTLE_DATA_SERVICE_ELEMENT_TYPE_DESCRIPTION, verifyElementType.getDescription());
    verifyElementType = metaStore.getElementTypeByName(ns, PentahoDefaults.KETTLE_DATA_SERVICE_ELEMENT_TYPE_NAME);
    assertEquals(PentahoDefaults.KETTLE_DATA_SERVICE_ELEMENT_TYPE_NAME, verifyElementType.getName());
    assertEquals(PentahoDefaults.KETTLE_DATA_SERVICE_ELEMENT_TYPE_DESCRIPTION, verifyElementType.getDescription());
    // Get the list of element type ids.
    // 
    List<String> ids = metaStore.getElementTypeIds(ns);
    assertNotNull(ids);
    assertEquals(1, ids.size());
    assertEquals(elementType.getId(), ids.get(0));
    // 
    try {
        metaStore.deleteNamespace(ns);
        fail("The namespace deletion didn't cause an exception because there are still an element type in it");
    } catch (MetaStoreDependenciesExistsException e) {
        assertNotNull(e.getDependencies());
        assertEquals(1, e.getDependencies().size());
        assertEquals(elementType.getId(), e.getDependencies().get(0));
    }
    metaStore.deleteElementType(ns, elementType);
    assertEquals(0, metaStore.getElementTypes(ns).size());
    metaStore.deleteNamespace(ns);
}
Also used : IMetaStoreElementType(org.pentaho.metastore.api.IMetaStoreElementType) Matchers.anyString(org.mockito.Matchers.anyString) IMetaStore(org.pentaho.metastore.api.IMetaStore) MetaStoreDependenciesExistsException(org.pentaho.metastore.api.exceptions.MetaStoreDependenciesExistsException) Test(org.junit.Test)

Aggregations

IMetaStoreElementType (org.pentaho.metastore.api.IMetaStoreElementType)40 IMetaStoreElement (org.pentaho.metastore.api.IMetaStoreElement)19 MetaStoreException (org.pentaho.metastore.api.exceptions.MetaStoreException)12 MetaStoreDependenciesExistsException (org.pentaho.metastore.api.exceptions.MetaStoreDependenciesExistsException)10 ArrayList (java.util.ArrayList)9 Test (org.junit.Test)9 IMetaStore (org.pentaho.metastore.api.IMetaStore)9 MetaStoreElementTypeExistsException (org.pentaho.metastore.api.exceptions.MetaStoreElementTypeExistsException)9 StringObjectId (org.pentaho.di.repository.StringObjectId)7 MetaStoreElementExistException (org.pentaho.metastore.api.exceptions.MetaStoreElementExistException)7 LongObjectId (org.pentaho.di.repository.LongObjectId)6 MetaStoreNamespaceExistsException (org.pentaho.metastore.api.exceptions.MetaStoreNamespaceExistsException)6 Matchers.anyString (org.mockito.Matchers.anyString)4 List (java.util.List)3 ObjectId (org.pentaho.di.repository.ObjectId)3 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)3 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)2 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)2 KettlePluginException (org.pentaho.di.core.exception.KettlePluginException)2 StarDomain (org.pentaho.di.starmodeler.StarDomain)2