details:   /erp/devel/pi/rev/12360b546545
changeset: 9623:12360b546545
user:      Martin Taal <martin.taal <at> openbravo.com>
date:      Sat Jan 08 00:15:08 2011 +0100
summary:   Solved errors in date formatting in input fields

details:   /erp/devel/pi/rev/6c4b963ab33a
changeset: 9624:6c4b963ab33a
user:      Martin Taal <martin.taal <at> openbravo.com>
date:      Sat Jan 08 00:16:46 2011 +0100
summary:   Handle references to non-pk columns

details:   /erp/devel/pi/rev/60230d10f248
changeset: 9625:60230d10f248
user:      Martin Taal <martin.taal <at> openbravo.com>
date:      Sat Jan 08 00:17:45 2011 +0100
summary:   Improved error reporting

details:   /erp/devel/pi/rev/10551bb5e8ca
changeset: 9626:10551bb5e8ca
user:      Martin Taal <martin.taal <at> openbravo.com>
date:      Sat Jan 08 00:18:38 2011 +0100
summary:   Made boolean fields non-mandatory

diffstat:

 
modules/org.openbravo.service.datasource/src/org/openbravo/service/datasource/DataSourceProperty.java
                          |   3 +-
 
modules/org.openbravo.service.json/src/org/openbravo/service/json/DefaultJsonDataService.java
                                  |   8 +-
 
modules/org.openbravo.service.json/src/org/openbravo/service/json/JsonToDataConverter.java
                                     |  82 ++++++++-
 
modules/org.openbravo.userinterface.smartclient/src/org/openbravo/userinterface/smartclient/templates/smartclient_types_js.ftl
 |  16 +-
 4 files changed, 87 insertions(+), 22 deletions(-)

diffs (202 lines):

diff -r eb2af384ae4c -r 10551bb5e8ca 
modules/org.openbravo.service.datasource/src/org/openbravo/service/datasource/DataSourceProperty.java
--- 
a/modules/org.openbravo.service.datasource/src/org/openbravo/service/datasource/DataSourceProperty.java
     Sat Jan 08 00:14:18 2011 +0100
+++ 
b/modules/org.openbravo.service.datasource/src/org/openbravo/service/datasource/DataSourceProperty.java
     Sat Jan 08 00:18:38 2011 +0100
@@ -67,7 +67,8 @@
     final DataSourceProperty dsProperty = new DataSourceProperty();
     dsProperty.setName(property.getName());
     dsProperty.setId(property.isId());
-    dsProperty.setMandatory(property.isMandatory());
+    // note booleans are never mandatory as they only have inputs with 2 values
+    dsProperty.setMandatory(!property.isBoolean() && property.isMandatory());
     dsProperty.setAuditInfo(property.isAuditInfo());
     dsProperty.setUpdatable(property.isUpdatable());
     dsProperty.setBoolean(property.isBoolean());
diff -r eb2af384ae4c -r 10551bb5e8ca 
modules/org.openbravo.service.json/src/org/openbravo/service/json/DefaultJsonDataService.java
--- 
a/modules/org.openbravo.service.json/src/org/openbravo/service/json/DefaultJsonDataService.java
     Sat Jan 08 00:14:18 2011 +0100
+++ 
b/modules/org.openbravo.service.json/src/org/openbravo/service/json/DefaultJsonDataService.java
     Sat Jan 08 00:18:38 2011 +0100
@@ -303,6 +303,7 @@
       }
 
       if (fromJsonConverter.hasErrors()) {
+        OBDal.getInstance().rollbackAndClose();
         // report the errors
         final JSONObject jsonResult = new JSONObject();
         final JSONObject jsonResponse = new JSONObject();
@@ -313,12 +314,7 @@
           final JSONObject errorMessageObject = new JSONObject();
           errorMessageObject.put(JsonConstants.RESPONSE_ERRORMESSAGE, 
error.getThrowable()
               .getMessage());
-          if (error.getProperty().isPrimitive()) {
-            errorsObject.put(error.getProperty().getName(), 
errorMessageObject);
-          } else {
-            errorsObject.put(error.getProperty().getName() + "." + 
JsonConstants.ID,
-                errorMessageObject);
-          }
+          errorsObject.put(error.getProperty().getName(), errorMessageObject);
         }
         jsonResponse.put(JsonConstants.RESPONSE_ERRORS, errorsObject);
         jsonResult.put(JsonConstants.RESPONSE_RESPONSE, jsonResponse);
