use of org.pentaho.metaverse.api.model.BaseDatabaseResourceInfo in project pentaho-metaverse by pentaho.
the class TableOutputStepAnalyzer method createTableNode.
@Override
protected IMetaverseNode createTableNode(IExternalResourceInfo resource) throws MetaverseAnalyzerException {
BaseDatabaseResourceInfo resourceInfo = (BaseDatabaseResourceInfo) resource;
Object obj = resourceInfo.getAttributes().get(DictionaryConst.PROPERTY_TABLE);
String tableName = obj == null ? null : obj.toString();
obj = resourceInfo.getAttributes().get(DictionaryConst.PROPERTY_SCHEMA);
String schema = obj == null ? null : obj.toString();
// create a node for the table
MetaverseComponentDescriptor componentDescriptor = new MetaverseComponentDescriptor(tableName, DictionaryConst.NODE_TYPE_DATA_TABLE, getConnectionNode(), getDescriptor().getContext());
// set the namespace to be the id of the connection node.
IMetaverseNode tableNode = createNodeFromDescriptor(componentDescriptor);
tableNode.setProperty(DictionaryConst.PROPERTY_NAMESPACE, componentDescriptor.getNamespace().getNamespaceId());
tableNode.setProperty(DictionaryConst.PROPERTY_TABLE, tableName);
tableNode.setProperty(DictionaryConst.PROPERTY_SCHEMA, schema);
tableNode.setLogicalIdGenerator(DictionaryConst.LOGICAL_ID_GENERATOR_DB_TABLE);
return tableNode;
}
use of org.pentaho.metaverse.api.model.BaseDatabaseResourceInfo in project pentaho-metaverse by pentaho.
the class TableInputStepAnalyzer method createTableNode.
@Override
protected IMetaverseNode createTableNode(IExternalResourceInfo resource) throws MetaverseAnalyzerException {
BaseDatabaseResourceInfo resourceInfo = (BaseDatabaseResourceInfo) resource;
Object obj = resourceInfo.getAttributes().get(DictionaryConst.PROPERTY_QUERY);
String query = obj == null ? null : obj.toString();
// create a node for the table
MetaverseComponentDescriptor componentDescriptor = new MetaverseComponentDescriptor("SQL", DictionaryConst.NODE_TYPE_SQL_QUERY, getConnectionNode(), getDescriptor().getContext());
// set the namespace to be the id of the connection node.
IMetaverseNode tableNode = createNodeFromDescriptor(componentDescriptor);
tableNode.setProperty(DictionaryConst.PROPERTY_NAMESPACE, componentDescriptor.getNamespace().getNamespaceId());
tableNode.setProperty(DictionaryConst.PROPERTY_QUERY, query);
tableNode.setLogicalIdGenerator(DictionaryConst.LOGICAL_ID_GENERATOR_DB_QUERY);
return tableNode;
}
use of org.pentaho.metaverse.api.model.BaseDatabaseResourceInfo in project pentaho-metaverse by pentaho.
the class TableInputStepAnalyzerTest method testCreateTableNode.
@Test
public void testCreateTableNode() throws Exception {
BaseDatabaseResourceInfo resourceInfo = mock(BaseDatabaseResourceInfo.class);
Map<Object, Object> attributes = new HashMap<>();
attributes.put(DictionaryConst.PROPERTY_QUERY, "select * from mytable");
when(resourceInfo.getAttributes()).thenReturn(attributes);
IMetaverseNode connectionNode = mock(IMetaverseNode.class);
doReturn(connectionNode).when(analyzer).getConnectionNode();
when(connectionNode.getLogicalId()).thenReturn("CONNECTION_ID");
IMetaverseNode resourceNode = analyzer.createTableNode(resourceInfo);
assertEquals("select * from mytable", resourceNode.getProperty(DictionaryConst.PROPERTY_QUERY));
assertEquals("SQL", resourceNode.getName());
assertEquals("CONNECTION_ID", resourceNode.getProperty(DictionaryConst.PROPERTY_NAMESPACE));
}
use of org.pentaho.metaverse.api.model.BaseDatabaseResourceInfo in project pentaho-metaverse by pentaho.
the class TableOutputStepAnalyzerTest method testCreateTableNode_nullTable.
@Test
public void testCreateTableNode_nullTable() throws Exception {
IConnectionAnalyzer connectionAnalyzer = mock(IConnectionAnalyzer.class);
doReturn(connectionAnalyzer).when(analyzer).getConnectionAnalyzer();
IMetaverseNode connNode = mock(IMetaverseNode.class);
when(connectionAnalyzer.analyze(any(IComponentDescriptor.class), anyObject())).thenReturn(connNode);
BaseDatabaseResourceInfo resourceInfo = mock(BaseDatabaseResourceInfo.class);
Map<Object, Object> attributes = new HashMap<>();
when(resourceInfo.getAttributes()).thenReturn(attributes);
IMetaverseNode connectionNode = mock(IMetaverseNode.class);
doReturn(connectionNode).when(analyzer).getConnectionNode();
when(connectionNode.getLogicalId()).thenReturn("CONNECTION_ID");
IMetaverseNode resourceNode = analyzer.createTableNode(resourceInfo);
assertNull(resourceNode.getProperty(DictionaryConst.PROPERTY_TABLE));
assertNull(resourceNode.getProperty(DictionaryConst.PROPERTY_SCHEMA));
assertEquals("CONNECTION_ID", resourceNode.getProperty(DictionaryConst.PROPERTY_NAMESPACE));
}
use of org.pentaho.metaverse.api.model.BaseDatabaseResourceInfo in project pentaho-metaverse by pentaho.
the class TableOutputStepAnalyzerTest method testCreateTableNode.
@Test
public void testCreateTableNode() throws Exception {
IConnectionAnalyzer connectionAnalyzer = mock(IConnectionAnalyzer.class);
doReturn(connectionAnalyzer).when(analyzer).getConnectionAnalyzer();
IMetaverseNode connNode = mock(IMetaverseNode.class);
when(connectionAnalyzer.analyze(any(IComponentDescriptor.class), anyObject())).thenReturn(connNode);
BaseDatabaseResourceInfo resourceInfo = mock(BaseDatabaseResourceInfo.class);
Map<Object, Object> attributes = new HashMap<>();
attributes.put(DictionaryConst.PROPERTY_TABLE, "tableName");
attributes.put(DictionaryConst.PROPERTY_SCHEMA, "schemaName");
when(resourceInfo.getAttributes()).thenReturn(attributes);
IMetaverseNode connectionNode = mock(IMetaverseNode.class);
doReturn(connectionNode).when(analyzer).getConnectionNode();
when(connectionNode.getLogicalId()).thenReturn("CONNECTION_ID");
IMetaverseNode resourceNode = analyzer.createTableNode(resourceInfo);
assertEquals("tableName", resourceNode.getProperty(DictionaryConst.PROPERTY_TABLE));
assertEquals("tableName", resourceNode.getName());
assertEquals("schemaName", resourceNode.getProperty(DictionaryConst.PROPERTY_SCHEMA));
assertEquals("CONNECTION_ID", resourceNode.getProperty(DictionaryConst.PROPERTY_NAMESPACE));
}
Aggregations