fixes issue 31578: alert fetches with where parameter
authorCarlos Aristu <carlos.aristu@openbravo.com>
Tue, 01 Dec 2015 18:36:24 +0100
changeset 28134 742cf5efa2d9
parent 28133 f8452f44752e
child 28135 4883ab9e4334
fixes issue 31578: alert fetches with where parameter

In order to avoid the fetching of the where parameter we generate the where clause inside the datasource. A new datasource has been created, ADAlertDatasourceService, to support the requests from the Alert Management window.

In addition, it has been fixed a problem in the Alert Rule drop-down filter of the grids in the Alert Management window which was displaying alert rules from all the grids in the window instead of those displayed just on a particular grid.
modules/org.openbravo.client.application/src-db/database/sourcedata/OBSERDS_DATASOURCE.xml
modules/org.openbravo.client.application/src/org/openbravo/client/application/ADAlertDatasourceService.java
modules/org.openbravo.client.application/src/org/openbravo/client/application/AlertManagementActionHandler.java
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/alert-management/ob-alert-grid.js
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/alert-management/ob-alert-management-view.js
--- a/modules/org.openbravo.client.application/src-db/database/sourcedata/OBSERDS_DATASOURCE.xml	Mon Nov 30 14:24:17 2015 +0530
+++ b/modules/org.openbravo.client.application/src-db/database/sourcedata/OBSERDS_DATASOURCE.xml	Tue Dec 01 18:36:24 2015 +0100
@@ -56,4 +56,17 @@
 <!--C17951F970E942FD9F3771B7BE91D049-->  <IDFKFILTERING><![CDATA[Y]]></IDFKFILTERING>
 <!--C17951F970E942FD9F3771B7BE91D049--></OBSERDS_DATASOURCE>
 
+<!--DB9F062472294F12A0291A7BD203F922--><OBSERDS_DATASOURCE>
+<!--DB9F062472294F12A0291A7BD203F922-->  <OBSERDS_DATASOURCE_ID><![CDATA[DB9F062472294F12A0291A7BD203F922]]></OBSERDS_DATASOURCE_ID>
+<!--DB9F062472294F12A0291A7BD203F922-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--DB9F062472294F12A0291A7BD203F922-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--DB9F062472294F12A0291A7BD203F922-->  <AD_MODULE_ID><![CDATA[9BA0836A3CD74EE4AB48753A47211BCC]]></AD_MODULE_ID>
+<!--DB9F062472294F12A0291A7BD203F922-->  <NAME><![CDATA[AD Alert Datasource]]></NAME>
+<!--DB9F062472294F12A0291A7BD203F922-->  <CLASSNAME><![CDATA[org.openbravo.client.application.ADAlertDatasourceService]]></CLASSNAME>
+<!--DB9F062472294F12A0291A7BD203F922-->  <OBCLKER_TEMPLATE_ID><![CDATA[2BAD445C2A0343C58E455F9BD379C690]]></OBCLKER_TEMPLATE_ID>
+<!--DB9F062472294F12A0291A7BD203F922-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--DB9F062472294F12A0291A7BD203F922-->  <USEASTABLEDATAORIGIN><![CDATA[N]]></USEASTABLEDATAORIGIN>
+<!--DB9F062472294F12A0291A7BD203F922-->  <IDFKFILTERING><![CDATA[Y]]></IDFKFILTERING>
+<!--DB9F062472294F12A0291A7BD203F922--></OBSERDS_DATASOURCE>
+
 </data>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/org.openbravo.client.application/src/org/openbravo/client/application/ADAlertDatasourceService.java	Tue Dec 01 18:36:24 2015 +0100
