use of org.pentaho.metastore.api.IMetaStoreElement in project pentaho-kettle by pentaho.
the class StarDomainMetaStoreUtilTest method testLoadStarDomain.
@Test
public void testLoadStarDomain() throws Exception {
final String id = "id";
final String msName = "MSName";
when(metaStore.getName()).thenReturn(msName);
final DelegatingMetaStore delegatingMetaStore = spy(new DelegatingMetaStore(metaStore));
delegatingMetaStore.setActiveMetaStoreName(msName);
doAnswer(new Answer<IMetaStoreElementType>() {
@Override
public IMetaStoreElementType answer(InvocationOnMock invocationOnMock) throws Throwable {
return metaStore.getElementTypeByName((String) invocationOnMock.getArguments()[0], (String) invocationOnMock.getArguments()[1]);
}
}).when(delegatingMetaStore).getElementTypeByName(anyString(), anyString());
assertNull(StarDomainMetaStoreUtil.loadStarDomain(delegatingMetaStore, id));
final IMetaStoreElement metaStoreElement = mock(IMetaStoreElement.class);
final String name = "name";
when(metaStoreElement.getName()).thenReturn(name);
doReturn(metaStoreElement).when(delegatingMetaStore).getElement(anyString(), eq(metaStoreElementType), eq(id));
final StarDomain starDomain = StarDomainMetaStoreUtil.loadStarDomain(delegatingMetaStore, id);
assertEquals(id, starDomain.getObjectId().getId());
assertEquals(name, starDomain.getName());
}
use of org.pentaho.metastore.api.IMetaStoreElement in project pentaho-kettle by pentaho.
the class StarModelerPerspective method testMetaStore.
protected void testMetaStore() {
try {
// Force repository meta store
IMetaStore metaStore = Spoon.getInstance().getRepository().getMetaStore();
LogChannel.GENERAL.logBasic("Active metastore: " + metaStore.getName());
StarDomainMetaStoreUtil.verifyNamespaceCreated(metaStore, "pentaho");
IMetaStoreElementType elementType = StarDomainMetaStoreUtil.getStarDomainElementType(metaStore);
if (elementType == null) {
throw new KettleException("Unable to find star domain element type");
}
LogChannel.GENERAL.logBasic("Found star domain element type: " + elementType.getName() + " : " + elementType.getDescription());
elementType = metaStore.getElementTypeByName(PentahoDefaults.NAMESPACE, elementType.getName());
if (elementType == null) {
throw new KettleException("Unable to find star domain element type by name");
}
LogChannel.GENERAL.logBasic("Found element type by name");
List<IdNameDescription> list = new ArrayList<IdNameDescription>();
for (IMetaStoreElement element : metaStore.getElements(PentahoDefaults.NAMESPACE, elementType)) {
IdNameDescription nameDescription = new IdNameDescription(element.getId(), element.getName(), null);
list.add(nameDescription);
}
LogChannel.GENERAL.logBasic("Found " + list.size() + " star domain elements.");
StarDomainMetaStoreUtil.getStarDomainList(metaStore);
} catch (Exception e) {
new ErrorDialog(Spoon.getInstance().getShell(), "ERROR", "Error testing meta store: ", e);
}
}
use of org.pentaho.metastore.api.IMetaStoreElement in project pentaho-kettle by pentaho.
the class ModelMetaStoreUtil method saveLogicalModel.
public static IMetaStoreElement saveLogicalModel(IMetaStore metaStore, LogicalModel model) throws MetaStoreException {
IMetaStoreElementType elementType = getLogicalModelElementType(metaStore);
IMetaStoreElement oldElement = metaStore.getElementByName(PentahoDefaults.NAMESPACE, elementType, model.getName(defaultLocale));
if (oldElement == null) {
// populate and create...
//
IMetaStoreElement newElement = populateElement(metaStore, model);
metaStore.createElement(PentahoDefaults.NAMESPACE, elementType, newElement);
return newElement;
} else {
// The element exists, update...
//
IMetaStoreElement newElement = populateElement(metaStore, model);
metaStore.updateElement(PentahoDefaults.NAMESPACE, elementType, oldElement.getId(), newElement);
return newElement;
}
}
use of org.pentaho.metastore.api.IMetaStoreElement in project pentaho-kettle by pentaho.
the class SharedDimensionMetaStoreUtil method saveSharedDimension.
public static void saveSharedDimension(IMetaStore metaStore, LogicalTable sharedDimension, String locale) throws MetaStoreException {
IMetaStoreElementType elementType = getSharedDimensionElementType(metaStore);
IMetaStoreElement element = null;
if (sharedDimension.getId() != null) {
element = metaStore.getElement(namespace, elementType, sharedDimension.getId());
}
if (element != null) {
// Update the shared dimension!
//
populateElementWithSharedDimension(metaStore, sharedDimension, locale, elementType, element);
metaStore.updateElement(namespace, elementType, sharedDimension.getId(), element);
} else {
// New shared dimension
//
element = metaStore.newElement();
populateElementWithSharedDimension(metaStore, sharedDimension, locale, elementType, element);
metaStore.createElement(namespace, elementType, element);
}
sharedDimension.setId(element.getId());
}
use of org.pentaho.metastore.api.IMetaStoreElement in project pentaho-kettle by pentaho.
the class StarDomainMetaStoreUtil method loadStarDomain.
public static StarDomain loadStarDomain(DelegatingMetaStore metaStore, String id) throws MetaStoreException {
IMetaStoreElementType elementType = getStarDomainElementType(metaStore);
IMetaStoreElement element = metaStore.getElement(namespace, elementType, id);
if (element == null) {
return null;
}
StarDomain starDomain = new StarDomain();
starDomain.setObjectId(new StringObjectId(id));
starDomain.setName(element.getName());
starDomain.setDescription(getChildString(element, Attribute.ID_STAR_DOMAIN_DESCRIPTION.id));
return starDomain;
}
Aggregations