Search in sources :

Example 1 with SAPException

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

the class SAPConnectionFactoryMock method getConnectionTestReport.

/**
 * The SAP connection to test, links to the TEST button in the database dialog.
 */
public String getConnectionTestReport(DatabaseMeta databaseMeta) throws KettleDatabaseException {
    StringBuilder report = new StringBuilder();
    SAPConnection sc = null;
    try {
        sc = create();
        sc.open(databaseMeta);
        // If the connection was successful
        // 
        report.append("Connecting to SAP ERP server [").append(databaseMeta.getName()).append("] succeeded without a problem.").append(Const.CR);
    } catch (SAPException e) {
        report.append("Unable to connect to the SAP ERP server: ").append(e.getMessage()).append(Const.CR);
        report.append(Const.getStackTracker(e));
    } finally {
        sc.close();
    }
    return report.toString();
}
Also used : SAPException(org.pentaho.di.trans.steps.sapinput.sap.SAPException) SAPConnection(org.pentaho.di.trans.steps.sapinput.sap.SAPConnection)

Example 2 with SAPException

use of org.pentaho.di.trans.steps.sapinput.sap.SAPException 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)

Aggregations

SAPException (org.pentaho.di.trans.steps.sapinput.sap.SAPException)2 ArrayList (java.util.ArrayList)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 SAPField (org.pentaho.di.trans.steps.sapinput.sap.SAPField)1 SAPRow (org.pentaho.di.trans.steps.sapinput.sap.SAPRow)1 SAPRowIterator (org.pentaho.di.trans.steps.sapinput.sap.impl.SAPRowIterator)1