modules/core/domain/src/main/java/org/rhq/core/domain/criteria/RoleCriteria.java
| 12
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/NewNotificationEditor.java
| 2
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/SystemRolesNotificationSenderForm.java
| 202 ++++++++++
modules/enterprise/server/plugins/alert-roles/src/main/java/org/rhq/enterprise/server/plugins/alertRoles/RolesBackingBean.java
| 83 ----
modules/enterprise/server/plugins/alert-roles/src/main/resources/META-INF/rhq-serverplugin.xml
| 12
modules/enterprise/server/plugins/alert-roles/src/main/resources/roles.xhtml
| 22 -
6 files changed, 217 insertions(+), 116 deletions(-)
New commits:
commit 885a5f526a3868a44d3f07f61c5df1ed1ef4ae16
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Mon Oct 4 17:02:47 2010 -0400
implement the new alert-role server plugin notification editor. this needs to be
tested to make sure the sender still works. but the notification configuration is
consistent with how it was before so it should work
diff --git
a/modules/core/domain/src/main/java/org/rhq/core/domain/criteria/RoleCriteria.java
b/modules/core/domain/src/main/java/org/rhq/core/domain/criteria/RoleCriteria.java
index 3237c49..2d18670 100644
--- a/modules/core/domain/src/main/java/org/rhq/core/domain/criteria/RoleCriteria.java
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/criteria/RoleCriteria.java
@@ -22,10 +22,13 @@
*/
package org.rhq.core.domain.criteria;
+import java.util.List;
+
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import org.rhq.core.domain.authz.Role;
+import org.rhq.core.domain.util.CriteriaUtils;
import org.rhq.core.domain.util.PageOrdering;
/**
@@ -39,7 +42,8 @@ public class RoleCriteria extends Criteria {
private Integer filterId;
private String filterDescription;
private String filterName;
- private Integer filterSubjectId;
+ private Integer filterSubjectId; // needs overrides
+ private List<Integer> filterIds; // needs overrides
private boolean fetchPermissions;
private boolean fetchResourceGroups;
@@ -54,6 +58,8 @@ public class RoleCriteria extends Criteria {
+ " FROM Role innerRole " //
+ " JOIN innerRole.subjects innerSubject " //
+ " WHERE innerSubject.id = ? )");
+
+ filterOverrides.put("ids", "id IN ( ? )");
}
@Override
@@ -77,6 +83,10 @@ public class RoleCriteria extends Criteria {
this.filterSubjectId = filterSubjectId;
}
+ public void addFilterIds(Integer... filterIds) {
+ this.filterIds = CriteriaUtils.getListIgnoringNulls(filterIds);
+ }
+
/**
* Requires MANAGE_SECURITY
* @param fetchSubjects
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/NewNotificationEditor.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/NewNotificationEditor.java
index 7d8745d..40bd990 100644
---
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/NewNotificationEditor.java
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/NewNotificationEditor.java
@@ -220,7 +220,7 @@ public class NewNotificationEditor extends LocatableDynamicForm {
if ("System Users".equals(sender)) {
newCanvas = new SystemUsersNotificationSenderForm(newLocatorId,
notificationToEdit, sender);
} else if ("System Roles".equals(sender)) {
- newCanvas = null; // TODO
+ newCanvas = new SystemRolesNotificationSenderForm(newLocatorId,
notificationToEdit, sender);
} else if ("Resource Operations".equals(sender)) {
newCanvas = null; // TODO
} else {
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/SystemRolesNotificationSenderForm.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/SystemRolesNotificationSenderForm.java
new file mode 100644
index 0000000..fe4cf36
--- /dev/null
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/SystemRolesNotificationSenderForm.java
@@ -0,0 +1,202 @@
+/*
+ * 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, version 2, as
+ * published by the Free Software Foundation, and/or the GNU Lesser
+ * General Public License, version 2.1, also as published by the Free
+ * Software Foundation.
+ *
+ * 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 and the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * and the GNU Lesser General Public License along with this program;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.rhq.enterprise.gui.coregui.client.alert.definitions;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+
+import com.google.gwt.user.client.rpc.AsyncCallback;
+import com.smartgwt.client.data.Criteria;
+import com.smartgwt.client.widgets.form.DynamicForm;
+import com.smartgwt.client.widgets.grid.ListGridRecord;
+
+import org.rhq.core.domain.alert.notification.AlertNotification;
+import org.rhq.core.domain.authz.Role;
+import org.rhq.core.domain.configuration.PropertySimple;
+import org.rhq.core.domain.criteria.RoleCriteria;
+import org.rhq.core.domain.util.PageList;
+import org.rhq.enterprise.gui.coregui.client.CoreGUI;
+import org.rhq.enterprise.gui.coregui.client.admin.roles.RolesDataSource;
+import org.rhq.enterprise.gui.coregui.client.components.selector.AbstractSelector;
+import org.rhq.enterprise.gui.coregui.client.gwt.GWTServiceLookup;
+import org.rhq.enterprise.gui.coregui.client.util.RPCDataSource;
+
+/**
+ * This notification form will be used for the System Roles sender. This form lets
+ * you pick roles that the sender will send notifications to.
+ *
+ * @author John Mazzitelli
+ */
+public class SystemRolesNotificationSenderForm extends AbstractNotificationSenderForm {
+
+ // the alert configuration property name where the IDs are stored in |-separated
form
+ private static final String PROPNAME = "roleId";
+
+ private RoleSelector selector;
+
+ public SystemRolesNotificationSenderForm(String locatorId, AlertNotification notif,
String sender) {
+ super(locatorId, notif, sender);
+ }
+
+ @Override
+ protected void onInit() {
+ super.onInit();
+
+ String roleIds = getConfiguration().getSimpleValue(PROPNAME, ""); // we
know the role plugin defines this
+ if (roleIds != null && roleIds.length() > 0) {
+ try {
+ List<Integer> ids = unfence(roleIds, Integer.class);
+ RoleCriteria criteria = new RoleCriteria();
+ criteria.addFilterIds(ids.toArray(new Integer[ids.size()]));
+ GWTServiceLookup.getRoleService().findRolesByCriteria(criteria, new
AsyncCallback<PageList<Role>>() {
+ @Override
+ public void onSuccess(PageList<Role> result) {
+ createNewSelector(result);
+ }
+
+ @Override
+ public void onFailure(Throwable caught) {
+ CoreGUI.getErrorHandler()
+ .handleError("Cannot determine current roles - starting
empty", caught);
+ createNewSelector(null);
+ }
+ });
+ } catch (Exception e) {
+ CoreGUI.getErrorHandler().handleError("Cannot use current roles -
starting empty", e);
+ createNewSelector(null);
+ }
+ } else {
+ createNewSelector(null);
+ }
+ }
+
+ private void createNewSelector(Collection<Role> preselectedRoles) {
+ String selectorLocatorId = extendLocatorId("roleSelector");
+ selector = new RoleSelector(selectorLocatorId, preselectedRoles);
+ selector.setWidth(400);
+ selector.setHeight(300);
+ addMember(selector);
+ markForRedraw();
+ }
+
+ @Override
+ public boolean validate() {
+ if (selector != null) {
+ try {
+ HashSet<Integer> selectedIds = selector.getSelection();
+ String newPropValue = fence(selectedIds);
+ getConfiguration().put(new PropertySimple(PROPNAME, newPropValue));
+ return true;
+ } catch (Exception e) {
+ CoreGUI.getErrorHandler().handleError("Cannot save the selected
roles", e);
+ return false;
+ }
+ }
+ return true;
+ }
+
+ @SuppressWarnings("unchecked")
+ private <T> List<T> unfence(String fencedData, Class<T> type) {
+ String delimiter = "\\|";
+ String[] elements = fencedData.split(delimiter);
+ List<T> results = new ArrayList<T>(elements.length);
+
+ if (Integer.class.equals(type)) {
+ for (String next : elements) {
+ if (next.length() != 0) {
+ results.add((T) Integer.valueOf(next));
+ }
+ }
+ } else if (String.class.equals(type)) {
+ for (String next : elements) {
+ if (next.length() != 0) {
+ results.add((T) next);
+ }
+ }
+ } else {
+ throw new IllegalArgumentException("No support for unfencing data of
type " + type);
+ }
+ return results;
+ }
+
+ /**
+ * Takes the list of elements e1, e2, e3 and fences
+ * them with '|' delimiters such that the result looks
+ * like "|e1|e2|e3|"
+ */
+ private String fence(Collection<?> elements) {
+ if (elements.size() == 0) {
+ return "";
+ }
+ StringBuilder builder = new StringBuilder();
+ builder.append('|');
+ for (Object next : elements) {
+ builder.append(String.valueOf(next)).append('|');
+ }
+ return builder.toString();
+ }
+
+ private class RoleSelector extends AbstractSelector<Role> {
+
+ public RoleSelector(String id, Collection<Role> roles) {
+ super(id);
+ if (roles != null) {
+ ListGridRecord[] data = (new RolesDataSource()).buildRecords(roles);
+ setAssigned(data);
+ }
+ }
+
+ @Override
+ protected RPCDataSource<Role> getDataSource() {
+ return new SelectedRolesDataSource();
+ }
+
+ @Override
+ protected DynamicForm getAvailableFilterForm() {
+ return null; // No Filters Currently
+ }
+
+ @Override
+ protected Criteria getLatestCriteria(DynamicForm availableFilterForm) {
+ return null; // No Filters Currently
+ }
+
+ public class SelectedRolesDataSource extends RolesDataSource {
+
+ @Override
+ public ListGridRecord[] buildRecords(Collection<Role> roles) {
+ ListGridRecord[] records = super.buildRecords(roles);
+ for (ListGridRecord record : records) {
+ if (selection.contains(record.getAttributeAsInt("id"))) {
+ record.setEnabled(false);
+ }
+ }
+ return records;
+ }
+ }
+
+ }
+}
diff --git
a/modules/enterprise/server/plugins/alert-roles/src/main/java/org/rhq/enterprise/server/plugins/alertRoles/RolesBackingBean.java
b/modules/enterprise/server/plugins/alert-roles/src/main/java/org/rhq/enterprise/server/plugins/alertRoles/RolesBackingBean.java
deleted file mode 100644
index a7f556e..0000000
---
a/modules/enterprise/server/plugins/alert-roles/src/main/java/org/rhq/enterprise/server/plugins/alertRoles/RolesBackingBean.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * RHQ Management Platform
- * Copyright (C) 2005-2009 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.server.plugins.alertRoles;
-
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.rhq.core.domain.authz.Role;
-import org.rhq.core.domain.configuration.PropertySimple;
-import org.rhq.core.domain.util.PageControl;
-import org.rhq.enterprise.server.plugin.pc.alert.AlertSender;
-import org.rhq.enterprise.server.plugin.pc.alert.CustomAlertSenderBackingBean;
-import org.rhq.enterprise.server.util.LookupUtil;
-
-/**
- * Backing Bean for the roles sender alert sender plugin custom UI
- * @author Joseph Marques
- */
-public class RolesBackingBean extends CustomAlertSenderBackingBean {
-
- private Map<String, String> available;
- private List<String> currentRoles;
- private static final String ROLE_ID = "roleId";
-
- @Override
- public void loadView() {
- // get available/all subjects
- List<Role> allRoles = LookupUtil.getRoleManager().findRoles(new
PageControl());
- available = new HashMap<String, String>();
- for (Role role : allRoles) {
- String roleId = String.valueOf(role.getId());
- available.put(role.getName(), roleId);
- }
-
- // get current subjects
- String subjectString = alertParameters.getSimpleValue(ROLE_ID, "");
- currentRoles = AlertSender.unfence(subjectString, String.class);
- }
-
- @Override
- public void saveView() {
- String roleIds = AlertSender.fence(currentRoles);
-
- PropertySimple p = alertParameters.getSimple(ROLE_ID);
- if (p == null) {
- p = new PropertySimple(ROLE_ID, roleIds);
- alertParameters.put(p);
- } else {
- p.setStringValue(roleIds);
- }
-
- alertParameters = persistConfiguration(alertParameters);
- }
-
- public List<String> getCurrentRoles() {
- return currentRoles;
- }
-
- public void setCurrentRoles(List<String> currentRoles) {
- this.currentRoles = currentRoles;
- }
-
- public Map<String, String> getAvailableRolesMap() {
- return available;
- }
-}
diff --git
a/modules/enterprise/server/plugins/alert-roles/src/main/resources/META-INF/rhq-serverplugin.xml
b/modules/enterprise/server/plugins/alert-roles/src/main/resources/META-INF/rhq-serverplugin.xml
index 7d7551c..4e50100 100644
---
a/modules/enterprise/server/plugins/alert-roles/src/main/resources/META-INF/rhq-serverplugin.xml
+++
b/modules/enterprise/server/plugins/alert-roles/src/main/resources/META-INF/rhq-serverplugin.xml
@@ -14,19 +14,13 @@
Used to send notifications to all users in the selected system roles.
</serverplugin:help>
- <!-- startup & tear down listener, + scheduled jobs
- <serverplugin:plugin-component class="Foo" />
- -->
-
<!-- How does this sender show up in drop downs etc -->
<short-name>System Roles</short-name>
<!-- Class that does the actual sending -->
<plugin-class>RolesSender</plugin-class>
- <custom-ui>
- <ui-snippet-name>roles.xhtml</ui-snippet-name>
- <backing-bean-class>RolesBackingBean</backing-bean-class>
- <backing-bean-name>rolesBean</backing-bean-name>
- </custom-ui>
+ <alert-configuration>
+ <c:simple-property name="roleId" type="string"
required="true" description="The roles (ids are |-separated) to be
notified"/>
+ </alert-configuration>
</alert-plugin>
\ No newline at end of file
diff --git a/modules/enterprise/server/plugins/alert-roles/src/main/resources/roles.xhtml
b/modules/enterprise/server/plugins/alert-roles/src/main/resources/roles.xhtml
deleted file mode 100644
index f807414..0000000
--- a/modules/enterprise/server/plugins/alert-roles/src/main/resources/roles.xhtml
+++ /dev/null
@@ -1,22 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-
-<html
xmlns="http://www.w3.org/1999/xhtml"
-
xmlns:h="http://java.sun.com/jsf/html"
-
xmlns:f="http://java.sun.com/jsf/core"
-
xmlns:ui="http://java.sun.com/jsf/facelets"
-
xmlns:c="http://java.sun.com/jstl/core"
-
xmlns:a4j="https://richfaces.org/a4j"
-
xmlns:rich="http://richfaces.ajax4jsf.org/rich">
-
-<body>
- <rich:pickList fastMoveControlsVisible="false"
- sourceListWidth="200px"
- targetListWidth="200px"
- copyControlLabel="Add Roles"
- removeControlLabel="Remove Roles"
- value="#{rolesBean.currentRoles}">
- <f:selectItems value="#{rolesBean.availableRolesMap}" />
- </rich:pickList>
-</body>
-
-</html>
\ No newline at end of file