Aug 16, 2011

Retrieving Openbravo properties in DAL code

by Shankar Balachandran
Openbravo.properties is the configuration page in which we specify the source folder, the database configuration and many other configuration parameters. For more information on Openbravo.properties configuration, refer here.


There will be many cases where we will need the values of the parameters configured in the Openbravo.properties. Few cases are.
  1. When you have a native jdbc connectivity code and you do not want to change that, but bring that under a DAL code.
  2. When you have attached a file to a record and want to process that using the actual file path.
  3. When you need your current database name. 
  4. When you need your current database parameters like URL, username,password, etc
  5. When you want the current context name using which the instance will be accessed.
Now lets see how we can access the Openbravo.properties in DAL code.
  1. Import the package  org.openbravo.base.session.OBPropertiesProvider.
  2. Use the getProperty(property name) method on the OBPropertiesProvider
  3. Pass the name of the parameter whose value you require to the getProperty() method.
 Provided below is a sample code to retrieve the source path, database name, URL, database user name and database password.
package com.fugoconsulting.XXX.erpCommon.ad_process;

import org.apache.log4j.*;
import org.openbravo.erpCommon.utility.OBError;
import org.openbravo.scheduling.ProcessBundle;
import org.openbravo.dal.service.OBQuery;
import org.openbravo.dal.service.OBDal;
import org.openbravo.dal.core.SessionHandler;
import org.openbravo.base.session.OBPropertiesProvider;

/**
 *
 * @author shankar
 */
public class ImportFile implements
DalBaseProcess{

  private static Logger log=Logger.getLogger(ImportFile.class);
    
  public void execute(ProcessBundle bundle) throws Exception {
    try{      
      String RecordId=(String) bundle.getParams().get("XXX_Import_ID");
      log.info("Record ID "+RecordId);
      String sourcepath=        OBPropertiesProvider.getInstance().getOpenbravoProperties().getProperty("source.path");
      String dburl= OBPropertiesProvider.getInstance().getOpenbravoProperties().getProperty("bbdd.url");
      String database = OBPropertiesProvider.getInstance().getOpenbravoProperties().getProperty("bbdd.sid");
      String systemUser = OBPropertiesProvider.getInstance().getOpenbravoProperties().getProperty("bbdd.systemUser");
      String systemPassword = OBPropertiesProvider.getInstance().getOpenbravoProperties().getProperty("bbdd.systemPassword");

   }
   catch(Exception e){
   }
}
Happy Working...     



Jul 7, 2011

Retrieving last changed value in Openbravo Callout

by Shankar Balachandran
Callout in Openbravo is the feature that enables us to do runtime operations with the data. Callout is generally attached to a field and triggered in the onchange event. Openbravo has implemented a java class file called SimpleCallout.java, that we can extend and use it for implementing Callouts. For more information on implementing callouts, refer here and here.
As Callouts are attached to a field, you can use the field name with the prefix 'inp' to retrieve the run time value. Based upon that, you can do manipulations. But using this method, restrict the usage of that callout to a particular field. Say for instance I have a same logic to be implemented across five different fields, then I have to write 5 different callout, as we are hard coding the field names. But there is also a method provided to retrieve the last changed field and then using that, you can retrieve that value.
I have provided below the code, that retrieves the name of the last changed field and then the value of the corresponding field.

package com.fugoconsulting.xxx.erpCommon.ad_callout;
import javax.servlet.ServletException;
import java.util.*;
import java.lang.*;
import org.openbravo.utils.FormatUtilities;
import org.apache.log4j.Logger;
import org.hibernate.criterion.Expression;
import org.openbravo.erpCommon.ad_callouts.SimpleCallout;
import org.openbravo.base.secureApp.VariablesSecureApp;
import org.openbravo.dal.service.OBDal;
public class NameValidation extends SimpleCallout {
private static final long serialVersionUID = 1L;
private static Logger log = Logger.getLogger(NameValidation.class);
@Override
protected void execute(CalloutInfo info) throws ServletException {
//Gets the last changed field
String lastChanged = info.getStringParameter("inpLastFieldChanged",null);
int length = lastChanged.length();
//Gets the value of the last changed field
String lastChangedValue = info.getStringParameter(lastChanged,null);
log.info("Last field changed:"+lastChanged);
log.info("Last field length:"+length);
}
}
 Happy Working...



Jun 10, 2011

Creating Charts in Openbravo Reports

by Shankar Balachandran

                Reporting is a decisive factor that determines the reach of an ERP among the Users. OpenbravoERP in particular have laid a lot of emphasis on the reporting structures. iReport is the tool officially supported by Openbravo for generating reports within Openbravo.For basic on developing reports in iReport, refer here. You can download iReport here.

                   iReport is an opensource java based reporting tool. iReport provides lots of features like sub-reports,crosstab references, and various presentation gadgets like charts, bar graph, plotted line, etc. I have provided the steps for creating charts in reports in Openbravo.

Lets see an example. I have 10 product categories and 500 products. I want to see which products fall under which category and how much is the stock available. Lets see how this could look.
 If you have not worked in iReports before, you can take a look at this. You can download iReport here. To add a chart to a window, use the chart tool icon in the interface. A screen shot of where it is located is provided below:


                                                   Once you have added the chart, you can access the chart properties as provided in the below screen shot.



                              In the chart properties, go to chart data -> details. Here you can add the categories based upon which you want the data. Here I have added the category as product Category and the series values in terms of the products in that particular category. Here the following key points to be noted are:

1. Series Expression:
This represents the bars that appears on the chart. Here we want all the products with the count. so we choose the products here.

2. Category Expression:
This represents the  x-axis. Here the product category is our base and we provide that here.

3. Value Expression
Value is nothing but the quantity that determines the height of the bars in the report. Here we are providing the count of each product.

4. Label Expression (optional)
This provides the additional information about the bars in the chart that is provided under the chart. If its left empty, the name from the value expression will be pulled up.



Once all this is done, refer to the steps to import the same in the Openbravo Application and if you run the report, you will get the following output.


There are three presentation output types provided by Openbravo. You can use that by defining a parameter called output type. This will help us to view the report as Html, Excel, PDF. Note that when you are using charts or any images like these, it will come properly only in PDF or Excel view. The html view may not present the image.

Having presented all this, generating reports in this format is really helpful. However Openbravo has now become the agile, tamed ERP...:). There is a new and powerful feature called widgets. You can gather more information about it here.



