modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/legacy/action/resource/common/monitor/alerts/AckAlertAction.java | 78 ++++++++++ modules/enterprise/gui/portal-war/src/main/webapp/WEB-INF/struts-config.xml | 10 + modules/enterprise/gui/portal-war/src/main/webapp/resource/common/monitor/alerts/ViewAlertProperties.jsp | 49 +++--- modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/alert/CustomAlertSenderBackingBean.java | 30 +++ 4 files changed, 148 insertions(+), 19 deletions(-)
New commits: commit e956b6f8b2608bc9d2941daba6e732caf4ad5715 Author: Heiko W. Rupp hwr@redhat.com Date: Tue Feb 23 22:25:45 2010 +0100
Introduce the possibility to ack an alert on the detail page. BZ 567383
diff --git a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/legacy/action/resource/common/monitor/alerts/AckAlertAction.java b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/legacy/action/resource/common/monitor/alerts/AckAlertAction.java new file mode 100644 index 0000000..6043d19 --- /dev/null +++ b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/legacy/action/resource/common/monitor/alerts/AckAlertAction.java @@ -0,0 +1,78 @@ +/* + * RHQ Management Platform + * Copyright (C) 2005-2010 Red Hat, Inc. + * All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ +package org.rhq.enterprise.gui.legacy.action.resource.common.monitor.alerts; + +import java.util.HashMap; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.struts.action.ActionForm; +import org.apache.struts.action.ActionForward; +import org.apache.struts.action.ActionMapping; +import org.apache.struts.tiles.ComponentContext; +import org.apache.struts.tiles.actions.TilesAction; + +import org.rhq.core.domain.alert.Alert; +import org.rhq.core.domain.auth.Subject; +import org.rhq.enterprise.gui.legacy.action.BaseAction; +import org.rhq.enterprise.gui.legacy.util.RequestUtils; +import org.rhq.enterprise.server.alert.AlertManagerLocal; +import org.rhq.enterprise.server.util.LookupUtil; + +/** + * Struts action to acknowledge one single alert from the + * ViewAlertProperties.jsp page + * @author Heiko W. Rupp + */ +public class AckAlertAction extends BaseAction { + + Log log = LogFactory.getLog(AckAlertAction.class); + + public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) throws Exception { + + Subject subject = RequestUtils.getSubject(request); + AlertManagerLocal alertManager = LookupUtil.getAlertManager(); + + Map params = new HashMap(3); + // pass-through the alertId and resource id + Integer alertId = new Integer(request.getParameter("a")); + request.setAttribute("a", alertId); + params.put("a",alertId); + + Integer resourceId = new Integer(request.getParameter("id")); + request.setAttribute("id",resourceId); + params.put("id",resourceId); + + String mode = request.getParameter("mode"); + request.setAttribute("mode",mode); + params.put("mode",mode); + + alertManager.acknowledgeAlert(alertId,subject); + + log.debug("Acknowledged Alert with id " + alertId + " and user " + subject.getName()); + + return returnSuccess(request,mapping,params); + } + +} diff --git a/modules/enterprise/gui/portal-war/src/main/webapp/WEB-INF/struts-config.xml b/modules/enterprise/gui/portal-war/src/main/webapp/WEB-INF/struts-config.xml index 41da1ee..a4c1b31 100644 --- a/modules/enterprise/gui/portal-war/src/main/webapp/WEB-INF/struts-config.xml +++ b/modules/enterprise/gui/portal-war/src/main/webapp/WEB-INF/struts-config.xml @@ -2559,6 +2559,16 @@ path="/common/GenericError.jsp"/> </action>
+ <action path="/alerts/AckAlert" + scope="request" + type="org.rhq.enterprise.gui.legacy.action.resource.common.monitor.alerts.AckAlertAction"> + <set-property property="title" value="View+Alert"/> + <exception key="exception.AlertNotFoundException" + type="org.rhq.enterprise.server.legacy.events.AlertNotFoundException" + path="/common/GenericError.jsp"/> + <forward name="success" path="/alerts/Alerts.do" redirect="true" /> + </action> + <action path="/alerts/ViewDefinition" scope="request" type="org.rhq.enterprise.gui.legacy.action.resource.common.monitor.alerts.config.ViewDefinitionAction"> diff --git a/modules/enterprise/gui/portal-war/src/main/webapp/resource/common/monitor/alerts/ViewAlertProperties.jsp b/modules/enterprise/gui/portal-war/src/main/webapp/resource/common/monitor/alerts/ViewAlertProperties.jsp index 1b1c04b..0b49ecb 100644 --- a/modules/enterprise/gui/portal-war/src/main/webapp/resource/common/monitor/alerts/ViewAlertProperties.jsp +++ b/modules/enterprise/gui/portal-war/src/main/webapp/resource/common/monitor/alerts/ViewAlertProperties.jsp @@ -39,26 +39,37 @@ <td class="BlockLabel"><fmt:message key="alert.current.detail.props.AlertDate"/></td> <td class="BlockContent" colspan="2"><hq:dateFormatter time="false" value="${alert.ctime}"/></td> </tr> - <tr valign="top"> - <td class="BlockLabel">Acknowledged by:</td> - <td class="BlockContent"> - <c:if test="${not empty alert.ackBy}"> - <c:out value="${alert.ackBy.firstName}"/> - <c:out value=" "/> - <c:out value="${alert.ackBy.lastName}"/> - <c:out value=" ("/> - <c:out value="${alert.ackBy.name}"/> - <c:out value=")"/> - </c:if> - </td> - <td class="BlockLabel">Acknowledged at:</td> - <td class="BlockContent"> - <c:if test="${alert.ackTime > 0}"> - <hq:dateFormatter time="false" value="${alert.ackTime}"/> - </c:if> + <c:choose> + <c:when test="${not empty alert.ackBy}"> + <tr valign="top"> + <td class="BlockLabel">Acknowledged by:</td> + <td class="BlockContent"> + <c:out value="${alert.ackBy.firstName}"/> + <c:out value=" "/> + <c:out value="${alert.ackBy.lastName}"/> + <c:out value=" ("/> + <c:out value="${alert.ackBy.name}"/> + <c:out value=")"/> + </td> + <td class="BlockLabel">Acknowledged at:</td> + <td class="BlockContent"> + <hq:dateFormatter time="false" value="${alert.ackTime}"/> + </td> + </tr> + </c:when> + <c:otherwise> + <tr valign="top"> + <td class="BlockLabel">Acknowledge Alert</td> + <td class="BlockContent"> + <a href="/alerts/AckAlert.do?id=${Resource.id}&a=${alert.id}&mode=${param.mode}">click here</a> + </td> + <td class="BlockContent"> </td> + <td class="BlockContent"> </td> + </tr>
- </td> - </tr> + </c:otherwise> + + </c:choose> <tr> <td colspan="5" class="BlockContent"><html:img page="/images/spacer.gif" width="1" height="1" border="0"/></td> </tr>
commit b22dc41c2c2251ee2c29387eabbdfbf9a616a41d Author: Heiko W. Rupp hwr@redhat.com Date: Tue Feb 23 16:20:56 2010 +0100
Add a new cleanup() method and some JavaDoc
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/alert/CustomAlertSenderBackingBean.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/alert/CustomAlertSenderBackingBean.java index 72f6ec8..5b39eae 100644 --- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/alert/CustomAlertSenderBackingBean.java +++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/alert/CustomAlertSenderBackingBean.java @@ -40,9 +40,24 @@ public class CustomAlertSenderBackingBean { public void setAlertParameters(Configuration alertParameters) { this.alertParameters = alertParameters; } + /** + * This method is called when the alert notification that uses this backing bean + * is removed, so that the backing bean can do some cleanup work + */ + protected void cleanup() {}
+ /** + * Persist the passed configuration object. This can be a new object or one + * that already exists in the database. If the input is null, not persistence + * happens and null is returned. + * @param config configuration to persist or update + * @return a merged copy of the configuration or null + */ protected Configuration persistConfiguration(Configuration config) {
+ if (config==null) + return null; + ConfigurationManagerLocal mgr = LookupUtil.getConfigurationManager(); config = mgr.mergeConfiguration(config);
@@ -50,6 +65,14 @@ public class CustomAlertSenderBackingBean {
}
+ /** + * Persist a single property of a given configuration. If the property does not yet exist, + * it is created otherwise overwritten with the new value. + * @param config configuration the property is on + * @param propertyName name of the property to persist + * @param value (new) value of the property to persist + * @return the updated configuration + */ protected Configuration persistProperty(Configuration config, String propertyName, Object value) {
PropertySimple prop = config.getSimple(propertyName); @@ -65,6 +88,12 @@ public class CustomAlertSenderBackingBean { return ret; }
+ /** + * Remove one property from the passed configuration. Returns the updated configuration + * @param config configuration the property is on + * @param propertyName name of the property to remove + * @return the updated configuration + */ protected Configuration cleanProperty(Configuration config, String propertyName) {
Configuration ret = config; @@ -76,4 +105,5 @@ public class CustomAlertSenderBackingBean {
return ret; } + }
rhq-commits@lists.fedorahosted.org