details:   https://code.openbravo.com/erp/devel/pi/rev/7bdf08273195
changeset: 20688:7bdf08273195
user:      Augusto Mauch <augusto.mauch <at> openbravo.com>
date:      Tue Jul 02 18:08:40 2013 +0200
summary:   Fixes issue 24181: Displayed Value flag in Table Reference works

The Displayed Value flag was not being taken into account in the 
DataToJsonConverter class, so it was not being shown in the grid. To fix this, 
the displayedV
alue property has been added to the RefTable base class. This property is 
checked in the isDisplayedValue method of the Property class which is used in 
the Da
taToJsonConverter to check if the value (searchKey property) of the entity 
should be appended to its identifier.

diffstat:

 
modules/org.openbravo.service.json/src/org/openbravo/service/json/DataToJsonConverter.java
 |  21 ++++++++-
 src/org/openbravo/base/model/Property.java                                     
            |  18 ++++++++
 src/org/openbravo/base/model/RefTable.hbm.xml                                  
            |   6 +-
 src/org/openbravo/base/model/RefTable.java                                     
            |  10 ++++
 4 files changed, 49 insertions(+), 6 deletions(-)

diffs (123 lines):

diff -r c12babe222f6 -r 7bdf08273195 
modules/org.openbravo.service.json/src/org/openbravo/service/json/DataToJsonConverter.java
--- 
a/modules/org.openbravo.service.json/src/org/openbravo/service/json/DataToJsonConverter.java
        Tue Jul 02 15:11:09 2013 +0530
+++ 
b/modules/org.openbravo.service.json/src/org/openbravo/service/json/DataToJsonConverter.java
        Tue Jul 02 18:08:40 2013 +0200
@@ -41,6 +41,8 @@
 import org.openbravo.base.structure.BaseOBObject;
 import org.openbravo.dal.core.DalUtil;
 import org.openbravo.dal.core.OBContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * Is responsible for converting Openbravo business objects ({@link 
BaseOBObject} to a json
@@ -73,6 +75,8 @@
   // limit the json serialization to these properties
   private List<String> selectedProperties = new ArrayList<String>();
 
+  private static final Logger log = 
LoggerFactory.getLogger(DataToJsonConverter.class);
+
   /**
    * Convert a list of Maps with key value pairs to a list of {@link 
JSONObject}.
    * 
@@ -260,12 +264,21 @@
 
       Property displayColumnProperty = 
DalUtil.getPropertyFromPath(referencedProperty.getEntity(),
           referencingProperty.getDisplayPropertyName());
-      if (displayColumnProperty.hasDisplayColumn()) {
+      if (referencingProperty.hasDisplayColumn()) {
+        String identifier = (String) 
obObject.get(referencingProperty.getDisplayPropertyName());
+        if (referencingProperty.isDisplayValue()) {
+          if (obObject.getEntity().hasProperty("searchKey")) {
+            String value = (String) obObject.get("searchKey");
+            identifier = value + " - " + identifier;
+          } else {
+            log.warn("Entity "
+                + obObject.getEntity().getName()
+                + " does not have a searchKey property, the flag Displayed 
Value should not be used");
+          }
+        }
         // Allowing one level deep of displayed column pointing to references 
with display column
         jsonObject.put(propertyName.replace(DalUtil.DOT, 
DalUtil.FIELDSEPARATOR)
-            + DalUtil.FIELDSEPARATOR + JsonConstants.IDENTIFIER, 
((BaseOBObject) obObject
-            
.get(referencingProperty.getDisplayPropertyName())).get(displayColumnProperty
-            .getDisplayPropertyName()));
+            + DalUtil.FIELDSEPARATOR + JsonConstants.IDENTIFIER, identifier);
       } else if (!displayColumnProperty.isPrimitive()) {
         // Displaying identifier for non primitive properties
         jsonObject.put(propertyName.replace(DalUtil.DOT, 
DalUtil.FIELDSEPARATOR)
diff -r c12babe222f6 -r 7bdf08273195 src/org/openbravo/base/model/Property.java
--- a/src/org/openbravo/base/model/Property.java        Tue Jul 02 15:11:09 
2013 +0530
+++ b/src/org/openbravo/base/model/Property.java        Tue Jul 02 18:08:40 
2013 +0200
@@ -114,6 +114,7 @@
   private int indexInEntity;
 
   private Boolean hasDisplayColumn;
+  private Boolean isDisplayValue;
   private String displayProperty;
 
   private Property trlParentProperty;
@@ -1139,6 +1140,23 @@
     return hasDisplayColumn;
   }
 
+  /**
+   * @return true if the property is a table reference which defines an 
explicit display column.
+   *         This display column is then used as the identifier of objects 
referenced through this
+   *         property.
+   */
+  public boolean isDisplayValue() {
+    if (isDisplayValue == null) {
+      if (domainType instanceof TableDomainType) {
+        final TableDomainType tableDomainType = (TableDomainType) domainType;
+        isDisplayValue = tableDomainType.getRefTable().getDisplayedValue();
+      } else {
+        isDisplayValue = false;
+      }
+    }
+    return isDisplayValue;
+  }
+
   public String getDisplayPropertyName() {
     if (displayProperty == null) {
       final Column column = ((TableDomainType) 
domainType).getRefTable().getDisplayColumn();
diff -r c12babe222f6 -r 7bdf08273195 
src/org/openbravo/base/model/RefTable.hbm.xml
--- a/src/org/openbravo/base/model/RefTable.hbm.xml     Tue Jul 02 15:11:09 
2013 +0530
+++ b/src/org/openbravo/base/model/RefTable.hbm.xml     Tue Jul 02 18:08:40 
2013 +0200
@@ -30,8 +30,10 @@
          
         <many-to-one name="reference" not-null="true" 
class="org.openbravo.base.model.Reference" column="ad_reference_id" 
insert="false" update="false"/>
 
-               <many-to-one name="column" not-null="true" 
class="org.openbravo.base.model.Column" column="ad_key"/>                       
     
-
+               <many-to-one name="column" not-null="true" 
class="org.openbravo.base.model.Column" column="ad_key"/>    
+    
+        <property name="displayedValue" 
type="org.openbravo.base.session.OBYesNoType" not-null="true" 
column="IsValueDisplayed"/>
+                       
     <many-to-one name="displayColumn" not-null="true" 
class="org.openbravo.base.model.Column" column="ad_display"/>        
                
                <property name="updated"/>
diff -r c12babe222f6 -r 7bdf08273195 src/org/openbravo/base/model/RefTable.java
--- a/src/org/openbravo/base/model/RefTable.java        Tue Jul 02 15:11:09 
2013 +0530
+++ b/src/org/openbravo/base/model/RefTable.java        Tue Jul 02 18:08:40 
2013 +0200
@@ -39,6 +39,8 @@
 
   private Column displayColumn;
 
+  private boolean displayedValue;
+
   public Column getColumn() {
     return column;
   }
@@ -69,4 +71,12 @@
   public void setDisplayColumn(Column displayColumn) {
     this.displayColumn = displayColumn;
   }
+
+  public boolean getDisplayedValue() {
+    return this.displayedValue;
+  }
+
+  public void setDisplayedValue(boolean displayedValue) {
+    this.displayedValue = displayedValue;
+  }
 }

------------------------------------------------------------------------------
This SF.net email is sponsored by Windows:

Build for Windows Store.

http://p.sf.net/sfu/windows-dev2dev
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to