Jan 28, 2010

Integrating the Data Access Layer with Openbravo XSQL and ConnectionProvider

by Martin Taal
More and more developers are using the Data Access Layer (DAL) for coding business logic in the Openbravo application. I sometimes get questions related to how to integrate DAL constructs with standard Openbravo approaches like Stored Procedures and XSQL generated classes.

As there are several options I felt it was time to spend a blog on this. In this blog I will discuss a number of 'good-to-know' classes which can be handy when you want to integrate DAL with the classic Openbravo approaches.

The first one to cover is the probably the most important one: the DalConnectionProvider. The DalConnectionProvider can be used when you call utility methods which need a ConnectionProvider object. The great thing of the DalConnectionProvider is that it shares the same connection and transaction as the DAL itself. Let's take an example. This one is from the MassInvoicing module, computing the DocumentNo for a new invoice:

// create a new invoice object
final Invoice invoice = OBProvider.getInstance().get(Invoice.class);
// set some properties for the invoice
invoice.setOrganization(org);
invoice.setBusinessPartner(bp);
invoice.setInvoiceDate(invoiceDate);
invoice.setAccountingDate(invoiceDate);
// .... code truncated for clarity

// now compute a documentno, in the same database transaction
final String documentNo = Utility.getDocumentNo(conn,
new DalConnectionProvider(), vars, "", Invoice.TABLE_NAME,
invoice.getDocumentType().getId(),
invoice.getDocumentType().getId(), false, true);
invoice.setDocumentNo(documentNo);


The above code creates an invoice and then calls a stored procedure using the DalConnectionProvider as the connect provider. As the same transaction is used any updates done by the stored procedure can be committed together with the rest of your work. As you can see the DalConnectionProvider is easy to work with as it does not need any extra parameters, you can create and use it directly.
Sometimes it makes sense to call OBDal.getInstance().flush() before calling a stored procedure. This ensures that Hibernate has flushed all your changes to the database so that the stored procedure can see them. Also read the remark at the end of this blog!

The next two are somewhat related: CallProcess and CallStoredProcedure, they both call/run database logic in the database. The first, the CallProcess, can be used to call a process (defined in AD_PROCESS) directly. You can get a CallProcess by calling CallProcess.getInstance() (there is one instance shared by all threads). Again an example from the MassInvoicing module, calling the C_Order_Post process for a list of invoices:

// get an AD_Process instance, 111 is the C_Invoice_Post process
final org.openbravo.model.ad.ui.Process process = OBDal.getInstance().get(org.openbravo.model.ad.ui.Process.class, "111");

// iterate over the invoices and post them
for (Invoice invoice : invoices) {

final ProcessInstance processInstance = CallProcess.getInstance().call(process,
invoice.getId(), new HashMap<String, String>());
// the processInstance now contains the result
final String errorMsg = processInstance.getErrorMsg();
final Object result = processInstance.getResult();
final String recordID = processInstance.getRecordID();
// code truncated for clarity

}


The last parameter in the CallProcess.call method is a map of parameters, these are placed in the ad_pinstance_para table.

The CallStoredProcedure class makes it possible to call any stored procedure in the database in a java programmer friendly way. The nice thing of this class is that you can pass in actual java objects as parameters, so you don't need to worry about String conversions. The return is also a type-specific java object. This code snippet shows its usage (calling the C_Divide stored procedure):

// set some parameters
final List parameters = new ArrayList();
parameters.add(new BigDecimal("10.1"));
parameters.add(new BigDecimal("2.0"));
// the procedure name
final String procedureName = "C_Divide";
// calling the procedure and getting the result
final BigDecimal bigDecimal = (BigDecimal)CallStoredProcedure.getInstance().call(procedureName, parameters, null);

The last one to discuss: the OBObjectFieldProvider class makes it possible to wrap an Openbravo business object in a FieldProvider interface. The FieldProvider is used throughout the Openbravo system to wrap data read from the database (for example through a XSQL generated class). The OBObjectFieldProvider is useful when you read business objects through the DAL and need to pass them on to code expecting a FieldProvider.

The discussed classes are all documented with javadoc describing the meaning of parameters and methods and you can ofcourse study the source code directly.

