Fixes issue 42285: Apply new HQL Style to AccessTypeInjector and implementors
authorCristian Berner <cristian.berner@openbravo.com>
Thu, 14 Nov 2019 15:47:30 +0100
changeset 36843 5a438a7a4de3
parent 36842 c47b63fff577
child 36844 2861c11135dd
Fixes issue 42285: Apply new HQL Style to AccessTypeInjector and implementors
src/org/openbravo/role/inheritance/access/AccessTypeInjector.java
src/org/openbravo/role/inheritance/access/AlertRecipientAccessInjector.java
src/org/openbravo/role/inheritance/access/PreferenceAccessInjector.java
--- a/src/org/openbravo/role/inheritance/access/AccessTypeInjector.java	Tue Oct 08 11:48:18 2019 +0200
+++ b/src/org/openbravo/role/inheritance/access/AccessTypeInjector.java	Thu Nov 14 15:47:30 2019 +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) 2015 Openbravo SLU 
+ * All portions are Copyright (C) 2015-2019 Openbravo SLU 
  * All Rights Reserved. 
  ************************************************************************
  */
@@ -204,12 +204,14 @@
     try {
       String roleProperty = getRoleProperty();
       Class<T> clazz = (Class<T>) Class.forName(className);
-      final StringBuilder whereClause = new StringBuilder();
-      whereClause.append(" as p ");
-      whereClause.append(" where p.").append(roleProperty).append(" = :roleId");
-      addEntityWhereClause(whereClause);
-      final OBQuery<T> query = OBDal.getInstance().createQuery(clazz, whereClause.toString());
-      query.setNamedParameter("roleId", role.getId());
+      //@formatter:off
+      String whereClause = 
+              " as p " +
+              " where p." + roleProperty + " = :roleId";
+      //@formatter:on
+      whereClause = addEntityWhereClause(whereClause);
+      final OBQuery<T> query = OBDal.getInstance().createQuery(clazz, whereClause)
+              .setNamedParameter("roleId", role.getId());
       doEntityParameterReplacement(query);
       query.setFilterOnActive(false);
       return (List<? extends InheritedAccessEnabled>) query.list();
@@ -233,16 +235,18 @@
       String roleId) throws ClassNotFoundException {
     String roleProperty = getRoleProperty();
     Class<T> clazz = (Class<T>) Class.forName(getClassName());
-    final StringBuilder whereClause = new StringBuilder();
-    whereClause.append(" as p");
-    whereClause.append(" where p.").append(roleProperty).append(" = :roleId");
-    whereClause.append(" and p.").append(getSecuredElementName()).append(".id = :elementId");
-    addEntityWhereClause(whereClause);
-    final OBQuery<T> query = OBDal.getInstance().createQuery(clazz, whereClause.toString());
-    query.setNamedParameter("roleId", roleId);
-    query.setNamedParameter("elementId", getSecuredElementIdentifier(access));
-    query.setFilterOnActive(false);
-    query.setMaxResult(1);
+    //@formatter:off
+    String whereClause = 
+            " as p " +
+            " where p." + roleProperty + " = :roleId" +
+            "   and p." + getSecuredElementName() + ".id = :elementId";
+    //@formatter:on
+    whereClause = addEntityWhereClause(whereClause);
+    final OBQuery<T> query = OBDal.getInstance().createQuery(clazz, whereClause)
+            .setNamedParameter("roleId", roleId)
+            .setNamedParameter("elementId", getSecuredElementIdentifier(access))
+            .setFilterOnActive(false)
+            .setMaxResult(1);
     return (InheritedAccessEnabled) query.uniqueResult();
   }
 
@@ -250,9 +254,11 @@
    * Includes in the where clause some filtering needed for same cases.
    * 
    * @param whereClause
-   *          The where clause where the particular filtering will be included
+   *          The initial where clause
+   * @return Entity where clause with the filtering included
    */
-  public void addEntityWhereClause(StringBuilder whereClause) {
+  public String addEntityWhereClause(String whereClause) {
+    return whereClause;
   }
 
   /**
--- a/src/org/openbravo/role/inheritance/access/AlertRecipientAccessInjector.java	Tue Oct 08 11:48:18 2019 +0200
+++ b/src/org/openbravo/role/inheritance/access/AlertRecipientAccessInjector.java	Thu Nov 14 15:47:30 2019 +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) 2015 Openbravo SLU 
+ * All portions are Copyright (C) 2015-2019 Openbravo SLU 
  * All Rights Reserved. 
  ************************************************************************
  */
@@ -65,9 +65,9 @@
   }
 
   @Override
-  public void addEntityWhereClause(StringBuilder whereClause) {
+  public String addEntityWhereClause(String whereClause) {
     // Inheritable alert recipients are those with empty User/Contact field
-    whereClause.append(" and p.userContact is null");
+    return whereClause + " and p.userContact is null";
   }
 
   @Override
--- a/src/org/openbravo/role/inheritance/access/PreferenceAccessInjector.java	Tue Oct 08 11:48:18 2019 +0200
+++ b/src/org/openbravo/role/inheritance/access/PreferenceAccessInjector.java	Thu Nov 14 15:47:30 2019 +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) 2015 Openbravo SLU 
+ * All portions are Copyright (C) 2015-2019 Openbravo SLU 
  * All Rights Reserved. 
  ************************************************************************
  */
@@ -93,11 +93,14 @@
   }
 
   @Override
-  public void addEntityWhereClause(StringBuilder whereClause) {
+  public String addEntityWhereClause(String whereClause) {
     // Inheritable preferences are those that are not in the black list and also has a value in
     // the Visible At Role field
-    whereClause.append(" and p.visibleAtRole is not null");
-    whereClause.append(" and p.property not in (:blackList)");
+    //@formatter:off
+    return whereClause + 
+            "   and p.visibleAtRole is not null" +
+            "   and p.property not in (:blackList)";
+    //@formatter:on
   }
 
   @Override