details:   https://code.openbravo.com/erp/devel/pi/rev/af0539a25f8c
changeset: 13224:af0539a25f8c
user:      Asier Lostalé <asier.lostale <at> openbravo.com>
date:      Mon Jul 18 12:26:21 2011 +0200
summary:   fixed issue 16464: Handle translations in grid

  Using isTranlsated column to determine whether a property can be translated.
  Based on this tranlsate the property when needed to shown in UI as single 
property
  or part of an identifier.

details:   https://code.openbravo.com/erp/devel/pi/rev/389abd2b89f7
changeset: 13225:389abd2b89f7
user:      Asier Lostalé <asier.lostale <at> openbravo.com>
date:      Mon Jul 18 12:27:04 2011 +0200
summary:   fixed issue 16464: Handle translations in grid

  Filter taking into account translations

details:   https://code.openbravo.com/erp/devel/pi/rev/f7319ac66cd2
changeset: 13226:f7319ac66cd2
user:      Asier Lostalé <asier.lostale <at> openbravo.com>
date:      Mon Jul 18 12:27:31 2011 +0200
summary:   fixed issue 16464: Handle translations in grid

  Removed incorrect isTranlsated setting

details:   https://code.openbravo.com/erp/devel/pi/rev/f8b10899ee01
changeset: 13227:f8b10899ee01
user:      Asier Lostalé <asier.lostale <at> openbravo.com>
date:      Thu Jul 21 10:22:13 2011 +0200
summary:   related to issue 16464: Handle translations in grid

  Using Collection filtering instead of Criteria to improve performance.

details:   https://code.openbravo.com/erp/devel/pi/rev/661e642807ed
changeset: 13228:661e642807ed
user:      Asier Lostalé <asier.lostale <at> openbravo.com>
date:      Thu Jul 21 11:06:38 2011 +0200
summary:   related to issue 16464: Handle translations in grid

  Properties are not translatable in case there are not installed translations
  in the sytem. In this way in case of no translations installed trl tables are
  not queried improving performance.

diffstat:

 
modules/org.openbravo.service.json/src/org/openbravo/service/json/AdvancedQueryBuilder.java
 |  22 ++-
 src-db/database/sourcedata/AD_COLUMN.xml                                       
             |   2 +-
 src/org/openbravo/base/model/Column.hbm.xml                                    
             |   1 +
 src/org/openbravo/base/model/Column.java                                       
             |   9 +
 src/org/openbravo/base/model/ModelProvider.java                                
             |  32 +++-
 src/org/openbravo/base/model/Property.java                                     
             |  86 ++++++++++
 src/org/openbravo/base/structure/BaseOBObject.java                             
             |  70 ++++++++-
 src/org/openbravo/base/structure/IdentifierProvider.java                       
             |  19 +-
 src/org/openbravo/dal/core/OBContext.java                                      
             |  24 ++
 9 files changed, 254 insertions(+), 11 deletions(-)

diffs (truncated from 505 to 300 lines):

diff -r 08b15a140ffa -r 661e642807ed 
modules/org.openbravo.service.json/src/org/openbravo/service/json/AdvancedQueryBuilder.java
--- 
a/modules/org.openbravo.service.json/src/org/openbravo/service/json/AdvancedQueryBuilder.java
       Thu Jul 21 10:47:42 2011 +0200
+++ 
b/modules/org.openbravo.service.json/src/org/openbravo/service/json/AdvancedQueryBuilder.java
       Thu Jul 21 11:06:38 2011 +0200
