Search in sources :

Example 21 with IMetaStoreElementType

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

the class PurRepositoryMetaStore method getElementType.

@Override
public IMetaStoreElementType getElementType(String namespace, String elementTypeId) throws MetaStoreException {
    RepositoryFile elementTypeFolder = pur.getFileById(elementTypeId);
    if (elementTypeFolder == null) {
        return null;
    }
    IMetaStoreElementType elementType = newElementType(namespace);
    elementType.setId(elementTypeFolder.getId().toString());
    elementType.setName(elementTypeFolder.getName());
    RepositoryFile detailsFile = findChildByName(elementTypeFolder.getId(), ELEMENT_TYPE_DETAILS_FILENAME, true);
    if (detailsFile != null) {
        NodeRepositoryFileData data = pur.getDataForRead(detailsFile.getId(), NodeRepositoryFileData.class);
        DataProperty property = data.getNode().getProperty("element_type_description");
        if (property != null) {
            elementType.setDescription(property.getString());
        }
    }
    return elementType;
}
Also used : IMetaStoreElementType(org.pentaho.metastore.api.IMetaStoreElementType) NodeRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) DataProperty(org.pentaho.platform.api.repository2.unified.data.node.DataProperty)

Example 22 with IMetaStoreElementType

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

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

the class KettleDatabaseRepositoryMetaStore method deleteNamespace.

@Override
public void deleteNamespace(String namespace) throws MetaStoreException, MetaStoreDependenciesExistsException {
    try {
        ObjectId namespaceId = delegate.verifyNamespace(namespace);
        List<IMetaStoreElementType> elementTypes = getElementTypes(namespace);
        if (!elementTypes.isEmpty()) {
            List<String> dependencies = new ArrayList<String>();
            for (IMetaStoreElementType elementType : elementTypes) {
                dependencies.add(elementType.getId());
            }
            throw new MetaStoreDependenciesExistsException(dependencies, "The namespace to delete, '" + namespace + "' is not empty");
        }
        // Now delete the namespace
        // 
        delegate.deleteNamespace(namespaceId);
        repository.commit();
    } catch (MetaStoreDependenciesExistsException e) {
        throw e;
    } catch (MetaStoreException e) {
        repository.rollback();
        throw e;
    } catch (Exception e) {
        repository.rollback();
        throw new MetaStoreException("Unable to delete namespace '" + namespace + "'", e);
    }
}
Also used : MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) IMetaStoreElementType(org.pentaho.metastore.api.IMetaStoreElementType) LongObjectId(org.pentaho.di.repository.LongObjectId) ObjectId(org.pentaho.di.repository.ObjectId) StringObjectId(org.pentaho.di.repository.StringObjectId) ArrayList(java.util.ArrayList) MetaStoreDependenciesExistsException(org.pentaho.metastore.api.exceptions.MetaStoreDependenciesExistsException) 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 24 with IMetaStoreElementType

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

the class KettleDatabaseRepositoryMetaStore method deleteElement.

@Override
public void deleteElement(String namespace, IMetaStoreElementType elementType, String elementId) throws MetaStoreException {
    try {
        IMetaStoreElementType type = getElementTypeByName(namespace, elementType.getName());
        if (type == null) {
            throw new MetaStoreException("Unable to find element type with name '" + elementType.getName() + "'");
        }
        delegate.deleteElement(new LongObjectId(new StringObjectId(elementId)));
        repository.commit();
    } catch (Exception e) {
        repository.rollback();
        throw new MetaStoreException("Unable to delete element with id '" + elementId + "' of type '" + elementType.getName() + "'", e);
    }
}
Also used : MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) IMetaStoreElementType(org.pentaho.metastore.api.IMetaStoreElementType) 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 25 with IMetaStoreElementType

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

the class KettleDatabaseRepositoryMetaStore method createElementType.

// Handle the element types
public void createElementType(String namespace, IMetaStoreElementType elementType) throws MetaStoreException, MetaStoreElementTypeExistsException {
    try {
        ObjectId namespaceId = delegate.verifyNamespace(namespace);
        // See if the element already exists in this namespace
        // 
        IMetaStoreElementType existingType = getElementTypeByName(namespace, elementType.getName());
        if (existingType != null) {
            throw new MetaStoreElementTypeExistsException(Arrays.asList(existingType), "Can not create element type with id '" + elementType.getId() + "' because it already exists");
        }
        KDBRMetaStoreElementType newElementType = new KDBRMetaStoreElementType(delegate, namespace, namespaceId, elementType.getName(), elementType.getDescription());
        newElementType.save();
        elementType.setId(newElementType.getId());
        repository.commit();
    } catch (MetaStoreElementTypeExistsException e) {
        throw e;
    } catch (MetaStoreException e) {
        repository.rollback();
        throw e;
    } catch (Exception e) {
        repository.rollback();
        throw new MetaStoreException(e);
    }
}
Also used : MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) IMetaStoreElementType(org.pentaho.metastore.api.IMetaStoreElementType) LongObjectId(org.pentaho.di.repository.LongObjectId) ObjectId(org.pentaho.di.repository.ObjectId) StringObjectId(org.pentaho.di.repository.StringObjectId) MetaStoreElementTypeExistsException(org.pentaho.metastore.api.exceptions.MetaStoreElementTypeExistsException) 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)

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