use of org.pentaho.metastore.api.IMetaStoreElementType 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());
}
use of org.pentaho.metastore.api.IMetaStoreElementType in project pentaho-kettle by pentaho.
the class SharedDimensionMetaStoreUtil method getSharedDimensionElementType.
public static IMetaStoreElementType getSharedDimensionElementType(IMetaStore metaStore) throws MetaStoreException {
verifyNamespaceCreated(metaStore, namespace);
IMetaStoreElementType elementType = metaStore.getElementTypeByName(namespace, METASTORE_SHARED_DIMENSION_TYPE_NAME);
if (elementType == null) {
// create the type
//
elementType = metaStore.newElementType(namespace);
elementType.setName(METASTORE_SHARED_DIMENSION_TYPE_NAME);
elementType.setDescription(METASTORE_SHARED_DIMENSION_TYPE_DESCRIPTION);
metaStore.createElementType(namespace, elementType);
}
return elementType;
}
use of org.pentaho.metastore.api.IMetaStoreElementType in project pentaho-kettle by pentaho.
the class StarDomainMetaStoreUtil method getStarDomainElementType.
public static IMetaStoreElementType getStarDomainElementType(IMetaStore metaStore) throws MetaStoreException {
verifyNamespaceCreated(metaStore, namespace);
IMetaStoreElementType elementType = metaStore.getElementTypeByName(namespace, METASTORE_STAR_DOMAIN_TYPE_NAME);
if (elementType == null) {
// create the type
//
elementType = createStarDomainElementType(metaStore);
}
return elementType;
}
use of org.pentaho.metastore.api.IMetaStoreElementType in project pentaho-kettle by pentaho.
the class StarDomainMetaStoreUtil method saveStarDomain.
public static void saveStarDomain(IMetaStore metaStore, StarDomain starDomain) throws MetaStoreException {
IMetaStoreElementType elementType = getStarDomainElementType(metaStore);
IMetaStoreElement element = null;
if (starDomain.getObjectId() != null) {
// verify the ID!
//
element = metaStore.getElement(namespace, elementType, starDomain.getObjectId().toString());
}
if (element == null) {
// Create a new element
//
element = metaStore.newElement();
populateElementWithStarDomain(metaStore, starDomain, element, elementType);
metaStore.createElement(namespace, elementType, element);
} else {
// Update an existing element
//
populateElementWithStarDomain(metaStore, starDomain, element, elementType);
metaStore.updateElement(namespace, elementType, starDomain.getObjectId().toString(), element);
}
starDomain.setObjectId(new StringObjectId(element.getId().toString()));
}
use of org.pentaho.metastore.api.IMetaStoreElementType in project pentaho-kettle by pentaho.
the class SharedDimensionMetaStoreUtilTest method testGetSharedDimensionElementTypeNew.
@Test
public void testGetSharedDimensionElementTypeNew() throws Exception {
final IMetaStore metaStore = mock(IMetaStore.class);
final IMetaStoreElementType metaStoreElementType = mock(IMetaStoreElementType.class);
when(metaStore.newElementType(anyString())).thenReturn(metaStoreElementType);
final IMetaStoreElementType sharedDimensionElementType = SharedDimensionMetaStoreUtil.getSharedDimensionElementType(metaStore);
verify(metaStore, times(1)).createNamespace(anyString());
assertNotNull(sharedDimensionElementType);
assertEquals(metaStoreElementType, sharedDimensionElementType);
verify(sharedDimensionElementType, times(1)).setName(eq(SharedDimensionMetaStoreUtil.METASTORE_SHARED_DIMENSION_TYPE_NAME));
verify(sharedDimensionElementType, times(1)).setDescription(eq(SharedDimensionMetaStoreUtil.METASTORE_SHARED_DIMENSION_TYPE_DESCRIPTION));
verify(metaStore, times(1)).createElementType(anyString(), eq(sharedDimensionElementType));
}
Aggregations