Search in sources :

Example 1 with WebServiceResourceInfo

use of org.pentaho.metaverse.api.model.WebServiceResourceInfo 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 2 with WebServiceResourceInfo

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

the class RestClientExternalResourceConsumer method getResourcesFromMeta.

@Override
public Collection<IExternalResourceInfo> getResourcesFromMeta(RestMeta meta, IAnalysisContext context) {
    List<IExternalResourceInfo> resources = new ArrayList<>();
    if (!meta.isUrlInField()) {
        String url = meta.getUrl();
        WebServiceResourceInfo resourceInfo = createResourceInfo(url, meta);
        resources.add(resourceInfo);
    }
    return resources;
}
Also used : IExternalResourceInfo(org.pentaho.metaverse.api.model.IExternalResourceInfo) WebServiceResourceInfo(org.pentaho.metaverse.api.model.WebServiceResourceInfo) ArrayList(java.util.ArrayList)

Example 3 with WebServiceResourceInfo

use of org.pentaho.metaverse.api.model.WebServiceResourceInfo 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 4 with WebServiceResourceInfo

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

the class RestClientExternalResourceConsumer method createResourceInfo.

private WebServiceResourceInfo createResourceInfo(String url, RestMeta meta) {
    WebServiceResourceInfo resourceInfo = (WebServiceResourceInfo) ExternalResourceInfoFactory.createURLResource(url, true);
    if (!meta.isDynamicMethod()) {
        resourceInfo.setMethod(meta.getMethod());
    }
    if (StringUtils.isNotEmpty(meta.getBodyField())) {
        resourceInfo.setBody(meta.getBodyField());
    }
    resourceInfo.setApplicationType(meta.getApplicationType());
    return resourceInfo;
}
Also used : WebServiceResourceInfo(org.pentaho.metaverse.api.model.WebServiceResourceInfo)

Example 5 with WebServiceResourceInfo

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

the class HTTPClientExternalResourceConsumer method getResourcesFromRow.

@Override
public Collection<IExternalResourceInfo> getResourcesFromRow(HTTP 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
    HTTPMeta meta = (HTTPMeta) httpClientInput.getStepMetaInterface();
    if (meta == null) {
        meta = (HTTPMeta) 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.getHeaderField())) {
                    for (int i = 0; i < meta.getHeaderField().length; i++) {
                        String field = meta.getHeaderField()[i];
                        String label = meta.getHeaderParameter()[i];
                        resourceInfo.addHeader(label, rowMeta.getString(row, field, null));
                    }
                }
                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.addParameter(label, rowMeta.getString(row, field, null));
                    }
                }
                resources.add(resourceInfo);
            }
        } 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) WebServiceResourceInfo(org.pentaho.metaverse.api.model.WebServiceResourceInfo) LinkedList(java.util.LinkedList) HTTPMeta(org.pentaho.di.trans.steps.http.HTTPMeta)

Aggregations

WebServiceResourceInfo (org.pentaho.metaverse.api.model.WebServiceResourceInfo)5 IExternalResourceInfo (org.pentaho.metaverse.api.model.IExternalResourceInfo)4 LinkedList (java.util.LinkedList)2 KettleException (org.pentaho.di.core.exception.KettleException)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 KettleValueException (org.pentaho.di.core.exception.KettleValueException)1 HTTPMeta (org.pentaho.di.trans.steps.http.HTTPMeta)1 HTTPPOSTMeta (org.pentaho.di.trans.steps.httppost.HTTPPOSTMeta)1 RestMeta (org.pentaho.di.trans.steps.rest.RestMeta)1