Search in sources :

Example 6 with IExternalResourceInfo

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

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

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

the class TableInputExternalResourceConsumer method getResourcesFromMeta.

@Override
public Collection<IExternalResourceInfo> getResourcesFromMeta(TableInputMeta meta, IAnalysisContext context) {
    Set<IExternalResourceInfo> resources = new HashSet<IExternalResourceInfo>();
    DatabaseMeta dbMeta = meta.getDatabaseMeta();
    if (dbMeta != null) {
        IExternalResourceInfo databaseResource = ExternalResourceInfoFactory.createDatabaseResource(dbMeta, true);
        String query = context.equals(DictionaryConst.CONTEXT_RUNTIME) ? meta.getParentStepMeta().getParentTransMeta().environmentSubstitute(meta.getSQL()) : meta.getSQL();
        databaseResource.getAttributes().put(DictionaryConst.PROPERTY_QUERY, query);
        resources.add(databaseResource);
    }
    return resources;
}
Also used : IExternalResourceInfo(org.pentaho.metaverse.api.model.IExternalResourceInfo) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) HashSet(java.util.HashSet)

Example 9 with IExternalResourceInfo

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

the class TextFileInputExternalResourceConsumer method getResourcesFromRow.

@Override
public Collection<IExternalResourceInfo> getResourcesFromRow(TextFileInput textFileInput, RowMetaInterface rowMeta, Object[] row) {
    Collection<IExternalResourceInfo> resources = new LinkedList<>();
    // For some reason the step doesn't return the StepMetaInterface directly, so go around it
    TextFileInputMeta meta = (TextFileInputMeta) textFileInput.getStepMetaInterface();
    if (meta == null) {
        meta = (TextFileInputMeta) textFileInput.getStepMeta().getStepMetaInterface();
    }
    try {
        String filename = meta == null ? null : rowMeta.getString(row, meta.getAcceptingField(), null);
        if (!Const.isEmpty(filename)) {
            FileObject fileObject = KettleVFS.getFileObject(filename);
            resources.add(ExternalResourceInfoFactory.createFileResource(fileObject, true));
        }
    } 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) TextFileInputMeta(org.pentaho.di.trans.steps.textfileinput.TextFileInputMeta) FileObject(org.apache.commons.vfs2.FileObject) LinkedList(java.util.LinkedList)

Example 10 with IExternalResourceInfo

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

the class StepExternalConsumerRowListener method rowReadEvent.

/**
 * Called when rows are read by the step to which this listener is attached
 *
 * @param rowMeta The metadata (value types, e.g.) of the associated row data
 * @param row     An array of Objects corresponding to the row data
 * @see org.pentaho.di.trans.step.RowListener#rowReadEvent(org.pentaho.di.core.row.RowMetaInterface,
 * Object[])
 */
@Override
@SuppressWarnings("unchecked")
public void rowReadEvent(RowMetaInterface rowMeta, Object[] row) throws KettleStepException {
    Collection<IExternalResourceInfo> resources = stepExternalResourceConsumer.getResourcesFromRow((BaseStep) step, rowMeta, row);
    if (resources != null) {
        // Add the resources to the execution profile
        IExecutionProfile executionProfile = TransLineageHolderMap.getInstance().getLineageHolder(step.getTrans()).getExecutionProfile();
        if (executionProfile != null) {
            String stepName = step.getStepname();
            Map<String, List<IExternalResourceInfo>> resourceMap = executionProfile.getExecutionData().getExternalResources();
            List<IExternalResourceInfo> externalResources = resourceMap.get(stepName);
            if (externalResources == null) {
                externalResources = new LinkedList<IExternalResourceInfo>();
            }
            externalResources.addAll(resources);
            resourceMap.put(stepName, externalResources);
        }
    }
}
Also used : IExternalResourceInfo(org.pentaho.metaverse.api.model.IExternalResourceInfo) IExecutionProfile(org.pentaho.metaverse.api.model.IExecutionProfile) List(java.util.List) LinkedList(java.util.LinkedList)

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