Before concluding this blog, as a last tip: The DAL (Hibernate) queues actions to the database. So when updating the database through DAL and then calling a stored procedure using a DalConnectionProvider make sure to call OBDal.getInstance().flush() before calling the stored procedure. This flushes the queue to the database and ensures that the stored procedures sees your changes. Also when you want to work with the results from the stored procedure and read them back through the DAL read this tip.

As always I hope this is an interesting read, feedback is always welcomed. If you have any questions or remarks visit the Openbravo forge forum and post them there.

Happy Coding!



Jan 27, 2010

Initial Data Load demostration – Feb 4th, 2010

by Adrián Romero
Open to all Openbravo Community members, this webinar will demonstrate Openbravo modularity, will help you better understand development techniques, processes and tools you can use to create extension modules, and will show concrete functional solutions to address specific requirements that might inspire you to create your own solutions.

Initial Data Load is focused to Openbravo ERP partners and customers that aims to reduce the time needed to deploy a fresh Openbravo ERP installation simplifying the import of all master data and operational data needed to start working with Openbravo ERP. This can save a lot of time in the deployment of Openbravo ERP.

The Initial Data Load module is a commercial module available in the Openbravo Exchange Marketplace at no additional cost for Openbravo Professional subscribers.

Take a look at this post for more details about the webinar.



Jan 26, 2010

Launch of Openbravo Exchange: the ERP Marketplace

by John Fandl
I have written in the past about Openbravo Forge, Openbravo's collaborative development environment, and now I'm pleased to announce the launch of Openbravo Exchange--the place to go for information about extension modules that are "ready for prime time". If the Forge is the sausage factory, then the Exchange is the delicatessen, featuring a series of "ready-to-use" software packages that are catalogued and described with the end user in mind. :)



