Search in sources :

Example 1 with SAPRow

use of org.pentaho.di.trans.steps.sapinput.sap.SAPRow in project pentaho-kettle by pentaho.

the class SAPConnectionMock method executeFunctionUncursored.

public SAPResultSet executeFunctionUncursored(SAPFunction function, Collection<SAPField> input, Collection<SAPField> output) throws SAPException {
    SAPResultSet srs = new SAPResultSet();
    if (function.getName().equalsIgnoreCase("SearchCustomer")) {
        for (int i = 1; i <= 9; i++) {
            SAPRow sr = new SAPRow();
            sr.addField(new SAPField("Name", "", "String", "Casters" + i));
            sr.addField(new SAPField("Firstname", "", "String", "Matt" + i));
            sr.addField(new SAPField("Adress", "", "String", "Pentahoway 77"));
            sr.addField(new SAPField("Zipcode", "", "Number", 12345 + (i * 10000)));
            sr.addField(new SAPField("CustomerGroup", "", "String", "ABC" + i));
            srs.addRow(sr);
        }
    } else {
        for (int i = 1; i <= 9; i++) {
            SAPRow sr = new SAPRow();
            sr.addField(new SAPField("Field4", "", "String", "Testvalue" + i));
            sr.addField(new SAPField("Field5", "", "Number", 12345 + (i * 10000)));
            sr.addField(new SAPField("Field6", "", "Decimal", 77.88 + (i * 10)));
            srs.addRow(sr);
        }
    }
    return srs;
}
Also used : SAPRow(org.pentaho.di.trans.steps.sapinput.sap.SAPRow) SAPResultSet(org.pentaho.di.trans.steps.sapinput.sap.SAPResultSet) SAPField(org.pentaho.di.trans.steps.sapinput.sap.SAPField)

Example 2 with SAPRow

use of org.pentaho.di.trans.steps.sapinput.sap.SAPRow in project pentaho-kettle by pentaho.

the class SapInput method processRow.

public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws KettleException {
    Object[] r = getRow();
    if (r == null) {
        // no more input to be expected...
        setOutputDone();
        return false;
    }
    if (first) {
        first = false;
        // Determine the output row metadata of this step
        // 
        data.outputRowMeta = new RowMeta();
        meta.getFields(data.outputRowMeta, getStepname(), null, null, this, repository, metaStore);
        // Pre-calculate the indexes of the parameters for performance reasons...
        // 
        data.parameterIndexes = new ArrayList<Integer>();
        for (SapParameter parameter : meta.getParameters()) {
            int index = getInputRowMeta().indexOfValue(parameter.getFieldName());
            if (index < 0) {
                throw new KettleException("Unable to find field '" + parameter.getFieldName() + "'");
            }
            data.parameterIndexes.add(index);
        }
        // Pre-calculate the output fields
        // 
        data.output = new ArrayList<SAPField>();
        for (SapOutputField outputField : meta.getOutputFields()) {
            SAPField field = new SAPField(outputField.getSapFieldName(), outputField.getTableName(), "output_" + outputField.getSapType().getDescription());
            data.output.add(field);
        }
    }
    // Assemble the list of input fields for the SAP function execution...
    // 
    ArrayList<SAPField> input = new ArrayList<SAPField>();
    for (int i = 0; i < meta.getParameters().size(); i++) {
        SapParameter parameter = meta.getParameters().get(i);
        int fieldIndex = data.parameterIndexes.get(i);
        ValueMetaInterface valueMeta = getInputRowMeta().getValueMeta(fieldIndex);
        Object value = valueMeta.convertToNormalStorageType(r[fieldIndex]);
        // TODO: figure out if the executeFunction needs the data to be in a specific data type or format!!
        // If so, value needs to be converted to the appropriate data type here.
        SAPField field = new SAPField(parameter.getParameterName(), parameter.getTableName(), "input_" + parameter.getSapType().getDescription(), value);
        input.add(field);
    }
    // Get the output...
    // 
    SAPRowIterator resultSet;
    try {
        resultSet = data.sapConnection.executeFunctionCursored(meta.getFunction(), input, data.output);
    } catch (SAPException e) {
        throw new KettleException(e);
    }
    while (resultSet.hasNext()) {
        SAPRow sapRow = resultSet.next();
        Object[] outputRowData = RowDataUtil.allocateRowData(data.outputRowMeta.size());
        // Makes it easier to add all sorts of fields later on, like row number, input fields, etc.
        int outputIndex = 0;
        for (SAPField field : sapRow.getFields()) {
            // TODO: Here we should check as well whether or not the correct data types are delivered from SAP.
            // Make sure that we don't pass the appropriate data types : String, long, double, Date, BigDecimal, Boolean,
            // byte[] ONLY!!
            // 
            outputRowData[outputIndex++] = field.getValue();
        }
        // Pass the row along: row metadata and data need to correspond!!
        // 
        putRow(data.outputRowMeta, outputRowData);
        if (getTrans().isStopped()) {
            break;
        }
    }
    return true;
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) SAPRow(org.pentaho.di.trans.steps.sapinput.sap.SAPRow) RowMeta(org.pentaho.di.core.row.RowMeta) ArrayList(java.util.ArrayList) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) SAPException(org.pentaho.di.trans.steps.sapinput.sap.SAPException) SAPRowIterator(org.pentaho.di.trans.steps.sapinput.sap.impl.SAPRowIterator) SAPField(org.pentaho.di.trans.steps.sapinput.sap.SAPField)

