use of org.pentaho.metastore.api.exceptions.MetaStoreDependenciesExistsException 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.exceptions.MetaStoreDependenciesExistsException in project pentaho-kettle by pentaho.
the class PurRepositoryMetaStore method deleteNamespace.
@Override
public void deleteNamespace(String namespace) throws MetaStoreException {
RepositoryFile namespaceFile = getNamespaceRepositoryFile(namespace);
if (namespaceFile == null) {
// already gone.
return;
}
List<RepositoryFile> children = getChildren(namespaceFile.getId());
if (children == null || children.isEmpty()) {
// Delete the file, there are no children.
//
pur.deleteFile(namespaceFile.getId(), true, "Delete namespace");
} else {
// Dependencies exists, throw an exception.
//
List<String> elementTypeIds = new ArrayList<String>();
for (RepositoryFile child : children) {
elementTypeIds.add(child.getId().toString());
}
throw new MetaStoreDependenciesExistsException(elementTypeIds, "Namespace '" + namespace + " can not be deleted because it is not empty");
}
}
use of org.pentaho.metastore.api.exceptions.MetaStoreDependenciesExistsException 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