Search in sources :

Example 1 with IMetaStoreElementType

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);
    }
}
Also used : MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) IMetaStoreElementType(org.pentaho.metastore.api.IMetaStoreElementType) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) IMetaStoreElement(org.pentaho.metastore.api.IMetaStoreElement) IMetaStore(org.pentaho.metastore.api.IMetaStore)

Example 2 with IMetaStoreElementType

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);
}
Also used : IMetaStoreElementType(org.pentaho.metastore.api.IMetaStoreElementType) Listener(org.eclipse.swt.widgets.Listener) MenuDetectListener(org.eclipse.swt.events.MenuDetectListener) TreeItem(org.eclipse.swt.widgets.TreeItem) Event(org.eclipse.swt.widgets.Event) ShellEvent(org.eclipse.swt.events.ShellEvent) MenuDetectEvent(org.eclipse.swt.events.MenuDetectEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) IMetaStoreElement(org.pentaho.metastore.api.IMetaStoreElement) IMetaStore(org.pentaho.metastore.api.IMetaStore)

Example 3 with IMetaStoreElementType

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);
    }
}
Also used : MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) IMetaStoreElementType(org.pentaho.metastore.api.IMetaStoreElementType) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) ArrayList(java.util.ArrayList) IMetaStoreElement(org.pentaho.metastore.api.IMetaStoreElement) LongObjectId(org.pentaho.di.repository.LongObjectId) StringObjectId(org.pentaho.di.repository.StringObjectId) MetaStoreNamespaceExistsException(org.pentaho.metastore.api.exceptions.MetaStoreNamespaceExistsException) MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) MetaStoreDependenciesExistsException(org.pentaho.metastore.api.exceptions.MetaStoreDependenciesExistsException) MetaStoreElementExistException(org.pentaho.metastore.api.exceptions.MetaStoreElementExistException) MetaStoreElementTypeExistsException(org.pentaho.metastore.api.exceptions.MetaStoreElementTypeExistsException)

Example 4 with IMetaStoreElementType

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);
    }
}
Also used : MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) IMetaStoreElementType(org.pentaho.metastore.api.IMetaStoreElementType) LongObjectId(org.pentaho.di.repository.LongObjectId) ObjectId(org.pentaho.di.repository.ObjectId) StringObjectId(org.pentaho.di.repository.StringObjectId) LongObjectId(org.pentaho.di.repository.LongObjectId) StringObjectId(org.pentaho.di.repository.StringObjectId) MetaStoreNamespaceExistsException(org.pentaho.metastore.api.exceptions.MetaStoreNamespaceExistsException) MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) MetaStoreDependenciesExistsException(org.pentaho.metastore.api.exceptions.MetaStoreDependenciesExistsException) MetaStoreElementExistException(org.pentaho.metastore.api.exceptions.MetaStoreElementExistException) MetaStoreElementTypeExistsException(org.pentaho.metastore.api.exceptions.MetaStoreElementTypeExistsException)

Example 5 with IMetaStoreElementType

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;
}
Also used : IMetaStoreElementType(org.pentaho.metastore.api.IMetaStoreElementType) ArrayList(java.util.ArrayList)

Aggregations

IMetaStoreElementType (org.pentaho.metastore.api.IMetaStoreElementType)40 IMetaStoreElement (org.pentaho.metastore.api.IMetaStoreElement)19 MetaStoreException (org.pentaho.metastore.api.exceptions.MetaStoreException)12 MetaStoreDependenciesExistsException (org.pentaho.metastore.api.exceptions.MetaStoreDependenciesExistsException)10 ArrayList (java.util.ArrayList)9 Test (org.junit.Test)9 IMetaStore (org.pentaho.metastore.api.IMetaStore)9 MetaStoreElementTypeExistsException (org.pentaho.metastore.api.exceptions.MetaStoreElementTypeExistsException)9 StringObjectId (org.pentaho.di.repository.StringObjectId)7 MetaStoreElementExistException (org.pentaho.metastore.api.exceptions.MetaStoreElementExistException)7 LongObjectId (org.pentaho.di.repository.LongObjectId)6 MetaStoreNamespaceExistsException (org.pentaho.metastore.api.exceptions.MetaStoreNamespaceExistsException)6 Matchers.anyString (org.mockito.Matchers.anyString)4 List (java.util.List)3 ObjectId (org.pentaho.di.repository.ObjectId)3 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)3 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)2 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)2 KettlePluginException (org.pentaho.di.core.exception.KettlePluginException)2 StarDomain (org.pentaho.di.starmodeler.StarDomain)2