Here are the top things to know about Openbravo Exchange:
  • Openbravo business partners now have an official, high-profile web site they can leverage to promote and monetize their Openbravo commercial extension modules and templates
  • All business partners are allowed evaluation-only access to all Exchange modules (so they can sell them on the author's behalf, and get a sales commission of course)
  • As an author, you don't have to worry about invoicing and collecting money--we do that, and you collect periodic author royalty payments!
  • Good zero-cost open source modules from anyone are also welcome, of course (nice way to get your name out there)
  • We are starting with a self-certification model, here are the certification criteria
  • You ain't seen nothin' yet! (this is just version 1.0, stay tuned for a more dynamic Exchange with reviews, ratings, etc.)
If you are a business partner with Openbravo-based commercial software to sell through our channel, here are the steps to package and sell it. If you are a business partner implementing solutions for your clients, check Openbravo Exchange before proposing to close functional gaps with a custom project--what your customer needs may already be available off-the-shelf, as a fully-tested package! If you are new to Openbravo and interested in leveraging your development skills, the Openbravo ERP Developer's Guide is the place to start.

Here is the official press release, which features the Hotel Management System from Bonsai Consulting--best of luck to you with this module, Ravi. And happy developing and selling to all in the Openbravo community in 2010, as we unleash the business of modularity!



Jan 20, 2010

RM Updates : 2.50MP10 released, Quickstart-spain OBX automated, User manual to setup testing environment for openbravoERP, Scrum master less sprint.

by Priya Muthukumar

MaintancePack Release:
2.50MP10 is released. OBX and the update through the MMC is available exclusively for professional customers. The appliance, tarball are available for everyone.

Quickstart-spain OBX: Created new job to build QuickStart-spain obx with this automation we are ensure better quality through all the development cycle, which leads to stable release dates and high quality in solution.
Latest obx is available here

User manual:
Created guide on how to replicate the Openbravo ERP running in a production environment into a testing environment.

Scrum master less sprint:
We successfully made this sprint with no scrum master, which means we shared the work of Scrum Master and we have two people from the team on rotation to represent Scrum-of-Scrum and ScrumMaster's meeting.



Jan 19, 2010

Openbravo ERP Payment Monitor

by Richard Morley
There are many new things in OB ERP 2.50 MP10, but I thought you would like to hear about one in particular...the Payment Monitor.

The Payment Monitor provides users with a quick, single click, view of the latest payment information related to an invoice. If payment has been received in full then the status is now clearly shown as "Payment Complete". If payment is still pending, then by clicking on the new Payment Monitor button on the invoice header, the payment monitor information displays the number of days until the due date of the next payment and the amount that needs to be paid on that date. The user can also see how much has been paid, how much is pending and the last time the payment status was calculated. This feature is particularly useful if an invoice has multiple due dates as the Payment Monitor tracks the invoice payment status for each payment. The payment status can be updated automatically by a background process that automatically scans new invoices or manually (by clicking on the "Update Payment Monitor" button.

One of the great thing about this feature is that all of this information is available as filter criteria and exposed in the grid view. This makes the Payment Monitor a very handy and agile tool that allows users to manage collections very easily and could in many ways replace the Payments Report.

This new feature is a great example of functionality that is being added to improve the usability of Openbravo. It is very "demonstrable" to partners and users (if you want to impress) and pre-empts most questions about how a user can see the payment status of an invoice.

Please investigate this feature and add it to your arsenal of cool features that improve user productivity. You can find out more information at http://wiki.openbravo.com/wiki/Functional_Documentation/Procurement_Management#Relationship_to_Financial_Management:_Payment_and_Payment_monitor.



Jan 15, 2010

Development tips – Part I

by Iván Perdomo

This is the first one of a series of posts about development tips that I use in a daily basis. I think that you can benefit from them, and speed up your daily work. There are some one-line commands that you can use to execute several things in one shot. Those is targeting GNU/Linux users.

Speeding up Firefox

I have found a few tips that can improve its performance.

Use different profiles

Add-ons could decrease the performance of your browser. One example of decreasing performance add-on is Firebug. It’s just a great tool to debug JavaScript, CSS, HTML, monitor requests, etc, but it has a known issue:

“… If you have Firebug installed you are probably not getting fast Javascript. Firebug doesn’t have to be active on your current page …”

That’s why is a best practice to use Firebug in a different profile.

I have a profile named “debug” where the only add-on installed is Firebug and made a simple bash script ffbug to open Firefox with that profile:

#!/bin/bash
firefox -no-remote -P "debug" &

The -no-remote parameter allows you open a new instance of Firefox and not just a new window linked to the current running one. The -P is to define which profile you want to use.

VACUUM the SQLite databases

You can improve the performance of Firefox by vacuum your bookmarks, history, etc. databases.
Close all your running Firefox instances and execute:

~ $ for i in $(find -name '*.sqlite'); do sqlite3 $i VACUUM; done;

Useful one-line commands

Updating the source code of the modules your working on

In some cases you work with several modules at the same time, and you want to get all the changes made by your colleagues. You can update your local repositories by executing this line inside your modules folder:

for i in $(ls -1); do cd $i; hg pull -u; cd ..; done;

Example of the output of this is:

~/src/openbravo/working/pi-reference/modules $ for i in $(ls -1); do cd $i; hg pull -u; cd ..; done;
pulling from https://code.openbravo.com/erp/mods/org.openbravo.base.seam
searching for changes
no changes found
pulling from https://code.openbravo.com/erp/mods/org.openbravo.client.freemarker/
searching for changes
no changes found
pulling from https://code.openbravo.com/erp/mods/org.openbravo.client.kernel/
searching for changes
no changes found
pulling from https://code.openbravo.com/erp/mods/org.openbravo.service.datasource
searching for changes
no changes found
pulling from https://code.openbravo.com/erp/mods/org.openbravo.service.json/
searching for changes
no changes found
pulling from https://code.openbravo.com/erp/mods/org.openbravo.userinterface.selector
searching for changes
adding changesets
adding manifests
adding file changes
added 1 changesets with 13 changes to 13 files
13 files updated, 0 files merged, 0 files removed, 0 files unresolved
pulling from https://code.openbravo.com/erp/mods/org.openbravo.userinterface.smartclient
searching for changes
adding changesets
adding manifests
adding file changes
added 1 changesets with 3 changes to 3 files
3 files updated, 0 files merged, 0 files removed, 0 files unresolved

You can easily hack this line by executing another Mercurial command, e.g. See what’s the status on each repository:

for i in $(ls -1); do cd $i; hg st; cd ..; done;

Update and build the latest pi

Assuming that you want to use the latest stable revision from pi, you can check our continuous integration framework and see what’s the latest revision that passed all the tests, then you can update your local repository to that revision and rebuild your system. Or you can copy this bash script (pi-update), and execute it inside your pi working copy:

#!/bin/bash
REVISION=`wget -q -O - http://builds.openbravo.com/job/erp_devel_pi-full-pgsql/lastSuccessfulBuild/changes | awk -F: '/https:\/\/code\.openbravo\.com\/erp\/devel\/pi\/rev\// {print substr($3,0,12)}' | head -n1`
hg pull
echo "Updating to rev $REVISION"
hg up -r $REVISION
ant smartbuild -Dlocal=no

This script uses wget and awk to get the latest revision from the last successful build page, pulls all the changesets of PI and updates your working copy to the detected revision, then updates your database and compiles the application.

Cleanup your working copy

The hg status command will tell you which files Mercurial doesn’t know about; it uses a “?” to display such files …

I often want to clean my working copy and remove all unversioned files. You can rid of those file by executing:

 hg st -nu | xargs rm -rf

That’s all folks! I’ll come back with more tips in the future. Disclaimer: I’m not a bash expert so I know that some of this commands could be simplified. I would also like to thank iarwain for simplifying some of this commands.




Jan 13, 2010

Openbravo reaches 1.5 million downloads

by Josep Mitjà


Today we have reached an accumulated 1.5 M downloads.

Cumulative downloads, and even better -monthly download rate-, is a great indicator of an open source project's interest. We are very proud to reach this figure after the first publication of code in April 2006. I interpret it as a sign of our long-term commitment to becoming the leading ERP in the space.

Also, since October 2006, Openbravo ERP has been on a monthly basis the open source ERP hosted in SourceForge with the highest download rate in the category. This is no less than 39 months in a row that the public has continued to choose Openbravo ERP over other alternatives. One download at a time, Openbravo is earning a solid reputation, and customers all over the world are joining in.

Thanks again and keep in mind this is just the beginning!



Jan 8, 2010

Taking the beta out of the Openbravo Forge

by Peter Nuding
In two months it will be a year since our initial launch of the Openbravo Forge.
We are rapidly growing towards 9000 users and it won't be long before we cross the 300 projects mark either.
These are great numbers because they confirm what we were hoping for: the Openbravo Forge is now a serious tool for both our community and partners.

We have fixed a lot of issues and improved usability in many areas. Now it's time to drop the "beta" label from the site logo.
But of course we are far from being done.

This year we will continue our journey and make the Openbravo Forge even easier to use. We will add exciting possibilities that allow you to better publish your projects around Openbravo ERP and POS and it will also become even easier to find the solutions you are looking for.
On this journey we also need your help:
Remember to use our Help pages, FAQ and the Forge Help forum whenever you run into trouble using the site.
Surely you also have great ideas on how you would like to see the site and our help documentation improve. So I can't wait to get your comments!



Jan 7, 2010

RM Updates: Amazon backup stratergy, Mantis Upgrade, Establish automatic process for releasing 2.40, OB@OB

by Harpreet Singh Wadhwa
These are the latest news from the Openbravo's Release Management Team:


Backup Strategy: EBS boot.

Amazon has a new feature ebs boot, this helps us to keep our root partition in ebs volume and also allows us to have data up to 1TB in root partition. This helps us in the following way : better backup strategy and from now we can pause & re-start an instance and thus saving cost. My colleague gnuyoga has a blog about the same.


Mantis Upgrade: Upgrade issues.openbravo.com to mantis-1.2.0

As you know our existing issue tracker is based on mantis 1.1.8. With the release of mantis 1.2.0, it promises lot of interesting productivity boosters. We are migrating our current mantis to latest. This involves quiet bit of challenge. In this sprint we address customization like SSO (Single Sign On, etc), and custom css. If you want to be a beta tester to testing our new mantis please drop us an email for us to give you a test account.


Continuous release of 2.40 branch

So the mantra of 2.40 branch is continuous release as detailed in my colleague juan pablo's blog post. Now this task is complete and for details see here



OB@OB: Documentation and Linux tool

This task was about documenting the process of replicating production environment to testing environment and creating a new tool that automates this process in linux.