use of org.pentaho.metastore.api.exceptions.MetaStoreException 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.MetaStoreException in project pentaho-kettle by pentaho.
the class PurRepositoryMetaStore method updateElement.
@Override
public synchronized void updateElement(String namespace, IMetaStoreElementType elementType, String elementId, IMetaStoreElement element) throws MetaStoreException {
//
if (elementType.getMetaStoreName() == null || !elementType.getName().equals(getName())) {
String elementTypeName = elementType.getName();
elementType = getElementTypeByName(namespace, elementTypeName);
if (elementType == null) {
throw new MetaStoreException("The element type '" + elementTypeName + "' could not be found in the meta store in which you are updating.");
}
}
RepositoryFile existingFile = pur.getFileById(elementId);
if (existingFile == null) {
throw new MetaStoreException("The element to update with id " + elementId + " could not be found in the store");
}
DataNode elementDataNode = new DataNode(PurRepository.checkAndSanitize(element.getName()));
elementToDataNode(element, elementDataNode);
RepositoryFile updatedFile = pur.updateFile(existingFile, new NodeRepositoryFileData(elementDataNode), null);
element.setId(updatedFile.getId().toString());
}
use of org.pentaho.metastore.api.exceptions.MetaStoreException in project pdi-dataservice-server-plugin by pentaho.
the class DataServiceMetaStoreUtil method getDataServiceByStepName.
public DataServiceMeta getDataServiceByStepName(TransMeta transMeta, String stepName) {
Set<Integer> cacheKeys = createCacheKeys(transMeta, stepName);
for (Map.Entry<Integer, String> entry : stepCache.getAll(cacheKeys).entrySet()) {
String serviceName = entry.getValue();
if (serviceName.isEmpty()) {
// Step is marked as not having a Data Service
return null;
}
// Check if Data Service is still valid
DataServiceMeta dataServiceMeta;
try {
dataServiceMeta = getDataService(serviceName, transMeta);
} catch (MetaStoreException e) {
dataServiceMeta = null;
}
if (dataServiceMeta != null && dataServiceMeta.getStepname().equals(stepName)) {
return dataServiceMeta;
} else {
stepCache.remove(entry.getKey(), serviceName);
}
}
// Look up from embedded metastore
for (DataServiceMeta dataServiceMeta : getDataServices(transMeta)) {
if (dataServiceMeta.getStepname().equalsIgnoreCase(stepName)) {
return dataServiceMeta;
}
}
// Data service not found on step, store negative result in the cache
stepCache.putAll(Maps.asMap(cacheKeys, Functions.constant("")));
return null;
}
use of org.pentaho.metastore.api.exceptions.MetaStoreException in project pdi-dataservice-server-plugin by pentaho.
the class DataServiceMetaStoreUtil method removeDataService.
public void removeDataService(DataServiceMeta dataService) {
TransMeta transMeta = dataService.getServiceTrans();
try {
deleteDataServiceElementAndCleanCache(dataService, transMeta);
transMeta.setChanged();
} catch (MetaStoreException e) {
getLogChannel().logBasic(e.getMessage());
}
}
use of org.pentaho.metastore.api.exceptions.MetaStoreException in project pdi-dataservice-server-plugin by pentaho.
the class DataServiceDelegate method suggestEdit.
public void suggestEdit(DataServiceMeta dataServiceMeta, String title, String text) {
TransMeta serviceTrans = dataServiceMeta.getServiceTrans();
if (!serviceTrans.hasChanged()) {
if (showPrompt(title, text)) {
editDataService(dataServiceMeta);
serviceTrans.setChanged();
} else {
// can not exist duplicate, delete dataService and save transformation (PDI-15584)
try {
deleteDataServiceElementAndCleanCache(dataServiceMeta, serviceTrans);
serviceTrans.setChanged();
} catch (MetaStoreException e) {
getLogChannel().logBasic(e.getMessage());
}
}
}
}
Aggregations