ERP 2.50:Developers Guide/Concepts/Processes
Contents |
Process
A process is a systematic series of actions directed to some end. Typically a process receives some parameters and taking them into account performs some actions to obtain a result. Openbravo ERP define two main kind of process Java Processes and PL/SQL Processes.
All processes (as well as Reports) are managed from the same window: Application Dictionary || Report and Process.
Once a process is defined it can be added to the menu to be called directly from it, or it can be invoked through a button.
Parameters
When a process (PL/SQL or Java) or a Jasper Report is set as Standard UI Pattern a pop up is automatically generated to invoke it, this poup-up looks like:
Note that in this pop-up there is a section with information about the process, this information is obtained from the Help field in the Report and Process tab.
It also prompts for a number of parameters, and finally there are two buttons, OK to start the process and Cancel to close the pop up and do not do nothing else. In case the process did not require any parameter that section would be empty.
When this kind of process require parameters they must be defined in Application Dictionary || Report and Process || Report & Process >> Parameter tab.
Parameters are defined in a very similar way than columns are, depending on the Reference the parameter is assigned the generated UI for it will be different.
Let's overview some of the most important fields in this tab:
- DB Column name: This is the name the parameter will be passed with to the process. When the process is going to use this parameter it will have to use this name. Please notice that Postgresql is case-sensitive. In case the parameter references an existing column in database (for example, it is a parameter of type search), then the DB Column name must be cased the same way as the column in the AD.
- Sequence: It is a numeric value to order the parameter in the UI.
- Application Element: It is the Element that will be used to get the label from, in this way parameters are translatable. Note that it is also possible to set or not this element as Centrally Maintained.
- Reference, Reference Search Key and Validation: These three fields works exactly like the same ones when defining references for columns.
- Range: If it is checked UI will generate two parameters in order to define a range, the first parameter will be named as specified in DB Column name field and the second one will have the same name with a _TO suffix.
PL/SQL Processes
PL/SQL Processes are implemented by database stored procedures. For more information read the documentation on stored procedures.
Defining a PL/SQL process
PL/SQL processes are defined in Application Dictionary || Report and Process. The only field to take into account for this kind of processes is Procedure: It is the procedure name in database. Note that as PL/SQL procedures are assigned to modules, they must be named following the naming rules, this is: the name for the procedure must start with the module's DBPrefix.
As the UI for PL/SQL processes is always automatically generated, the UI Pattern field must be set as Standard.
In case the process requires any parameter is possible to define them, to learn more about how to do it read the section above.
Java Processes
It is possible to implement process with Java. They are also defined in Application Dictionary || Report and Process window. Depending on the UI pattern they use they can be split in Standard and Manual.
Standard UI Pattern
User interface to invoke Java processes with standard UI pattern is automatically generated in the same way the interface for PL/SQL processes is done.
Defining in Application Dictionary
To set a Java process to be have Standard UI just set the UI Pattern field to Standard in Application Dictionary || Report and Process || Report & Process tab. It is also necessary to indicate the class that is going to implement the process, this is done adding a new record in Process Class tab. At least, one record in this tab must be checked as default.
If the process requires parameters they can be defined in the Parameter tab as explained in the Parameters section of this document.
Java Implementation
The Java class implementing the process must extend the org.openbravo.scheduling.Process interface. This interface just defines a method:
public void execute(ProcessBundle bundle) throws Exception;
This method receives a ProcessBundle, this bundle contains all the parameters for the process. When the process finishes it must add a result to this bundle, this result is an OBError instance that will be shown in the UI.
Let's explain it using a little example:
package my.package; import org.openbravo.erpCommon.utility.OBError; import org.openbravo.scheduling.ProcessBundle; public class ImportClientProcess implements org.openbravo.scheduling.Process { public void execute(ProcessBundle bundle) throws Exception { try { //retrieve custom params final String myParam = (String) bundle.getParams().get("myParam"); // retrieve standard params final String recordID = (String) bundle.getParams().get("C_Order_ID"); final String clientID = (String) bundle.getParams().get("adClientID"); final String orgID = (String) bundle.getParams().get("adOrgId"); //Available from 2.50MP26 final String tabId = (String) bundle.getParams().get("tabId"); // implement your process here final OBError msg = new OBError(); msg.setType("Success"); msg.setTitle("Done"); msg.setMessage("Process finished correctly"); bundle.setResult(msg); } catch (final Exception e) { e.printStackTrace(System.err); final OBError msg = new OBError(); msg.setType("Error"); msg.setMessage(e.getMessage()); msg.setTitle("Error occurred"); bundle.setResult(msg); } } }
In this example a parameter named myParam is expected. It is read by the following line:
final String myParam = (String) bundle.getParams().get("myParam");
In the standard parameters section it is obtained the ID for the record that invoked the process (recordID variable), note that the name for this parameter is the same as the primary key column in the tab invoking it, in this case this process is called from a tab for C_Order table. It also obtains the client and organization for that record.
It is possible to retrieve the tab id the process was invoked from using the tabId parameter. (Available from 2.50MP26).
Once the process is finished a new OBError is created to handle the message and it is added as result to the bundle, for more information about message read the Message section in this document.
bundle.setResult(msg);
Manual UI Pattern
The difference between Standard and Manual UI pattern is that no UI is automatically generated for Manual UI pattern processes, in this case UI must be manually genereted by the class implementing the process.
Application Dictionary definition
Manual Java processes are defined in application dictionary in the same way Standard ones are. Additionally is necessary to include an entry in Process Mapping to make it accessible in the web.xml.
Java Implementation
Manual processes are implemented by a Java class extending org.openbravo.base.secureApp.HttpSecureAppServlet, this is a standard servlet that generates the UI.
Languages: |
ERP 2.50:Developers Guide/Concepts/Reports | ERP 2.50:Developers Guide/Concepts/WebServices