details:   /erp/devel/int/rev/e871ecee3de7
changeset: 6952:e871ecee3de7
user:      Harikrishnan Raja <harikrishnan.raja <at> openbravo.com>
date:      Thu Apr 08 10:08:35 2010 +0530
summary:   Fixes Issue 12899: Amortization lines are not displayed in sequence 
of year

details:   /erp/devel/int/rev/9b652ee60f8d
changeset: 6953:9b652ee60f8d
user:      Martin Taal <martin.taal <at> openbravo.com>
date:      Thu Apr 08 09:44:50 2010 +0200
summary:   Improved logging of received content in case of exception

details:   /erp/devel/int/rev/13d2fc73db5d
changeset: 6954:13d2fc73db5d
user:      Martin Taal <martin.taal <at> openbravo.com>
date:      Thu Apr 08 09:45:22 2010 +0200
summary:   fixes issue 12883: Rest Webservice testcases fail because test data 
is not what is expected

details:   /erp/devel/int/rev/8e0cb4346d50
changeset: 6955:8e0cb4346d50
user:      Martin Taal <martin.taal <at> openbravo.com>
date:      Thu Apr 08 09:47:11 2010 +0200
summary:   fixes issue 12901: OBDal.getInstance().getConnection() does not 
setup dateFormat correctly

details:   /erp/devel/int/rev/c56bf3953565
changeset: 6956:c56bf3953565
user:      Martin Taal <martin.taal <at> openbravo.com>
date:      Thu Apr 08 09:47:48 2010 +0200
summary:   fixes issue 12903: Error in OBQuery when using with hql clause 
having order by but not where part

diffstat:

 src-db/database/model/functions/A_ASSET_POST.xml        |    9 +-
 src-test/org/openbravo/test/dal/IssuesTest.java         |   41 +++++-
 src-test/org/openbravo/test/webservice/BaseWSTest.java  |   35 +++-
 src-test/org/openbravo/test/webservice/WSReadTest.java  |   21 +-
 src/org/openbravo/dal/service/OBDal.java                |   17 ++-
 src/org/openbravo/dal/service/OBQuery.java              |  121 +++++++--------
 src/org/openbravo/service/db/DalConnectionProvider.java |   13 +-
 7 files changed, 151 insertions(+), 106 deletions(-)

diffs (truncated from 498 to 300 lines):

diff -r c9b94427d692 -r c56bf3953565 
src-db/database/model/functions/A_ASSET_POST.xml
--- a/src-db/database/model/functions/A_ASSET_POST.xml  Wed Apr 07 17:32:16 
2010 +0200
+++ b/src-db/database/model/functions/A_ASSET_POST.xml  Thu Apr 08 09:47:48 
2010 +0200
@@ -205,6 +205,11 @@
             finish:=false;
             WHILE not finish
             LOOP
+            SELECT COALESCE(MAX(SEQ_NO_ASSET), 0) +10
+              INTO v_SEQ_ASSET
+              FROM A_AMORTIZATIONLINE, A_ASSET
+              WHERE A_AMORTIZATIONLINE.A_ASSET_ID = A_ASSET.A_ASSET_ID
+              AND A_ASSET.A_ASSET_ID=v_Record_ID;
               IF(v_COUNT=1 AND to_number(v_BEGINING_DATE-v_FIRST_DAY_DATE)<>0) 
THEN
                 
v_Percentage:=to_number(to_number(TO_DATE('31-12-'||to_char(v_AMORTIZATIONSTARTDATE,
 'YYYY'), 'DD-MM-YYYY') -v_AMORTIZATIONSTARTDATE) 
/(TO_DATE('31-12-'||to_char(v_AMORTIZATIONSTARTDATE, 'YYYY'), 'DD-MM-YYYY') 
-TO_DATE('01-01-'||to_char(v_AMORTIZATIONSTARTDATE, 'YYYY'), 'DD-MM-YYYY'))) * 
v_PercentageGeneral;
                 v_USELIFEYEARS:=v_USELIFEYEARS+1;
@@ -259,10 +264,10 @@
                     A_AMORTIZATION_ID, A_AMORTIZATIONLINE_ID, A_ASSET_ID, 
AD_CLIENT_ID,
                     AD_ORG_ID, CREATED, CREATEDBY, UPDATED,
                     UPDATEDBY, AMORTIZATION_PERCENTAGE, AMORTIZATIONAMT, 
C_CURRENCY_ID,
-                    ISACTIVE, LINE
+                    ISACTIVE, LINE, SEQ_NO_ASSET
                   )
                   VALUES
