Search in sources :

Example 56 with IExternalResourceInfo

use of org.pentaho.metaverse.api.model.IExternalResourceInfo in project pentaho-metaverse by pentaho.

the class KettleAnalyzerUtil method getResourcesFromMeta.

public static Collection<IExternalResourceInfo> getResourcesFromMeta(final BaseFileInputMeta meta, final IAnalysisContext context) {
    Collection<IExternalResourceInfo> resources = Collections.emptyList();
    final StepMeta parentStepMeta = meta.getParentStepMeta();
    if (parentStepMeta != null) {
        final TransMeta parentTransMeta = parentStepMeta.getParentTransMeta();
        if (parentTransMeta != null) {
            final FileInputList inputList = meta.getFileInputList(parentTransMeta);
            if (inputList != null) {
                final String[] paths = inputList.getFileStrings();
                if (paths != null) {
                    resources = new ArrayList<>(paths.length);
                    for (final String path : paths) {
                        if (!Const.isEmpty(path)) {
                            try {
                                final IExternalResourceInfo resource = ExternalResourceInfoFactory.createFileResource(KettleVFS.getFileObject(path), true);
                                if (resource != null) {
                                    resources.add(resource);
                                } else {
                                    throw new KettleFileException("Error getting file resource!");
                                }
                            } catch (KettleFileException kfe) {
                            // TODO throw or ignore?
                            }
                        }
                    }
                }
            }
        }
    }
    return resources;
}
Also used : KettleFileException(org.pentaho.di.core.exception.KettleFileException) IExternalResourceInfo(org.pentaho.metaverse.api.model.IExternalResourceInfo) TransMeta(org.pentaho.di.trans.TransMeta) StepMeta(org.pentaho.di.trans.step.StepMeta) FileInputList(org.pentaho.di.core.fileinput.FileInputList)

Example 57 with IExternalResourceInfo

use of org.pentaho.metaverse.api.model.IExternalResourceInfo in project pentaho-metaverse by pentaho.

the class ExternalResourceStepAnalyzer method customAnalyze.

@Override
protected void customAnalyze(T meta, IMetaverseNode node) throws MetaverseAnalyzerException {
    // handle all of the external resources
    if (getExternalResourceConsumer() != null) {
        IAnalysisContext context = getDescriptor().getContext();
        Collection<IExternalResourceInfo> resources = getExternalResourceConsumer().getResources(meta, context);
        for (IExternalResourceInfo resource : resources) {
            try {
                if (resource.isInput()) {
                    String label = DictionaryConst.LINK_READBY;
                    IMetaverseNode resourceNode = createResourceNode(resource);
                    getMetaverseBuilder().addNode(resourceNode);
                    getMetaverseBuilder().addLink(resourceNode, label, node);
                }
                if (resource.isOutput()) {
                    String label = DictionaryConst.LINK_WRITESTO;
                    IMetaverseNode resourceNode = createResourceNode(resource);
                    getMetaverseBuilder().addNode(resourceNode);
                    getMetaverseBuilder().addLink(node, label, resourceNode);
                }
            } catch (MetaverseException e) {
                LOGGER.warn(e.getLocalizedMessage());
                LOGGER.debug(Messages.getString("ERROR.ErrorDuringAnalysisStackTrace"), e);
            }
        }
    }
}
Also used : IExternalResourceInfo(org.pentaho.metaverse.api.model.IExternalResourceInfo) IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) IAnalysisContext(org.pentaho.metaverse.api.IAnalysisContext) MetaverseException(org.pentaho.metaverse.api.MetaverseException)

Example 58 with IExternalResourceInfo

use of org.pentaho.metaverse.api.model.IExternalResourceInfo in project pentaho-metaverse by pentaho.

the class ConnectionExternalResourceStepAnalyzerTest method testCreateResourceNode_outputs.

