Search in sources :

Example 1 with BaseFileInputMeta

use of org.pentaho.di.trans.steps.file.BaseFileInputMeta in project pentaho-metaverse by pentaho.

the class KettleAnalyzerUtil method getResourcesFromRow.

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

Example 2 with BaseFileInputMeta

use of org.pentaho.di.trans.steps.file.BaseFileInputMeta in project pentaho-metaverse by pentaho.

the class ExternalResourceStepAnalyzer method getInputFieldsToIgnore.

/**
 * Returns a {@lnk Set} of field names that are to be ignored when fetching "resource" fields. This set will
 * typically include any field that is either provided by a previous step, or is some "additional" field.
 */
protected Set<String> getInputFieldsToIgnore(final T meta, final Map<String, RowMetaInterface> inputRows, final RowMetaInterface rowMeta) {
    Set<String> inputFieldsToIgnore = new HashSet<>();
    for (RowMetaInterface rowMetaInterface : inputRows.values()) {
        for (ValueMetaInterface inputField : rowMetaInterface.getValueMetaList()) {
            inputFieldsToIgnore.add(inputField.getName());
        }
    }
    if (meta instanceof BaseFileInputMeta) {
        final BaseFileInputMeta fileMeta = (BaseFileInputMeta) meta;
        final BaseFileField[] inputFields = fileMeta.getInputFields();
        final List<String> inputFieldNames = new ArrayList<>();
        for (final BaseFileField inputField : inputFields) {
            inputFieldNames.add(inputField.getName());
        }
        // get the fields within rowMeta - any field tha ISN'T a meta input field, should be ignored
        final List<ValueMetaInterface> rowMetaValueMetaList = rowMeta.getValueMetaList();
        for (final ValueMetaInterface rowMetaValueMeta : rowMetaValueMetaList) {
            if (!inputFieldNames.contains(rowMetaValueMeta.getName())) {
                inputFieldsToIgnore.add(rowMetaValueMeta.getName());
            }
        }
    }
    return inputFieldsToIgnore;
}
Also used : BaseFileInputMeta(org.pentaho.di.trans.steps.file.BaseFileInputMeta) BaseFileField(org.pentaho.di.trans.steps.file.BaseFileField) ArrayList(java.util.ArrayList) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) HashSet(java.util.HashSet) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Aggregations

BaseFileInputMeta (org.pentaho.di.trans.steps.file.BaseFileInputMeta)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 FileObject (org.apache.commons.vfs2.FileObject)1 KettleException (org.pentaho.di.core.exception.KettleException)1 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)1 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)1 BaseFileField (org.pentaho.di.trans.steps.file.BaseFileField)1 IExternalResourceInfo (org.pentaho.metaverse.api.model.IExternalResourceInfo)1