diff -r eb2af384ae4c -r 10551bb5e8ca 
modules/org.openbravo.service.json/src/org/openbravo/service/json/JsonToDataConverter.java
--- 
a/modules/org.openbravo.service.json/src/org/openbravo/service/json/JsonToDataConverter.java
        Sat Jan 08 00:14:18 2011 +0100
+++ 
b/modules/org.openbravo.service.json/src/org/openbravo/service/json/JsonToDataConverter.java
        Sat Jan 08 00:18:38 2011 +0100
@@ -34,12 +34,14 @@
 import org.codehaus.jettison.json.JSONArray;
 import org.codehaus.jettison.json.JSONException;
 import org.codehaus.jettison.json.JSONObject;
+import org.jfree.util.Log;
 import org.openbravo.base.model.Entity;
 import org.openbravo.base.model.Property;
 import org.openbravo.base.provider.OBProvider;
 import org.openbravo.base.structure.BaseOBObject;
 import org.openbravo.base.util.Check;
 import org.openbravo.dal.service.OBDal;
+import org.openbravo.dal.service.OBQuery;
 
 /**
  * Converts json data to Openbravo business object(s).
@@ -326,16 +328,7 @@
   }
 
   /**
-   * Tries to find an object first in the internal map which is maintained to 
first resolve id's
-   * internally within the complete json string. If not found there then the 
database is queried
-   * using the entity and referenceId. If not found there (or the referenceId 
== null) then create a
-   * new instance of the entity.
-   * 
-   * @param entity
-   *          the entity to retrieve/create
-   * @param referencedId
-   *          the id of the entity
-   * @return an existing of new BaseOBObject
+   * @see #getBaseOBObjectFromId(Entity, Property, String)
    */
   protected BaseOBObject getBaseOBObjectFromId(Entity entity, String 
referencedId) {
     BaseOBObject value = null;
@@ -363,6 +356,65 @@
   }
 
   /**
+   * Tries to find an object first in the internal map which is maintained to 
first resolve id's
+   * internally within the complete json string. If not found there then the 
database is queried
+   * using the entity and referenceId. If not found there (or the referenceId 
== null) then create a
+   * new instance of the entity.
+   * 
+   * @param entity
+   *          the entity to retrieve/create
+   * @param property
+   *          the property referencing to the entity
+   * @param referencedId
+   *          the id of the entity
+   * @return an existing of new BaseOBObject
+   */
+  protected BaseOBObject getBaseOBObjectFromId(Entity entity, Property 
property, String referencedId) {
+    BaseOBObject value = null;
+    if (referencedId != null) {
+      final String key = getObjectKey(referencedId, entity.getName());
+      if (keyToObject.get(key) != null) {
+        value = keyToObject.get(key);
+      } else {
+        if (property.getReferencedProperty() != null) {
+          final OBQuery<BaseOBObject> qry = 
OBDal.getInstance().createQuery(entity.getName(),
+              property.getReferencedProperty().getName() + "=:reference");
+          qry.setNamedParameter("reference", referencedId);
+          qry.setFilterOnActive(false);
+          qry.setFilterOnReadableClients(false);
+          qry.setFilterOnReadableOrganization(false);
+          final List<BaseOBObject> result = qry.list();
+          if (result.size() > 1) {
+            Log.warn("More than one result when querying " + entity + " using 
property "
+                + property.getReferencedProperty() + " with value " + 
referencedId
+                + ", choosing the first result");
+            value = result.get(0);
+          } else if (result.size() == 1) {
+            value = result.get(0);
+          } else {
+            value = null;
+          }
+        } else {
+          value = OBDal.getInstance().get(entity.getName(), referencedId);
+        }
+      }
+      if (value == null) {
+        value = (BaseOBObject) OBProvider.getInstance().get(entity.getName());
+        // put it here, it must be imported later as a real object
+        newObjects.put(key, (BaseOBObject) value);
+      }
+      keyToObject.put(key, (BaseOBObject) value);
+    } else {
+      value = (BaseOBObject) OBProvider.getInstance().get(entity.getName());
+    }
+
+    // note: when inheritance is supported then this Check should be 
changed/removed
+    Check.isTrue(value.getEntity() == entity, "The object " + value
+        + " has a different entity then the request entity " + entity);
+    return value;
+  }
+
+  /**
    * Checks if the property is settable ({...@link 
#isNotConvertable(BaseOBObject, Property)}. If so
    * the jsonValue is converted ({...@link #convertPrimitive(Property, 
Object)}, in case of a primive),
    * or in case of a reference property the referenced object is read/created.
@@ -395,7 +447,11 @@
       } else if (jsonValue instanceof String) {
         // an id
         final String referenceId = (String) jsonValue;
-        value = getBaseOBObjectFromId(property.getTargetEntity(), referenceId);
+        if (property.getReferencedProperty() != null) {
+          value = getBaseOBObjectFromId(property.getTargetEntity(), property, 
referenceId);
+        } else {
+          value = getBaseOBObjectFromId(property.getTargetEntity(), 
referenceId);
+        }
       } else {
         // a json object
         // try another approach, maybe the value is a jsonobject itself
@@ -525,6 +581,8 @@
       } catch (ParseException e) {
         throw new Error(e);
       }
+    } else if (property.isBoolean() && value instanceof String) {
+      return Boolean.parseBoolean((String) value);
     } else if (value instanceof Double) {
       return new BigDecimal((Double) value);
     } else if (value instanceof Integer && property.getPrimitiveObjectType() 
== Long.class) {
@@ -535,6 +593,8 @@
       return new Float((Long) value);
     } else if (value instanceof Number && property.getPrimitiveObjectType() == 
BigDecimal.class) {
       return new BigDecimal(((Number) value).doubleValue());
+    } else if (value instanceof String && ((String) value).trim().length() == 
0) {
+      return null;
     }
     return value;
   }
diff -r eb2af384ae4c -r 10551bb5e8ca 
modules/org.openbravo.userinterface.smartclient/src/org/openbravo/userinterface/smartclient/templates/smartclient_types_js.ftl
--- 
a/modules/org.openbravo.userinterface.smartclient/src/org/openbravo/userinterface/smartclient/templates/smartclient_types_js.ftl
    Sat Jan 08 00:14:18 2011 +0100
+++ 
b/modules/org.openbravo.userinterface.smartclient/src/org/openbravo/userinterface/smartclient/templates/smartclient_types_js.ftl
    Sat Jan 08 00:18:38 2011 +0100
@@ -35,15 +35,23 @@
 </#list>       
 
 // set the global date format
-isc.Date.setShortDisplayFormat(function(value) {
-    return OB.Utilities.Date.JSToOB(value, OB.Format.date);
+isc.Date.setShortDisplayFormat(function(useCustomTimeZone) {
+    return OB.Utilities.Date.JSToOB(this, OB.Format.date);
 });
 
-isc.Date.setNormalDisplayFormat(function(value) {
-    return OB.Utilities.Date.JSToOB(value, OB.Format.date);
+isc.Date.setNormalDisplayFormat(function(useCustomTimeZone) {
+    return OB.Utilities.Date.JSToOB(this, OB.Format.date);
 });
 
+isc.Date.inputFormat = function(dateString, format, centuryThreshold, 
suppressConversion) {
+    return OB.Utilities.Date.OBToJS(dateString, OB.Format.date);
+};
+
 isc.Date.setInputFormat(function(value) {
     return OB.Utilities.Date.OBToJS(value, OB.Format.date);
 });
 
+isc.Date.setShortDatetimeDisplayFormat(function(useCustomTimeZone) {
+    return OB.Utilities.Date.JSToOB(this, OB.Format.dateTime);
+});
+

------------------------------------------------------------------------------
Gaining the trust of online customers is vital for the success of any company
that requires sensitive data to be transmitted over the Web.   Learn how to 
best implement a security strategy that keeps consumers' information secure 
and instills the confidence they need to proceed with transactions.
http://p.sf.net/sfu/oracle-sfdevnl 
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to