May 27, 2011

Understanding OBDal in Openbravo

by Shankar Balachandran

OBDal is an extensively used class in Openbravo. If offers lots of useful functions to enable external access to the Data Access Layer. OBDal provides the basic functions like insert,save,remove, etc. OBDal forms the base for the Data Access Layer(DAL) in Openbravo.
DAL Architecture
Though there are lots of useful functions in OBDal, we often use only few basic functions like save, remove, etc. Lets see the use of  the methods in OBDal and its usage.
1. void commitAndClose():
This function commits the transaction and closes the transaction. It will not only commit the current transaction but all the pending transactions. However, having more than one open transactions at a time is not advisable. There are few reasons why we should not have more than one open transactions. One of the reason is, if one of the open transactions failed to commit, all the pending transactions will be rolled back. This can be used in the code as follows.
OBDal.getInstance().commitAndClose();
There may be situations where we still need the transaction but just commit it. But when we use this method, it will not only commit but also closes the transaction. In this scenario, we can make use of the class SessionHandler( This class is exclusively for maintaining hibernate session for transactions). This class has a method commitAndStart(). This method will commit the transaction and starts a new session. This can be used in the code as follows.
SessionHandler.getInstance().commitAndStart();
2. void rollbackAndClose()
This method is used to rollback the transaction. Similar to commitAndClose() Method, this method will rollback all the open transactions.
OBDal.getInstance().rollbackAndClose();
The SessionHandler has a method rollback() which can be used when we don't want to close the session but rollback the transaction.
SessionHandler.getInstance().rollback();
The SessionHandler class has two other methods that enables us to mark the transactions that needs to be rolled back. This can be done using the method, void setDoRollback(boolean). If the argument is true, then the transaction will be marked for rollback and if it is false, the transaction will not be marked for rollback. The other method is boolean getDoRollback() which will return whether the transaction is marked for rollback or not.
SessionHandler.getInstance().setDoRollback(true);
SessionHandler.getInstance().getDoRollback();
3. void disableActiveFilter() and void enableActiveFilter()
By default, the active filters will be enabled. Consider the line below.
Client clientList = OBDal.getInstance().get(Client.class,null); //Client is the class which we are referring and null denotes there is no filter
This will return all the records in ad_client  table that are active. We can disable this by using the method disableActiveFilter(). After disabling, the above line will return all the records irrespective of either the record is active or not. enableActiveFilter() is used to enable the filter. This methods can be used as follows.
OBDal.getInstance().disableActiveFilter();
Client clientList = OBDal.getInstance().get(Client.class,null);
for(Client client : clientList.list()) {
//Processing
}
OBDal.getIstance().enableActiveFilter();
4. boolean isActiveFilterEnabled()
This method is used to verify whether the active filter is enabled or not. At any point of time, the active filter can be enabled and disabled and this method is useful to verify the status.
if(OBDal.getInstance().isActiveFilterEnabled()) {
OBDal.getInstance().disableActiveFilter();
}
5. boolean exists(String entityName, Object id)
This method is used to check whether a particular record exists in the database.

