Search in sources :

Example 6 with IMetaStoreAttribute

use of org.pentaho.metastore.api.IMetaStoreAttribute in project pentaho-kettle by pentaho.

the class StarDomainMetaStoreUtilTest method testGetStarDomainList.

@Test
public void testGetStarDomainList() throws Exception {
    final IMetaStoreElement metaStoreElement = mock(IMetaStoreElement.class);
    final String id = "id";
    when(metaStoreElement.getId()).thenReturn(id);
    final String name = "name";
    when(metaStoreElement.getName()).thenReturn(name);
    final IMetaStoreAttribute metaStoreAttribute = mock(IMetaStoreAttribute.class);
    when(metaStoreElement.getChild(eq(StarDomainMetaStoreUtil.Attribute.ID_STAR_DOMAIN_DESCRIPTION.id))).thenReturn(metaStoreAttribute);
    when(metaStore.getElements(anyString(), eq(metaStoreElementType))).thenReturn(new LinkedList<IMetaStoreElement>() {

        {
            add(metaStoreElement);
        }
    });
    final List<IdNameDescription> starDomainList = StarDomainMetaStoreUtil.getStarDomainList(metaStore);
    assertNotNull(starDomainList);
    assertEquals(1, starDomainList.size());
    final IdNameDescription result = starDomainList.get(0);
    assertEquals(id, result.getId());
    assertEquals(name, result.getName());
}
Also used : IMetaStoreAttribute(org.pentaho.metastore.api.IMetaStoreAttribute) IMetaStoreElement(org.pentaho.metastore.api.IMetaStoreElement) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 7 with IMetaStoreAttribute

use of org.pentaho.metastore.api.IMetaStoreAttribute in project pentaho-kettle by pentaho.

the class PurRepositoryMetaStore method dataNodeToAttribute.

protected void dataNodeToAttribute(DataNode dataNode, IMetaStoreAttribute attribute) throws MetaStoreException {
    for (DataProperty dataProperty : dataNode.getProperties()) {
        Object value;
        switch(dataProperty.getType()) {
            case DATE:
                value = (dataProperty.getDate());
                break;
            case DOUBLE:
                value = (dataProperty.getDouble());
                break;
            case LONG:
                value = (dataProperty.getLong());
                break;
            case STRING:
                value = (dataProperty.getString());
                break;
            default:
                continue;
        }
        // Backwards Compatibility
        if (dataProperty.getName().equals(dataNode.getName())) {
            attribute.setValue(value);
        }
        attribute.addChild(newAttribute(dataProperty.getName(), value));
    }
    for (DataNode subNode : dataNode.getNodes()) {
        IMetaStoreAttribute subAttr = newAttribute(subNode.getName(), null);
        dataNodeToAttribute(subNode, subAttr);
        attribute.addChild(subAttr);
    }
}
Also used : DataNode(org.pentaho.platform.api.repository2.unified.data.node.DataNode) IMetaStoreAttribute(org.pentaho.metastore.api.IMetaStoreAttribute) DataProperty(org.pentaho.platform.api.repository2.unified.data.node.DataProperty)

Example 8 with IMetaStoreAttribute

use of org.pentaho.metastore.api.IMetaStoreAttribute in project pentaho-kettle by pentaho.

the class KettleDatabaseRepositoryMetaStoreDelegate method insertAttributes.

private void insertAttributes(List<IMetaStoreAttribute> children, LongObjectId elementId, LongObjectId parentAttributeId) throws Exception {
    for (IMetaStoreAttribute child : children) {
        LongObjectId attributeId = repository.connectionDelegate.getNextID(quoteTable(KettleDatabaseRepository.TABLE_R_ELEMENT_ATTRIBUTE), quote(KettleDatabaseRepository.FIELD_ELEMENT_ATTRIBUTE_ID_ELEMENT_ATTRIBUTE));
        RowMetaAndData table = new RowMetaAndData();
        table.addValue(new ValueMetaInteger(KettleDatabaseRepository.FIELD_ELEMENT_ATTRIBUTE_ID_ELEMENT_ATTRIBUTE), attributeId.longValue());
        table.addValue(new ValueMetaInteger(KettleDatabaseRepository.FIELD_ELEMENT_ATTRIBUTE_ID_ELEMENT), elementId.longValue());
        table.addValue(new ValueMetaInteger(KettleDatabaseRepository.FIELD_ELEMENT_ATTRIBUTE_ID_ELEMENT_ATTRIBUTE_PARENT), parentAttributeId.longValue());
        table.addValue(new ValueMetaString(KettleDatabaseRepository.FIELD_ELEMENT_ATTRIBUTE_KEY), child.getId());
        table.addValue(new ValueMetaString(KettleDatabaseRepository.FIELD_ELEMENT_ATTRIBUTE_VALUE), encodeAttributeValue(child.getValue()));
        repository.connectionDelegate.getDatabase().prepareInsert(table.getRowMeta(), KettleDatabaseRepository.TABLE_R_ELEMENT_ATTRIBUTE);
        repository.connectionDelegate.getDatabase().setValuesInsert(table);
        repository.connectionDelegate.getDatabase().insertRow();
        repository.connectionDelegate.getDatabase().closeInsert();
        child.setId(attributeId.toString());
    }
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) IMetaStoreAttribute(org.pentaho.metastore.api.IMetaStoreAttribute) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) LongObjectId(org.pentaho.di.repository.LongObjectId)

