use of org.pentaho.di.trans.steps.sapinput.sap.SAPFunction in project pentaho-kettle by pentaho.
the class SapInputDialog method open.
public String open() {
Shell parent = getParent();
Display display = parent.getDisplay();
shell = new Shell(parent, SWT.DIALOG_TRIM | SWT.RESIZE | SWT.MAX | SWT.MIN);
props.setLook(shell);
setShellImage(shell, input);
if (!SAPLibraryTester.isJCoLibAvailable()) {
int style = SWT.ICON_ERROR;
MessageBox messageBox = new MessageBox(shell, style);
messageBox.setMessage(BaseMessages.getString(PKG, "SapInputDialog.JCoLibNotFound"));
messageBox.open();
// dispose();
// return stepname;
}
if (!SAPLibraryTester.isJCoImplAvailable()) {
int style = SWT.ICON_ERROR;
MessageBox messageBox = new MessageBox(shell, style);
messageBox.setMessage(BaseMessages.getString(PKG, "SapInputDialog.JCoImplNotFound"));
messageBox.open();
// dispose();
// return stepname;
}
ModifyListener lsMod = new ModifyListener() {
public void modifyText(ModifyEvent e) {
input.setChanged();
}
};
ModifyListener lsConnectionMod = new ModifyListener() {
public void modifyText(ModifyEvent e) {
input.setChanged();
}
};
backupChanged = input.hasChanged();
FormLayout formLayout = new FormLayout();
formLayout.marginWidth = Const.FORM_MARGIN;
formLayout.marginHeight = Const.FORM_MARGIN;
shell.setLayout(formLayout);
shell.setText(BaseMessages.getString(PKG, "SapInputDialog.shell.Title"));
int middle = props.getMiddlePct();
int margin = Const.MARGIN;
// Stepname line
wlStepname = new Label(shell, SWT.RIGHT);
wlStepname.setText(BaseMessages.getString(PKG, "SapInputDialog.Stepname.Label"));
props.setLook(wlStepname);
fdlStepname = new FormData();
fdlStepname.left = new FormAttachment(0, 0);
fdlStepname.right = new FormAttachment(middle, -margin);
fdlStepname.top = new FormAttachment(0, margin);
wlStepname.setLayoutData(fdlStepname);
wStepname = new Text(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
wStepname.setText(stepname);
props.setLook(wStepname);
wStepname.addModifyListener(lsMod);
fdStepname = new FormData();
fdStepname.left = new FormAttachment(middle, 0);
fdStepname.top = new FormAttachment(0, margin);
fdStepname.right = new FormAttachment(100, 0);
wStepname.setLayoutData(fdStepname);
Control lastControl = wStepname;
// Connection line
//
wConnection = addConnectionLine(shell, lastControl, middle, margin);
List<String> items = new ArrayList<String>();
for (DatabaseMeta dbMeta : transMeta.getDatabases()) {
if (dbMeta.getDatabaseInterface() instanceof SAPR3DatabaseMeta) {
items.add(dbMeta.getName());
}
}
wConnection.setItems(items.toArray(new String[items.size()]));
if (input.getDatabaseMeta() == null && transMeta.nrDatabases() == 1) {
wConnection.select(0);
}
wConnection.addModifyListener(lsConnectionMod);
lastControl = wConnection;
// Function
//
wlFunction = new Label(shell, SWT.RIGHT);
wlFunction.setText(BaseMessages.getString(PKG, "SapInputDialog.Function.Label"));
props.setLook(wlFunction);
FormData fdlFunction = new FormData();
fdlFunction.left = new FormAttachment(0, 0);
fdlFunction.right = new FormAttachment(middle, -margin);
fdlFunction.top = new FormAttachment(lastControl, margin);
wlFunction.setLayoutData(fdlFunction);
wbFunction = new Button(shell, SWT.PUSH);
props.setLook(wbFunction);
wbFunction.setText(BaseMessages.getString(PKG, "SapInputDialog.FindFunctionButton.Label"));
FormData fdbFunction = new FormData();
fdbFunction.right = new FormAttachment(100, 0);
fdbFunction.top = new FormAttachment(lastControl, margin);
wbFunction.setLayoutData(fdbFunction);
wbFunction.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
getFunction();
}
});
wFunction = new Text(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
props.setLook(wFunction);
wFunction.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
function = new SAPFunction(((Text) e.widget).getText());
input.setChanged();
}
});
FormData fdFunction = new FormData();
fdFunction.left = new FormAttachment(middle, 0);
fdFunction.right = new FormAttachment(wbFunction, -margin);
fdFunction.top = new FormAttachment(lastControl, margin);
wFunction.setLayoutData(fdFunction);
lastControl = wFunction;
// The parameter input fields...
//
wlInput = new Label(shell, SWT.NONE);
wlInput.setText(BaseMessages.getString(PKG, "SapInputDialog.Input.Label"));
props.setLook(wlInput);
FormData fdlInput = new FormData();
fdlInput.left = new FormAttachment(0, 0);
fdlInput.top = new FormAttachment(lastControl, margin);
wlInput.setLayoutData(fdlInput);
ColumnInfo[] ciKey = new ColumnInfo[] { new ColumnInfo(BaseMessages.getString(PKG, "SapInputDialog.ColumnInfo.Field"), ColumnInfo.COLUMN_TYPE_CCOMBO, new String[] { "" }, false), new ColumnInfo(BaseMessages.getString(PKG, "SapInputDialog.ColumnInfo.SAPType"), ColumnInfo.COLUMN_TYPE_CCOMBO, SapType.getDescriptions()), new ColumnInfo(BaseMessages.getString(PKG, "SapInputDialog.ColumnInfo.TableOrStruct"), ColumnInfo.COLUMN_TYPE_TEXT, false, false), new ColumnInfo(BaseMessages.getString(PKG, "SapInputDialog.ColumnInfo.SAPParameterName"), ColumnInfo.COLUMN_TYPE_TEXT, false, false), new ColumnInfo(BaseMessages.getString(PKG, "SapInputDialog.ColumnInfo.TargetType"), ColumnInfo.COLUMN_TYPE_CCOMBO, ValueMeta.getTypes()) };
inputFieldColumns.add(ciKey[0]);
wInput = new TableView(transMeta, shell, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL, ciKey, input.getParameters().size(), lsMod, props);
FormData fdInput = new FormData();
fdInput.left = new FormAttachment(0, 0);
fdInput.top = new FormAttachment(wlInput, margin);
fdInput.right = new FormAttachment(100, 0);
fdInput.bottom = new FormAttachment(40, 0);
wInput.setLayoutData(fdInput);
lastControl = wInput;
// THE BUTTONS
wOK = new Button(shell, SWT.PUSH);
wOK.setText(BaseMessages.getString(PKG, "System.Button.OK"));
// wPreview = new Button(shell, SWT.PUSH);
// wPreview.setText(BaseMessages.getString(PKG, "System.Button.Preview"));
wGet = new Button(shell, SWT.PUSH);
wGet.setText(BaseMessages.getString(PKG, "SapInputDialog.GetFields.Button"));
wCancel = new Button(shell, SWT.PUSH);
wCancel.setText(BaseMessages.getString(PKG, "System.Button.Cancel"));
wAbout = new Button(shell, SWT.PUSH);
wAbout.setText(BaseMessages.getString(PKG, "SapInputDialog.About.Button"));
// Preview not possible without inputRowSets in BaseStep.getRow()
// setButtonPositions(new Button[] { wOK, wPreview, wAbout , wGet, wCancel}, margin, null);
setButtonPositions(new Button[] { wOK, wAbout, wGet, wCancel }, margin, null);
// The output fields...
//
wlOutput = new Label(shell, SWT.NONE);
wlOutput.setText(BaseMessages.getString(PKG, "SapInputDialog.Output.Label"));
props.setLook(wlOutput);
FormData fdlOutput = new FormData();
fdlOutput.left = new FormAttachment(0, 0);
fdlOutput.top = new FormAttachment(wInput, margin);
wlOutput.setLayoutData(fdlOutput);
ColumnInfo[] ciReturn = new ColumnInfo[] { new ColumnInfo(BaseMessages.getString(PKG, "SapInputDialog.ColumnInfo.SAPField"), ColumnInfo.COLUMN_TYPE_CCOMBO, new String[] {}, false), new ColumnInfo(BaseMessages.getString(PKG, "SapInputDialog.ColumnInfo.SAPType"), ColumnInfo.COLUMN_TYPE_CCOMBO, SapType.getDescriptions(), false), new ColumnInfo(BaseMessages.getString(PKG, "SapInputDialog.ColumnInfo.TableOrStruct"), ColumnInfo.COLUMN_TYPE_TEXT, false), new ColumnInfo(BaseMessages.getString(PKG, "SapInputDialog.ColumnInfo.NewName"), ColumnInfo.COLUMN_TYPE_TEXT, false), new ColumnInfo(BaseMessages.getString(PKG, "SapInputDialog.ColumnInfo.TargetType"), ColumnInfo.COLUMN_TYPE_CCOMBO, ValueMeta.getTypes()) };
outputFieldColumns.add(ciReturn[0]);
wOutput = new TableView(transMeta, shell, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL, ciReturn, input.getOutputFields().size(), lsMod, props);
FormData fdOutput = new FormData();
fdOutput.left = new FormAttachment(0, 0);
fdOutput.top = new FormAttachment(wlOutput, margin);
fdOutput.right = new FormAttachment(100, 0);
fdOutput.bottom = new FormAttachment(wOK, -8 * margin);
wOutput.setLayoutData(fdOutput);
lastControl = wOutput;
this.wAscLink = new Link(this.shell, SWT.NONE);
FormData fdAscLink = new FormData();
fdAscLink.left = new FormAttachment(0, 0);
fdAscLink.top = new FormAttachment(wOutput, margin);
wAscLink.setLayoutData(fdAscLink);
this.wAscLink.setText(BaseMessages.getString(PKG, "SapInputDialog.Provided.Info"));
lastControl = wAscLink;
// Add listeners
lsOK = new Listener() {
public void handleEvent(Event e) {
ok();
}
};
lsPreview = new Listener() {
public void handleEvent(Event e) {
preview();
}
};
lsGet = new Listener() {
public void handleEvent(Event e) {
get();
}
};
lsCancel = new Listener() {
public void handleEvent(Event e) {
cancel();
}
};
Listener lsAbout = new Listener() {
public void handleEvent(Event e) {
about();
}
};
wOK.addListener(SWT.Selection, lsOK);
// wPreview.addListener(SWT.Selection, lsPreview);
wGet.addListener(SWT.Selection, lsGet);
wCancel.addListener(SWT.Selection, lsCancel);
this.wAbout.addListener(SWT.Selection, lsAbout);
this.wAscLink.addListener(SWT.Selection, new Listener() {
public void handleEvent(final Event event) {
Program.launch(event.text);
}
});
lsDef = new SelectionAdapter() {
public void widgetDefaultSelected(SelectionEvent e) {
ok();
}
};
wStepname.addSelectionListener(lsDef);
wFunction.addSelectionListener(lsDef);
// Detect X or ALT-F4 or something that kills this window...
shell.addShellListener(new ShellAdapter() {
public void shellClosed(ShellEvent e) {
cancel();
}
});
getData();
// Set the shell size, based upon previous time...
setSize();
input.setChanged(backupChanged);
setComboValues();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
return stepname;
}
use of org.pentaho.di.trans.steps.sapinput.sap.SAPFunction in project pentaho-kettle by pentaho.
the class SapInputMeta method readData.
private void readData(Node stepnode, List<? extends SharedObjectInterface> databases) throws KettleXMLException {
try {
databaseMeta = DatabaseMeta.findDatabase(databases, XMLHandler.getTagValue(stepnode, "connection"));
String functionName = XMLHandler.getTagValue(stepnode, XML_TAG_FUNCTION, "name");
String functionDescription = XMLHandler.getTagValue(stepnode, XML_TAG_FUNCTION, "description");
String functionGroup = XMLHandler.getTagValue(stepnode, XML_TAG_FUNCTION, "group");
String functionApplication = XMLHandler.getTagValue(stepnode, XML_TAG_FUNCTION, "application");
String functionHost = XMLHandler.getTagValue(stepnode, XML_TAG_FUNCTION, "host");
if (!Utils.isEmpty(functionName)) {
function = new SAPFunction(functionName, functionDescription, functionGroup, functionApplication, functionHost);
} else {
function = null;
}
Node paramsNode = XMLHandler.getSubNode(stepnode, XML_TAG_PARAMETERS);
int nrParameters = XMLHandler.countNodes(paramsNode, XML_TAG_PARAMETER);
for (int i = 0; i < nrParameters; i++) {
Node paramNode = XMLHandler.getSubNodeByNr(paramsNode, XML_TAG_PARAMETER, i);
String fieldName = XMLHandler.getTagValue(paramNode, "field_name");
SapType sapType = SapType.findTypeForCode(XMLHandler.getTagValue(paramNode, "sap_type"));
String tableName = XMLHandler.getTagValue(paramNode, "table_name");
int targetType = ValueMeta.getType(XMLHandler.getTagValue(paramNode, "target_type"));
String parameterName = XMLHandler.getTagValue(paramNode, "parameter_name");
parameters.add(new SapParameter(fieldName, sapType, tableName, parameterName, targetType));
}
Node fieldsNode = XMLHandler.getSubNode(stepnode, XML_TAG_FIELDS);
int nrFields = XMLHandler.countNodes(fieldsNode, XML_TAG_FIELD);
for (int i = 0; i < nrFields; i++) {
Node fieldNode = XMLHandler.getSubNodeByNr(fieldsNode, XML_TAG_FIELD, i);
String sapFieldName = XMLHandler.getTagValue(fieldNode, "field_name");
SapType sapType = SapType.findTypeForCode(XMLHandler.getTagValue(fieldNode, "sap_type"));
String tableName = XMLHandler.getTagValue(fieldNode, "table_name");
int targetType = ValueMeta.getType(XMLHandler.getTagValue(fieldNode, "target_type"));
String newName = XMLHandler.getTagValue(fieldNode, "new_name");
outputFields.add(new SapOutputField(sapFieldName, sapType, tableName, newName, targetType));
}
} catch (Exception e) {
throw new KettleXMLException("Unable to load step info from XML", e);
}
}
use of org.pentaho.di.trans.steps.sapinput.sap.SAPFunction in project pentaho-kettle by pentaho.
the class SapInputMeta method readRep.
public void readRep(Repository rep, IMetaStore metaStore, ObjectId id_step, List<DatabaseMeta> databases) throws KettleException {
try {
databaseMeta = rep.loadDatabaseMetaFromStepAttribute(id_step, "id_connection", databases);
String functionName = rep.getStepAttributeString(id_step, "function_name");
String functionDescription = rep.getStepAttributeString(id_step, "function_description");
String functionGroup = rep.getStepAttributeString(id_step, "function_group");
String functionApplication = rep.getStepAttributeString(id_step, "function_application");
String functionHost = rep.getStepAttributeString(id_step, "function_host");
if (!Utils.isEmpty(functionName)) {
function = new SAPFunction(functionName, functionDescription, functionGroup, functionApplication, functionHost);
} else {
function = null;
}
int nrParameters = rep.countNrStepAttributes(id_step, "parameter_field_name");
for (int i = 0; i < nrParameters; i++) {
String fieldName = rep.getStepAttributeString(id_step, i, "parameter_field_name");
SapType sapType = SapType.findTypeForCode(rep.getStepAttributeString(id_step, i, "parameter_sap_type"));
String tableName = rep.getStepAttributeString(id_step, i, "parameter_table_name");
int targetType = ValueMeta.getType(rep.getStepAttributeString(id_step, i, "parameter_target_type"));
String parameterName = rep.getStepAttributeString(id_step, i, "parameter_name");
parameters.add(new SapParameter(fieldName, sapType, tableName, parameterName, targetType));
}
int nrFields = rep.countNrStepAttributes(id_step, "field_sap_field_name");
for (int i = 0; i < nrFields; i++) {
String sapFieldName = rep.getStepAttributeString(id_step, i, "field_sap_field_name");
SapType sapType = SapType.findTypeForCode(rep.getStepAttributeString(id_step, i, "field_sap_type"));
String tableName = rep.getStepAttributeString(id_step, i, "field_table_name");
int targetType = ValueMeta.getType(rep.getStepAttributeString(id_step, i, "field_target_type"));
String newName = rep.getStepAttributeString(id_step, i, "field_new_name");
outputFields.add(new SapOutputField(sapFieldName, sapType, tableName, newName, targetType));
}
} catch (Exception e) {
throw new KettleException("Unexpected error reading step information from the repository", e);
}
}
use of org.pentaho.di.trans.steps.sapinput.sap.SAPFunction 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();
}
use of org.pentaho.di.trans.steps.sapinput.sap.SAPFunction 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();
}
}
}
Aggregations