OBDal.getInstance().exists(ADClient,"0");//ADClient is the entity name for Client Class and "0" refers to ad_client_id
To understand the use of this method, consider the code below.
Client clientList = OBDal.getInstance().get(Client.class,"45");
try {
String name = clientList.getName();
} catch(Exception e) {
log.info(e.getMessage());
}
In the above code, if the record with ad_client_id = "45" doesn't exists, it will throw java.lang.NullPointerException since we are trying to access the value(clientList.getName()). To avoid this, we can use exists() method as follows.
Client clientList = OBDal.getInstance().get(Client.class,"45");
if(clientList.getInstance().exists(ADClient,"45"))  {
try {
String name = clientList.getName();
} catch(Exception e) {
log.info(e.getMessage());
}
The above code will be executed only if the record is present in the database.
6. String getReadableClientsInClause() & String getReadableOrganizationsInClause()
This method returns an in-clause string of the clients that are readable by the current user. The In-Clause String looks like ("0","1000000"). This method is useful in many scenarios. Below is one such scenario.
While retrieving the records using OBDal, it will automatically take care of the security. However, when we use HQL Queries, we need to take care of the security. In order to retrieve the client and organization readable by the user, we can use this method.
For example,
String hql = "SELECT name  "
+"FROM ADRole r"
+"WHERE r.organization IN "+OBDal.getInstance().getReadableOrganizationsInClause()
+" AND r.client IN "+OBDal.getInstance().getReadableClientsInClause()
+" AND r.active=true ";
Query query = OBDal.getInstance().getSession().createQuery(hql);
This query will return the name of the roles that are readable for the current user.
These are few methods that I felt important in OBDal that would ease development using DAL. For details on how to write DAL code, refer ([1] and [2]).



May 25, 2011

Postgresql database configuration for global access

by Shankar Balachandran

Openbravo ERP supports  couple of database like Oracle and PostgreSql. But my inclination is for PostgreSql database, because it is Opensource, and has almost all features of an Enterprise level RDBMS (Relational Database Management System). For more information on PostgreSql, refer here. For installation of PostgreSql on Ubuntu, refer here and for Windows, you can download from here. You can also refer a more expanded version of the same from here.
Installing PostgreSql is pretty easy and there is tool pgAdmin that will further simplify the use of the database. By default, PostgreSql will be mapped to your localhost, but for accessing it across Systems and for connecting to other PostgreSql database listening across various Systems, couple of configurations are to be done. I have presented the configuration steps in Ubuntu and it is nearly the same in Windows machine also. Just that the folders will be little different.
Step 1 : Modifying pg_hba.conf
  • Type the following commands in the Terminal.
1cd /etc/postgresql/8.4/main/
2
3sudo gedit pg_hba.conf
  • This will open the pg_hba.conf configuration file in text editor. The pg_hba.conf file controls which hosts are allowed to connect, how clients are authenticated, which PostgreSql user names they can use, which databases they can access. There will be values like,
1HOST       DATABASE  USER  CIDR-ADDRESS  METHOD  [OPTIONS]
  • In the Method, the values will be ident by default. We have to change all ‘ident’ to ‘md5′ because md5 sends encrypted passwords.
  • Under the heading IPV4 local connections, we should add rows for IP values that can be connected to our System. For that we have to provide the IP addresses that we want to connect. By default, the value will be 127.0.0.1/32 which is the localhost. If we provide 0.0.0.0/0 it will be available for connections to all Systems.
  • Though the connections are available for all Systems, you have to map which addresses the database should listen on. This is configured in postgresql.conf. That configuration is presented below.
Step 2: Modifying postgresql.conf
  • Type the following commands in the Terminal.
    • sudo gedit pg_hba.conf
    • This configuration file is read on server startup and when the server receives a SIGHUP signal.  If you edit the file on a running system, you have to SIGHUP the server for the changes to take effect, or use “pg_ctl reload”.
    • Under Connection Settings, there will be  a value for Listen Address. This provides us the information about what IP address(es) to listen on.
    • By default this value will be, listen_addresses = ‘localhost’, we have to modify it to listen_addresses = ‘*’.There will be  ’#’ before this line. # character is used for commenting. So for this changes to take place, you have to uncomment it by removing the ‘#’ character.
    You have to restart the PostgreSql database for these changes to take effect. Keep me posted here, if you have any doubts in this regard.
    Happy Working..:)



    May 16, 2011

    Tree Structure for Custom Windows in Openbravo

    by Shankar Balachandran
    Generating Tree Structure is a great innovative feature that is present in OpenbravoERP. If you are wondering what it looks like, refer to Organization window in the Client Mode or the Menu Window in System Admin mode. There will be an icon called Tree in the Toolbar. Click on that and you will see something similar to the screen shot below.
    This functionality will find its use in most places where there is a hierarchy to be shown and segregations are to be visualized. One more appreciably feature is that you can drag and drop the items and rearrange it. Doesn’t it sound really cool to you? I was really excited to test this out for the custom windows and with the help of Wiki, Forge and of course my colleague, I was able to create a tree similar to the one shown above for a custom window called ‘Department’. I have attached a screen shot of my tree below.
    This feature is really helpful in lot of cases. I have shared the sequence of steps that I followed that enabled me to create such a structure.
    1.    Create a new table for storing the tree nodes. Eg: XYZ_treenodedp
    2.    Add logic in the Department Table to insert values in XYZ_treenodedp and the corresponding delete logic also. Refer Organisation table trigger for more information.
    3.    Add a new entry in the list reference ad_treetype. Eg: Search key: XYZ_DP Name: Department
    4.    Create a new entry in Tree and Node Image window both in System administrator and desired client admin. Eg. Name: Primary Department Tree type: Department in System Administrator and Name: F&B International Admin Department Tree Type: Department in F&B International Admin.
    5.    Add a new column in ad_clientinfo. Eg: em_XYZ_tree_department
    6.    Update and set the value for the em_XYZ_tree_department field as the client's tree entry. Eg: In F&B International Admin, Set the value as 'F&B International Admin Department.
    7.    Set the field 'Tree Included' to Yes in Fields Tab. Eg: In Department window
    8.    Modify the following files.
    8.1    src/org/openbravo/erpCommon/utility/WindowTreeUtility.java
    8.2    src/org/openbravo/erpCommon/utility/WindowTree_data.xsql
    8.3    src/org/openbravo/erpCommon/utility/WindowTreeChecks.java
    Make the following Modifications
    • In WindowTreeUtility.java, add the following lines in checkSpecificChanges() Method.
    else if (TreeType.equals("XYZ_DP")) { //Department
    result = "";
    }
    In WindowTreeUtility.java, add the following lines in getTreeType() Method.
    else if (keyColumnName.equals("XYZ_Department_ID"))
    TreeType = "XYZ_DP";
     In WindowTreeUtility.java, add the following lines in getTree() Method.
    else if (TreeType.equals("XYZ_DP"))
    data = WindowTreeData.selectDepartment(conn, vars.getUser(), strEditable, strParentID,  strNodeId, TreeID);
    • In WindowTreeUtility.java, add the following lines in setNode() Method.

    else if (TreeType.equals("XYZ_DP"))
    WindowTreeData.updateDP(conn, vars.getUser(), strParentID, strSeqNo, TreeID, strLink);
    •  In WindowTree_data.xsql, add two new sql methods to select and update the tree nodes.
    <SqlMethod name="updateDP" type="preparedStatement" return="rowCount">
    <SqlMethodComment></SqlMethodComment>
    <Sql>
    UPDATE XYZ_TREENODEDP SET UPDATED=now(), UPDATEDBY = ?,                 PARENT_id = ?, SEQNO=TO_NUMBER(?)   WHERE AD_TREE_ID = ?
    AND NODE_ID = ?
    </Sql>
    <Parameter name="updatedby"/>
    <Parameter name="parentId"/>
    <Parameter name="seqno"/>
    <Parameter name="adTreeId"/>
    <Parameter name="nodeId"/>
    </SqlMethod>
    <SqlMethod name="selectDepartment" type="preparedStatement" return="multiple">
    <SqlMethodComment></SqlMethodComment>
    <Sql>
    SELECT tn.Node_ID,tn.Parent_ID,tn.SeqNo,tb.IsActive,                             m.XYZ_Department_ID AS ID, m.Name,m.Description,m.IsSummary
    FROM XYZ_TreeNodedp tn left join AD_TreeBar tb on                         tn.AD_Tree_ID=tb.AD_Tree_ID
    AND tn.Node_ID=tb.Node_ID
    AND tb.AD_User_ID  = ? ,
    XYZ_Department m
    WHERE tn.Node_ID = m.XYZ_Department_ID
    AND tn.AD_Tree_ID = ?
    ORDER BY COALESCE(tn.Parent_ID, '-1'), tn.SeqNo
    </Sql>
    <Parameter name="adUserId"/>
    <Parameter name="editable" optional="true" type="none" after="WHERE "                 text="tn.IsActive='Y' AND m.isActive='Y' AND "/>
    <Parameter name="parentId" optional="true" after="WHERE " text="tn.Parent_ID = ?             AND "/>
    <Parameter name="nodeId" optional="true" after="WHERE " text="tn.Node_ID = ?             AND "/>
    <Parameter name="adTreeId"/>
    </SqlMethod>
    Get back to me for any doubts in this regards...

    Happy Working.... 



    Apr 30, 2011

    Purpose of Application Element in Openbravo

    by Shankar Balachandran

    Hi All,
               Application Element is one really cool feature in Openbravo, that I managed to get hold of after a while. But still I feel there is no special interest shown on application element till now. So I just wanted to share the importance and the influence of the application elements as it will cause lots of problems if not handled properly.

                Application Element is mainly used for Re-Usability. It will actually reduce lots of our development time when handled properly. Whenever we create a new column, the synchronize terminology process will create a new application element(if it doesn't have any element for the same column name). Thereafter whenever we create a new column with the same dbname, it will map the same application element for that column. Because of this mapping, we can manage the display name,help/comment, description globally. That is we need not go to each and every column and change the display name,help comment or description. It will be mapped globally to all columns that uses a particular column name. Web Service is one of the most important thing in openbravo. This web service will use the name which we provide as column name in column table.

                 A good example could be, think of the column ad_client_id. We should use that field in all tables. Just think what will happen if we need to give the display name, help/comment and description manually for all the tables. Its not just tables, but windows too. As of now, we are not doing that because, we have the application element that is created already for the ad_client_id column that does all these things.All these are possible only when the required application element is in your module or in any module that your module depends on. This can be set in the dependency tab of the module window.

    I have attached a screen shot where AD_Client column's name is updated to 'Client' and description and help comment are added by itself. I have also attached the Application Element from which these comments are taken from.









    Handling Application Element Properly:

    1. Always use the common notation for column names that represents same meaning.
    ie., Always remember to check whether we have any column that already have the same name. If exists, use the already existing one.
    Eg: If the requirement is to create a field to store begin date, we can give the column name as begin_date, bgn_dt,begin_dt,etc.,  But we already have the column used in many places as begin_date. So use that.
    2. Always use the meaningful notation for representing column names.
    Eg: Though most people can understand begin_date,begin_dt,bgn_dt,bgn_date represents begin date, begin_date makes more sense.
    3. Consider, you added a new column that is not present in the system.
    Eg: previous_month
    For this column, when you give synchronize terminology, the application element will be created as, Previous_Month. It will displayed in the application element field in the columns as Previous_Month-Previous_Month.
    1. Go to Application Dictionary -> Setup -> Element.
    2. Search Previous_Month
    3. Rename the Name field to Previous Month.
    5. Give the description and Help/Comment
    4. Rename the Name field to Previous Month in the column window also.
    As you can see, you only need to rename the name field in column table. The help comment/Description would have been populated automatically.
    Thereafter the same name will be used when ever the same column name is used.

                               In Openbravo, if we have wrong application element,  DAL related process, procedures, callouts, etc(EVERYTHING since openbravo is completely implementing DAL from 3.0), will not work. From a developer's perspective, none of our efforts in writing any code is going to work with improper application element. I just wanted to stress out the need for better care towards it.

                             Thanks to my Colleague Pandi to gather all these points and for stressing to me the need for Application Element that made me to write this blog..:)



    Apr 28, 2011

    Import Loader Process For Custom Modules

    by Shankar Balachandran

    Hi All,
    The import loader process is used to load data into the openbravo windows from input files. Openbravo has provided the options to load product, business partner, etc., Now we have the option of creating import process for our own modules with a simple java file (Refer here). Right now this process reads data from csv file(The Input format is parsed using the file IdlServiceJava.java file). This can also be extended to read input from other formats by creating a service file similar to IdlServiceJava. The only catch here is that to try this out you need the Professional Subscription, after all not everything comes free in life…:).  I installed the modules, Initial Data Load and Initial Data Load Extension for Java. I used the sample import process that comes along with initial data load extension module and created a new import process for the window frequency.
    Here are the steps which I followed.
    1. Creating the Java Process file

     package com.fugoconsulting.xyzz.module.template.erpCommon.ad_process;

    import org.openbravo.idl.proc.Parameter;
     import org.openbravo.idl.proc.Validator;
     import java.text.DateFormat;
     import java.text.SimpleDateFormat;
     import java.text.ParseException;
     import java.math.BigDecimal;
     import java.util.Date;
     import org.apache.log4j.*;
    import org.openbravo.base.exception.OBException;
     import org.openbravo.base.provider.OBProvider;
     import org.openbravo.base.structure.BaseOBObject;
     import org.openbravo.dal.service.OBDal;
     import org.openbravo.erpCommon.utility.Utility;
     import org.openbravo.idl.proc.Value;
     import org.openbravo.module.idljava.proc.IdlServiceJava;
     import com.fugoconsulting.xyzz.module.template.XYZZFrequency;
    /**
     *
     * @author Pandeeswari
     */
     public class ImportFrequency extends IdlServiceJava {
    private static Logger log=Logger.getLogger(ImportFrequency.class);
     DateFormat df = new SimpleDateFormat("dd-MM-yyyy");
    @Override
     public String getEntityName() {
     return "Simple Frequency";
     }
    @Override
     public Parameter[] getParameters() {
     return new Parameter[] {
     new Parameter("Organization", Parameter.STRING),
     new Parameter("SearchKey", Parameter.STRING),
     new Parameter("Name", Parameter.STRING),
     new Parameter("Description", Parameter.STRING),
     new Parameter("Factor", Parameter.STRING),
     new Parameter("Date", Parameter.STRING) };
     }
    @Override
     protected Object[] validateProcess(Validator validator, String... values) throws Exception {
     validator.checkOrganization(values[0]);
     validator.checkNotNull(validator.checkString(values[1], 40), "SearchKey");
     validator.checkNotNull(validator.checkString(values[2], 60), "Name");
     validator.checkString(values[3], 255);
     validator.checkBigDecimal(values[4]);
     validator.checkDate(values[5]);
     return values;
     }
    @Override
     public BaseOBObject internalProcess(Object... values) throws Exception {
    return createFrequency((String) values[0], (String) values[1], (String) values[2],
     (String) values[3], (String) values[4], (String) values[5]);
     }
    public BaseOBObject createFrequency(final String Organization, final String searchkey,
     final String name, final String description, final String factor,
     final String aDate)
     throws Exception {
    // Frequency
     XYZZFrequency frequencyExist = findDALInstance(false, XYZZFrequency.class, new Value("searchKey", searchkey));
     if (frequencyExist != null) {
     throw new OBException(Utility.messageBD(conn, "XYZZ_FREQ_EXISTS", vars.getLanguage())
     + searchkey);
     }
     XYZZFrequency frequency = OBProvider.getInstance().get(XYZZFrequency.class);
    try {
     frequency.setActive(true);
     frequency.setOrganization(rowOrganization);
     frequency.setSearchKey(searchkey);
     frequency.setName(name);
     frequency.setDescription(description);
     frequency.setFactor(new BigDecimal(factor));
     // Date date = df.parse(aDate);
     Date  date = new Date();
     frequency.setDate(date);
    OBDal.getInstance().save(frequency);
     OBDal.getInstance().flush();
     } catch (Exception e) {
     e.printStackTrace();
     }
    // End process
     OBDal.getInstance().commitAndClose();
    return frequency;
     }
     }

    I have created the Java File inside modules/mymodule/erpCommon/ad_process. You can place it where ever you want but just be careful to provide the proper Java package name.
    Inside the getParameters() method, we provide the columns in the same order as it is in the input file. But the parameter names used in the method need not be the same.
    The createFrequency() just inserts the value into the table using OBProvider.  The internalProcess(Object… values) Method which is inherited from IdlServiceJava class is used to call the appropriate method with appropriate parameters.
    2. Register the file in entity default value
    Register the Entity in Master Data Management -> Initial Data Load  -> Setup  -> Entity Default Value
    Make Special note on the class name while adding the entity default value.
    3. Import the data using import window
    • Go to Master Data Management -> Initial Data Load -> Process -> Import
    • Choose the input file
    • Choose the entity as Frequency
    • Give Validate
    • Once the input values are validated, the data can be loaded into the actual table by giving process.
    • If there occurs any problem with the input data, it will be logged in the boxes provided in the import screen.
    Note: I thank my Colleague Pandi for helping me a lot in this regard.



    Apr 12, 2011

    Database Development Perspective in Eclipse for Openbravo,Postgres

    by Shankar Balachandran
    Eclipse IDE is a great tool for Development and specially for development for an ERP like Openbravo. Also Eclipse Provides many plug ins that could make the development even easier. There are many perspectives provided in Eclipse. (Refer Screen shot below)
    Lets see about the Database Development Perspective in this Blog. Database Development Perspective allows us to connect to database directly, export data as files, import data, query, etc...
    To connect your Openbravo postgresql database, these are the steps to be performed.
    1. Choose Database Development from the available list of perspectives.

    2. Create a new Connection and connect the driver to database. Refer the following screen shots.


    3. In the Driver definition, choose your host and database name, the database field can be anything (column1), it does not matter. Its just the name that will show in Eclipse.
    4. Once this is done, your eclipse will be as below.
    Under Schemas, you will have public that will have the tables and functions.
    Now you are connected to your database and you can query, or use the other options as I have shown in the screen shot below. 

    Happy Working..:)



    Mar 29, 2011

    Openbravo 3.0 Shortcuts

    by Shankar Balachandran

    Hi Folks,
    Presented below is the Openbravo ERP 3.0 Shortcuts. As suggested in the Pic, it's not exhaustive yet. Will update as and when they are updated.
    For the list of short cuts for Openbravo ERP 2.50 click here .