Example 9 with IMetaStoreAttribute

use of org.pentaho.metastore.api.IMetaStoreAttribute in project pentaho-kettle by pentaho.

the class ModelMetaStoreUtil method populateElement.

private static IMetaStoreElement populateElement(IMetaStore metaStore, LogicalModel model) throws MetaStoreException {
    try {
        IMetaStoreElement element = metaStore.newElement();
        element.setName(model.getName(defaultLocale));
        element.addChild(metaStore.newAttribute(Attribute.ID_MODEL_DESCRIPTION.id, model.getDescription(defaultLocale)));
        IMetaStoreAttribute logicalTablesAttribute = metaStore.newAttribute(Attribute.ID_LOGICAL_TABLES.id, model.getDescription(defaultLocale));
        element.addChild(logicalTablesAttribute);
        for (LogicalTable logicalTable : model.getLogicalTables()) {
            IMetaStoreAttribute logicalTableAttribute = metaStore.newAttribute(Attribute.ID_LOGICAL_TABLE.id, model.getDescription(defaultLocale));
            logicalTablesAttribute.addChild(logicalTableAttribute);
            // 
            // Save the ID as well as the name (for safety)
            // 
            logicalTableAttribute.addChild(metaStore.newAttribute(Attribute.ID_LOGICAL_TABLE_ID.id, logicalTable.getId()));
            logicalTableAttribute.addChild(metaStore.newAttribute(Attribute.ID_LOGICAL_TABLE_NAME.id, logicalTable.getName()));
        }
        return element;
    } catch (Exception e) {
        throw new MetaStoreException("Unable to populate metastore element from logical model", e);
    }
}
Also used : MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) IMetaStoreAttribute(org.pentaho.metastore.api.IMetaStoreAttribute) IMetaStoreElement(org.pentaho.metastore.api.IMetaStoreElement) LogicalTable(org.pentaho.metadata.model.LogicalTable) MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException)

Example 10 with IMetaStoreAttribute

use of org.pentaho.metastore.api.IMetaStoreAttribute in project pentaho-kettle by pentaho.

the class SharedDimensionMetaStoreUtil method populateElementWithSharedDimension.

private static void populateElementWithSharedDimension(IMetaStore metaStore, LogicalTable sharedDimension, String locale, IMetaStoreElementType elementType, IMetaStoreElement element) throws MetaStoreException {
    element.setElementType(elementType);
    element.setName(sharedDimension.getName(locale));
    element.addChild(metaStore.newAttribute(Attribute.ID_SHARED_DIMENSION_DESCRIPTION.id, sharedDimension.getDescription(locale)));
    IMetaStoreAttribute columnsAttribute = metaStore.newAttribute(Attribute.ID_SHARED_DIMENSION_COLUMNS.id, null);
    element.addChild(columnsAttribute);
    for (LogicalColumn column : sharedDimension.getLogicalColumns()) {
        IMetaStoreAttribute columnAttribute = metaStore.newAttribute(Attribute.ID_SHARED_DIMENSION_COLUMN.id, null);
        columnsAttribute.addChild(columnAttribute);
        columnAttribute.addChild(metaStore.newAttribute(Attribute.ID_SHARED_DIMENSION_COLUMN_NAME.id, column.getName(locale)));
        columnAttribute.addChild(metaStore.newAttribute(Attribute.ID_SHARED_DIMENSION_COLUMN_DESCRIPTION.id, column.getDescription(locale)));
    }
}
Also used : LogicalColumn(org.pentaho.metadata.model.LogicalColumn) IMetaStoreAttribute(org.pentaho.metastore.api.IMetaStoreAttribute)

Aggregations

IMetaStoreAttribute (org.pentaho.metastore.api.IMetaStoreAttribute)13 IMetaStoreElement (org.pentaho.metastore.api.IMetaStoreElement)6 Properties (java.util.Properties)2 KettlePluginException (org.pentaho.di.core.exception.KettlePluginException)2 MetaStoreException (org.pentaho.metastore.api.exceptions.MetaStoreException)2 IMetaStoreElementOwner (org.pentaho.metastore.api.security.IMetaStoreElementOwner)2 MetaStoreOwnerPermissions (org.pentaho.metastore.api.security.MetaStoreOwnerPermissions)2 DataNode (org.pentaho.platform.api.repository2.unified.data.node.DataNode)2 Date (java.util.Date)1 TreeItem (org.eclipse.swt.widgets.TreeItem)1 Test (org.junit.Test)1 Matchers.anyString (org.mockito.Matchers.anyString)1 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)1 DatabaseInterface (org.pentaho.di.core.database.DatabaseInterface)1 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)1 PluginInterface (org.pentaho.di.core.plugins.PluginInterface)1 PluginRegistry (org.pentaho.di.core.plugins.PluginRegistry)1 ValueMetaInteger (org.pentaho.di.core.row.value.ValueMetaInteger)1 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)1 LongObjectId (org.pentaho.di.repository.LongObjectId)1