use of org.pentaho.metastore.api.IMetaStoreElement 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.IMetaStoreElement in project pentaho-kettle by pentaho.
the class StarDomainMetaStoreUtilTest method testSaveStarDomain.
@Test
public void testSaveStarDomain() throws Exception {
final StarDomain starDomain = mock(StarDomain.class);
final ObjectId objectId = mock(ObjectId.class);
final String objectIdStr = "objectIdStr";
when(objectId.toString()).thenReturn(objectIdStr);
when(starDomain.getObjectId()).thenReturn(objectId);
final String starDomainName = "starDomainName";
when(starDomain.getName()).thenReturn(starDomainName);
final IMetaStoreElement metaStoreElement = mock(IMetaStoreElement.class);
when(metaStoreElement.getId()).thenReturn("id");
when(metaStore.getElement(anyString(), eq(metaStoreElementType), eq(objectIdStr))).thenReturn(metaStoreElement);
StarDomainMetaStoreUtil.saveStarDomain(metaStore, starDomain);
verify(metaStoreElement, times(1)).setElementType(eq(metaStoreElementType));
verify(metaStoreElement, times(1)).setName(eq(starDomainName));
verify(metaStoreElement, times(1)).addChild(any(IMetaStoreAttribute.class));
verify(metaStore, times(1)).updateElement(anyString(), eq(metaStoreElementType), eq(objectIdStr), eq(metaStoreElement));
verify(starDomain, times(1)).setObjectId(any(ObjectId.class));
}
use of org.pentaho.metastore.api.IMetaStoreElement in project pentaho-kettle by pentaho.
the class PurRepositoryMetaStoreTest method testDataNodeConversion.
@Test
public void testDataNodeConversion() throws Exception {
IMetaStoreElement expected = new MemoryMetaStoreElement();
expected.setName("parent");
expected.addChild(new MemoryMetaStoreAttribute("date", new Date()));
expected.addChild(new MemoryMetaStoreAttribute("long", 32L));
expected.addChild(new MemoryMetaStoreAttribute("double", 3.2));
expected.addChild(new MemoryMetaStoreAttribute("string", "value"));
MemoryMetaStoreAttribute collection = new MemoryMetaStoreAttribute("collection", "collection-value");
for (int i = 0; i < 10; i++) {
collection.addChild(new MemoryMetaStoreAttribute("key-" + i, "value-" + i));
}
expected.addChild(collection);
DataNode dataNode = new DataNode("test");
metaStore.elementToDataNode(expected, dataNode);
IMetaStoreElement verify = new MemoryMetaStoreElement();
metaStore.dataNodeToElement(dataNode, verify);
assertEquals(expected.getName(), verify.getName());
validate(expected, verify);
}
use of org.pentaho.metastore.api.IMetaStoreElement in project pentaho-kettle by pentaho.
the class PurRepositoryMetaStore method getElement.
@Override
public IMetaStoreElement getElement(String namespace, IMetaStoreElementType elementType, String elementId) throws MetaStoreException {
NodeRepositoryFileData data = pur.getDataForRead(elementId, NodeRepositoryFileData.class);
if (data == null) {
return null;
}
IMetaStoreElement element = newElement();
element.setId(elementId);
element.setElementType(elementType);
DataNode dataNode = data.getNode();
dataNodeToElement(dataNode, element);
return element;
}
use of org.pentaho.metastore.api.IMetaStoreElement in project pentaho-kettle by pentaho.
the class KettleMetaStoreTestBase method testFunctionality.
public void testFunctionality(IMetaStore metaStore) throws MetaStoreException {
if (!metaStore.namespaceExists(namespace)) {
metaStore.createNamespace(namespace);
}
List<String> namespaces = metaStore.getNamespaces();
assertEquals(1, namespaces.size());
IMetaStoreElementType elementType = metaStore.newElementType(namespace);
elementType.setName(SHARED_DIMENSION_NAME);
elementType.setDescription(SHARED_DIMENSION_DESCRIPTION);
metaStore.createElementType(namespace, elementType);
assertNotNull(elementType.getId());
List<IMetaStoreElementType> elementTypes = metaStore.getElementTypes(namespace);
assertEquals(1, elementTypes.size());
try {
metaStore.createElementType(namespace, elementType);
fail("Duplicate creation error expected!");
} catch (MetaStoreElementTypeExistsException e) {
// OK!
} catch (MetaStoreException e) {
e.printStackTrace();
fail("Create exception needs to be MetaStoreDataTypesExistException");
}
//
try {
metaStore.deleteNamespace(namespace);
fail("Expected error while deleting namespace with content!");
} catch (MetaStoreDependenciesExistsException e) {
// OK!
List<String> dependencies = e.getDependencies();
assertNotNull(dependencies);
assertEquals(1, dependencies.size());
assertEquals(elementType.getId(), dependencies.get(0));
}
IMetaStoreElement customerDimension = generateCustomerDimensionElement(metaStore, elementType);
IMetaStoreElementOwner elementOwner = customerDimension.getOwner();
assertNotNull(elementOwner);
assertEquals("joe", elementOwner.getName());
assertEquals(MetaStoreElementOwnerType.USER, elementOwner.getOwnerType());
metaStore.createElement(namespace, elementType, customerDimension);
assertNotNull(customerDimension.getId());
List<IMetaStoreElement> elements = metaStore.getElements(namespace, elementType);
assertEquals(1, elements.size());
assertNotNull(elements.get(0));
assertEquals(CUSTOMER_DIMENSION_NAME, elements.get(0).getName());
//
try {
metaStore.deleteElementType(namespace, elementType);
fail("Expected error while deleting data type with content!");
} catch (MetaStoreDependenciesExistsException e) {
// OK!
List<String> dependencies = e.getDependencies();
assertNotNull(dependencies);
assertEquals(1, dependencies.size());
assertEquals(customerDimension.getId(), dependencies.get(0));
}
// Some lookup-by-name tests...
//
assertNotNull(metaStore.getElementTypeByName(namespace, SHARED_DIMENSION_NAME));
assertNotNull(metaStore.getElementByName(namespace, elementType, CUSTOMER_DIMENSION_NAME));
// Clean up shop!
//
metaStore.deleteElement(namespace, elementType, customerDimension.getId());
elements = metaStore.getElements(namespace, elementType);
assertEquals(0, elements.size());
metaStore.deleteElementType(namespace, elementType);
elementTypes = metaStore.getElementTypes(namespace);
assertEquals(0, elementTypes.size());
metaStore.deleteNamespace(namespace);
namespaces = metaStore.getNamespaces();
assertEquals(0, namespaces.size());
}
Aggregations