Example 3 with SAPRow

use of org.pentaho.di.trans.steps.sapinput.sap.SAPRow in project pentaho-kettle by pentaho.

the class SAPConnectionMockTest method main.

/**
 * How to use a SAPConnection
 *
 * @throws SAPException
 */
public static void main(String[] args) throws SAPException {
    // how to obtain a connection
    SAPConnection sc = SAPConnectionFactoryMock.create();
    // how to open a connection
    // @Matt:
    // please show us how to retrieve the connection params from the
    // pentaho environment
    DatabaseMeta cp = new DatabaseMeta("SAP", "SAPR3", "Plugin", "192.168.9.50", null, null, "USER", "PASSWORT");
    cp.getAttributes().setProperty(SAPR3DatabaseMeta.ATTRIBUTE_SAP_SYSTEM_NUMBER, "00");
    cp.getAttributes().setProperty(SAPR3DatabaseMeta.ATTRIBUTE_SAP_CLIENT, "100");
    cp.getAttributes().setProperty(SAPR3DatabaseMeta.ATTRIBUTE_SAP_LANGUAGE, "DE");
    sc.open(cp);
    // how to query all functions
    System.out.println("how to query all functions");
    Collection<SAPFunction> csf1 = sc.getFunctions("");
    for (SAPFunction sapFunction : csf1) {
        System.out.println(sapFunction);
    }
    System.out.println();
    // how to query functions
    System.out.println("how to query functions");
    Collection<SAPFunction> csf2 = sc.getFunctions("1");
    for (SAPFunction sapFunction : csf2) {
        System.out.println(sapFunction);
    }
    System.out.println();
    // how to get a function
    System.out.println("how to get a function");
    SAPFunction sf = sc.getFunction("SearchCustomer");
    System.out.println(sf);
    System.out.println();
    // how to get function signature
    System.out.println("how to get function signature");
    SAPFunctionSignature sfs = sc.getFunctionSignature(sf);
    System.out.println("input:");
    for (SAPField field : sfs.getInput()) {
        System.out.println(field);
    }
    System.out.println("output:");
    for (SAPField field : sfs.getOutput()) {
        System.out.println(field);
    }
    System.out.println();
    // how to execute a function
    System.out.println("how to execute a function");
    Collection<SAPField> input = new Vector<SAPField>();
    input.add(new SAPField("Name", "", "input_single", "Casters"));
    Collection<SAPField> output = new Vector<SAPField>();
    output.add(new SAPField("Name", "", "output_single"));
    output.add(new SAPField("Firstname", "", "output_single"));
    output.add(new SAPField("Adress", "", "output_single"));
    output.add(new SAPField("Zipcode", "", "output_single"));
    output.add(new SAPField("CustomerGroup", "", "output_single"));
    SAPResultSet sfr = sc.executeFunctionUncursored(sf, input, output);
    for (SAPRow row : sfr.getRows()) {
        System.out.println(row);
    }
    System.out.println();
    // Close the connection
    // 
    sc.close();
}
Also used : SAPFunctionSignature(org.pentaho.di.trans.steps.sapinput.sap.SAPFunctionSignature) SAPFunction(org.pentaho.di.trans.steps.sapinput.sap.SAPFunction) SAPRow(org.pentaho.di.trans.steps.sapinput.sap.SAPRow) SAPConnection(org.pentaho.di.trans.steps.sapinput.sap.SAPConnection) SAPResultSet(org.pentaho.di.trans.steps.sapinput.sap.SAPResultSet) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) SAPR3DatabaseMeta(org.pentaho.di.core.database.sap.SAPR3DatabaseMeta) SAPField(org.pentaho.di.trans.steps.sapinput.sap.SAPField) Vector(java.util.Vector)

Aggregations

SAPField (org.pentaho.di.trans.steps.sapinput.sap.SAPField)3 SAPRow (org.pentaho.di.trans.steps.sapinput.sap.SAPRow)3 SAPResultSet (org.pentaho.di.trans.steps.sapinput.sap.SAPResultSet)2 ArrayList (java.util.ArrayList)1 Vector (java.util.Vector)1 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)1 SAPR3DatabaseMeta (org.pentaho.di.core.database.sap.SAPR3DatabaseMeta)1 KettleException (org.pentaho.di.core.exception.KettleException)1 RowMeta (org.pentaho.di.core.row.RowMeta)1 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)1 SAPConnection (org.pentaho.di.trans.steps.sapinput.sap.SAPConnection)1 SAPException (org.pentaho.di.trans.steps.sapinput.sap.SAPException)1 SAPFunction (org.pentaho.di.trans.steps.sapinput.sap.SAPFunction)1 SAPFunctionSignature (org.pentaho.di.trans.steps.sapinput.sap.SAPFunctionSignature)1 SAPRowIterator (org.pentaho.di.trans.steps.sapinput.sap.impl.SAPRowIterator)1