Search in sources :

Example 16 with IComponentDescriptor

use of org.pentaho.metaverse.api.IComponentDescriptor in project pentaho-metaverse by pentaho.

the class JobEntryAnalyzer method addConnectionNodes.

/**
 * Adds any used database connections to the metaverse using the appropriate analyzer
 *
 * @throws MetaverseAnalyzerException
 */
protected void addConnectionNodes(IComponentDescriptor descriptor) throws MetaverseAnalyzerException {
    if (jobEntryInterface == null) {
        throw new MetaverseAnalyzerException(Messages.getString("ERROR.JobEntryInterface.IsNull"));
    }
    if (connectionAnalyzer != null) {
        List<? extends Object> connections = connectionAnalyzer.getUsedConnections(jobEntryInterface);
        for (Object connection : connections) {
            String connName = null;
            // see if the connection object has a getName method
            try {
                Method getNameMethod = connection.getClass().getMethod("getName", null);
                connName = (String) getNameMethod.invoke(connection, null);
            } catch (Exception e) {
            // doesn't have a getName method, will try to get it from the descriptor later
            }
            try {
                IComponentDescriptor connDescriptor = connectionAnalyzer.buildComponentDescriptor(descriptor, connection);
                connName = connName == null ? descriptor.getName() : connName;
                IMetaverseNode connNode = connectionAnalyzer.analyze(connDescriptor, connection);
                metaverseBuilder.addLink(connNode, DictionaryConst.LINK_DEPENDENCYOF, rootNode);
            } catch (Throwable t) {
                // Don't throw the exception if a DB connection couldn't be analyzed, just log it and move on
                LOGGER.warn(Messages.getString("WARNING.AnalyzingDatabaseConnection", connName), t);
            }
        }
    }
}
Also used : IComponentDescriptor(org.pentaho.metaverse.api.IComponentDescriptor) MetaverseAnalyzerException(org.pentaho.metaverse.api.MetaverseAnalyzerException) IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) Method(java.lang.reflect.Method) MetaverseAnalyzerException(org.pentaho.metaverse.api.MetaverseAnalyzerException)

Example 17 with IComponentDescriptor

use of org.pentaho.metaverse.api.IComponentDescriptor in project pentaho-metaverse by pentaho.

the class StepAnalyzer method getPrevFieldDescriptor.

/**
 * Create a new IComponentDescriptor for a field input into this step
 *
 * @param prevStepName
 * @param fieldName
 * @return
 */
protected IComponentDescriptor getPrevFieldDescriptor(String prevStepName, String fieldName) {
    IComponentDescriptor prevFieldDescriptor = null;
    if (StringUtils.isNotEmpty(prevStepName)) {
        Object nsObj = rootNode.getProperty(DictionaryConst.PROPERTY_NAMESPACE);
        INamespace ns = new Namespace(nsObj != null ? nsObj.toString() : null);
        IMetaverseNode tmpOriginNode = getMetaverseObjectFactory().createNodeObject(ns, prevStepName, DictionaryConst.NODE_TYPE_TRANS_STEP);
        INamespace stepFieldNamespace = new Namespace(tmpOriginNode.getLogicalId());
        prevFieldDescriptor = new MetaverseComponentDescriptor(fieldName, getInputNodeType(), stepFieldNamespace, getDescriptor().getContext());
    }
    return prevFieldDescriptor;
}
Also used : IComponentDescriptor(org.pentaho.metaverse.api.IComponentDescriptor) INamespace(org.pentaho.metaverse.api.INamespace) IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) INamespace(org.pentaho.metaverse.api.INamespace) Namespace(org.pentaho.metaverse.api.Namespace) MetaverseComponentDescriptor(org.pentaho.metaverse.api.MetaverseComponentDescriptor)

Example 18 with IComponentDescriptor

use of org.pentaho.metaverse.api.IComponentDescriptor in project pentaho-metaverse by pentaho.

the class BaseKettleMetaverseComponentTest method testCreateFileNode.

@Test
public void testCreateFileNode() throws Exception {
    component.createFileNode(null, null);
    assertNull(component.createFileNode("/path/to/my/file", null));
    IMetaverseBuilder metaverseBuilder = mock(IMetaverseBuilder.class);
    when(metaverseBuilder.getMetaverseObjectFactory()).thenReturn(new MetaverseObjectFactory());
    component.setMetaverseBuilder(metaverseBuilder);
    IComponentDescriptor descriptor = mock(IComponentDescriptor.class);
    INamespace ns = mock(INamespace.class);
    when(descriptor.getNamespace()).thenReturn(ns);
    assertNotNull(component.createFileNode("/path/to/my/file", descriptor));
}
Also used : IComponentDescriptor(org.pentaho.metaverse.api.IComponentDescriptor) INamespace(org.pentaho.metaverse.api.INamespace) MetaverseObjectFactory(org.pentaho.metaverse.api.MetaverseObjectFactory) IMetaverseBuilder(org.pentaho.metaverse.api.IMetaverseBuilder) Test(org.junit.Test)