@@ -884,7 +884,27 @@
       }
       // note to_char is added to handle null values correctly
       if (prop.getReferencedProperty() == null) {
-        sb.append("COALESCE(to_char(" + prefix + prop.getName() + "),'')");
+        if (prop.isTranslatable()) {
+          // HQL for trl properties. Doing it as a select because it cannot be 
done as left join.
+          // Example:
+          //
+          // select coalesce(w.name, t.name)
+          // from ADWindow w left join w.aDWindowTrlList as t with t.language 
= :lang
+          // where w.id=:window
+          //
+          // raises: with clause can only reference columns in the driving 
table
+
+          sb.append("COALESCE(to_char((select " + 
prop.getTranslationProperty().getName()
+              + " from " + prop.getTranslationProperty().getEntity().getName() 
+ " as t where t."
+              + prop.getTrlParentProperty().getName() + " = "
+              + prefix.substring(0, prefix.lastIndexOf('.')) + " and 
t.language.language='"
+              + OBContext.getOBContext().getLanguage().getLanguage() + "')), 
to_char(" + prefix
+              + prop.getName() + "), '')");
+
+        } else {
+          sb.append("COALESCE(to_char(" + prefix + prop.getName() + "),'')");
+        }
+
       } else {
         final List<Property> newIdentifierProperties = 
prop.getReferencedProperty().getEntity()
             .getIdentifierProperties();
diff -r 08b15a140ffa -r 661e642807ed src-db/database/sourcedata/AD_COLUMN.xml
--- a/src-db/database/sourcedata/AD_COLUMN.xml  Thu Jul 21 10:47:42 2011 +0200
+++ b/src-db/database/sourcedata/AD_COLUMN.xml  Thu Jul 21 11:06:38 2011 +0200
@@ -49522,7 +49522,7 @@
 <!--3378-->  <ISMANDATORY><![CDATA[N]]></ISMANDATORY>
 <!--3378-->  <ISUPDATEABLE><![CDATA[N]]></ISUPDATEABLE>
 <!--3378-->  <ISIDENTIFIER><![CDATA[N]]></ISIDENTIFIER>
-<!--3378-->  <ISTRANSLATED><![CDATA[Y]]></ISTRANSLATED>
+<!--3378-->  <ISTRANSLATED><![CDATA[N]]></ISTRANSLATED>
 <!--3378-->  <ISENCRYPTED><![CDATA[N]]></ISENCRYPTED>
 <!--3378-->  <ISSELECTIONCOLUMN><![CDATA[N]]></ISSELECTIONCOLUMN>
 <!--3378-->  <AD_ELEMENT_ID><![CDATA[1005]]></AD_ELEMENT_ID>
diff -r 08b15a140ffa -r 661e642807ed src/org/openbravo/base/model/Column.hbm.xml
--- a/src/org/openbravo/base/model/Column.hbm.xml       Thu Jul 21 10:47:42 
2011 +0200
+++ b/src/org/openbravo/base/model/Column.hbm.xml       Thu Jul 21 11:06:38 
2011 +0200
@@ -40,6 +40,7 @@
                <property name="mandatory" 
type="org.openbravo.base.session.OBYesNoType" column="ismandatory"/>
                <property name="encrypted" 
type="org.openbravo.base.session.OBYesNoType" column="isencrypted"/>
                <property name="decryptable" 
type="org.openbravo.base.session.OBYesNoType" column="isdesencryptable"/>
+               <property name="translatable" 
type="org.openbravo.base.session.OBYesNoType" column="istranslated"/>
                <property name="valueMin"/>
                <property name="valueMax"/>
                <property name="developmentStatus"/>
diff -r 08b15a140ffa -r 661e642807ed src/org/openbravo/base/model/Column.java
--- a/src/org/openbravo/base/model/Column.java  Thu Jul 21 10:47:42 2011 +0200
+++ b/src/org/openbravo/base/model/Column.java  Thu Jul 21 11:06:38 2011 +0200
@@ -65,6 +65,7 @@
   private Boolean isTransient;
   private String isTransientCondition;
   private Integer position;
+  private boolean translatable;
 
   private Module module;
 
@@ -436,4 +437,12 @@
   public void setDecryptable(boolean decryptable) {
     this.decryptable = decryptable;
   }
+
+  public boolean isTranslatable() {
+    return translatable;
+  }
+
+  public void setTranslatable(boolean translatable) {
+    this.translatable = translatable;
+  }
 }
diff -r 08b15a140ffa -r 661e642807ed 
src/org/openbravo/base/model/ModelProvider.java
--- a/src/org/openbravo/base/model/ModelProvider.java   Thu Jul 21 10:47:42 
2011 +0200
+++ b/src/org/openbravo/base/model/ModelProvider.java   Thu Jul 21 11:06:38 
2011 +0200
@@ -230,8 +230,10 @@
 
       // in the second pass set all the referenceProperties
       // and targetEntities
-      // uses global member tablesByTableName
-      setReferenceProperties();
+      // uses global member tablesByTableName.
+      // Obtains list of columns candidate to be translated, to be handled 
after setting properties
+      // in parent entities.
+      List<Column> translatableColumns = setReferenceProperties();
 
       // add virtual property for the case that the
       // id property is also a reference (a foreign key)
@@ -281,6 +283,9 @@
           }
         }
       }
