Search in sources :

Example 1 with IExternalResourceInfo

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

the class XMLOutputStepAnalyzerTest method testXMLOutputExternalResourceConsumer.

@Test
public void testXMLOutputExternalResourceConsumer() throws Exception {
    XMLOutputExternalResourceConsumer consumer = new XMLOutputExternalResourceConsumer();
    StepMeta meta = new StepMeta("test", this.meta);
    StepMeta spyMeta = spy(meta);
    when(this.meta.getParentStepMeta()).thenReturn(spyMeta);
    when(spyMeta.getParentTransMeta()).thenReturn(mockTransMeta);
    when(this.meta.getFileName()).thenReturn(null);
    String[] filePaths = { "/path/to/file1", "/another/path/to/file2" };
    when(this.meta.getFiles(Mockito.any(VariableSpace.class))).thenReturn(filePaths);
    assertFalse(consumer.isDataDriven(this.meta));
    Collection<IExternalResourceInfo> resources = consumer.getResourcesFromMeta(this.meta);
    assertFalse(resources.isEmpty());
    assertEquals(2, resources.size());
    when(this.meta.getExtension()).thenReturn("txt");
    assertEquals(XMLOutputMeta.class, consumer.getMetaClass());
}
Also used : IExternalResourceInfo(org.pentaho.metaverse.api.model.IExternalResourceInfo) VariableSpace(org.pentaho.di.core.variables.VariableSpace) StepMeta(org.pentaho.di.trans.step.StepMeta) BaseStepMeta(org.pentaho.di.trans.step.BaseStepMeta) Test(org.junit.Test)

Example 2 with IExternalResourceInfo

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

the class GetXMLDataExternalResourceConsumer method getResourcesFromRow.

@Override
public Collection<IExternalResourceInfo> getResourcesFromRow(GetXMLData textFileInput, RowMetaInterface rowMeta, Object[] row) {
    Collection<IExternalResourceInfo> resources = new LinkedList<IExternalResourceInfo>();
    // For some reason the step doesn't return the StepMetaInterface directly, so go around it
    GetXMLDataMeta meta = (GetXMLDataMeta) textFileInput.getStepMetaInterface();
    if (meta == null) {
        meta = (GetXMLDataMeta) textFileInput.getStepMeta().getStepMetaInterface();
    }
    try {
        if (meta.getIsAFile()) {
            String filename = (meta == null) ? null : rowMeta.getString(row, meta.getXMLField(), null);
            if (!Utils.isEmpty(filename)) {
                FileObject fileObject = KettleVFS.getFileObject(filename);
                resources.add(ExternalResourceInfoFactory.createFileResource(fileObject, true));
            }
        }
    // TODO URLs?
    } catch (KettleException kve) {
    // TODO throw exception or ignore?
    }
    return resources;
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) IExternalResourceInfo(org.pentaho.metaverse.api.model.IExternalResourceInfo) FileObject(org.apache.commons.vfs2.FileObject) LinkedList(java.util.LinkedList)

Example 3 with IExternalResourceInfo

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

the class JsonInputAnalyzerTest method testJsonInputExternalResourceConsumer.

@Test
public void testJsonInputExternalResourceConsumer() throws Exception {
    JsonInputExternalResourceConsumer consumer = new JsonInputExternalResourceConsumer() {

        @Override
        protected boolean resolveExternalResources() {
            return true;
        }
    };
    StepMeta spyMeta = spy(new StepMeta("test", meta));
    when(meta.getParentStepMeta()).thenReturn(spyMeta);
    when(spyMeta.getParentTransMeta()).thenReturn(transMeta);
    when(meta.getFileName()).thenReturn(null);
    when(meta.isAcceptingFilenames()).thenReturn(false);
    FileInputList inputFiles = new FileInputList();
    inputFiles.addFile(KettleVFS.getFileObject("/path/to/file1"));
    inputFiles.addFile(KettleVFS.getFileObject("/another/path/to/file2"));
    when(meta.getFileInputList(Mockito.any(VariableSpace.class))).thenReturn(inputFiles);
    assertFalse(consumer.isDataDriven(meta));
    Collection<IExternalResourceInfo> resources = consumer.getResourcesFromMeta(meta);
    assertFalse(resources.isEmpty());
    assertEquals(2, resources.size());
    when(meta.isAcceptingFilenames()).thenReturn(true);
    assertTrue(consumer.isDataDriven(meta));
    assertTrue(consumer.getResourcesFromMeta(meta).isEmpty());
    when(mockJsonInput.environmentSubstitute(Mockito.any(String.class))).thenReturn("/path/to/row/file");
    when(mockJsonInput.getStepMetaInterface()).thenReturn(meta);
    resources = consumer.getResourcesFromRow(mockJsonInput, mockRowMetaInterface, new String[] { "id", "name" });
    assertFalse(resources.isEmpty());
    assertEquals(1, resources.size());
    when(mockRowMetaInterface.getString(Mockito.any(Object[].class), Mockito.anyString(), Mockito.anyString())).thenThrow(KettleException.class);
    resources = consumer.getResourcesFromRow(mockJsonInput, mockRowMetaInterface, new String[] { "id", "name" });
    assertTrue(resources.isEmpty());
    assertEquals(JsonInputMeta.class, consumer.getMetaClass());
}
Also used : IExternalResourceInfo(org.pentaho.metaverse.api.model.IExternalResourceInfo) VariableSpace(org.pentaho.di.core.variables.VariableSpace) StepMeta(org.pentaho.di.trans.step.StepMeta) BaseStepMeta(org.pentaho.di.trans.step.BaseStepMeta) FileInputList(org.pentaho.di.core.fileinput.FileInputList) Test(org.junit.Test)

