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