-                  (v_NEW_AMORTIZATION, v_AMORTIZATIONLINE, v_Record_ID, 
v_AD_CLIENT_ID, v_AD_ORG_ID, now(), v_CREATEDBY, now(), v_CREATEDBY, 
ROUND(v_PERCENTAGE,v_Currency_Pre), ROUND(v_AMOUNT,v_Currency_Pre), 
v_C_CURRENCY_ID, 'Y', v_LINE) ;
+                  (v_NEW_AMORTIZATION, v_AMORTIZATIONLINE, v_Record_ID, 
v_AD_CLIENT_ID, v_AD_ORG_ID, now(), v_CREATEDBY, now(), v_CREATEDBY, 
ROUND(v_PERCENTAGE,v_Currency_Pre), ROUND(v_AMOUNT,v_Currency_Pre), 
v_C_CURRENCY_ID, 'Y', v_LINE, v_SEQ_ASSET) ;
                  v_Inserted := v_Inserted +1;
               end if;
               v_BEGINING_DATE:=TO_DATE('31-12-' || TO_CHAR(v_BEGINING_DATE, 
'yyyy'), 'DD-MM-YYYY') + 1;
diff -r c9b94427d692 -r c56bf3953565 
src-test/org/openbravo/test/dal/IssuesTest.java
--- a/src-test/org/openbravo/test/dal/IssuesTest.java   Wed Apr 07 17:32:16 
2010 +0200
+++ b/src-test/org/openbravo/test/dal/IssuesTest.java   Thu Apr 08 09:47:48 
2010 +0200
@@ -76,6 +76,9 @@
  * - https://issues.openbravo.com/view.php?id=12853: OBQuery count not working 
with a query with
  * aliases
  * 
+ * - https://issues.openbravo.com/view.php?id=12903: Eror in OBQuery when 
using with hql clause
+ * having order by but not where part
+ * 
  * @author mtaal
  * @author iperdomo
  */
@@ -117,9 +120,7 @@
       final Order order = OBDal.getInstance().get(Order.class, orderId);
       final String dalIdentifier = 
IdentifierProvider.getInstance().getIdentifier(order);
 
-      // assert equals disabled for now as apparently in oracle the date 
returned is one day before
-      // postgress and java, at least in the testcase we have
-      // assertEquals(sqlIdentifier, dalIdentifier);
+      assertEquals(sqlIdentifier, dalIdentifier);
     }
     {
       final List<Object> params = new ArrayList<Object>();
@@ -292,4 +293,38 @@
     products.setFilterOnReadableClients(false);
     assertTrue(products.count() > 0);
   }
