use of org.pentaho.metastore.api.IMetaStoreElement in project pentaho-kettle by pentaho.
the class PurRepositoryMetaStore method getElements.
@Override
public List<IMetaStoreElement> getElements(String namespace, IMetaStoreElementType elementType) throws MetaStoreException {
List<IMetaStoreElement> elements = new ArrayList<IMetaStoreElement>();
RepositoryFile typeFolder = validateElementTypeRepositoryFolder(namespace, elementType);
List<RepositoryFile> children = getChildren(typeFolder.getId());
removeHiddenFilesFromList(children);
for (RepositoryFile child : children) {
IMetaStoreElement element = getElement(namespace, elementType, child.getId().toString());
elements.add(element);
}
return elements;
}
use of org.pentaho.metastore.api.IMetaStoreElement 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.IMetaStoreElement in project pentaho-kettle by pentaho.
the class DatabaseMetaStoreUtil method populateDatabaseElement.
public static IMetaStoreElement populateDatabaseElement(IMetaStore metaStore, DatabaseMeta databaseMeta) throws MetaStoreException {
if (!metaStore.namespaceExists(PentahoDefaults.NAMESPACE)) {
throw new MetaStoreException("Namespace '" + PentahoDefaults.NAMESPACE + "' doesn't exist.");
}
// If the data type doesn't exist, error out...
//
IMetaStoreElementType elementType = metaStore.getElementTypeByName(PentahoDefaults.NAMESPACE, PentahoDefaults.DATABASE_CONNECTION_ELEMENT_TYPE_NAME);
if (elementType == null) {
throw new MetaStoreException("Unable to find the database connection type");
}
elementType = populateDatabaseElementType(metaStore);
// generate a new database element and populate it with metadata
//
IMetaStoreElement element = metaStore.newElement(elementType, databaseMeta.getName(), null);
element.addChild(metaStore.newAttribute(MetaStoreConst.DB_ATTR_ID_PLUGIN_ID, databaseMeta.getPluginId()));
element.setName(databaseMeta.getName());
element.addChild(metaStore.newAttribute(MetaStoreConst.DB_ATTR_ID_DESCRIPTION, databaseMeta.getDescription()));
element.addChild(metaStore.newAttribute(MetaStoreConst.DB_ATTR_ID_ACCESS_TYPE, databaseMeta.getAccessTypeDesc()));
element.addChild(metaStore.newAttribute(MetaStoreConst.DB_ATTR_ID_HOSTNAME, databaseMeta.getHostname()));
element.addChild(metaStore.newAttribute(MetaStoreConst.DB_ATTR_ID_PORT, databaseMeta.getDatabasePortNumberString()));
element.addChild(metaStore.newAttribute(MetaStoreConst.DB_ATTR_ID_DATABASE_NAME, databaseMeta.getDatabaseName()));
element.addChild(metaStore.newAttribute(MetaStoreConst.DB_ATTR_ID_USERNAME, databaseMeta.getUsername()));
element.addChild(metaStore.newAttribute(MetaStoreConst.DB_ATTR_ID_PASSWORD, metaStore.getTwoWayPasswordEncoder().encode(databaseMeta.getPassword())));
element.addChild(metaStore.newAttribute(MetaStoreConst.DB_ATTR_ID_SERVERNAME, databaseMeta.getServername()));
element.addChild(metaStore.newAttribute(MetaStoreConst.DB_ATTR_ID_DATA_TABLESPACE, databaseMeta.getDataTablespace()));
element.addChild(metaStore.newAttribute(MetaStoreConst.DB_ATTR_ID_INDEX_TABLESPACE, databaseMeta.getIndexTablespace()));
IMetaStoreAttribute attributesChild = metaStore.newAttribute(MetaStoreConst.DB_ATTR_ID_ATTRIBUTES, null);
element.addChild(attributesChild);
// Now add a list of all the attributes set on the database connection...
//
Properties attributes = databaseMeta.getAttributes();
Enumeration<Object> keys = databaseMeta.getAttributes().keys();
while (keys.hasMoreElements()) {
String code = (String) keys.nextElement();
String attribute = (String) attributes.get(code);
// Add it to the attributes child
//
attributesChild.addChild(metaStore.newAttribute(code, attribute));
}
// Extra information for 3rd-party tools:
//
// The driver class
//
element.addChild(metaStore.newAttribute(MetaStoreConst.DB_ATTR_DRIVER_CLASS, databaseMeta.getDriverClass()));
//
try {
element.addChild(metaStore.newAttribute(MetaStoreConst.DB_ATTR_JDBC_URL, databaseMeta.getURL()));
} catch (Exception e) {
throw new MetaStoreException("Unable to assemble URL from database '" + databaseMeta.getName() + "'", e);
}
return element;
}
use of org.pentaho.metastore.api.IMetaStoreElement in project pentaho-kettle by pentaho.
the class DatabaseMetaStoreUtil method getDatabaseElements.
public static List<DatabaseMeta> getDatabaseElements(IMetaStore metaStore) throws MetaStoreException {
List<DatabaseMeta> databases = new ArrayList<DatabaseMeta>();
// If the data type doesn't exist, it's an empty list...
//
IMetaStoreElementType elementType = metaStore.getElementTypeByName(PentahoDefaults.NAMESPACE, PentahoDefaults.DATABASE_CONNECTION_ELEMENT_TYPE_NAME);
if (elementType == null) {
return databases;
}
List<IMetaStoreElement> elements = metaStore.getElements(PentahoDefaults.NAMESPACE, elementType);
for (IMetaStoreElement element : elements) {
try {
DatabaseMeta databaseMeta = loadDatabaseMetaFromDatabaseElement(metaStore, element);
databases.add(databaseMeta);
} catch (Exception e) {
throw new MetaStoreException("Unable to load database from element with name '" + element.getName() + "' and type '" + elementType.getName() + "'", e);
}
}
return databases;
}
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());
}
Aggregations