+
+      setTranslatableColumns(translatableColumns);
+
     } finally {
       log.debug("Closing session and sessionfactory used during model read");
       tx.commit();
@@ -290,6 +295,19 @@
     clearLists();
   }
 
+  private void setTranslatableColumns(List<Column> translatableColumns) {
+    for (Column c : translatableColumns) {
+      final Entity translationEntity = 
getEntityByTableName(c.getTable().getTableName() + "_Trl");
+
+      Property translationProperty = null;
+      if (translationEntity != null) {
+        translationProperty = 
translationEntity.getPropertyByColumnName(c.getColumnName());
+      }
+      final Property thisProp = c.getProperty();
+      thisProp.setTranslatable(translationProperty);
+    }
+  }
+
   /**
    * This method uses a normal JDBC connection to retrieve the classes of the 
references. These
    * classes will be instantiated and if they implement the correct interface, 
they will be added to
@@ -427,9 +445,11 @@
     }
   }
 
-  private void setReferenceProperties() {
+  private List<Column> setReferenceProperties() {
     log.debug("Setting reference property");
     // uses global member tablesByTableName
+
+    List<Column> translatableColumns = new ArrayList<Column>();
     for (final Table t : tablesByTableName.values()) {
       for (final Column c : t.getColumns()) {
         if (!c.isPrimitiveType()) {
@@ -465,9 +485,15 @@
           final Property thatProperty = thatColumn.getProperty();
           thisProp.setReferencedProperty(thatProperty);
         }
+
+        if (c.isTranslatable()) {
+          translatableColumns.add(c);
+        }
       }
     }
 
+    return translatableColumns;
+
   }
 
   private List<Table> removeInvalidTables(List<Table> allTables) {
diff -r 08b15a140ffa -r 661e642807ed src/org/openbravo/base/model/Property.java
--- a/src/org/openbravo/base/model/Property.java        Thu Jul 21 10:47:42 
2011 +0200
+++ b/src/org/openbravo/base/model/Property.java        Thu Jul 21 11:06:38 
2011 +0200
@@ -39,6 +39,7 @@
 import org.openbravo.base.util.Check;
 import org.openbravo.base.validation.PropertyValidator;
 import org.openbravo.base.validation.ValidationException;
+import org.openbravo.dal.core.OBContext;
 
 /**
  * Together with {@link Entity Entity}, the Property is the main part of the 
in-memory model. A
@@ -89,6 +90,8 @@
   private Boolean allowDerivedRead;
   private boolean isClientOrOrganization;
   private DomainType domainType;
+  private boolean translatable = false;
+  private Property translationProperty;
 
   private PropertyValidator validator;
 
@@ -109,6 +112,9 @@
   private Boolean hasDisplayColumn;
   private String displayProperty;
 
+  private Property trlParentProperty;
+  private Property trlOneToManyProperty;
+
   /**
    * Initializes this Property using the information from the Column.
    * 
@@ -173,6 +179,7 @@
     setInactive(!fromColumn.isActive());
 
     setModule(fromColumn.getModule());
+
   }
 
   // TODO: remove this hack when possible
@@ -1132,4 +1139,83 @@
     }
     return displayProperty;
   }
+
+  /**
+   * Returns whether a property is translatable to other languages. A property 
can be translated in
+   * case it has been marked in AD and there are translations installed in the 
system.
+   * 
+   */
+  public boolean isTranslatable() {
+    return translatable && OBContext.hasTranslationInstalled();
+  }
+
+  /**
+   * This property is candidate to be translatable (marked in DB as 
isTranlated). It checks it is
+   * actually translatable and sets the property as translatable or not 
regarding this.
+   * 
+   * @param translationProperty
+   *          it is the property in the trl table that holds the translation 
for this property
+   */
+  void setTranslatable(Property translationProperty) {
+    log.debug("Setting translatable for " + this.getEntity().getTableName() + 
"."
+        + this.getColumnName());
+
+    if (translationProperty == null) {
+      log.warn(this.getEntity().getTableName() + "." + this.getColumnName()
+          + " is not translatable: null translationProperty");
+      translatable = false;
+      return;
+    }
+
+    Property pk = entity.getIdProperties().get(0); // Assuming a single 
property as PK
+
+    try {
+      translationProperty.getEntity().getPropertyByColumnName("ad_language");
+    } catch (org.openbravo.base.util.CheckException e) {
+      // This exception is raised when the property is not found
+      translatable = false;
+      log.warn(this.getEntity().getTableName() + "." + this.getColumnName()
+          + " is not translatable: ad_language column not found in its trl 
table");
+      return;
+    }
+
+    Property trlPropertyListInBase = null;
+    for (Property p : this.getEntity().getProperties()) {
+      if (p.isOneToMany() && 
translationProperty.getEntity().equals(p.getTargetEntity())) {
+        trlPropertyListInBase = p;
+        break;
+      }
+    }
+
+    if (trlPropertyListInBase == null) {
+      translatable = false;
+      log.warn(this.getEntity().getTableName() + "." + this.getColumnName()
+          + " is not translatable: not found one to many property to trl 
table");
+      return;
+    }
+
+    for (Property trlParent : 
translationProperty.getEntity().getParentProperties()) {
+      if (pk.equals(trlParent.getReferencedProperty())) {
+        this.trlParentProperty = trlParent;
+        this.translationProperty = translationProperty;
+        this.trlOneToManyProperty = trlPropertyListInBase;
+        translatable = true;
+        return;
+      }
+    }
+    log.warn(this.getEntity().getTableName() + "." + this.getColumnName()
+        + " is not translatable: not found correspoding property in its trl 
table");
+  }
+
+  public Property getTranslationProperty() {
+    return translationProperty;
+  }
+
+  public Property getTrlParentProperty() {
+    return trlParentProperty;
+  }
+
+  public Property getTrlOneToManyProperty() {
+    return trlOneToManyProperty;
+  }
 }
diff -r 08b15a140ffa -r 661e642807ed 
src/org/openbravo/base/structure/BaseOBObject.java
--- a/src/org/openbravo/base/structure/BaseOBObject.java        Thu Jul 21 
10:47:42 2011 +0200
+++ b/src/org/openbravo/base/structure/BaseOBObject.java        Thu Jul 21 
11:06:38 2011 +0200
@@ -20,6 +20,7 @@
 package org.openbravo.base.structure;
 
 import java.io.Serializable;
+import java.util.List;
 
 import org.openbravo.base.exception.OBSecurityException;
 import org.openbravo.base.model.BaseOBObjectDef;
@@ -32,6 +33,8 @@
 import org.openbravo.base.validation.ValidationException;
 import org.openbravo.dal.core.OBContext;
 import org.openbravo.dal.core.OBInterceptor;
+import org.openbravo.dal.service.OBDal;
+import org.openbravo.model.ad.system.Language;
 
 /**
  * Base business object, the root of the inheritance tree for all business 
objects. The class model
@@ -67,6 +70,14 @@
   // if set to true then derived readable is not checked
   private boolean allowRead = false;
 

------------------------------------------------------------------------------
5 Ways to Improve & Secure Unified Communications
Unified Communications promises greater efficiencies for business. UC can 
improve internal communications as well as offer faster, more efficient ways
to interact with customers and streamline customer service. Learn more!
http://www.accelacomm.com/jaw/sfnl/114/51426253/
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to