Search in sources :

Example 21 with IMetaStoreElement

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

the class SharedObjectsMetaStore method createElement.

@Override
public void createElement(String namespace, IMetaStoreElementType elementType, IMetaStoreElement element) throws MetaStoreException, MetaStoreElementExistException {
    try {
        IMetaStoreElement exists = getElementByName(namespace, elementType, element.getId());
        if (exists != null) {
            throw new MetaStoreException("The shared objects meta store already contains an element with type name '" + elementType.getName() + "' and element name '" + element.getName());
        }
        if (elementType.getName().equals(databaseElementType.getName())) {
            // convert the element to DatabaseMeta and store it in the shared objects file, then save the file
            // 
            sharedObjects.storeObject(DatabaseMetaStoreUtil.loadDatabaseMetaFromDatabaseElement(this, element));
            sharedObjects.saveToFile();
            return;
        }
        throw new MetaStoreException("Storing elements with element type name '" + elementType.getName() + "' is not supported in the shared objects meta store");
    } catch (Exception e) {
        throw new MetaStoreException("Unexpected error creating an element in the shared objects meta store", e);
    }
}
Also used : MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) 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 22 with IMetaStoreElement

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

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

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

the class PurRepositoryIT method testMetaStoreElements.

@Test
public void testMetaStoreElements() throws MetaStoreException {
    // Set up a namespace
    // 
    String ns = PentahoDefaults.NAMESPACE;
    IMetaStore metaStore = repository.getMetaStore();
    if (!metaStore.namespaceExists(ns)) {
        metaStore.createNamespace(ns);
    }
    // And 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);
    // Now we play with elements...
    // 
    IMetaStoreElement oneElement = populateElement(metaStore, elementType, "Element One");
    metaStore.createElement(ns, elementType, oneElement);
    IMetaStoreElement verifyOneElement = metaStore.getElement(ns, elementType, oneElement.getId());
    assertNotNull(verifyOneElement);
    validateElement(verifyOneElement, "Element One");
    assertEquals(1, metaStore.getElements(ns, elementType).size());
    IMetaStoreElement twoElement = populateElement(metaStore, elementType, "Element Two");
    metaStore.createElement(ns, elementType, twoElement);
    IMetaStoreElement verifyTwoElement = metaStore.getElement(ns, elementType, twoElement.getId());
    assertNotNull(verifyTwoElement);
    assertEquals(2, metaStore.getElements(ns, elementType).size());
    try {
        metaStore.deleteElementType(ns, elementType);
        fail("Delete element type failed to properly detect element dependencies");
    } catch (MetaStoreDependenciesExistsException e) {
        List<String> ids = e.getDependencies();
        assertEquals(2, ids.size());
        assertTrue(ids.contains(oneElement.getId()));
        assertTrue(ids.contains(twoElement.getId()));
    }
    metaStore.deleteElement(ns, elementType, oneElement.getId());
    assertEquals(1, metaStore.getElements(ns, elementType).size());
    metaStore.deleteElement(ns, elementType, twoElement.getId());
    assertEquals(0, metaStore.getElements(ns, elementType).size());
}
Also used : IMetaStoreElementType(org.pentaho.metastore.api.IMetaStoreElementType) IMetaStoreElement(org.pentaho.metastore.api.IMetaStoreElement) ArrayList(java.util.ArrayList) AbstractList(java.util.AbstractList) List(java.util.List) Matchers.anyString(org.mockito.Matchers.anyString) IMetaStore(org.pentaho.metastore.api.IMetaStore) MetaStoreDependenciesExistsException(org.pentaho.metastore.api.exceptions.MetaStoreDependenciesExistsException) Test(org.junit.Test)

Example 25 with IMetaStoreElement

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

the class ModelMetaStoreUtil method populateElement.

private static IMetaStoreElement populateElement(IMetaStore metaStore, LogicalModel model) throws MetaStoreException {
    try {
        IMetaStoreElement element = metaStore.newElement();
        element.setName(model.getName(defaultLocale));
        element.addChild(metaStore.newAttribute(Attribute.ID_MODEL_DESCRIPTION.id, model.getDescription(defaultLocale)));
        IMetaStoreAttribute logicalTablesAttribute = metaStore.newAttribute(Attribute.ID_LOGICAL_TABLES.id, model.getDescription(defaultLocale));
        element.addChild(logicalTablesAttribute);
        for (LogicalTable logicalTable : model.getLogicalTables()) {
            IMetaStoreAttribute logicalTableAttribute = metaStore.newAttribute(Attribute.ID_LOGICAL_TABLE.id, model.getDescription(defaultLocale));
            logicalTablesAttribute.addChild(logicalTableAttribute);
            // 
            // Save the ID as well as the name (for safety)
            // 
            logicalTableAttribute.addChild(metaStore.newAttribute(Attribute.ID_LOGICAL_TABLE_ID.id, logicalTable.getId()));
            logicalTableAttribute.addChild(metaStore.newAttribute(Attribute.ID_LOGICAL_TABLE_NAME.id, logicalTable.getName()));
        }
        return element;
    } catch (Exception e) {
        throw new MetaStoreException("Unable to populate metastore element from logical model", e);
    }
}
Also used : MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) IMetaStoreAttribute(org.pentaho.metastore.api.IMetaStoreAttribute) IMetaStoreElement(org.pentaho.metastore.api.IMetaStoreElement) LogicalTable(org.pentaho.metadata.model.LogicalTable) MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException)

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