Search in sources :

Example 1 with SAPConnection

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

the class SapInputDialog method get.

private void get() {
    try {
        RowMetaInterface r = transMeta.getPrevStepFields(stepname);
        if (r != null && !r.isEmpty()) {
            TableItemInsertListener listener = new TableItemInsertListener() {

                public boolean tableItemInserted(TableItem tableItem, ValueMetaInterface v) {
                    tableItem.setText(2, "=");
                    return true;
                }
            };
            BaseStepDialog.getFieldsFromPrevious(r, wInput, 1, new int[] { 1, 3 }, new int[] {}, -1, -1, listener);
        }
        DatabaseMeta databaseMeta = transMeta.findDatabase(wConnection.getText());
        if (databaseMeta == null) {
            showDatabaseWarning(false);
            return;
        }
        // 
        if (function != null) {
            wFunction.setText(function.getName());
            if (wInput.nrNonEmpty() != 0 || wOutput.nrNonEmpty() != 0) {
                MessageBox mb = new MessageBox(shell, SWT.YES | SWT.NO | SWT.ICON_QUESTION);
                mb.setMessage(BaseMessages.getString(PKG, "SapInputDialog.ClearInputOutput.DialogMessage"));
                mb.setText(BaseMessages.getString(PKG, "SapInputDialog.ClearInputOutput.DialogTitle"));
                int answer = mb.open();
                if (answer == SWT.NO) {
                    return;
                }
            }
            wInput.clearAll(false);
            wOutput.clearAll(false);
            Cursor hourGlass = new Cursor(shell.getDisplay(), SWT.CURSOR_WAIT);
            SAPConnection sc = SAPConnectionFactory.create();
            try {
                shell.setCursor(hourGlass);
                sc.open(databaseMeta);
                SAPFunctionSignature signature = sc.getFunctionSignature(function);
                // Populate the input view
                // TODO: clean this up a bit, feels a bit messy
                // 
                int rownr = 0;
                for (SAPField field : signature.getInput()) {
                    TableItem item;
                    if (rownr == 0) {
                        item = wInput.table.getItem(0);
                    } else {
                        item = new TableItem(wInput.table, SWT.NONE);
                    }
                    rownr++;
                    SapType type = getSapType(field);
                    int colnr = 1;
                    item.setText(colnr++, Const.NVL(field.getName(), ""));
                    item.setText(colnr++, type == null ? "" : type.getDescription());
                    item.setText(colnr++, Const.NVL(field.getTable(), ""));
                    item.setText(colnr++, Const.NVL(field.getName(), ""));
                    item.setText(colnr++, field.getTypePentaho());
                }
                wInput.setRowNums();
                wInput.optWidth(true);
                // Get the output rows
                // 
                rownr = 0;
                for (SAPField field : signature.getOutput()) {
                    TableItem item;
                    if (rownr == 0) {
                        item = wOutput.table.getItem(0);
                    } else {
                        item = new TableItem(wOutput.table, SWT.NONE);
                    }
                    rownr++;
                    SapType type = getSapType(field);
                    int colnr = 1;
                    item.setText(colnr++, Const.NVL(field.getName(), ""));
                    item.setText(colnr++, type == null ? "" : type.getDescription());
                    item.setText(colnr++, Const.NVL(field.getTable(), ""));
                    item.setText(colnr++, Const.NVL(field.getName(), ""));
                    item.setText(colnr++, field.getTypePentaho());
                }
                wOutput.setRowNums();
                wOutput.optWidth(true);
            } catch (Exception e) {
                throw new KettleException(e);
            } finally {
                sc.close();
                shell.setCursor(null);
                hourGlass.dispose();
            }
        }
    } catch (KettleException ke) {
        new ErrorDialog(shell, BaseMessages.getString(PKG, "SapInputDialog.GetFieldsFailed.DialogTitle"), BaseMessages.getString(PKG, "SapInputDialog.GetFieldsFailed.DialogMessage"), ke);
    }
}
Also used : SAPFunctionSignature(org.pentaho.di.trans.steps.sapinput.sap.SAPFunctionSignature) KettleException(org.pentaho.di.core.exception.KettleException) TableItemInsertListener(org.pentaho.di.ui.trans.step.TableItemInsertListener) SAPConnection(org.pentaho.di.trans.steps.sapinput.sap.SAPConnection) TableItem(org.eclipse.swt.widgets.TableItem) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) Cursor(org.eclipse.swt.graphics.Cursor) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) SAPR3DatabaseMeta(org.pentaho.di.core.database.sap.SAPR3DatabaseMeta) KettleException(org.pentaho.di.core.exception.KettleException) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) MessageBox(org.eclipse.swt.widgets.MessageBox) SAPField(org.pentaho.di.trans.steps.sapinput.sap.SAPField)

Example 2 with SAPConnection

use of org.pentaho.di.trans.steps.sapinput.sap.SAPConnection 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 3 with SAPConnection

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

Example 4 with SAPConnection

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

the class SapFunctionBrowser method find.

protected void find(String searchString) {
    this.searchString = searchString;
    SAPConnection sc = null;
    try {
        sc = SAPConnectionFactory.create();
        sc.open(sapConnection);
        functionList = new ArrayList<SAPFunction>(sc.getFunctions(searchString));
    } catch (Exception e) {
        new ErrorDialog(shell, BaseMessages.getString(PKG, "SapFunctionBrowser.ExceptionDialog.ErrorDuringSearch.Title"), BaseMessages.getString(PKG, "SapFunctionBrowser.ExceptionDialog.ErrorDuringSearch.Message"), e);
    } finally {
        if (sc != null) {
            sc.close();
        }
    }
}
Also used : SAPFunction(org.pentaho.di.trans.steps.sapinput.sap.SAPFunction) SAPConnection(org.pentaho.di.trans.steps.sapinput.sap.SAPConnection) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog)

Aggregations

SAPConnection (org.pentaho.di.trans.steps.sapinput.sap.SAPConnection)4 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)2 SAPR3DatabaseMeta (org.pentaho.di.core.database.sap.SAPR3DatabaseMeta)2 SAPField (org.pentaho.di.trans.steps.sapinput.sap.SAPField)2 SAPFunction (org.pentaho.di.trans.steps.sapinput.sap.SAPFunction)2 SAPFunctionSignature (org.pentaho.di.trans.steps.sapinput.sap.SAPFunctionSignature)2 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)2 Vector (java.util.Vector)1 Cursor (org.eclipse.swt.graphics.Cursor)1 MessageBox (org.eclipse.swt.widgets.MessageBox)1 TableItem (org.eclipse.swt.widgets.TableItem)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 SAPException (org.pentaho.di.trans.steps.sapinput.sap.SAPException)1 SAPResultSet (org.pentaho.di.trans.steps.sapinput.sap.SAPResultSet)1 SAPRow (org.pentaho.di.trans.steps.sapinput.sap.SAPRow)1 TableItemInsertListener (org.pentaho.di.ui.trans.step.TableItemInsertListener)1