use of org.pentaho.metastore.api.exceptions.MetaStoreElementTypeExistsException 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.MetaStoreElementTypeExistsException in project pentaho-kettle by pentaho.
the class PurRepositoryMetaStore method createElementType.
// The element types
@Override
public void createElementType(String namespace, IMetaStoreElementType elementType) throws MetaStoreException {
RepositoryFile namespaceFile = validateNamespace(namespace);
IMetaStoreElementType existingType = getElementTypeByName(namespace, elementType.getName());
if (existingType != null) {
throw new MetaStoreElementTypeExistsException(Collections.singletonList(existingType), "Can not create element type with id '" + elementType.getId() + "' because it already exists");
}
RepositoryFile elementTypeFile = new RepositoryFile.Builder(elementType.getName()).folder(true).versioned(false).build();
RepositoryFile folder = pur.createFolder(namespaceFile.getId(), elementTypeFile, null);
elementType.setId(folder.getId().toString());
// In this folder there is a hidden file which contains the description
// and the other future properties of the element type
//
RepositoryFile detailsFile = new RepositoryFile.Builder(ELEMENT_TYPE_DETAILS_FILENAME).folder(false).title(ELEMENT_TYPE_DETAILS_FILENAME).description(elementType.getDescription()).hidden(true).build();
DataNode dataNode = getElementTypeDataNode(elementType);
pur.createFile(folder.getId(), detailsFile, new NodeRepositoryFileData(dataNode), null);
elementType.setMetaStoreName(getName());
}
use of org.pentaho.metastore.api.exceptions.MetaStoreElementTypeExistsException 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);
}
}
use of org.pentaho.metastore.api.exceptions.MetaStoreElementTypeExistsException 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