Example 19 with IComponentDescriptor

use of org.pentaho.metaverse.api.IComponentDescriptor in project pentaho-metaverse by pentaho.

the class StepAnalyzerTest method testCreateFieldNode_virtual.

@Test
public void testCreateFieldNode_virtual() throws Exception {
    IComponentDescriptor fieldDescriptor = mock(IComponentDescriptor.class);
    ValueMetaInterface fieldMeta = new ValueMeta("address");
    MetaverseTransientNode node = new MetaverseTransientNode("hello");
    doReturn(node).when(analyzer).createNodeFromDescriptor(fieldDescriptor);
    IMetaverseNode fieldNode = analyzer.createFieldNode(fieldDescriptor, fieldMeta, "nextStep", false);
    assertNotNull(fieldNode);
    assertNotNull(fieldNode.getProperty(DictionaryConst.PROPERTY_KETTLE_TYPE));
    assertEquals("nextStep", fieldNode.getProperty(DictionaryConst.PROPERTY_TARGET_STEP));
    // make sure it did not added to the graph
    verify(builder, never()).addNode(node);
}
Also used : IComponentDescriptor(org.pentaho.metaverse.api.IComponentDescriptor) IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) MetaverseTransientNode(org.pentaho.dictionary.MetaverseTransientNode) ValueMeta(org.pentaho.di.core.row.ValueMeta) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) Test(org.junit.Test)

Example 20 with IComponentDescriptor

use of org.pentaho.metaverse.api.IComponentDescriptor in project pentaho-metaverse by pentaho.

the class StepAnalyzerTest method testCreateFieldNode_NoTargetStep.

@Test
public void testCreateFieldNode_NoTargetStep() throws Exception {
    IComponentDescriptor fieldDescriptor = mock(IComponentDescriptor.class);
    ValueMetaInterface fieldMeta = new ValueMeta("address");
    MetaverseTransientNode node = new MetaverseTransientNode("hello");
    doReturn(node).when(analyzer).createNodeFromDescriptor(fieldDescriptor);
    IMetaverseNode fieldNode = analyzer.createFieldNode(fieldDescriptor, fieldMeta, null, true);
    assertNotNull(fieldNode);
    assertNotNull(fieldNode.getProperty(DictionaryConst.PROPERTY_KETTLE_TYPE));
    assertNull(fieldNode.getProperty(DictionaryConst.PROPERTY_TARGET_STEP));
    // make sure it did not added to the graph
    verify(builder, never()).addNode(node);
}
Also used : IComponentDescriptor(org.pentaho.metaverse.api.IComponentDescriptor) IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) MetaverseTransientNode(org.pentaho.dictionary.MetaverseTransientNode) ValueMeta(org.pentaho.di.core.row.ValueMeta) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) Test(org.junit.Test)

Aggregations

IComponentDescriptor (org.pentaho.metaverse.api.IComponentDescriptor)20 IMetaverseNode (org.pentaho.metaverse.api.IMetaverseNode)15 Test (org.junit.Test)10 MetaverseComponentDescriptor (org.pentaho.metaverse.api.MetaverseComponentDescriptor)9 MetaverseAnalyzerException (org.pentaho.metaverse.api.MetaverseAnalyzerException)8 INamespace (org.pentaho.metaverse.api.INamespace)6 KettleException (org.pentaho.di.core.exception.KettleException)5 KettleXMLException (org.pentaho.di.core.exception.KettleXMLException)5 FileNotFoundException (java.io.FileNotFoundException)4 KettleMissingPluginsException (org.pentaho.di.core.exception.KettleMissingPluginsException)4 KettleStepException (org.pentaho.di.core.exception.KettleStepException)4 JobMeta (org.pentaho.di.job.JobMeta)4 Repository (org.pentaho.di.repository.Repository)4 RepositoryDirectoryInterface (org.pentaho.di.repository.RepositoryDirectoryInterface)4 BaseStepMeta (org.pentaho.di.trans.step.BaseStepMeta)4 ValueMeta (org.pentaho.di.core.row.ValueMeta)3 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)3 TransMeta (org.pentaho.di.trans.TransMeta)3 StepMeta (org.pentaho.di.trans.step.StepMeta)3 MetaverseTransientNode (org.pentaho.dictionary.MetaverseTransientNode)3