@@ -0,0 +1,205 @@
+/*
+ *************************************************************************
+ * The contents of this file are subject to the Openbravo  Public  License
+ * Version  1.1  (the  "License"),  being   the  Mozilla   Public  License
+ * Version 1.1  with a permitted attribution clause; you may not  use this
+ * file except in compliance with the License. You  may  obtain  a copy of
+ * the License at http://www.openbravo.com/legal/license.html 
+ * Software distributed under the License  is  distributed  on  an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific  language  governing  rights  and  limitations
+ * 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 Rights Reserved.
+ * Contributor(s):  ______________________________________.
+ ************************************************************************
+ */
+package org.openbravo.client.application;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import javax.servlet.ServletException;
+
+import org.apache.commons.lang.StringEscapeUtils;
+import org.apache.commons.lang.StringUtils;
+import org.hibernate.SQLQuery;
+import org.hibernate.exception.SQLGrammarException;
+import org.openbravo.base.exception.OBException;
+import org.openbravo.base.model.Entity;
+import org.openbravo.base.model.ModelProvider;
+import org.openbravo.client.kernel.RequestContext;
+import org.openbravo.dal.core.DalUtil;
+import org.openbravo.dal.core.OBContext;
+import org.openbravo.dal.service.OBDal;
+import org.openbravo.dal.service.OBQuery;
+import org.openbravo.erpCommon.utility.UsedByLink;
+import org.openbravo.model.ad.alert.Alert;
+import org.openbravo.model.ad.alert.AlertRecipient;
+import org.openbravo.model.ad.alert.AlertRule;
+import org.openbravo.service.datasource.DefaultDataSourceService;
+import org.openbravo.service.json.JsonConstants;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Datasource used by the Alert Management window
+ */
+public class ADAlertDatasourceService extends DefaultDataSourceService {
+  private static final String AD_TABLE_ID = "594";
+  private static final String ALERT_STATUS = "_alertStatus";
+  private static final String ALERT_RULE_TAB = "alertRule.tab.id";
+  private static final Logger log = LoggerFactory.getLogger(ADAlertDatasourceService.class);
+
+  @Override
+  public Entity getEntity() {
+    return ModelProvider.getInstance().getEntityByTableId(AD_TABLE_ID);
+  }
+
+  @Override
+  public String fetch(Map<String, String> parameters) {
+    long t = System.currentTimeMillis();
+    String alertStatus = "";
+    try {
+      // Retrieve the information from the request parameters
+      if (parameters.get(JsonConstants.WHERE_PARAMETER) != null) {
+        log.warn("_where parameter is not allowed, ignoring it");
+      }
+      alertStatus = parameters.get(ALERT_STATUS);
+      alertStatus = StringUtils.isEmpty(alertStatus) ? "" : alertStatus.toUpperCase();
+
+      List<String> alertList = getAlertIds();
+
+      String whereClause = buildWhereClause(alertStatus, alertList);
+      parameters.put(JsonConstants.WHERE_PARAMETER, whereClause);
+
+      if (parameters.get(JsonConstants.DISTINCT_PARAMETER) == null) {
+        // Also return the tab id of the alert rule, just when loading the grid from the server.
+        // This is used in the Alert Management window to navigate to the record related to an alert
+        parameters.put(JsonConstants.ADDITIONAL_PROPERTIES_PARAMETER, ALERT_RULE_TAB);
+      }
+
+      return super.fetch(parameters, true);
+    } catch (Exception ex) {
+      log.error("Error while fetching alert data", ex);
+      throw new OBException(ex);
+    } finally {
+      log.debug("Alert list with status {} retrieved in {} ms", alertStatus,
+          System.currentTimeMillis() - t);
+    }
+  }
+
+  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))");
+
+    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());
+  }
+
+  private List<String> getAlertIdsFromAlertRules(List<AlertRule> alertRules) {
+    List<String> alertIds = new ArrayList<String>();
+    for (AlertRule alertRule : alertRules) {
+      // Adding alert rule if it has not filter clause. In case it has, it will be added only in
+      // case it returns data after applying the filter clause.
+      if (alertRule.getFilterClause() == null) {
+        for (Alert alert : alertRule.getADAlertList()) {
+          alertIds.add((String) DalUtil.getId(alert));
+        }
+      }
+
+      String filterClause = null;
+      if (alertRule.getFilterClause() != null) {
+        try {
+          filterClause = new UsedByLink().getWhereClause(RequestContext.get()
+              .getVariablesSecureApp(), "", alertRule.getFilterClause());
+        } catch (ServletException e) {
+          throw new IllegalStateException(e);
+        }
+        final String sql = "select * from AD_ALERT where ISACTIVE='Y'" + " AND AD_CLIENT_ID "
+            + OBDal.getInstance().getReadableClientsInClause() + " AND AD_ORG_ID "
+            + OBDal.getInstance().getReadableOrganizationsInClause() + " AND AD_ALERTRULE_ID = ? "
+            + (filterClause == null ? "" : filterClause);
+        final SQLQuery sqlQuery = OBDal.getInstance().getSession().createSQLQuery(sql)
+            .addEntity(Alert.ENTITY_NAME);
+        sqlQuery.setParameter(0, alertRule.getId());
+
+        try {
+          @SuppressWarnings("unchecked")
+          List<Alert> alertsWithFilterClause = sqlQuery.list();
+          log.debug("Alert " + alertRule.getName() + " (" + alertRule.getId() + ") - SQL:'" + sql
+              + "' - Rows: " + alertsWithFilterClause.size());
+          for (Alert alert : alertsWithFilterClause) {
+            alertIds.add((String) DalUtil.getId(alert));
+          }
+        } catch (SQLGrammarException e) {
+          log.error("An error has ocurred when trying to process the alerts: " + e.getMessage(), e);
+        }
+      }
+    }
+    return alertIds;
+  }
+
+  private String buildWhereClause(String alertStatus, List<String> alertList) {
+    int chunkSize = 1000;
+    String filterClause;
+    String whereClause = "coalesce(to_char(status), 'NEW') = upper('"
+        + StringEscapeUtils.escapeSql(alertStatus) + "')";
+    ArrayList<String> alertListToRemove;
+
+    if (alertList.size() == 0) {
+      return "1 = 2";
+    }
+
+    if (alertList.size() <= chunkSize) {
+      whereClause += " and e.id in (" + toStringList(alertList) + ")";
+      return whereClause;
+    }
+
+    // There are more than 1000 alerts to include in the where clause, Oracle doesn't
+    // support it, so let's split them in chunks with <=1000 elements each
+    alertListToRemove = new ArrayList<String>();
+    filterClause = "";
+    while (alertList.size() > chunkSize) {
+      alertListToRemove = new ArrayList<String>(alertList.subList(0, chunkSize - 1));
+      if (StringUtils.isEmpty(filterClause)) {
+        filterClause = " and (e.id in (" + toStringList(alertListToRemove) + ")";
+      } else {
+        filterClause += " or e.id in (" + toStringList(alertListToRemove) + ")";
+      }
+      alertList.removeAll(alertListToRemove);
+    }
+    if (!alertList.isEmpty()) {
+      filterClause += " or e.id in (" + toStringList(alertList) + "))";
+    } else {
+      filterClause += ")";
+    }
+    whereClause += filterClause;
+    return whereClause;
+  }
+
+  private String toStringList(List<String> list) {
+    String result = "";
+    for (String s : list) {
+      if (!StringUtils.isEmpty(result)) {
+        result += ", ";
+      }
+      result += "'" + s + "'";
+    }
+    return result;
+  }
+}
\ No newline at end of file
--- a/modules/org.openbravo.client.application/src/org/openbravo/client/application/AlertManagementActionHandler.java	Mon Nov 30 14:24:17 2015 +0530
+++ b/modules/org.openbravo.client.application/src/org/openbravo/client/application/AlertManagementActionHandler.java	Tue Dec 01 18:36:24 2015 +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) 2011 Openbravo SLU
+ * All portions are Copyright (C) 2015 Openbravo SLU
  * All Rights Reserved.
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -22,25 +22,17 @@
 import java.util.Map;
 
 import javax.enterprise.context.ApplicationScoped;
