related to issue 31579: code review improvements
authorCarlos Aristu <carlos.aristu@openbravo.com>
Wed, 02 Dec 2015 10:39:19 +0100
changeset 28110 9818e69a1a14
parent 28109 953d9e609f21
child 28111 8dabadcfeceb
related to issue 31579: 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	Tue Dec 01 18:32:25 2015 +0100
+++ b/modules/org.openbravo.client.application/src/org/openbravo/client/application/ADAlertDatasourceService.java	Wed Dec 02 10:39:19 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) {