use of org.pentaho.metastore.api.exceptions.MetaStoreDependenciesExistsException in project pentaho-kettle by pentaho.
the class MetaStoreTestBase 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());
}
use of org.pentaho.metastore.api.exceptions.MetaStoreDependenciesExistsException in project pentaho-kettle by pentaho.
the class PurRepositoryMetaStore method deleteElementType.
@Override
public void deleteElementType(String namespace, IMetaStoreElementType elementType) throws MetaStoreException {
RepositoryFile namespaceRepositoryFile = validateNamespace(namespace);
RepositoryFile elementTypeFile = findChildByName(namespaceRepositoryFile.getId(), elementType.getName());
List<RepositoryFile> children = getChildren(elementTypeFile.getId());
removeHiddenFilesFromList(children);
if (children.isEmpty()) {
pur.deleteFile(elementTypeFile.getId(), true, null);
} else {
List<String> ids = getElementIds(namespace, elementType);
throw new MetaStoreDependenciesExistsException(ids, "Can't delete element type with name '" + elementType.getName() + "' because it is not empty");
}
}
use of org.pentaho.metastore.api.exceptions.MetaStoreDependenciesExistsException 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);
}
}
use of org.pentaho.metastore.api.exceptions.MetaStoreDependenciesExistsException in project pentaho-kettle by pentaho.
the class KettleDatabaseRepositoryMetaStore method deleteElementType.
@Override
public void deleteElementType(String namespace, IMetaStoreElementType elementType) throws MetaStoreException, MetaStoreDependenciesExistsException {
try {
Collection<RowMetaAndData> elementTypeRows = delegate.getElements(new LongObjectId(new StringObjectId(elementType.getId())));
if (!elementTypeRows.isEmpty()) {
List<String> dependencies = new ArrayList<String>();
for (RowMetaAndData elementTypeRow : elementTypeRows) {
Long elementTypeId = elementTypeRow.getInteger(KettleDatabaseRepository.FIELD_ELEMENT_TYPE_ID_ELEMENT_TYPE);
dependencies.add(Long.toString(elementTypeId));
}
throw new MetaStoreDependenciesExistsException(dependencies, "The namespace to delete, '" + namespace + "' is not empty");
}
delegate.deleteElementType(new LongObjectId(new StringObjectId(elementType.getId())));
repository.commit();
} catch (MetaStoreDependenciesExistsException e) {
throw e;
} catch (Exception e) {
repository.rollback();
throw new MetaStoreException(e);
}
}
use of org.pentaho.metastore.api.exceptions.MetaStoreDependenciesExistsException in project pentaho-kettle by pentaho.
the class PurRepositoryIT method testMetaStoreElementTypes.
@Test
public void testMetaStoreElementTypes() throws MetaStoreException {
IMetaStore metaStore = repository.getMetaStore();
assertNotNull(metaStore);
String ns = PentahoDefaults.NAMESPACE;
// We start with a clean slate...
//
assertEquals(1, metaStore.getNamespaces().size());
assertEquals(true, metaStore.namespaceExists(ns));
// Now create 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);
IMetaStoreElementType verifyElementType = metaStore.getElementType(ns, elementType.getId());
assertEquals(PentahoDefaults.KETTLE_DATA_SERVICE_ELEMENT_TYPE_NAME, verifyElementType.getName());
assertEquals(PentahoDefaults.KETTLE_DATA_SERVICE_ELEMENT_TYPE_DESCRIPTION, verifyElementType.getDescription());
verifyElementType = metaStore.getElementTypeByName(ns, PentahoDefaults.KETTLE_DATA_SERVICE_ELEMENT_TYPE_NAME);
assertEquals(PentahoDefaults.KETTLE_DATA_SERVICE_ELEMENT_TYPE_NAME, verifyElementType.getName());
assertEquals(PentahoDefaults.KETTLE_DATA_SERVICE_ELEMENT_TYPE_DESCRIPTION, verifyElementType.getDescription());
// Get the list of element type ids.
//
List<String> ids = metaStore.getElementTypeIds(ns);
assertNotNull(ids);
assertEquals(1, ids.size());
assertEquals(elementType.getId(), ids.get(0));
//
try {
metaStore.deleteNamespace(ns);
fail("The namespace deletion didn't cause an exception because there are still an element type in it");
} catch (MetaStoreDependenciesExistsException e) {
assertNotNull(e.getDependencies());
assertEquals(1, e.getDependencies().size());
assertEquals(elementType.getId(), e.getDependencies().get(0));
}
metaStore.deleteElementType(ns, elementType);
assertEquals(0, metaStore.getElementTypes(ns).size());
metaStore.deleteNamespace(ns);
}
Aggregations