use of org.pentaho.di.trans.steps.sapinput.sap.SAPField 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.SAPField 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.SAPField 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;
}
use of org.pentaho.di.trans.steps.sapinput.sap.SAPField 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;
}
use of org.pentaho.di.trans.steps.sapinput.sap.SAPField 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