use of org.pentaho.di.trans.steps.sapinput.sap.SAPFunctionSignature 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);
}
}
use of org.pentaho.di.trans.steps.sapinput.sap.SAPFunctionSignature in project pentaho-kettle by pentaho.
the class SAPConnectionMock method getFunctionSignature.
public SAPFunctionSignature getFunctionSignature(SAPFunction function) throws SAPException {
SAPFunctionSignature sfs = new SAPFunctionSignature();
if (function.getName().equalsIgnoreCase("SearchCustomer")) {
sfs.addInput(new SAPField("Name", "", "input_single"));
sfs.addInput(new SAPField("Zipcode", "", "input_single"));
sfs.addOutput(new SAPField("Name", "", "output_single"));
sfs.addOutput(new SAPField("Firstname", "", "output_single"));
sfs.addOutput(new SAPField("Adress", "", "output_single"));
sfs.addOutput(new SAPField("Zipcode", "", "output_single"));
sfs.addOutput(new SAPField("CustomerGroup", "", "output_single"));
} else {
sfs.addInput(new SAPField("Field1", "", "input_single"));
sfs.addInput(new SAPField("Field2", "", "input_single"));
sfs.addInput(new SAPField("Field3", "", "input_single"));
sfs.addOutput(new SAPField("Field4", "", "output_single"));
sfs.addOutput(new SAPField("Field5", "", "output_single"));
sfs.addOutput(new SAPField("Field6", "", "output_single"));
}
//
try {
Thread.sleep(1500);
} catch (InterruptedException e) {
/* Ignore */
}
return sfs;
}
use of org.pentaho.di.trans.steps.sapinput.sap.SAPFunctionSignature 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();
}
Aggregations