modules/core/domain/src/main/java/org/rhq/core/domain/alert/notification/AlertNotification.java
| 2
modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/alert/ListNotificationsUIBean.java
| 27 +++-
modules/enterprise/gui/portal-war/src/main/webapp/WEB-INF/jsf-managed-beans/alert-beans.xml
| 8 -
modules/enterprise/gui/portal-war/src/main/webapp/rhq/resource/alert/notif/listAlertSender.xhtml
| 29 +++++
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertNotificationManagerBean.java
| 57 +++++++++-
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertNotificationManagerLocal.java
| 22 +++
6 files changed, 121 insertions(+), 24 deletions(-)
New commits:
commit a6aad438dc5aac56cbafb65464700d5901569a8e
Author: Heiko W. Rupp <pilhuhn(a)fedorapeople.org>
Date: Mon Nov 30 15:52:48 2009 +0100
List exising notifications and be able to add new ones.
diff --git
a/modules/core/domain/src/main/java/org/rhq/core/domain/alert/notification/AlertNotification.java
b/modules/core/domain/src/main/java/org/rhq/core/domain/alert/notification/AlertNotification.java
index eec3a6c..7efa51b 100644
---
a/modules/core/domain/src/main/java/org/rhq/core/domain/alert/notification/AlertNotification.java
+++
b/modules/core/domain/src/main/java/org/rhq/core/domain/alert/notification/AlertNotification.java
@@ -75,7 +75,7 @@ public class AlertNotification implements Serializable {
private AlertDefinition alertDefinition;
@JoinColumn(name = "ALERT_CONFIG_ID", referencedColumnName =
"ID")
- @OneToOne(cascade = { CascadeType.REMOVE }, fetch = FetchType.LAZY)
+ @OneToOne(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY)
private Configuration configuration;
@Column(name = "ALERT_SENDER_NAME")
diff --git
a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/alert/ListNotificationsUIBean.java
b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/alert/ListNotificationsUIBean.java
index 7e79bab..f50705a 100644
---
a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/alert/ListNotificationsUIBean.java
+++
b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/alert/ListNotificationsUIBean.java
@@ -18,20 +18,27 @@
*/
package org.rhq.enterprise.gui.alert;
+import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import javax.faces.context.ExternalContext;
+import javax.faces.context.FacesContext;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
+import org.jboss.seam.annotations.web.RequestParameter;
+import org.rhq.core.domain.alert.notification.AlertNotification;
+import org.rhq.core.domain.auth.Subject;
import org.rhq.core.domain.configuration.Configuration;
-import org.rhq.core.domain.configuration.PropertySimple;
import org.rhq.core.domain.configuration.definition.ConfigurationDefinition;
+import org.rhq.enterprise.gui.util.EnterpriseFacesContextUtility;
import org.rhq.enterprise.server.alert.AlertNotificationManagerLocal;
import org.rhq.enterprise.server.util.LookupUtil;
@@ -52,8 +59,9 @@ public class ListNotificationsUIBean {
private ConfigurationDefinition alertConfigurationDefinition;
private Configuration alertProperties;
- int ad;
+ @RequestParameter("ad")
+ private int alertDefinitionId;
public ListNotificationsUIBean() {
}
@@ -109,16 +117,17 @@ public class ListNotificationsUIBean {
}
public String mySubmitForm() {
- System.out.println("In submit Form ");
log.info("In submit Form ");
+ AlertNotificationManagerLocal mgr = LookupUtil.getAlertNotificationManager();
+ Subject subject = EnterpriseFacesContextUtility.getSubject();
+ mgr.addAlertNotification(subject,
alertDefinitionId,selectedSender,alertProperties);
return OUTCOME_SUCCESS;
}
- public int getAd() {
- return ad;
- }
-
- public void setAd(int ad) {
- this.ad = ad;
+ public Collection<AlertNotification> getExistingNotifications() {
+ AlertNotificationManagerLocal mgr = LookupUtil.getAlertNotificationManager();
+ Subject subject = EnterpriseFacesContextUtility.getSubject();
+ List<AlertNotification> notifications =
mgr.getNotificationsForAlertDefinition(subject,alertDefinitionId);
+ return notifications;
}
}
\ No newline at end of file
diff --git
a/modules/enterprise/gui/portal-war/src/main/webapp/WEB-INF/jsf-managed-beans/alert-beans.xml
b/modules/enterprise/gui/portal-war/src/main/webapp/WEB-INF/jsf-managed-beans/alert-beans.xml
index d41bd31..8be8f7a 100644
---
a/modules/enterprise/gui/portal-war/src/main/webapp/WEB-INF/jsf-managed-beans/alert-beans.xml
+++
b/modules/enterprise/gui/portal-war/src/main/webapp/WEB-INF/jsf-managed-beans/alert-beans.xml
@@ -25,12 +25,4 @@
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
- <!-- /rhq/resource/alert/notif -->
- <managed-bean>
- <description>Handling of alert senders</description>
- <managed-bean-name>ListNotificationsUIBean</managed-bean-name>
-
<managed-bean-class>org.rhq.enterprise.gui.alert.ListNotificationsUIBean</managed-bean-class>
- <managed-bean-scope>request</managed-bean-scope>
- </managed-bean>
-
</faces-config>
\ No newline at end of file
diff --git
a/modules/enterprise/gui/portal-war/src/main/webapp/rhq/resource/alert/notif/listAlertSender.xhtml
b/modules/enterprise/gui/portal-war/src/main/webapp/rhq/resource/alert/notif/listAlertSender.xhtml
index e902b81..f365463 100644
---
a/modules/enterprise/gui/portal-war/src/main/webapp/rhq/resource/alert/notif/listAlertSender.xhtml
+++
b/modules/enterprise/gui/portal-war/src/main/webapp/rhq/resource/alert/notif/listAlertSender.xhtml
@@ -39,6 +39,35 @@
width="100%"/>
<p/>
+ <h:outputText>Existing notifications:</h:outputText>
+ <br/>
+ <rich:dataTable id="alertNotificationDataTable"
+
value="#{ListNotificationsUIBean.existingNotifications}"
+ var="notif"
+ width="100%"
+ headerClass="tableRowHeader"
+ footerClass="on-pager-footer"
+
onRowMouseOver="this.style.backgroundColor='#E7E7E7'"
+
onRowMouseOut="this.style.backgroundColor='#{a4jSkin.tableBackgroundColor}'">
+ <rich:column>
+ <f:facet name="header">
+ <h:outputText styleClass="headerText"
value="ID"/>
+ </f:facet>
+
+ <h:outputText value="#{notif.id}"/>
+ </rich:column>
+
+ <rich:column>
+ <f:facet name="header">
+ <h:outputText styleClass="headerText"
value="Sender"/>
+ </f:facet>
+
+ <h:outputText value="#{notif.senderName}"/>
+ </rich:column>
+
+ <!-- TODO add configuration -->
+ </rich:dataTable>
+
<h:outputText>Hello World</h:outputText>
<h:form id="listSenderForm">
<input type="hidden" name="id"
value="${param.id}"/>
diff --git
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertNotificationManagerBean.java
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertNotificationManagerBean.java
index de7362e..9a0399c 100644
---
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertNotificationManagerBean.java
+++
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertNotificationManagerBean.java
@@ -482,11 +482,6 @@ public class AlertNotificationManagerBean implements
AlertNotificationManagerLoc
}
}
- public Configuration getDefaultAlertConfiguration(ConfigurationDefinition def) {
- Configuration config = configManager.getConfigurationFromDefaultTemplate(def);
-
- return config;
- }
/**
* Return a list of all available AlertSenders in the system by their shortname.
@@ -497,4 +492,56 @@ public class AlertNotificationManagerBean implements
AlertNotificationManagerLoc
List<String> senders = pluginmanager.getPluginList();
return senders;
}
+
+ /**
+ * Add a new AlertNotification to the passed definition
+ * @param user subject of the caller
+ * @param alertDefinitionId Id of the alert definition
+ * @param senderName shortName of the {@link AlertSender}
+ * @param configuration Properties for this alert sender.
+ */
+ public void addAlertNotification(Subject user, int alertDefinitionId, String
senderName, Configuration configuration) {
+
+ AlertDefinition definition =
alertDefinitionManager.getAlertDefinition(user,alertDefinitionId);
+ if (definition==null) {
+ LOG.error("DId not find definition for id [" + alertDefinitionId+
"]");
+ return;
+ }
+
+ entityManager.persist(configuration);
+ AlertNotification notif = new AlertNotification(definition);
+ notif.setSenderName(senderName);
+ notif.setConfiguration(configuration);
+ entityManager.persist(notif);
+ definition.getAlertNotifications().add(notif);
+
+ }
+
+ /**
+ * Return notifications for a certain alertDefinitionId
+ *
+ * NOTE: this only returns notifications that have an AlertSender defined.
+ *
+ * @param user Subject of the caller
+ * @param alertDefinitionId Id of the alert definition
+ * @return list of defined notification of the passed alert definition
+ *
+ *
+ */
+ public List<AlertNotification> getNotificationsForAlertDefinition(Subject user,
int alertDefinitionId) {
+ AlertDefinition definition =
alertDefinitionManager.getAlertDefinition(user,alertDefinitionId);
+ if (definition==null) {
+ LOG.error("DId not find definition for id [" + alertDefinitionId+
"]");
+ return new ArrayList<AlertNotification>();
+ }
+ Set<AlertNotification> notifs = definition.getAlertNotifications();
+ List<AlertNotification> result = new ArrayList<AlertNotification>();
+ for (AlertNotification notif : notifs) {
+ if (notif.getSenderName()!=null) {
+ notif.getConfiguration().getProperties().size(); // Eager load
+ result.add(notif);
+ }
+ }
+ return result;
+ }
}
\ No newline at end of file
diff --git
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertNotificationManagerLocal.java
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertNotificationManagerLocal.java
index 532bd95..debec43 100644
---
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertNotificationManagerLocal.java
+++
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertNotificationManagerLocal.java
@@ -82,5 +82,25 @@ public interface AlertNotificationManagerLocal {
ConfigurationDefinition getConfigurationDefinitionForSender(String shortName);
- Configuration getDefaultAlertConfiguration(ConfigurationDefinition def);
+ /**
+ * Add a new AlertNotification to the passed definition
+ * @param user subject of the caller
+ * @param alertDefinitionId Id of the alert definition
+ * @param senderName shortName of the {@link AlertSender}
+ * @param configuration Properties for this alert sender.
+ */
+ void addAlertNotification(Subject user, int alertDefinitionId, String senderName,
Configuration configuration);
+
+ /**
+ * Return notifications for a certain alertDefinitionId
+ *
+ * NOTE: this only returns notifications that have an AlertSender defined.
+ *
+ * @param user Subject of the caller
+ * @param alertDefinitionId Id of the alert definition
+ * @return list of defined notification of the passed alert definition
+ *
+ *
+ */
+ List<AlertNotification> getNotificationsForAlertDefinition(Subject user, int
alertDefinitionId);
}
\ No newline at end of file
Show replies by date