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());
}
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);
}
}
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());
}
}
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);
}
}
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)));
}
}
Aggregations