Example 4 with IExternalResourceInfo

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

the class HTTPPostExternalResourceConsumer method getResourcesFromRow.

@Override
public Collection<IExternalResourceInfo> getResourcesFromRow(HTTPPOST httpClientInput, RowMetaInterface rowMeta, Object[] row) {
    Collection<IExternalResourceInfo> resources = new LinkedList<IExternalResourceInfo>();
    // For some reason the step doesn't return the StepMetaInterface directly, so go around it
    HTTPPOSTMeta meta = (HTTPPOSTMeta) httpClientInput.getStepMetaInterface();
    if (meta == null) {
        meta = (HTTPPOSTMeta) httpClientInput.getStepMeta().getStepMetaInterface();
    }
    if (meta != null) {
        try {
            String url;
            if (meta.isUrlInField()) {
                url = rowMeta.getString(row, meta.getUrlField(), null);
            } else {
                url = meta.getUrl();
            }
            if (!Const.isEmpty(url)) {
                WebServiceResourceInfo resourceInfo = (WebServiceResourceInfo) ExternalResourceInfoFactory.createURLResource(url, true);
                if (ArrayUtils.isNotEmpty(meta.getArgumentField())) {
                    for (int i = 0; i < meta.getArgumentField().length; i++) {
                        String field = meta.getArgumentField()[i];
                        String label = meta.getArgumentParameter()[i];
                        resourceInfo.addHeader(label, rowMeta.getString(row, field, null));
                    }
                }
                if (ArrayUtils.isNotEmpty(meta.getQueryField())) {
                    for (int i = 0; i < meta.getQueryField().length; i++) {
                        String field = meta.getQueryField()[i];
                        String label = meta.getQueryParameter()[i];
                        resourceInfo.addParameter(label, rowMeta.getString(row, field, null));
                    }
                }
                resources.add(resourceInfo);
            }
        } catch (KettleException kve) {
        // TODO throw exception or ignore?
        }
    }
    return resources;
}
Also used : HTTPPOSTMeta(org.pentaho.di.trans.steps.httppost.HTTPPOSTMeta) KettleException(org.pentaho.di.core.exception.KettleException) IExternalResourceInfo(org.pentaho.metaverse.api.model.IExternalResourceInfo) WebServiceResourceInfo(org.pentaho.metaverse.api.model.WebServiceResourceInfo) LinkedList(java.util.LinkedList)

Example 5 with IExternalResourceInfo

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

the class MongoDbInputExternalResourceConsumer method getResourcesFromMeta.

@Override
public Collection<IExternalResourceInfo> getResourcesFromMeta(MongoDbInputMeta meta, IAnalysisContext context) {
    Set<IExternalResourceInfo> resources = new HashSet<IExternalResourceInfo>();
    MongoDbResourceInfo mongoDbResourceInfo = new MongoDbResourceInfo(meta);
    mongoDbResourceInfo.setInput(true);
    resources.add(mongoDbResourceInfo);
    return resources;
}
Also used : IExternalResourceInfo(org.pentaho.metaverse.api.model.IExternalResourceInfo) MongoDbResourceInfo(org.pentaho.metaverse.impl.model.MongoDbResourceInfo) HashSet(java.util.HashSet)

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