Hi Openbravo developers!

I've been playing around a bit with DAL replacing an XSQL from a callout by
a DAL OBQuery.

The callout is SL_Project_PriceList.java [1], a simple callout that selects
the Currency from the Price List chosen in the Multiphase or Service Project
header.

The diff attached does the job but I would like to know if it can be
achieved in a cleaner way from a code perspective.

Based on this, I would like to update the How-To Callout example [2] in
order to use DAL OBQuery instead of an xSQL file.

Thanks for any comment.

Rafa Roda Palacios

[1]
https://code.openbravo.com/erp/devel/pi/file/74eb0fd11265/src/org/openbravo/erpCommon/ad_callouts/SL_Project_PriceList.java
[2]
http://wiki.openbravo.com/wiki/ERP/2.50/Developers_Guide/How_to_develop_a_callout
diff -r 402da4a11d1c src/org/openbravo/erpCommon/ad_callouts/SL_Project_PriceList.java
--- a/src/org/openbravo/erpCommon/ad_callouts/SL_Project_PriceList.java	Wed Sep 23 15:34:56 2009 +0200
+++ b/src/org/openbravo/erpCommon/ad_callouts/SL_Project_PriceList.java	Thu Oct 01 16:16:07 2009 +0200
@@ -20,6 +20,8 @@
 
 import java.io.IOException;
 import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.List;
 
 import javax.servlet.ServletConfig;
 import javax.servlet.ServletException;
@@ -28,6 +30,10 @@
 
 import org.openbravo.base.secureApp.HttpSecureAppServlet;
 import org.openbravo.base.secureApp.VariablesSecureApp;
+import org.openbravo.dal.service.OBDal;
+import org.openbravo.dal.service.OBCriteria;
+import org.openbravo.dal.service.OBQuery;
+import org.openbravo.model.pricing.pricelist.*;
 import org.openbravo.xmlEngine.XmlDocument;
 
 public class SL_Project_PriceList extends HttpSecureAppServlet {
@@ -66,6 +72,27 @@
 
     SLProjectPriceListData[] data = SLProjectPriceListData.select(this, strMPriceListID);
     StringBuffer resultado = new StringBuffer();
+    
+    // Start DAL code
+    
+    final StringBuilder whereClause = new StringBuilder();
+    whereClause.append(" as pl");
+    whereClause.append(" where pl.id=?");    
+  
+    final OBQuery<PriceList> qry = OBDal.getInstance().createQuery(PriceList.class, whereClause.toString());
+    
+    final List<Object> parameters = new ArrayList<Object>();
+    parameters.add(strMPriceListID);
+    qry.setParameters(parameters);
+    
+    final List<PriceList> plList = qry.list();
+    
+    String strPriceListCurrency = "";
+    for(PriceList pl : plList) {
+    	strPriceListCurrency = pl.getCurrency().getId().toString();
+    }
+    
+    // End DAL code
 
     resultado.append("var calloutName='SL_Project_PriceList';\n\n");
     resultado.append("var respuesta = new Array(");
@@ -73,7 +100,7 @@
       // resultado.append("new Array(\"inpistaxincluded\", \"" +
       // data[0].istaxincluded + "\"),\n"); C_Project table does not saves
       // IsTaxIncluded value
-      resultado.append("new Array(\"inpcCurrencyId\", \"" + data[0].cCurrencyId + "\")\n");
+      resultado.append("new Array(\"inpcCurrencyId\", \"" + strPriceListCurrency + "\")\n");
     }
     resultado.append(");\n");
 
------------------------------------------------------------------------------
Come build with us! The BlackBerry&reg; Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9&#45;12, 2009. Register now&#33;
http://p.sf.net/sfu/devconf
_______________________________________________
Openbravo-development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-development

Reply via email to