fixed bug 29117: empty linked items if computed column points current entity
authorAsier Lostalé <asier.lostale@openbravo.com>
Thu, 05 Mar 2015 16:04:13 +0100
changeset 26128 a410732b5a7f
parent 26127 1c75a6afca4e
child 26129 9a12a6271cdd
fixed bug 29117: empty linked items if computed column points current entity

Linked items section didn't receive any row and remained in "loading data" state
when a computed column in any entity linked to the entity the section was used in.

The problem was caused by an error when trying to deal with computed column in
linked items. No error was shown nor in UI nor in openbravo.log.

This fix:
- Adds log in openbravo.log including stack trace in case of error computing
linked items
- NPE getMessage is null which caused not to be shown in the UI, it is casted
to String
- Computed Columns are properly ignored in linked items

IMPORTANT NOTE: Computed Columns cannot be evaluated in linked items so they
are ignored
src/org/openbravo/erpCommon/utility/UsedByLink.java
--- a/src/org/openbravo/erpCommon/utility/UsedByLink.java	Thu Mar 05 10:49:36 2015 +0100
+++ b/src/org/openbravo/erpCommon/utility/UsedByLink.java	Thu Mar 05 16:04:13 2015 +0100
@@ -11,7 +11,7 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2001-2012 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2015 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -241,8 +241,10 @@
       jsonObject = buildJsonObject(jsonObject, searchResult);
 
     } catch (Exception e) {
+      log4j.error(
+          "Error getting Categories for windowId: " + windowId + " - entity: " + entityName, e);
       try {
-        jsonObject.put("msg", e.getMessage());
+        jsonObject.put("msg", "" + e.getMessage());
       } catch (JSONException jex) {
         log4j.error("Error trying to generate message: " + jex.getMessage(), jex);
       }
@@ -291,8 +293,9 @@
       }
 
     } catch (Exception e) {
+      log4j.error("Error getting linkend items for tab " + adTabId, e);
       try {
-        jsonObject.put("msg", e.getMessage());
+        jsonObject.put("msg", "" + e.getMessage());
       } catch (JSONException jex) {
         log4j.error("Error trying to generate message: " + jex.getMessage(), jex);
       }
@@ -538,7 +541,6 @@
         usedByLinkDataJsonObj.put("editOrDeleteOnly", "ED".equals(data.uipattern));
         usedByLinkDataJsonObjects.add(usedByLinkDataJsonObj);
       }
-
       jsonObject.put("usedByLinkData", usedByLinkDataJsonObjects);
     }
     if (msg != null) {
@@ -655,7 +657,8 @@
           // ignore one-to-many (a list of children)
           if (!property.isOneToMany() && property.getColumnName() != null
               && property.getTargetEntity() != null
-              && property.getTargetEntity().getTableName().equalsIgnoreCase(tableName)) {
+              && property.getTargetEntity().getTableName().equalsIgnoreCase(tableName)
+              && !property.isComputedColumn()) {
             // Datasource tables are skipped
             linkedTableId = property.getEntity().getTableId();
             linkedTableObject = OBDal.getInstance().get(Table.class, linkedTableId);