@Test
public void testCreateResourceNode_outputs() throws Exception {
    IExternalResourceInfo resInfo = mock(IExternalResourceInfo.class);
    StepNodes inputs = null;
    StepNodes outputs = mock(StepNodes.class);
    doReturn(inputs).when(analyzer).getInputs();
    doReturn(outputs).when(analyzer).getOutputs();
    doReturn(tableNode).when(analyzer).createTableNode(resInfo);
    doReturn(false).when(analyzer).isInput();
    IMetaverseNode resourceNode = analyzer.createResourceNode(resInfo);
    assertEquals(tableNode, resourceNode);
    verify(analyzer).linkResourceToFields(outputs);
    verify(analyzer, never()).linkResourceToFields(inputs);
}
Also used : IExternalResourceInfo(org.pentaho.metaverse.api.model.IExternalResourceInfo) IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) Test(org.junit.Test)

Example 59 with IExternalResourceInfo

use of org.pentaho.metaverse.api.model.IExternalResourceInfo in project pentaho-metaverse by pentaho.

the class ConnectionExternalResourceStepAnalyzerTest method testCreateResourceNode_inputs.

@Test
public void testCreateResourceNode_inputs() throws Exception {
    IExternalResourceInfo resInfo = mock(IExternalResourceInfo.class);
    StepNodes inputs = mock(StepNodes.class);
    StepNodes outputs = null;
    doReturn(inputs).when(analyzer).getInputs();
    doReturn(outputs).when(analyzer).getOutputs();
    doReturn(tableNode).when(analyzer).createTableNode(resInfo);
    doReturn(true).when(analyzer).isInput();
    IMetaverseNode resourceNode = analyzer.createResourceNode(resInfo);
    assertEquals(tableNode, resourceNode);
    verify(analyzer).linkResourceToFields(inputs);
    verify(analyzer, never()).linkResourceToFields(outputs);
    assertEquals(tableNode, analyzer.getTableNode());
}
Also used : IExternalResourceInfo(org.pentaho.metaverse.api.model.IExternalResourceInfo) IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) Test(org.junit.Test)

Example 60 with IExternalResourceInfo

use of org.pentaho.metaverse.api.model.IExternalResourceInfo in project pentaho-metaverse by pentaho.

the class ExternalResourceStepAnalyzerTest method testAnalyze_input.

@Test
public void testAnalyze_input() throws Exception {
    // fake the super.analyze call
    doReturn(node).when((StepAnalyzer<BaseStepMeta>) analyzer).analyze(descriptor, meta);
    analyzer.setExternalResourceConsumer(erc);
    List<IExternalResourceInfo> resources = new ArrayList<>();
    IExternalResourceInfo resInfo = mock(IExternalResourceInfo.class);
    resources.add(resInfo);
    when(resInfo.isInput()).thenReturn(true);
    when(erc.getResources(eq(meta), any(IAnalysisContext.class))).thenReturn(resources);
    analyzer.customAnalyze(meta, node);
    verify(builder).addNode(resourceNode);
    verify(builder).addLink(resourceNode, DictionaryConst.LINK_READBY, node);
}
Also used : IExternalResourceInfo(org.pentaho.metaverse.api.model.IExternalResourceInfo) ArrayList(java.util.ArrayList) IAnalysisContext(org.pentaho.metaverse.api.IAnalysisContext) Test(org.junit.Test)

Aggregations

IExternalResourceInfo (org.pentaho.metaverse.api.model.IExternalResourceInfo)64 Test (org.junit.Test)38 BaseStepMeta (org.pentaho.di.trans.step.BaseStepMeta)16 StepMeta (org.pentaho.di.trans.step.StepMeta)16 LinkedList (java.util.LinkedList)12 IMetaverseNode (org.pentaho.metaverse.api.IMetaverseNode)12 HashSet (java.util.HashSet)10 KettleException (org.pentaho.di.core.exception.KettleException)10 ArrayList (java.util.ArrayList)8 VariableSpace (org.pentaho.di.core.variables.VariableSpace)8 FileObject (org.apache.commons.vfs2.FileObject)7 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)5 IExecutionProfile (org.pentaho.metaverse.api.model.IExecutionProfile)5 List (java.util.List)4 IAnalysisContext (org.pentaho.metaverse.api.IAnalysisContext)4 IStepExternalResourceConsumer (org.pentaho.metaverse.api.analyzer.kettle.step.IStepExternalResourceConsumer)3 WebServiceResourceInfo (org.pentaho.metaverse.api.model.WebServiceResourceInfo)3 Before (org.junit.Before)2 Matchers.anyString (org.mockito.Matchers.anyString)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2