use of org.pentaho.metastore.api.IMetaStoreElementType in project pentaho-kettle by pentaho.
the class MetaStoreExplorerDialog method removeElement.
private void removeElement(String metaStoreName, String namespace, String elementTypeName, String elementName) {
try {
IMetaStore metaStore = findMetaStore(metaStoreName);
if (metaStore == null) {
throw new MetaStoreException("Unable to find metastore '" + metaStoreName + "'");
}
IMetaStoreElementType elementType = metaStore.getElementTypeByName(namespace, elementTypeName);
if (elementType == null) {
throw new MetaStoreException("Unable to find element type '" + elementTypeName + "' from metastore '" + metaStoreName + "' in namespace '" + namespace + "'");
}
IMetaStoreElement element = metaStore.getElementByName(namespace, elementType, elementName);
if (element == null) {
throw new MetaStoreException("Unable to find element '" + elementName + "' of type '" + elementTypeName + "' from metastore '" + metaStoreName + "' in namespace '" + namespace + "'");
}
metaStore.deleteElement(namespace, elementType, element.getId());
refreshTree();
} catch (MetaStoreException e) {
new ErrorDialog(shell, "Error removing element", "There was an error removing the element '" + elementName + "' of type '" + elementTypeName + "' from metastore '" + metaStoreName + "' in namespace '" + namespace + "'", e);
}
}
use of org.pentaho.metastore.api.IMetaStoreElementType in project pentaho-kettle by pentaho.
the class MetaStoreExplorerDialog method refreshTree.
public void refreshTree() throws MetaStoreException {
tree.removeAll();
//
for (int m = 0; m < metaStoreList.size(); m++) {
IMetaStore metaStore = metaStoreList.get(m);
TreeItem metaStoreItem = new TreeItem(tree, SWT.NONE);
metaStoreItem.setText(0, Const.NVL(metaStore.getName(), "metastore-" + (m + 1)));
metaStoreItem.setText(1, Const.NVL(metaStore.getDescription(), ""));
// level: Namespace
//
List<String> namespaces = metaStore.getNamespaces();
for (String namespace : namespaces) {
TreeItem namespaceItem = new TreeItem(metaStoreItem, SWT.NONE);
namespaceItem.setText(0, Const.NVL(namespace, ""));
// level: element type
//
List<IMetaStoreElementType> elementTypes = metaStore.getElementTypes(namespace);
for (IMetaStoreElementType elementType : elementTypes) {
TreeItem elementTypeItem = new TreeItem(namespaceItem, SWT.NONE);
elementTypeItem.setText(0, Const.NVL(elementType.getName(), ""));
elementTypeItem.setText(1, Const.NVL(elementType.getDescription(), ""));
// level: element
//
List<IMetaStoreElement> elements = metaStore.getElements(namespace, elementType);
for (final IMetaStoreElement element : elements) {
TreeItem elementItem = new TreeItem(elementTypeItem, SWT.NONE);
elementItem.setText(0, Const.NVL(element.getName(), ""));
elementItem.setText(2, Const.NVL(element.getId(), ""));
elementItem.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
log.logBasic("Selected : " + element.getName());
}
});
addAttributesToTree(elementItem, element);
}
}
}
}
TreeUtil.setOptimalWidthOnColumns(tree);
TreeMemory.setExpandedFromMemory(tree, META_STORE_EXPLORER_DIALOG_TREE);
}
use of org.pentaho.metastore.api.IMetaStoreElementType in project pentaho-kettle by pentaho.
the class KettleDatabaseRepositoryMetaStore method getElements.
@Override
public List<IMetaStoreElement> getElements(String namespace, IMetaStoreElementType elementType) throws MetaStoreException {
try {
IMetaStoreElementType type = getElementTypeByName(namespace, elementType.getName());
if (type == null) {
return new ArrayList<IMetaStoreElement>();
}
Collection<RowMetaAndData> elementRows = delegate.getElements(new LongObjectId(new StringObjectId(type.getId())));
List<IMetaStoreElement> elements = new ArrayList<IMetaStoreElement>();
for (RowMetaAndData elementRow : elementRows) {
IMetaStoreElement element = delegate.parseElement(elementType, elementRow);
elements.add(element);
}
return elements;
} catch (Exception e) {
throw new MetaStoreException("Unable to get list of elements from namespace '" + namespace + "' and for element type '" + elementType.getName() + "'", e);
}
}
use of org.pentaho.metastore.api.IMetaStoreElementType in project pentaho-kettle by pentaho.
the class KettleDatabaseRepositoryMetaStore method updateElementType.
@Override
public void updateElementType(String namespace, IMetaStoreElementType elementType) throws MetaStoreException {
try {
ObjectId namespaceId = delegate.verifyNamespace(namespace);
String elementTypeId = elementType.getId();
if (elementTypeId == null) {
IMetaStoreElementType type = getElementTypeByName(namespace, elementType.getName());
if (type != null) {
elementTypeId = type.getId();
}
}
if (elementTypeId != null) {
delegate.updateElementType(namespaceId, new LongObjectId(new StringObjectId(elementType.getId())), elementType);
repository.commit();
} else {
throw new MetaStoreException("Unable to update element type: no id was provided and the name '" + elementType.getName() + "' didn't match");
}
} catch (MetaStoreException e) {
throw e;
} catch (Exception e) {
repository.rollback();
throw new MetaStoreException("Unable to update element type", e);
}
}
use of org.pentaho.metastore.api.IMetaStoreElementType in project pentaho-kettle by pentaho.
the class KettleDatabaseRepositoryMetaStore method getElementTypeIds.
@Override
public List<String> getElementTypeIds(String namespace) throws MetaStoreException {
List<IMetaStoreElementType> elementTypes = getElementTypes(namespace);
ArrayList<String> ids = new ArrayList<String>();
for (IMetaStoreElementType elementType : elementTypes) {
ids.add(elementType.getId());
}
return ids;
}
Aggregations