+
+  /**
+   * Tests issue: https://issues.openbravo.com/view.php?id=12903
+   */
+  public void test12903() {
+    setSystemAdministratorContext();
+    OBQuery<Product> products;
+
+    products = OBDal.getInstance().createQuery(Product.class,
+        " as e where e.name is not null order by name");
+    products.setFilterOnReadableOrganization(false);
+    products.setFilterOnReadableClients(false);
+    assertTrue(products.count() > 0);
+
+    products = OBDal.getInstance().createQuery(Product.class, " as e order by 
name");
+    products.setFilterOnReadableOrganization(false);
+    products.setFilterOnReadableClients(false);
+    assertTrue(products.count() > 0);
+
+    products = OBDal.getInstance().createQuery(Product.class, "order by name");
+    products.setFilterOnReadableOrganization(false);
+    products.setFilterOnReadableClients(false);
+    assertTrue(products.count() > 0);
+
+    products = OBDal.getInstance().createQuery(Product.class, " where name is 
not null");
+    products.setFilterOnReadableOrganization(false);
+    products.setFilterOnReadableClients(false);
+    assertTrue(products.count() > 0);
+
+    products = OBDal.getInstance().createQuery(Product.class, "");
+    products.setFilterOnReadableOrganization(false);
+    products.setFilterOnReadableClients(false);
+    assertTrue(products.count() > 0);
+  }
 }
\ No newline at end of file
diff -r c9b94427d692 -r c56bf3953565 
src-test/org/openbravo/test/webservice/BaseWSTest.java
--- a/src-test/org/openbravo/test/webservice/BaseWSTest.java    Wed Apr 07 
17:32:16 2010 +0200
+++ b/src-test/org/openbravo/test/webservice/BaseWSTest.java    Thu Apr 08 
09:47:48 2010 +0200
@@ -19,7 +19,9 @@
 
 package org.openbravo.test.webservice;
 
+import java.io.BufferedReader;
 import java.io.InputStream;
+import java.io.InputStreamReader;
 import java.io.OutputStream;
 import java.io.Reader;
 import java.io.StringReader;
@@ -195,19 +197,30 @@
       hc.connect();
       final SAXReader sr = new SAXReader();
       final InputStream is = hc.getInputStream();
-      final Document doc = sr.read(is);
-      final String content = XMLUtil.getInstance().toString(doc);
-      if (testContent != null && content.indexOf(testContent) == -1) {
-        log.debug(content);
-        fail();
+      final StringBuilder sb = new StringBuilder();
+      BufferedReader reader = new BufferedReader(new InputStreamReader(is, 
"UTF-8"));
+      String line;
+      while ((line = reader.readLine()) != null) {
+        sb.append(line).append("\n");
       }
-      assertEquals(responseCode, hc.getResponseCode());
-      is.close();
-      // do not validate the xml schema itself, this results in infinite loops
-      if (validate) {
-        validateXML(content);
+      try {
+        final Document doc = sr.read(new StringReader(sb.toString()));
+        final String content = XMLUtil.getInstance().toString(doc);
+        if (testContent != null && content.indexOf(testContent) == -1) {
+          log.debug(content);
+          fail();
+        }
+        assertEquals(responseCode, hc.getResponseCode());
+        is.close();
+        // do not validate the xml schema itself, this results in infinite 
loops
+        if (validate) {
+          validateXML(content);
+        }
+        return content;
+      } catch (Exception e) {
+        log.debug(sb.toString());
+        throw e;
       }
-      return content;
     } catch (final Exception e) {
       throw new OBException("Exception when executing ws: " + wsPart, e);
     }
diff -r c9b94427d692 -r c56bf3953565 
src-test/org/openbravo/test/webservice/WSReadTest.java
--- a/src-test/org/openbravo/test/webservice/WSReadTest.java    Wed Apr 07 
17:32:16 2010 +0200
+++ b/src-test/org/openbravo/test/webservice/WSReadTest.java    Thu Apr 08 
09:47:48 2010 +0200
@@ -20,12 +20,9 @@
 package org.openbravo.test.webservice;
 
 import java.net.URLEncoder;
-import java.util.Iterator;
 
-import org.hibernate.cfg.Configuration;
-import org.hibernate.mapping.PersistentClass;
 import org.openbravo.base.model.Entity;
-import org.openbravo.base.session.SessionFactoryController;
+import org.openbravo.dal.core.OBContext;
 import org.openbravo.dal.service.OBDal;
 import org.openbravo.dal.service.OBQuery;
 import org.openbravo.model.ad.datamodel.Column;
@@ -114,17 +111,15 @@
   }
 
   /**
-   * Calls the webservice for every {...@link Entity} in the system. The test 
can take some time to run
-   * (about 5 minutes).
+   * Calls the webservice for every readable {...@link Entity} in the system. 
The test can take some
+   * time to run (about 5 minutes).
    */
   public void testAllToXML() {
-    setBigBazaarAdminContext();
-    final Configuration cfg = 
SessionFactoryController.getInstance().getConfiguration();
-
-    for (final Iterator<?> it = cfg.getClassMappings(); it.hasNext();) {
-      final PersistentClass pc = (PersistentClass) it.next();
-      final String entityName = pc.getEntityName();
-      doTestGetRequest("/ws/dal/" + entityName, "<ob:Openbravo", 200);
+    // do not replace this with a call to setUserContext,
+    OBContext.setOBContext("100");
+    for (Entity entity : 
OBContext.getOBContext().getEntityAccessChecker().getReadableEntities()) {
+      doTestGetRequest("/ws/dal/" + entity.getName() + 
"?includeChildren=false", "<ob:Openbravo",
+          200);
     }
   }
 
diff -r c9b94427d692 -r c56bf3953565 src/org/openbravo/dal/service/OBDal.java
--- a/src/org/openbravo/dal/service/OBDal.java  Wed Apr 07 17:32:16 2010 +0200
+++ b/src/org/openbravo/dal/service/OBDal.java  Thu Apr 08 09:47:48 2010 +0200
@@ -20,8 +20,10 @@
 package org.openbravo.dal.service;
 
 import java.sql.Connection;
+import java.sql.PreparedStatement;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Properties;
 
 import org.apache.log4j.Logger;
 import org.hibernate.Session;
@@ -34,6 +36,7 @@
 import org.openbravo.base.model.UniqueConstraint;
 import org.openbravo.base.provider.OBProvider;
 import org.openbravo.base.provider.OBSingleton;
+import org.openbravo.base.session.OBPropertiesProvider;
 import org.openbravo.base.structure.BaseOBObject;
 import org.openbravo.base.structure.ClientEnabled;
 import org.openbravo.base.structure.OrganizationEnabled;
@@ -90,7 +93,19 @@
     final ClassLoader currentLoader = 
Thread.currentThread().getContextClassLoader();
     try {
       
Thread.currentThread().setContextClassLoader(BorrowedConnectionProxy.class.getClassLoader());
-      return ((SessionImplementor) 
SessionHandler.getInstance().getSession()).connection();
+      final Connection connection = ((SessionImplementor) 
SessionHandler.getInstance().getSession())
+          .connection();
+
+      // set the date formatting
+      try {
+        final Properties props = 
OBPropertiesProvider.getInstance().getOpenbravoProperties();
+        final String dbSessionConfig = props.getProperty("bbdd.sessionConfig");
+        PreparedStatement pstmt = connection.prepareStatement(dbSessionConfig);
+        pstmt.executeQuery();
+      } catch (Exception e) {
+        throw new IllegalStateException(e);
+      }
+      return connection;
     } finally {
       Thread.currentThread().setContextClassLoader(currentLoader);
     }
diff -r c9b94427d692 -r c56bf3953565 src/org/openbravo/dal/service/OBQuery.java
--- a/src/org/openbravo/dal/service/OBQuery.java        Wed Apr 07 17:32:16 
2010 +0200
+++ b/src/org/openbravo/dal/service/OBQuery.java        Thu Apr 08 09:47:48 
2010 +0200
@@ -52,7 +52,11 @@
 public class OBQuery<E extends BaseOBObject> {
   private static final Logger log = Logger.getLogger(OBQuery.class);
 
-  private static final String FROM = " from ";
+  private static final String FROM_SPACED = " from ";
+  private static final String FROM = "from";
+  private static final String AS = "as";
+  private static final String WHERE = "where";
+  private static final String ORDERBY = "order by";
 
   private String whereAndOrderBy;
   private Entity entity;
@@ -138,18 +142,18 @@
   public int count() {
     // add a space because the FROM constant also starts with a space
     String qryStr = " " + stripOrderBy(createQueryString());
-    if (qryStr.toLowerCase().contains(FROM)) {
-      final int index = qryStr.indexOf(FROM) + FROM.length();
+    if (qryStr.toLowerCase().contains(FROM_SPACED)) {
+      final int index = qryStr.indexOf(FROM_SPACED) + FROM_SPACED.length();
       qryStr = qryStr.substring(index);
     }
-    final Query qry = getSession().createQuery("select count(*) " + FROM + 
qryStr);
+    final Query qry = getSession().createQuery("select count(*) " + 
FROM_SPACED + qryStr);
     setParameters(qry);
     return ((Number) qry.uniqueResult()).intValue();
   }
 
   private String stripOrderBy(String qryStr) {
-    if (qryStr.toLowerCase().indexOf("order by") != -1) {
-      return qryStr.substring(0, qryStr.toLowerCase().indexOf("order by"));
+    if (qryStr.toLowerCase().indexOf(ORDERBY) != -1) {
+      return qryStr.substring(0, qryStr.toLowerCase().indexOf(ORDERBY));
     }
     return qryStr;
   }
@@ -178,14 +182,11 @@
   }
 
   String createQueryString() {
-    final OBContext obContext = OBContext.getOBContext();
-    final Entity e = getEntity();
-
     // split the orderby and where
     final String qryStr = getWhereAndOrderBy();
     final String orderByClause;
     String whereClause;
-    final int orderByIndex = qryStr.toLowerCase().indexOf("order by");
+    final int orderByIndex = qryStr.toLowerCase().indexOf(ORDERBY);
     if (orderByIndex != -1) {
       whereClause = qryStr.substring(0, orderByIndex);
       orderByClause = qryStr.substring(orderByIndex);
@@ -195,10 +196,10 @@
     }
 
     // strip the where, is added later
-    if (whereClause.trim().toLowerCase().startsWith("where")) {
-      final int whereIndex = whereClause.toLowerCase().indexOf("where");
+    if (whereClause.trim().toLowerCase().startsWith(WHERE)) {
+      final int whereIndex = whereClause.toLowerCase().indexOf(WHERE);
       if (whereIndex != -1) {
-        whereClause = whereClause.substring(1 + whereIndex + "where".length());
+        whereClause = whereClause.substring(1 + whereIndex + WHERE.length());
       }

------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to