use of org.pentaho.di.trans.steps.rest.RestMeta in project pentaho-metaverse by pentaho.
the class RestClientExternalResourceConsumer method getResourcesFromRow.
@Override
public Collection<IExternalResourceInfo> getResourcesFromRow(Rest step, RowMetaInterface rowMeta, Object[] row) {
Set<IExternalResourceInfo> resources = new HashSet<>();
RestMeta meta = (RestMeta) step.getStepMetaInterface();
if (meta == null) {
meta = (RestMeta) step.getStepMeta().getStepMetaInterface();
}
if (meta != null) {
String url;
String method;
String body;
try {
if (meta.isUrlInField()) {
url = rowMeta.getString(row, meta.getUrlField(), null);
} else {
url = meta.getUrl();
}
if (StringUtils.isNotEmpty(url)) {
WebServiceResourceInfo resourceInfo = createResourceInfo(url, meta);
if (ArrayUtils.isNotEmpty(meta.getHeaderField())) {
for (int i = 0; i < meta.getHeaderField().length; i++) {
String field = meta.getHeaderField()[i];
String label = meta.getHeaderName()[i];
resourceInfo.addHeader(label, rowMeta.getString(row, field, null));
}
}
if (ArrayUtils.isNotEmpty(meta.getParameterField())) {
for (int i = 0; i < meta.getParameterField().length; i++) {
String field = meta.getParameterField()[i];
String label = meta.getParameterName()[i];
resourceInfo.addParameter(label, rowMeta.getString(row, field, null));
}
}
if (meta.isDynamicMethod()) {
method = rowMeta.getString(row, meta.getMethodFieldName(), null);
resourceInfo.setMethod(method);
}
if (StringUtils.isNotEmpty(meta.getBodyField())) {
body = rowMeta.getString(row, meta.getBodyField(), null);
resourceInfo.setBody(body);
}
resources.add(resourceInfo);
}
} catch (KettleValueException e) {
// could not find a url on this row
log.debug(e.getMessage(), e);
}
}
return resources;
}
use of org.pentaho.di.trans.steps.rest.RestMeta in project pentaho-metaverse by pentaho.
the class MetaverseValidationIT method testRestClientStepNode_urlFromField.
@Test
public void testRestClientStepNode_urlFromField() throws Exception {
RestClientStepNode node = root.getRestClientStepNode("REST Client - parameterized");
assertNotNull(node);
Iterable<FramedMetaverseNode> inputUrls = node.getInputUrls();
assertEquals("REST Client", node.getStepType());
RestMeta stepMeta = (RestMeta) getStepMeta(node);
for (FramedMetaverseNode inputUrl : inputUrls) {
assertEquals(stepMeta.getUrlField(), inputUrl.getName());
}
Set<String> usedFields = new HashSet<>();
Collections.addAll(usedFields, stepMeta.getHeaderField());
Collections.addAll(usedFields, stepMeta.getParameterField());
if (stepMeta.isUrlInField()) {
usedFields.add(stepMeta.getUrlField());
}
if (stepMeta.isDynamicMethod()) {
usedFields.add(stepMeta.getMethodFieldName());
}
if (StringUtils.isNotEmpty(stepMeta.getBodyField())) {
usedFields.add(stepMeta.getBodyField());
}
// check the param field is "used"
Iterable<StreamFieldNode> streamFieldNodesUses = node.getStreamFieldNodesUses();
assertEquals(usedFields.size(), getIterableSize(streamFieldNodesUses));
for (StreamFieldNode streamFieldNodesUse : streamFieldNodesUses) {
assertTrue(usedFields.contains(streamFieldNodesUse.getName()));
}
Iterable<StreamFieldNode> outputs = node.getOutputStreamFields();
assertEquals(getExpectedOutputFieldCount(stepMeta), getIterableSize(outputs));
}
use of org.pentaho.di.trans.steps.rest.RestMeta in project pentaho-metaverse by pentaho.
the class MetaverseValidationIT method testRestClientStepNode.
@Test
public void testRestClientStepNode() throws Exception {
RestClientStepNode node = root.getRestClientStepNode("REST Client");
assertNotNull(node);
Iterable<FramedMetaverseNode> inputUrls = node.getInputUrls();
int countInputUrls = getIterableSize(inputUrls);
assertEquals(1, countInputUrls);
assertEquals("REST Client", node.getStepType());
RestMeta stepMeta = (RestMeta) getStepMeta(node);
for (FramedMetaverseNode inputUrl : inputUrls) {
assertEquals(stepMeta.getUrl(), inputUrl.getName());
}
// check the param field is "used"
Iterable<StreamFieldNode> streamFieldNodesUses = node.getStreamFieldNodesUses();
assertEquals(1, getIterableSize(streamFieldNodesUses));
for (StreamFieldNode streamFieldNodesUse : streamFieldNodesUses) {
assertEquals(stepMeta.getParameterField()[0], streamFieldNodesUse.getName());
}
Iterable<StreamFieldNode> outputs = node.getOutputStreamFields();
assertEquals(4, getIterableSize(outputs));
Iterable<StreamFieldNode> inputs = node.getInputStreamFields();
assertEquals(3, getIterableSize(inputs));
for (StreamFieldNode in : inputs) {
assertNotNull(in.getFieldNodesDerivedFromMe());
assertEquals(in.getName(), in.getFieldNodesDerivedFromMe().iterator().next().getName());
}
}
Aggregations