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 23, 2011

    Announcing Openbravo 3.0 RC7

    by Ismael Ciordia
    I am pleased to announce the immediate availability of Openbravo 3.0 RC7, the seventh release candidate in the Openbravo 3 series.

    Openbravo 3.0 RC7 is primarily a stabilization release, including over 150 fixes for issues reported by early adopters of previous release candidates.

    Besides stabilization, Openbravo 3.0 RC7 also delivers some further productivity improvements that make the usage of the ERP easier and more agile:
    • Re-location of fields according to the new 4 columns layout in all windows: the form view windows change from a layout of 2 columns (in Openbravo 2.50) to a layout of 4 columns in Openbravo 3. All windows in Openbravo have been reviewed and fields re-located to take full advantage of this new layout. A new collapsed section named “More information” is added for other meaninful (but less frequenlty used) fields.
    • Status Bar: this is another improvement in the window form view layout. The status bar is the bar that is on top of the form and includes the navigation buttons (previous, next, close). It is possible to configure fields to be shown in the Status Bar. Usually the main non-editable fields will be included (eg. Document status, Totals, etc.), but any field can be placed there. This presentation helps to convey the main status information of that document.
    • Attachments: this is a very well know historical capability of Openbravo that has now been migrated to Openbravo 3. It is possible to attach any file (images, pdf’s, docs, etc.) to any document/record in the system. For example, you can save all project releated documentation linked to each project. With Openbravo 3 this feature is easier to use than ever.An example of how a window looks in Openbravo RC7
    • Financial Account window migrated to Openbravo 3 user interface: the Financial Account window is the main component of the new financial flows included in Openbravo 3. Because this window included a manual form (the Transaction tab) when it was originally implemented in Openbravo 2.50, it was shown in classic mode in Openbravo 3. This manual form has now been removed (the Transaction tab is now implemented as a standard Application Dictionary component). As a result the Financial Account window is shown with the new UI and the Transaction tab has much better usability than it had. This is a great demonstration of the Openbravo 3 power: code that is easier to develop and maintain provides much better usability!.
    • Remittances: Remittances is a very common financial feature in some countries (eg. Spain) that was not supported in the new financial flows. This feature is delivered as a community module, not included in the Openbravo 3 distribution. It has several improvements over the previous version on the old financial flows.
    • Remittances feature requires several improvements over the new financial flows, for more information, please take a look into the “Advanced Payables & Receivables Management Release Notes”.
    • Remittances feature supports different file generation formats such as the Spanish ones : “Cuaderno 19″ , “Cuaderno 58″ and “Cuaderno 34″. Each of these file generation formats is delivered as an optional commercial module (free for Professional Subscription instances), not included in the Openbravo 3 distribution.
  • Exclude columns from Audit: Added possibility of excluding individual columns of a table from the Audit Trail functionality.
  • Pop-up windows replaced with modal application windows: one of the most commonly reported usability issues in Openbravo 2.50 was a browser’s pop-up blocker preventing an Openbravo pop-up window from opening. In RC5 we started a replacement of the pop-up windows by modal application windows that are not blocked by the browser. Now most of them are replaced and only a few (less common events) are left. Please let us know if any of those that remain provide a negative user experience.
  • Ability to execute processes in header when focus is in lines: in previous versions of Openbravo 3 it was not possible to process an order when the focus was in the lines tab. This has now been addressed so that the process buttons in the header are accessible when the focus is the lines, making the process much easier to complete.
  • Performance Improvements: several improvements have been done to improve the responsiveness of the system. Grid-scrolling, editing the grid, navigating to linked records, callout execution, etc. are all much faster and smoother than before.
  • Internal improvements: invisible to users, but still very important to mention. When Openbravo 3 reaches MP0 (General Availability) we will not make any change that might reduce the stability of the system. Therefore these infrastructure changes are happening now. It includes:
      • Code clean-up: several deprecated components in Openbravo code have been removed from the system as they are no longer needed. In anticipation of a modified Openbravo 2.50 instance using a deprecated component we have created a module named “Legacy features no longer available in Core” to make the upgrade easier. Those instances should remove any dependency to that module as it is not going to be maintained! Besides a new public module named “Import Data” is also available. This module contains all the componets related to the old Import Data Load functionality that is replaced in Openbravo 3 with Initial Data Load module.
      • Library Update: most of the third party libraries used by the Openbravo code have been updated to newer versions. Most prominent are the changes from Jasperreports 3.0.1 to 4.0.1, and hibernate 3.2.5 to 3.6.3.
    Openbravo 3.0 RC7 is intended for production usage by early adopters and it is a fully supported release available in all editions, Community, Basic and Professional Edition.

    If you are a new user interested in learning about Openbravo and evaluating the product, you should use Openbravo 3.0 RC7. If you are an existing community member interested in staying up to speed with the latest evolutions of Openbravo, you should download and install Openbravo 3.0 RC7.

    If you are interested in deploying Openbravo for production usage in a new project, you should also consider Openbravo 3.0 RC7. Early adopters interested in deploying Openbravo 3.0 RC7 in production are recommended to thoroughly test the processes relevant to their business before deploying them in production.

    If you are already in production on an earlier version of Openbravo 3, we advise you to update your system to RC7 at your earliest convenience. If you are in production on Openbravo 2.50 or earlier, we advise you to wait for general availability before scheduling an upgrade.

    If you want to learn more about Openbravo 3.0 RC7, please review the release notes for a full description of the release, download instructions or Amazon EC2 AMI codes. If you are pressed for time and have only a few minutes to learn about the product, you can take it for a spin in our demo environment.

    As always, you are encouraged to tell us what you think, by posting a comment on this post, raising an issue in issues.openbravo.comor discussing it in the Early Releases Discussion forum.



    May 20, 2011

    Openbravo Revs up Retail! (check out the webinars in English and Spanish)

    by John Fandl
    Openbravo has delivered proven results in the retailsector for several years, and this week we are intensifying our Retail focuswith a new commercial offering called Point of Sale Retail (press release here).
    Pointof Sale Retail extends Openbravo 3 Professional Editionwith commercial support for Openbravo POS, providing a unified, highly scalableand cost-effective open source solution platform for Retail.

    To learnmore about the Point of Sale Retail Module and the agile Openbravo 3 platform,please register for the webinar

    ”How to affordablysuper-charge retail performance with an integrated, open source retailsolution”:

    This webinar will be informative for Retail companiesrequiring an agile, cost-effective retail solution, as well as IT servicescompanies who cater to the Retail sector—and who want to implement the bestpossible retail solutions for their customers.



    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.... 



    May 3, 2011

    Introducing the Openbravo 3 Module Monitor

    by John Fandl

    I'd like to announce a new tool to help keep you informed about the extensive module development activity happening across Openbravo's global Community--the Openbravo 3 Module Monitor Report. 

    The very first edition, for April 2011, is now available for direct download here If you want to receive this report automatically every month, please click here to sign up for our mailing list, and be sure to check the box re: "Technical Product Updates".   

    Since the Openbravo 3 Monitor Report can be a bit intimidating (there is always a LOT going on! :), read on to check out some summary highlights.  


    April 2011 Module Development Highlights

    This month Openbravo developers worldwide are heads down publishing their modules for Openbravo 3, and several localizations achieved GA (General Availability) or CR (Controlled Release) status for Openbravo 3, including localization modules from these countries:


    Dozens of of Openbravo’s own modules were updated to Release Candidate 6, adding new functionality and correcting over 100 defects as reported by Openbravo CEO Paolo Juvara in this blog post.

    I have a special call out for the Initial Data Load Extension for Java  module, which is now published in Test status for Openbravo 3. As Adrian Romero discussed in this blog post, the module makes it easy to tailor your initial data load process. If you are piloting Openbravo 3 and want to import your own specific data, give it a try!

    Similarly, if you are a developer authoring a module and want to add an import process to it, check out this post from Shankar Balachandran. A lot of people have data in spreadsheets (or can easily put it there), so it is often worth your time to go the extra mile to make it as easy as possible to import customer data into your new module (instead of entering it by hand).

    Great Example of Web-based Integration!

    Finally, I want to refer you to Asier Zabaleta’s excellent blog post describing how easy it is to integrate Openbravo 3 with Zoho reports, and expose a Zoho graph as an Openbravo 3 workspace widget. Asier sums it up very well at the end,

    • “And this is just an example of why web solutions are so powerful these days. Their ease of integration with other tools makes them a must”!!

    Indeed, open source is at the forefront of modular web technology, and Openbravo is leading the way in the ERP space, with Openbravo 3, the agile erp.

    Until Next Month...

     I hope you have found this monthly update on Openbravo 3 module development informative and useful. Openbravo 3 modules are the key to achieving a best fit, maintainable ERP implementation at a low cost. So stay informed informed about what modules are available, and don’t be shy about trying out a new module--it’s easy, just follow these simple instructions.


    Note that if you ever miss a month, I will keep a complete list of the monthly reports in the wiki, just click here.



    May 2, 2011

    An emotional review of Openbravo 3 history

    by Paolo Juvara
    Have you ever found yourself in a situation where, cleaning up a closet, you finding a box of old photos that you forgot even existed?

    I must confess. I am a nostalgic and that is one of those situations where I am prone to overwhelming emotions. The memories start coming back and I start thinking of old friends, choices made and times gone by.

    A couple of days ago, I had such an experience. I was answering a question on layout choices in the interface of Openbravo 3 and I started going back and look at the discussions in the UX forum labs.

    Eventually, I found the original concept videos and image mockups that Rob Goris published in February 2009.

    That's right February 2009, over 2 years ago!

    The publication of Openbravo 3 in February this year represents a very significant step forward in the history of the project. The key element of the release is a complete rearchitecture of the user experience, centered around the concepts of user agility and the introduction of workspaces, multi-tabbed UIs, master detail layouts and editable grid.

    The feedback that we are receiving from our users in overwhelmingly positive and enthusiastic.

    This new release has been a long way coming and, now that it is finally here, it is at the same time interesting, fun and moving to go back and see how the concepts behind it started, were debated and evolved, improving over time since their original form, yet staying remarkably close to the original vision.

    I have to take my hat off for all the members of the Openbravo development team and our community members who participated in the design process. Good job guys. Well done.