-import javax.servlet.ServletException;
 
 import org.apache.commons.lang.StringUtils;
-import org.apache.log4j.Logger;
-import org.codehaus.jettison.json.JSONArray;
 import org.codehaus.jettison.json.JSONException;
 import org.codehaus.jettison.json.JSONObject;
-import org.hibernate.SQLQuery;
-import org.hibernate.exception.SQLGrammarException;
 import org.openbravo.client.kernel.BaseActionHandler;
-import org.openbravo.client.kernel.RequestContext;
 import org.openbravo.dal.core.OBContext;
 import org.openbravo.dal.service.OBDal;
 import org.openbravo.dal.service.OBDao;
-import org.openbravo.dal.service.OBQuery;
-import org.openbravo.erpCommon.utility.UsedByLink;
 import org.openbravo.model.ad.alert.Alert;
-import org.openbravo.model.ad.alert.AlertRecipient;
-import org.openbravo.model.ad.alert.AlertRule;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * @author gorkaion
@@ -48,10 +40,8 @@
  */
 @ApplicationScoped
 public class AlertManagementActionHandler extends BaseActionHandler {
-  private static final Logger log = Logger.getLogger(AlertManagementActionHandler.class);
-  private static final String GET_ALERT_RULES = "getAlertRules";
+  private static final Logger log = LoggerFactory.getLogger(AlertManagementActionHandler.class);
   private static final String MOVE_TO_STATUS = "moveToStatus";
-  private static final Logger log4j = Logger.getLogger(AlertManagementActionHandler.class);
 
   /*
    * (non-Javadoc)
@@ -66,9 +56,7 @@
     try {
       JSONObject o = new JSONObject(content);
       final String strEventType = o.getString("eventType");
-      if (GET_ALERT_RULES.equals(strEventType)) {
-        object.put("alertRules", getAlertRules());
-      } else if (MOVE_TO_STATUS.equals(strEventType)) {
+      if (MOVE_TO_STATUS.equals(strEventType)) {
         final String alertIDs = o.getString("alertIDs");
         final String oldStatus = o.getString("oldStatus");
         final String newStatus = o.getString("newStatus");
@@ -88,103 +76,6 @@
     return object;
   }
 
-  private JSONArray getAlertRules() {
-    // 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))");
-
-    OBQuery<AlertRule> alertRulesQuery = OBDal.getInstance().createQuery(AlertRule.class,
-        whereClause.toString());
-    alertRulesQuery.setNamedParameter("user", OBContext.getOBContext().getUser().getId());
-    alertRulesQuery.setNamedParameter("role", OBContext.getOBContext().getRole().getId());
-
-    JSONArray alertRules = new JSONArray();
-    try {
-      if (alertRulesQuery.count() > 0) {
-        for (AlertRule alertRule : alertRulesQuery.list()) {
-          JSONObject alertRuleJson = null;
-
-          // Adding alert rule if it has not filter clause. In case it has, it will be added only in
-          // case it returns data after applying the filter clause.
-          if (alertRule.getFilterClause() == null) {
-            alertRuleJson = new JSONObject();
-            alertRuleJson.put("name", alertRule.getIdentifier());
-            alertRuleJson.put("alertRuleId", alertRule.getId());
-            if (alertRule.getTab() != null) {
-              alertRuleJson.put("tabId", alertRule.getTab().getId());
-            } else {
-              alertRuleJson.put("tabId", "");
-            }
-          }
-
-          String filterClause = null;
-          if (alertRule.getFilterClause() != null) {
-            try {
-              filterClause = new UsedByLink().getWhereClause(RequestContext.get()
-                  .getVariablesSecureApp(), "", alertRule.getFilterClause());
-            } catch (ServletException e) {
-              throw new IllegalStateException(e);
-            }
-            final String sql = "select * from AD_ALERT where ISACTIVE='Y'" + " AND AD_CLIENT_ID "
-                + OBDal.getInstance().getReadableClientsInClause() + " AND AD_ORG_ID "
-                + OBDal.getInstance().getReadableOrganizationsInClause()
-                + " AND AD_ALERTRULE_ID = ? " + (filterClause == null ? "" : filterClause);
-            final SQLQuery sqlQuery = OBDal.getInstance().getSession().createSQLQuery(sql)
-                .addEntity(Alert.ENTITY_NAME);
-            sqlQuery.setParameter(0, alertRule.getId());
-
-            try {
-              log4j.debug("Alert " + alertRule.getName() + " (" + alertRule.getId() + ") - SQL:'"
-                  + sql + "' - Rows: " + sqlQuery.list().size());
-              // It is not possible to add an SQL filter clause to the grid's default datasource.
-              // A String with the alert_id's to filter the grid's so only alerts with access are
-              // shown.
-              if (sqlQuery.list().size() > 0) {
-                // Alert rule returns data, adding it to list of alert rules.
-                alertRuleJson = new JSONObject();
-                alertRuleJson.put("name", alertRule.getIdentifier());
-                alertRuleJson.put("alertRuleId", alertRule.getId());
-                if (alertRule.getTab() != null) {
-                  alertRuleJson.put("tabId", alertRule.getTab().getId());
-                } else {
-                  alertRuleJson.put("tabId", "");
-                }
-
-                String filterAlerts = "";
-                @SuppressWarnings("unchecked")
-                List<Alert> alerts = sqlQuery.list();
-                for (Alert alert : alerts) {
-                  if (!filterAlerts.isEmpty()) {
-                    filterAlerts += ", ";
-                  }
-                  filterAlerts += "'" + alert.getId() + "'";
-                }
-                alertRuleJson.put("alerts", filterAlerts);
-
-              }
-            } catch (SQLGrammarException e) {
-              log4j.error(
-                  "An error has ocurred when trying to process the alerts: " + e.getMessage(), e);
-            }
-          }
-          if (alertRuleJson != null) {
-            alertRules.put(alertRuleJson);
-          }
-        }
-      }
-    } catch (JSONException e) {
-      log.error("Error executing action: " + e.getMessage(), e);
-    }
-
-    return alertRules;
-  }
-
   private void setNewStatus(String alertIDs, String newStatus) {
     if (StringUtils.isEmpty(alertIDs)) {
       return;
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/alert-management/ob-alert-grid.js	Mon Nov 30 14:24:17 2015 +0530
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/alert-management/ob-alert-grid.js	Tue Dec 01 18:36:24 2015 +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) 2011-2013 Openbravo SLU
+ * All portions are Copyright (C) 2011-2015 Openbravo SLU
  * All Rights Reserved.
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -125,7 +125,7 @@
       items: []
     });
 
-    OB.Datasource.get('ADAlert', this, null, true);
+    OB.Datasource.get('DB9F062472294F12A0291A7BD203F922', this, null, true);
 
     this.Super('initWidget', arguments);
   },
@@ -165,7 +165,7 @@
     if (!OB.AlertManagement.sections[this.alertStatus].expanded) {
       // fetch to the datasource with an empty criteria to get all the rows
       requestProperties.params = requestProperties.params || {};
-      requestProperties.params[OB.Constants.WHERE_PARAMETER] = this.getFilterClause();
+      requestProperties.params._alertStatus = this.alertStatus;
       requestProperties.params._startRow = 0;
       requestProperties.params._endRow = this.dataPageSize;
       requestProperties.clientContext = {
@@ -180,70 +180,19 @@
     }
   },
 
+  getFetchRequestParams: function (params) {
+    // include alertStatus in the request in order to identify the grid being filtered
+    // this allows to display the correct values on the Alert Rule filter drop-down
+    params = params || {};
+    params._alertStatus = this.alertStatus;
+    return params;
+  },
+
   onFetchData: function (criteria, requestProperties) {
     requestProperties = requestProperties || {};
     requestProperties.params = requestProperties.params || {};
 
-    requestProperties.params[OB.Constants.WHERE_PARAMETER] = this.getFilterClause();
-  },
-
-  getAlertsWithFilterClause: function (alertRule) {
-    var filterClause, alerts = alertRule.alerts.split(','),
-        alertsNum = alerts.length,
-        i, chunksOfAlerts = [],
-        j, chunkSize = 1000;
-    filterClause = ' and (e.alertRule.id != \'' + alertRule.alertRuleId + '\'';
-
-    if (alertsNum <= chunkSize) {
-      filterClause += ' or e.id in (' + alertRule.alerts + '))';
-      return filterClause;
-    }
-
-    // there are more than 1000 alerts to include in the where clause, Oracle doesn't
-    // support it, so let's split them in chunks with <=1000 elements each
-    for (i = 0; i < alertsNum; i += chunkSize) {
-      chunksOfAlerts.push(alerts.slice(i, i + chunkSize));
-    }
-
-    for (i = 0; i < chunksOfAlerts.length; i++) {
-      filterClause += ' or e.id in (';
-      for (j = 0; j < chunksOfAlerts[i].length; j++) {
-        filterClause += j > 0 ? ',' : '';
-        filterClause += chunksOfAlerts[i][j];
-      }
-      filterClause += ')';
-    }
-    filterClause += ')';
-    return filterClause;
-  },
-
-  getFilterClause: function () {
-    var i, filterClause = '',
-        alertRuleIds = '',
-        arlength = OB.AlertManagement.alertRules.length,
-        whereClause = 'coalesce(to_char(status), \'NEW\') = upper(\'' + this.alertStatus + '\')';
-
-    for (i = 0; i < arlength; i++) {
-      if (alertRuleIds !== '') {
-        alertRuleIds += ',';
-      }
-      alertRuleIds += '\'' + OB.AlertManagement.alertRules[i].alertRuleId + '\'';
-      // if an alertRule has some alerts to filter by, add them to the where clause as:
-      // alerts are of a different alertRule or only the alerts predefined
-      // this only happens if the alertRule has an SQL filter expression defined
-      if (OB.AlertManagement.alertRules[i].alerts) {
-        filterClause += this.getAlertsWithFilterClause(OB.AlertManagement.alertRules[i]);
-      }
-    }
-    if (alertRuleIds !== '') {
-      whereClause += ' and e.alertRule.id in (' + alertRuleIds + ')';
-    } else {
-      whereClause += ' and 1=2';
-    }
-    if (filterClause !== '') {
-      whereClause += filterClause;
-    }
-    return whereClause;
+    requestProperties.params._alertStatus = this.alertStatus;
   },
 
   headerClick: function (fieldNum, header, autoSaveDone) {
@@ -558,12 +507,7 @@
     this.setTitle(this.grid.formatLinkValue(this.record, this.field, this.colNum, this.rowNum, this.record[this.field.name]));
   },
   doAction: function () {
-    var i, tabId, length = OB.AlertManagement.alertRules.length;
-    for (i = 0; i < length; i++) {
-      if (OB.AlertManagement.alertRules[i].alertRuleId === this.record.alertRule) {
-        tabId = OB.AlertManagement.alertRules[i].tabId;
-      }
-    }
+    var tabId = this.record['alertRule' + OB.Constants.FIELDSEPARATOR + 'tab' + OB.Constants.FIELDSEPARATOR + OB.Constants.ID];
     if (tabId && tabId !== '') {
       OB.Utilities.openDirectTab(tabId, this.record.referenceSearchKey);
     }
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/alert-management/ob-alert-management-view.js	Mon Nov 30 14:24:17 2015 +0530
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/alert-management/ob-alert-management-view.js	Tue Dec 01 18:36:24 2015 +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) 2011-2013 Openbravo SLU
+ * All portions are Copyright (C) 2011-2015 Openbravo SLU
  * All Rights Reserved.
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -38,7 +38,6 @@
   sectionStack: null,
   grids: {},
   sections: {},
-  alertRules: null,
   //Section header controls:
   NewAcknowledged: null,
   NewSuppressed: null,
@@ -84,7 +83,7 @@
     this.addMember(this.sectionStack);
 
     this.Super('initWidget', arguments);
-    this.getAlertRules();
+    OB.AlertManagement.checkInitializeStatus();
   },
 
   tabSelected: function (tabNum, tabPane, ID, tab) {
@@ -97,20 +96,9 @@
     }
   },
 
-  getAlertRules: function () {
-    var post = {
-      'eventType': 'getAlertRules'
-    };
-
-    OB.RemoteCallManager.call('org.openbravo.client.application.AlertManagementActionHandler', post, {}, function (rpcResponse, data, rpcRequest) {
-      OB.AlertManagement.alertRules = data.alertRules;
-      OB.AlertManagement.checkInitializeStatus();
-    });
-  },
-
   checkInitializeStatus: function () {
-    if (OB.AlertManagement.translatedStatus.New !== '' && OB.AlertManagement.translatedStatus.Acknowledged !== '' && OB.AlertManagement.translatedStatus.Suppressed !== '' && OB.AlertManagement.translatedStatus.Solved !== '' && OB.AlertManagement.alertRules !== null) {
-      // Sections are created after alertRules are created and status translations are set.
+    if (OB.AlertManagement.translatedStatus.New !== '' && OB.AlertManagement.translatedStatus.Acknowledged !== '' && OB.AlertManagement.translatedStatus.Suppressed !== '' && OB.AlertManagement.translatedStatus.Solved !== '' && OB.AlertManagement.sectionStack) {
+      // Sections are created after status translations are set.
       // This is needed to be able to filter properly the grids of the sections.
       OB.AlertManagement.createSections();
     }