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());
}
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;
}
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());
}
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;
}
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;
}
Aggregations