use of org.pentaho.metastore.api.IMetaStoreElementType in project pentaho-kettle by pentaho.
the class PurRepositoryMetaStore method getElementType.
@Override
public IMetaStoreElementType getElementType(String namespace, String elementTypeId) throws MetaStoreException {
RepositoryFile elementTypeFolder = pur.getFileById(elementTypeId);
if (elementTypeFolder == null) {
return null;
}
IMetaStoreElementType elementType = newElementType(namespace);
elementType.setId(elementTypeFolder.getId().toString());
elementType.setName(elementTypeFolder.getName());
RepositoryFile detailsFile = findChildByName(elementTypeFolder.getId(), ELEMENT_TYPE_DETAILS_FILENAME, true);
if (detailsFile != null) {
NodeRepositoryFileData data = pur.getDataForRead(detailsFile.getId(), NodeRepositoryFileData.class);
DataProperty property = data.getNode().getProperty("element_type_description");
if (property != null) {
elementType.setDescription(property.getString());
}
}
return elementType;
}
use of org.pentaho.metastore.api.IMetaStoreElementType in project pentaho-kettle by pentaho.
the class AbstractMetaTest method testGetSetImportMetaStore.
@Test(expected = KettlePluginException.class)
public void testGetSetImportMetaStore() throws Exception {
assertNull(meta.getMetaStore());
meta.importFromMetaStore();
IMetaStore metastore = mock(IMetaStore.class);
meta.setMetaStore(metastore);
assertEquals(metastore, meta.getMetaStore());
meta.importFromMetaStore();
IMetaStoreElementType elementType = mock(IMetaStoreElementType.class);
when(metastore.getElementTypeByName(PentahoDefaults.NAMESPACE, PentahoDefaults.DATABASE_CONNECTION_ELEMENT_TYPE_NAME)).thenReturn(elementType);
when(metastore.getElements(PentahoDefaults.NAMESPACE, elementType)).thenReturn(new ArrayList<IMetaStoreElement>());
meta.importFromMetaStore();
IMetaStoreElement element = mock(IMetaStoreElement.class);
when(metastore.getElements(PentahoDefaults.NAMESPACE, elementType)).thenReturn(Arrays.asList(element));
meta.importFromMetaStore();
}
use of org.pentaho.metastore.api.IMetaStoreElementType 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.IMetaStoreElementType in project pentaho-kettle by pentaho.
the class KettleDatabaseRepositoryMetaStore method deleteElement.
@Override
public void deleteElement(String namespace, IMetaStoreElementType elementType, String elementId) throws MetaStoreException {
try {
IMetaStoreElementType type = getElementTypeByName(namespace, elementType.getName());
if (type == null) {
throw new MetaStoreException("Unable to find element type with name '" + elementType.getName() + "'");
}
delegate.deleteElement(new LongObjectId(new StringObjectId(elementId)));
repository.commit();
} catch (Exception e) {
repository.rollback();
throw new MetaStoreException("Unable to delete element with id '" + elementId + "' of type '" + elementType.getName() + "'", e);
}
}
use of org.pentaho.metastore.api.IMetaStoreElementType 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);
}
}
Aggregations