Search in sources :

Example 1 with RestMeta

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;
}
Also used : IExternalResourceInfo(org.pentaho.metaverse.api.model.IExternalResourceInfo) RestMeta(org.pentaho.di.trans.steps.rest.RestMeta) WebServiceResourceInfo(org.pentaho.metaverse.api.model.WebServiceResourceInfo) KettleValueException(org.pentaho.di.core.exception.KettleValueException) HashSet(java.util.HashSet)

Example 2 with RestMeta

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));
}
Also used : RestMeta(org.pentaho.di.trans.steps.rest.RestMeta) RestClientStepNode(org.pentaho.metaverse.frames.RestClientStepNode) StreamFieldNode(org.pentaho.metaverse.frames.StreamFieldNode) FramedMetaverseNode(org.pentaho.metaverse.frames.FramedMetaverseNode) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 3 with RestMeta

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());
    }
}
Also used : RestMeta(org.pentaho.di.trans.steps.rest.RestMeta) RestClientStepNode(org.pentaho.metaverse.frames.RestClientStepNode) StreamFieldNode(org.pentaho.metaverse.frames.StreamFieldNode) FramedMetaverseNode(org.pentaho.metaverse.frames.FramedMetaverseNode) Test(org.junit.Test)

Aggregations

RestMeta (org.pentaho.di.trans.steps.rest.RestMeta)3 HashSet (java.util.HashSet)2 Test (org.junit.Test)2 FramedMetaverseNode (org.pentaho.metaverse.frames.FramedMetaverseNode)2 RestClientStepNode (org.pentaho.metaverse.frames.RestClientStepNode)2 StreamFieldNode (org.pentaho.metaverse.frames.StreamFieldNode)2 KettleValueException (org.pentaho.di.core.exception.KettleValueException)1 IExternalResourceInfo (org.pentaho.metaverse.api.model.IExternalResourceInfo)1 WebServiceResourceInfo (org.pentaho.metaverse.api.model.WebServiceResourceInfo)1