related to issue 31577: code review improvements
authorCarlos Aristu <carlos.aristu@openbravo.com>
Wed, 02 Dec 2015 10:33:15 +0100
changeset 28088 9b3efdffbb5f
parent 28087 1e56db81f203
child 28089 d17c2694db1c
related to issue 31577: code review improvements
modules/org.openbravo.client.application/src/org/openbravo/client/application/ADAlertDatasourceService.java
--- a/modules/org.openbravo.client.application/src/org/openbravo/client/application/ADAlertDatasourceService.java	Wed Dec 02 09:03:46 2015 +0000
+++ b/modules/org.openbravo.client.application/src/org/openbravo/client/application/ADAlertDatasourceService.java	Wed Dec 02 10:33:15 2015 +0100
@@ -94,21 +94,26 @@
 
   private List<String> getAlertIds() {
     // Get alert rules visible for context's the role/user.
-    StringBuffer whereClause = new StringBuffer();
-    whereClause.append(" as ar ");
-    whereClause.append("\nwhere exists (select 1 from ar."
-        + AlertRule.PROPERTY_ADALERTRECIPIENTLIST + " as arr");
-    whereClause.append("\n    where arr." + AlertRecipient.PROPERTY_USERCONTACT + ".id = :user");
-    whereClause.append("\n      or (");
-    whereClause.append("arr." + AlertRecipient.PROPERTY_USERCONTACT + " is null");
-    whereClause.append("\n          and arr." + AlertRecipient.PROPERTY_ROLE + ".id = :role))");
+    try {
+      OBContext.setAdminMode(false);
+      StringBuffer whereClause = new StringBuffer();
+      whereClause.append(" as ar ");
+      whereClause.append("\nwhere exists (select 1 from ar."
+          + AlertRule.PROPERTY_ADALERTRECIPIENTLIST + " as arr");
+      whereClause.append("\n    where arr." + AlertRecipient.PROPERTY_USERCONTACT + ".id = :user");
+      whereClause.append("\n      or (");
+      whereClause.append("arr." + AlertRecipient.PROPERTY_USERCONTACT + " is null");
+      whereClause.append("\n          and arr." + AlertRecipient.PROPERTY_ROLE + ".id = :role))");
 
-    OBQuery<AlertRule> alertRulesQuery = OBDal.getInstance().createQuery(AlertRule.class,
-        whereClause.toString());
-    alertRulesQuery.setNamedParameter("user", DalUtil.getId(OBContext.getOBContext().getUser()));
-    alertRulesQuery.setNamedParameter("role", DalUtil.getId(OBContext.getOBContext().getRole()));
+      OBQuery<AlertRule> alertRulesQuery = OBDal.getInstance().createQuery(AlertRule.class,
+          whereClause.toString());
+      alertRulesQuery.setNamedParameter("user", DalUtil.getId(OBContext.getOBContext().getUser()));
+      alertRulesQuery.setNamedParameter("role", DalUtil.getId(OBContext.getOBContext().getRole()));
 
-    return getAlertIdsFromAlertRules(alertRulesQuery.list());
+      return getAlertIdsFromAlertRules(alertRulesQuery.list());
+    } finally {
+      OBContext.restorePreviousMode();
+    }
   }
 
   private List<String> getAlertIdsFromAlertRules(List<AlertRule> alertRules) {
@@ -157,8 +162,8 @@
   private String buildWhereClause(String alertStatus, List<String> alertList) {
     int chunkSize = 1000;
     String filterClause;
-    String whereClause = "coalesce(to_char(status), 'NEW') = upper('"
-        + StringEscapeUtils.escapeSql(alertStatus) + "')";
+    String whereClause = "coalesce(to_char(status), 'NEW') = '"
+        + StringEscapeUtils.escapeSql(alertStatus) + "'";
     ArrayList<String> alertListToRemove;
 
     if (alertList.size() == 0) {