modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertDataSource.java
| 87 -
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertHistoryView.java
| 34
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertPortletConfigurationDataSource.java
| 4
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertPortletDataSource.java
| 168 --
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/DashboardView.java
| 9
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/PortletWindow.java
| 14
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/groups/GroupAlertsPortlet.java
| 352 -----
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/groups/GroupAlertsPortlet3.java
| 378 ------
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/recent/alerts/AbstractRecentAlertsPortlet.java
| 376 ++++++
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/recent/alerts/PortletAlertSelector.java
| 96 -
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/recent/alerts/RecentAlertsPortlet.java
| 626 ----------
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/resource/ResourceAlertsPortlet.java
| 151 --
12 files changed, 520 insertions(+), 1775 deletions(-)
New commits:
commit ccbc787a51ecd53ab364e43046b8b4f49147c81d
Author: Jay Shaughnessy <jshaughn(a)redhat.com>
Date: Wed Mar 30 09:27:30 2011 -0400
Fix several issues in Alerts Portlets
- refactor to share a common abstract base class to simplify the
concrete classes and conslidate fixes.
- Fixed issue causing retrieval of all alerts
- Fixed issue with ordering of alerts
- Fixed issues with button enablement (affected resource alert history view as well)
- Removed some obsolete classes
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertDataSource.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertDataSource.java
index 3e51b24..d9d1eda 100644
---
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertDataSource.java
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertDataSource.java
@@ -225,56 +225,61 @@ public class AlertDataSource extends RPCDataSource<Alert,
AlertCriteria> {
long fetchTime = System.currentTimeMillis() - start;
Log.info(result.size() + " alerts fetched in: " + fetchTime +
"ms");
- if (entityContext.type != EntityContext.Type.Resource) {
- dataRetrieved(result, response, request);
- } else {
- response.setData(buildRecords(result));
- response.setTotalRows(result.getTotalSize()); // for paging to work
we have to specify size of full result set
- processResponse(request.getRequestId(), response);
- }
+ dataRetrieved(result, response, request);
+ processResponse(request.getRequestId(), response);
}
});
}
/**
- * Additional processing to support a cross-resource view)
- * @param result
- * @param response
- * @param request
+ * Additional processing to support entity-specific or cross-resource views, and
something that can be overidden.
*/
protected void dataRetrieved(final PageList<Alert> result, final DSResponse
response, final DSRequest request) {
- HashSet<Integer> typesSet = new HashSet<Integer>();
- HashSet<String> ancestries = new HashSet<String>();
- for (Alert alert : result) {
- Resource resource = alert.getAlertDefinition().getResource();
- typesSet.add(resource.getResourceType().getId());
- ancestries.add(resource.getAncestry());
- }
-
- // In addition to the types of the result resources, get the types of their
ancestry
- typesSet.addAll(AncestryUtil.getAncestryTypeIds(ancestries));
+ switch (entityContext.type) {
+
+ // no need to disambiguate, the alerts are for a singe resource
+ case Resource:
+ response.setData(buildRecords(result));
+ // for paging to work we have to specify size of full result set
+ response.setTotalRows(result.getTotalSize());
+ break;
+
+ // disambiguate as the results could be cross-resource
+ default:
+ HashSet<Integer> typesSet = new HashSet<Integer>();
+ HashSet<String> ancestries = new HashSet<String>();
+ for (Alert alert : result) {
+ Resource resource = alert.getAlertDefinition().getResource();
+ typesSet.add(resource.getResourceType().getId());
+ ancestries.add(resource.getAncestry());
+ }
- ResourceTypeRepository typeRepo = ResourceTypeRepository.Cache.getInstance();
- typeRepo.getResourceTypes(typesSet.toArray(new Integer[typesSet.size()]), new
TypesLoadedCallback() {
- @Override
- public void onTypesLoaded(Map<Integer, ResourceType> types) {
- // Smartgwt has issues storing a Map as a ListGridRecord attribute. Wrap
it in a pojo.
- AncestryUtil.MapWrapper typesWrapper = new
AncestryUtil.MapWrapper(types);
-
- Record[] records = buildRecords(result);
- for (Record record : records) {
- // To avoid a lot of unnecessary String construction, be lazy about
building ancestry hover text.
- // Store the types map off the records so we can build a detailed
hover string as needed.
- record.setAttribute(AncestryUtil.RESOURCE_ANCESTRY_TYPES,
typesWrapper);
-
- // Build the decoded ancestry Strings now for display
- record.setAttribute(AncestryUtil.RESOURCE_ANCESTRY_VALUE,
AncestryUtil.getAncestryValue(record));
+ // In addition to the types of the result resources, get the types of their
ancestry
+ typesSet.addAll(AncestryUtil.getAncestryTypeIds(ancestries));
+
+ ResourceTypeRepository typeRepo =
ResourceTypeRepository.Cache.getInstance();
+ typeRepo.getResourceTypes(typesSet.toArray(new Integer[typesSet.size()]), new
TypesLoadedCallback() {
+ @Override
+ public void onTypesLoaded(Map<Integer, ResourceType> types) {
+ // Smartgwt has issues storing a Map as a ListGridRecord attribute.
Wrap it in a pojo.
+ AncestryUtil.MapWrapper typesWrapper = new
AncestryUtil.MapWrapper(types);
+
+ Record[] records = buildRecords(result);
+ for (Record record : records) {
+ // To avoid a lot of unnecessary String construction, be lazy
about building ancestry hover text.
+ // Store the types map off the records so we can build a detailed
hover string as needed.
+ record.setAttribute(AncestryUtil.RESOURCE_ANCESTRY_TYPES,
typesWrapper);
+
+ // Build the decoded ancestry Strings now for display
+ record
+ .setAttribute(AncestryUtil.RESOURCE_ANCESTRY_VALUE,
AncestryUtil.getAncestryValue(record));
+ }
+ response.setData(records);
+ // for paging to work we have to specify size of full result set
+ response.setTotalRows(result.getTotalSize());
}
- response.setData(records);
- response.setTotalRows(result.getTotalSize()); // for paging to work we
have to specify size of full result set
- processResponse(request.getRequestId(), response);
- }
- });
+ });
+ }
}
@Override
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertHistoryView.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertHistoryView.java
index 98e4b34..f5fd917 100644
---
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertHistoryView.java
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertHistoryView.java
@@ -67,18 +67,31 @@ public class AlertHistoryView extends
TableSection<AlertDataSource> {
SortDirection.DESCENDING);
EntityContext context;
boolean hasWriteAccess;
+ AlertDataSource dataSource;
// for subsystem views
public AlertHistoryView(String locatorId) {
this(locatorId, SUBSYSTEM_VIEW_ID.getTitle(), EntityContext.forSubsystemView(),
false);
}
+ public AlertHistoryView(String locatorId, EntityContext entityContext) {
+ this(locatorId, SUBSYSTEM_VIEW_ID.getTitle(), entityContext, false);
+ }
+
protected AlertHistoryView(String locatorId, String tableTitle, EntityContext
context, boolean hasWriteAccess) {
super(locatorId, tableTitle, new SortSpecifier[] { DEFAULT_SORT_SPECIFIER });
this.context = context;
this.hasWriteAccess = hasWriteAccess;
- setDataSource(new AlertDataSource(context));
+ setDataSource(getDataSource());
+ }
+
+ @Override
+ public AlertDataSource getDataSource() {
+ if (null == this.dataSource) {
+ this.dataSource = new AlertDataSource(context);
+ }
+ return this.dataSource;
}
@Override
@@ -128,28 +141,28 @@ public class AlertHistoryView extends
TableSection<AlertDataSource> {
delete(selection);
}
});
+ addTableAction("AcknowledgeAlert", MSG.common_button_ack(),
MSG.view_alerts_ack_confirm(),
+ new AbstractTableAction(singleTargetEnablement) {
+ public void executeAction(ListGridRecord[] selection, Object actionValue)
{
+ acknowledge(selection);
+ }
+ });
addTableAction("DeleteAll", MSG.common_button_delete_all(),
MSG.view_alerts_delete_confirm_all(),
new TableAction() {
public boolean isEnabled(ListGridRecord[] selection) {
ListGrid grid = getListGrid();
- return (hasWriteAccess && grid != null &&
(getListGrid().getRecords().length >= 1));
+ return (hasWriteAccess && grid != null &&
!grid.getResultSet().isEmpty());
}
public void executeAction(ListGridRecord[] selection, Object actionValue)
{
deleteAll();
}
});
- addTableAction("AcknowledgeAlert", MSG.common_button_ack(),
MSG.view_alerts_ack_confirm(),
- new AbstractTableAction(singleTargetEnablement) {
- public void executeAction(ListGridRecord[] selection, Object actionValue)
{
- acknowledge(selection);
- }
- });
addTableAction("AcknowledgeAll", MSG.common_button_ack_all(),
MSG.view_alerts_ack_confirm_all(),
new TableAction() {
public boolean isEnabled(ListGridRecord[] selection) {
ListGrid grid = getListGrid();
- return (hasWriteAccess && grid != null &&
(grid.getRecords().length >= 1));
+ return (hasWriteAccess && grid != null &&
!grid.getResultSet().isEmpty());
}
public void executeAction(ListGridRecord[] selection, Object actionValue)
{
@@ -234,4 +247,7 @@ public class AlertHistoryView extends
TableSection<AlertDataSource> {
return AlertDetailsView.getInstance();
}
+ public EntityContext getContext() {
+ return context;
+ }
}
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertPortletConfigurationDataSource.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertPortletConfigurationDataSource.java
index 2cb7f74..db1e4ef 100644
---
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertPortletConfigurationDataSource.java
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertPortletConfigurationDataSource.java
@@ -41,7 +41,6 @@ import org.rhq.core.domain.util.PageOrdering;
import org.rhq.enterprise.gui.coregui.client.CoreGUI;
import
org.rhq.enterprise.gui.coregui.client.dashboard.portlets.PortletConfigurationEditorComponent;
import
org.rhq.enterprise.gui.coregui.client.dashboard.portlets.PortletConfigurationEditorComponent.Constant;
-import
org.rhq.enterprise.gui.coregui.client.dashboard.portlets.recent.alerts.RecentAlertsPortlet;
import org.rhq.enterprise.gui.coregui.client.util.MeasurementUtility;
/** Customize the AlertDataSource to pull fetch criteria information from
@@ -221,8 +220,7 @@ public class AlertPortletConfigurationDataSource extends
AlertDataSource {
}
public Integer[] extractFilterResourceIds(DashboardPortlet storedPortlet, Integer[]
filterResourceIds) {
- PropertyList propertyList = storedPortlet.getConfiguration().getList(
- RecentAlertsPortlet.ALERT_RANGE_RESOURCE_IDS);
+ PropertyList propertyList =
storedPortlet.getConfiguration().getList("alert-range-resource-ids");
if ((propertyList != null) && (propertyList.getList() != null) &&
(!propertyList.getList().isEmpty())
&& (propertyList.getList().get(0) != null)) {
Property container = propertyList.getList().get(0);
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertPortletDataSource.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertPortletDataSource.java
deleted file mode 100644
index a2d0aba..0000000
---
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertPortletDataSource.java
+++ /dev/null
@@ -1,168 +0,0 @@
-package org.rhq.enterprise.gui.coregui.client.alert;
-
-import com.google.gwt.user.client.rpc.AsyncCallback;
-import com.smartgwt.client.data.DSRequest;
-import com.smartgwt.client.data.DSResponse;
-import com.smartgwt.client.rpc.RPCResponse;
-
-import org.rhq.core.domain.alert.Alert;
-import org.rhq.core.domain.alert.AlertPriority;
-import org.rhq.core.domain.configuration.Property;
-import org.rhq.core.domain.configuration.PropertyList;
-import org.rhq.core.domain.configuration.PropertySimple;
-import org.rhq.core.domain.criteria.AlertCriteria;
-import org.rhq.core.domain.dashboard.DashboardPortlet;
-import org.rhq.core.domain.util.PageControl;
-import org.rhq.core.domain.util.PageList;
-import org.rhq.enterprise.gui.coregui.client.CoreGUI;
-import
org.rhq.enterprise.gui.coregui.client.dashboard.portlets.recent.alerts.RecentAlertsPortlet;
-
-public class AlertPortletDataSource extends AlertDataSource {
- //configuration attributes
- private int alertRangeCompleted = -1;
- private int alertPriorityIndex = -1;
- private long alertTimeRange = -1;
- private String alertResourcesToUse = "all";
- private Integer[] alertFilterResourceIds = {};
- private DashboardPortlet portlet = null;
-
- public AlertPortletDataSource() {
- super();
- }
-
- public AlertPortletDataSource(DashboardPortlet recentAlertsPortlet) {
- super();
- this.portlet = recentAlertsPortlet;
- }
-
- @Override
- protected AlertCriteria getFetchCriteria(DSRequest request) {
- //retrieve previous settings from portlet config
- if ((portlet != null) && (this.portlet instanceof DashboardPortlet)) {
- //must check for whether portlet config
- PropertySimple property = portlet.getConfiguration().getSimple(
- RecentAlertsPortlet.ALERT_RANGE_RESOURCES_VALUE);
- if ((property != null) && (property.getStringValue() != null)) {
- //retrieve and translate to int
- String retrieved = property.getStringValue();
- if
(retrieved.trim().equalsIgnoreCase(RecentAlertsPortlet.RESOURCES_SELECTED)) {
- setAlertResourcesToUse(RecentAlertsPortlet.RESOURCES_SELECTED);
- } else {
- setAlertResourcesToUse(RecentAlertsPortlet.RESOURCES_ALL);
- }
- //if 'selected' then check for previously set resource ids to
filter on
- if
(getAlertResourcesToUse().equals(RecentAlertsPortlet.RESOURCES_SELECTED)) {
- Integer[] alertResourceFilterIds = null;
- alertResourceFilterIds = extractFilterResourceIds(portlet,
alertResourceFilterIds);
- if (alertFilterResourceIds != null) {
- setAlertFilterResourceId(alertFilterResourceIds);
- }
- }
- } else {//create setting
- portlet.getConfiguration().put(
- new PropertySimple(RecentAlertsPortlet.ALERT_RANGE_RESOURCES_VALUE,
- RecentAlertsPortlet.defaultResourceValue));
- setAlertResourcesToUse(RecentAlertsPortlet.RESOURCES_ALL);
- }
- }
-
- AlertCriteria criteria = new AlertCriteria();
- criteria.fetchAlertDefinition(true);
- criteria.fetchRecoveryAlertDefinition(true);
- // TODO: Uncomment the below once the bad performance of it has been fixed.
- //criteria.fetchConditionLogs(true);
- PageControl pc = new PageControl(0, getAlertRangeCompleted());
- criteria.setPageControl(pc);//display per page
- criteria.addFilterStartTime(getAlertTimeRange());//alert age
- if
((getAlertResourcesToUse().equalsIgnoreCase(RecentAlertsPortlet.RESOURCES_SELECTED))
- && (getAlertFilterResourceIds().length > 0)) {
- //add resource ids to filter on
- criteria.addFilterResourceIds(getAlertFilterResourceIds());
- }
- if (getAlertPriorityIndex() > 0) {//add priority selection
-
criteria.addFilterPriorities(AlertPriority.getByLegacyIndex(getAlertPriorityIndex()));
- }
-
- return criteria;
- }
-
- /** Override the executeFetch for AlertPortlet to allow specifying smaller than
total
- * result displays.
- */
- @Override
- protected void executeFetch(final DSRequest request, final DSResponse response, final
AlertCriteria criteria) {
- getAlertService().findAlertsByCriteria(criteria, new
AsyncCallback<PageList<Alert>>() {
-
- public void onFailure(Throwable caught) {
- CoreGUI.getErrorHandler().handleError(MSG.view_alerts_loadFailed(),
caught);
- response.setStatus(RPCResponse.STATUS_FAILURE);
- processResponse(request.getRequestId(), response);
- }
-
- public void onSuccess(PageList<Alert> result) {
- dataRetrieved(result, response, request);
- }
- });
- }
-
- public int getAlertRangeCompleted() {
- return alertRangeCompleted;
- }
-
- public void setAlertRangeCompleted(int alertRangeCompleted) {
- this.alertRangeCompleted = alertRangeCompleted;
- }
-
- public int getAlertPriorityIndex() {
- return alertPriorityIndex;
- }
-
- public void setAlertPriorityIndex(int alertPriorityIndex) {
- this.alertPriorityIndex = alertPriorityIndex;
- }
-
- public long getAlertTimeRange() {
- return alertTimeRange;
- }
-
- public void setAlertTimeRange(long alertTimeRange) {
- this.alertTimeRange = alertTimeRange;
- }
-
- public String getAlertResourcesToUse() {
- return alertResourcesToUse;
- }
-
- public void setAlertResourcesToUse(String resourcesToUse) {
- this.alertResourcesToUse = resourcesToUse;
- }
-
- public Integer[] getAlertFilterResourceIds() {
- return alertFilterResourceIds;
- }
-
- public void setAlertFilterResourceId(Integer[] alertFilterResourceId) {
- this.alertFilterResourceIds = alertFilterResourceId;
- }
-
- public Integer[] extractFilterResourceIds(DashboardPortlet storedPortlet, Integer[]
filterResourceIds) {
- PropertyList propertyList = storedPortlet.getConfiguration().getList(
- RecentAlertsPortlet.ALERT_RANGE_RESOURCE_IDS);
- if ((propertyList != null) && (propertyList.getList() != null) &&
(!propertyList.getList().isEmpty())
- && (propertyList.getList().get(0) != null)) {
- Property container = propertyList.getList().get(0);
- if (container instanceof PropertyList) {
- PropertyList anotherList = (PropertyList) container;
- if (anotherList.getList() != null) {
- filterResourceIds = new Integer[anotherList.getList().size()];
- int index = 0;
- for (Property p : anotherList.getList()) {
- filterResourceIds[index++] = ((PropertySimple)
p).getIntegerValue();
- }
- }
- }
- }
- return filterResourceIds;
- }
-
-}
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/DashboardView.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/DashboardView.java
index 4c19ac1..ba91415 100644
---
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/DashboardView.java
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/DashboardView.java
@@ -889,4 +889,13 @@ public class DashboardView extends LocatableVLayout {
public Dashboard getStoredDashboard() {
return storedDashboard;
}
+
+ public ResourceGroupComposite getGroupComposite() {
+ return groupComposite;
+ }
+
+ public ResourceComposite getResourceComposite() {
+ return resourceComposite;
+ }
+
}
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/PortletWindow.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/PortletWindow.java
index 75710a8..e8d51d1 100644
---
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/PortletWindow.java
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/PortletWindow.java
@@ -41,6 +41,7 @@ import com.smartgwt.client.widgets.events.MouseOverHandler;
import org.rhq.core.domain.authz.Permission;
import org.rhq.core.domain.dashboard.DashboardPortlet;
+import org.rhq.core.domain.resource.composite.ResourcePermission;
import org.rhq.enterprise.gui.coregui.client.components.table.Table;
import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableHeaderControl;
import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableWindow;
@@ -246,4 +247,17 @@ public class PortletWindow extends LocatableWindow {
return dashboardView.getGlobalPermissions();
}
+ public ResourcePermission getResourcePermissions() {
+
+ ResourcePermission result = null;
+
+ if (null != dashboardView.getResourceComposite()) {
+ result = dashboardView.getResourceComposite().getResourcePermission();
+ } else if (null != dashboardView.getGroupComposite()) {
+ result = dashboardView.getGroupComposite().getResourcePermission();
+ }
+
+ return result;
+ }
+
}
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/groups/GroupAlertsPortlet.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/groups/GroupAlertsPortlet.java
index 6ac9afe..337989b 100644
---
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/groups/GroupAlertsPortlet.java
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/groups/GroupAlertsPortlet.java
@@ -18,363 +18,63 @@
*/
package org.rhq.enterprise.gui.coregui.client.dashboard.portlets.groups;
-import java.util.HashMap;
-import java.util.Set;
-
import com.google.gwt.user.client.History;
-import com.google.gwt.user.client.Timer;
-import com.smartgwt.client.types.Overflow;
-import com.smartgwt.client.widgets.Canvas;
-import com.smartgwt.client.widgets.HTMLFlow;
-import com.smartgwt.client.widgets.events.DoubleClickEvent;
-import com.smartgwt.client.widgets.events.DoubleClickHandler;
-import com.smartgwt.client.widgets.form.DynamicForm;
-import com.smartgwt.client.widgets.form.events.SubmitValuesEvent;
-import com.smartgwt.client.widgets.form.events.SubmitValuesHandler;
-import com.smartgwt.client.widgets.form.fields.SelectItem;
-import com.smartgwt.client.widgets.grid.CellFormatter;
-import com.smartgwt.client.widgets.grid.ListGrid;
-import com.smartgwt.client.widgets.grid.ListGridRecord;
-import org.rhq.core.domain.authz.Permission;
-import org.rhq.core.domain.configuration.Configuration;
-import org.rhq.core.domain.configuration.PropertySimple;
-import org.rhq.core.domain.dashboard.DashboardPortlet;
-import org.rhq.core.domain.resource.ResourceType;
-import org.rhq.enterprise.gui.coregui.client.CoreGUI;
-import org.rhq.enterprise.gui.coregui.client.LinkManager;
-import org.rhq.enterprise.gui.coregui.client.alert.AlertHistoryView;
-import org.rhq.enterprise.gui.coregui.client.alert.AlertPortletConfigurationDataSource;
-import
org.rhq.enterprise.gui.coregui.client.components.measurement.CustomConfigMeasurementRangeEditor;
-import org.rhq.enterprise.gui.coregui.client.dashboard.AutoRefreshPortlet;
-import org.rhq.enterprise.gui.coregui.client.dashboard.AutoRefreshPortletUtil;
-import org.rhq.enterprise.gui.coregui.client.dashboard.CustomSettingsPortlet;
+import org.rhq.core.domain.common.EntityContext;
import org.rhq.enterprise.gui.coregui.client.dashboard.Portlet;
import org.rhq.enterprise.gui.coregui.client.dashboard.PortletViewFactory;
-import org.rhq.enterprise.gui.coregui.client.dashboard.PortletWindow;
-import
org.rhq.enterprise.gui.coregui.client.dashboard.portlets.PortletConfigurationEditorComponent;
-import
org.rhq.enterprise.gui.coregui.client.dashboard.portlets.recent.alerts.PortletAlertSelector;
-import
org.rhq.enterprise.gui.coregui.client.inventory.common.detail.summary.AbstractActivityView;
-import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableDynamicForm;
-import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableVLayout;
-import org.rhq.enterprise.gui.coregui.client.util.selenium.SeleniumUtility;
+import
org.rhq.enterprise.gui.coregui.client.dashboard.portlets.recent.alerts.AbstractRecentAlertsPortlet;
/**
+ * @author Jay Shaughnessy
* @author Simeon Pinder
*/
-public class GroupAlertsPortlet extends AlertHistoryView implements
CustomSettingsPortlet, AutoRefreshPortlet {
+public class GroupAlertsPortlet extends AbstractRecentAlertsPortlet {
// A non-displayed, persisted identifier for the portlet
public static final String KEY = "GroupAlerts";
// A default displayed, persisted name for the portlet
public static final String NAME = MSG.view_portlet_defaultName_group_alerts();
- public static final String ALERT_RANGE_RESOURCES_VALUE =
"alert-range-resource-value";
- public static final String ALERT_RANGE_RESOURCE_IDS =
"alert-range-resource-ids";
- public static final String RESOURCES_ALL = MSG.common_label_all_resources();
- public static final String RESOURCES_SELECTED =
MSG.common_label_selected_resources();
- public static final String defaultResourceValue = RESOURCES_ALL;
- public static final String ID = "id";
- private boolean currentlyRefreshing = false;
-
- // set on initial configuration, the window for this portlet view.
- protected PortletWindow portletWindow;
-
- //shared private UI elements
- protected AlertResourceSelectorRegion resourceSelector;
-
- protected AlertPortletConfigurationDataSource dataSource;
- //instance ui widgets
- protected Canvas containerCanvas;
-
- protected Timer refreshTimer;
- protected DashboardPortlet storedPortlet;
- protected Configuration portletConfig;
private int groupId;
- protected boolean portletConfigInitialized = false;
- protected static HashMap<String, String> updatedMapping = new
HashMap<String, String>();
- static {
-
updatedMapping.putAll(PortletConfigurationEditorComponent.CONFIG_PROPERTY_INITIALIZATION);
- //Key, default
- updatedMapping.put(ALERT_RANGE_RESOURCES_VALUE, RESOURCES_ALL);
- updatedMapping.put(ALERT_RANGE_RESOURCE_IDS, RESOURCES_ALL);
- }
+ public GroupAlertsPortlet(String locatorId, int groupId) {
- public GroupAlertsPortlet(String locatorId) {
- super(locatorId);
+ // Since the group id is only used for filtering I don't think it matters
whether this is a
+ // standard group, autogroup, or autocluster, but if so, we'll have to
provide more specific
+ // contexts and more specific context handling.
+ super(locatorId, EntityContext.forGroup(groupId));
- //override the shared datasource
- //figure out which page we're loading
- String currentPage = History.getToken();
- //get groupId
- int groupId = AbstractActivityView.groupIdLookup(currentPage);
this.groupId = groupId;
-
- setShowFilterForm(false); //disable filter form for portlet
- setOverflow(Overflow.VISIBLE);
- }
-
- /**Defines layout for the portlet page.
- */
- protected void initializeUi() {
- //initalize the datasource
- this.dataSource = new AlertPortletConfigurationDataSource(storedPortlet,
portletConfig, this.groupId, null);
- setDataSource(this.dataSource);
-
- setShowHeader(false);
- setShowFooter(true);
- setShowFooterRefresh(false); //disable footer refresh
-
- getListGrid().setEmptyMessage(MSG.view_portlet_results_empty());
- }
-
- /** Responsible for initialization and lazy configuration of the portlet values
- */
- public void configure(PortletWindow portletWindow, DashboardPortlet storedPortlet) {
- //populate portlet configuration details
- if (null == this.portletWindow && null != portletWindow) {
- this.portletWindow = portletWindow;
- }
-
- if ((null == storedPortlet) || (null == storedPortlet.getConfiguration())) {
- return;
- }
- this.storedPortlet = storedPortlet;
- portletConfig = storedPortlet.getConfiguration();
-
- if (!portletConfigInitialized) {
- this.dataSource = new AlertPortletConfigurationDataSource(storedPortlet,
portletConfig, this.groupId, null);
- setDataSource(this.dataSource);
- portletConfigInitialized = true;
- }
-
- //lazy init any elements not yet configured.
- for (String key :
PortletConfigurationEditorComponent.CONFIG_PROPERTY_INITIALIZATION.keySet()) {
- if (portletConfig.getSimple(key) == null) {
- portletConfig.put(new PropertySimple(key,
-
PortletConfigurationEditorComponent.CONFIG_PROPERTY_INITIALIZATION.get(key)));
- }
- }
-
- //resource ids to be conditionally included in the query
- Integer[] filterResourceIds = null;
- filterResourceIds = getDataSource().extractFilterResourceIds(storedPortlet,
filterResourceIds);
- //no defaults
-
- if (filterResourceIds != null) {
- getDataSource().setAlertFilterResourceId(filterResourceIds);
- }
-
- //conditionally display the selected resources ui
- if (containerCanvas != null) {
- //empty out earlier canvas
- for (Canvas c : containerCanvas.getChildren()) {
- c.destroy();
- }
- if ((resourceSelector != null) &&
getDataSource().getAlertResourcesToUse().equals(RESOURCES_SELECTED)) {
- containerCanvas.addChild(resourceSelector.getCanvas());
- } else {
- containerCanvas.addChild(new Canvas());
- }
- }
-
- }
-
- public Canvas getHelpCanvas() {
- return new HTMLFlow(MSG.view_portlet_help_recentAlerts());
- }
-
- @Override
- public DynamicForm getCustomSettingsForm() {
- LocatableDynamicForm customSettings = new
LocatableDynamicForm(extendLocatorId("customSettings"));
- LocatableVLayout page = new
LocatableVLayout(customSettings.extendLocatorId("page"));
- //build editor form container
- final LocatableDynamicForm form = new
LocatableDynamicForm(page.extendLocatorId("alert-filter"));
- form.setMargin(5);
-
- //add label about what configuration affects
-
- //add alert priority selector
- final SelectItem alertPrioritySelector = PortletConfigurationEditorComponent
- .getAlertPriorityEditor(portletConfig);
- //add sort priority selector
- // final SelectItem resultSortSelector =
PortletConfigurationEditorComponent
- // .getResulSortOrderEditor(portletConfig);
- //add result count selector
- final SelectItem resultCountSelector =
PortletConfigurationEditorComponent.getResultCountEditor(portletConfig);
-
- //add range selector
- final CustomConfigMeasurementRangeEditor measurementRangeEditor =
PortletConfigurationEditorComponent
- .getMeasurementRangeEditor(portletConfig);
-
- form.setItems(alertPrioritySelector, resultCountSelector);
-
- //submit handler
- customSettings.addSubmitValuesHandler(new SubmitValuesHandler() {
-
- @Override
- public void onSubmitValues(SubmitValuesEvent event) {
- //alert severity
- portletConfig =
AbstractActivityView.saveAlertPrioritySettings(alertPrioritySelector, portletConfig);
-
- // //result sort order
- // selectedValue =
resultSortSelector.getValue().toString();
- // if ((selectedValue.trim().isEmpty()) ||
(selectedValue.equalsIgnoreCase(PageOrdering.DESC.name()))) {//then desc
- // portletConfig.put(new
PropertySimple(Constant.RESULT_SORT_ORDER, PageOrdering.DESC));
- // } else {
- // portletConfig.put(new
PropertySimple(Constant.RESULT_SORT_ORDER, PageOrdering.ASC));
- // }
- //result count
- portletConfig =
AbstractActivityView.saveResultCounterSettings(resultCountSelector, portletConfig);
-
- //time range settings
- portletConfig =
AbstractActivityView.saveMeasurementRangeEditorSettings(measurementRangeEditor,
- portletConfig);
-
- //persist and reload portlet
- storedPortlet.setConfiguration(portletConfig);
- configure(portletWindow, storedPortlet);
- refresh();
- }
- });
- form.markForRedraw();
- page.addMember(measurementRangeEditor);
- page.addMember(form);
- customSettings.addChild(page);
- return customSettings;
}
- public AlertPortletConfigurationDataSource getDataSource() {
- return dataSource;
+ public int getResourceId() {
+ return groupId;
}
public static final class Factory implements PortletViewFactory {
public static PortletViewFactory INSTANCE = new Factory();
+ /* (non-Javadoc)
+ * TODO: This factory ASSUMES the user is currently navigated to a group detail
view, and generates a portlet
+ * for that group. It will fail in other scenarios. This mechanism
should be improved such that the
+ * factory method can take an EntityContext explicitly indicating, in this
case, the group.
+ * @see
org.rhq.enterprise.gui.coregui.client.dashboard.PortletViewFactory#getInstance(java.lang.String)
+ */
public final Portlet getInstance(String locatorId) {
- return new GroupAlertsPortlet(locatorId);
- }
- }
-
- public void startRefreshCycle() {
- refreshTimer = AutoRefreshPortletUtil.startRefreshCycle(this, this,
refreshTimer);
- }
-
- @Override
- protected void onDestroy() {
- AutoRefreshPortletUtil.onDestroy(this, refreshTimer);
-
- super.onDestroy();
- }
-
- public boolean isRefreshing() {
- return this.currentlyRefreshing;
- }
-
- @Override
- protected void setupTableInteractions(boolean hasWriteAccess) {
- // The portlet is a "subsystem" view. Meaning the alerts displayed can
be from any accessible group for
- // the user. This means the user can have varying permissions on the underlying
groups and/or resources,
- // which makes button enablement tricky. So, for the portlet don't even show
the buttons unless the user
- // is inventory manager. Other users will just have to navigate to the alert in
question in order to
- // manipulate it.
-
- //determine if the user is inventory manager and if so render the buttons
- Set<Permission> permissions = this.portletWindow.getGlobalPermissions();
- if ((null != permissions) &&
permissions.contains(Permission.MANAGE_INVENTORY)) {
- super.setupTableInteractions(true);
- }
- }
-
- protected CellFormatter getDetailsLinkColumnCellFormatter() {
- return new CellFormatter() {
- public String format(Object value, ListGridRecord record, int i, int i1) {
- Integer recordId = getId(record);
- Integer resourceId = record.getAttributeAsInt("resourceId");
- String detailsUrl = LinkManager.getSubsystemAlertHistoryLink(resourceId,
recordId);
- return SeleniumUtility.getLocatableHref(detailsUrl, value.toString(),
null);
- }
- };
- }
-
- @Override
- protected void configureTable() {
- super.configureTable();
-
- setListGridDoubleClickHandler(new DoubleClickHandler() {
- @Override
- public void onDoubleClick(DoubleClickEvent event) {
- ListGrid listGrid = (ListGrid) event.getSource();
- ListGridRecord[] selectedRows = listGrid.getSelection();
- if (selectedRows != null && selectedRows.length == 1) {
- Integer recordId = getId(selectedRows[0]);
- Integer resourceId =
selectedRows[0].getAttributeAsInt("resourceId");
- CoreGUI.goToView(LinkManager.getSubsystemAlertHistoryLink(resourceId,
recordId));
- }
+ String currentPage = History.getToken();
+ int groupId = -1;
+ String[] elements = currentPage.split("/");
+ // process for groups and auto groups Ex. ResourceGroup/10111 or
ResourceGroup/AutoCluster/10321
+ try {
+ groupId = Integer.valueOf(elements[1]);
+ } catch (NumberFormatException nfe) {
+ groupId = Integer.valueOf(elements[2]);
}
- });
- }
-
- @Override
- protected void onInit() {
- super.onInit();
- initializeUi();
- }
-
- @Override
- protected void refreshTableInfo() {
- super.refreshTableInfo();
- if (getTableInfo() != null) {
- int count = getListGrid().getSelection().length;
- getTableInfo().setContents(
- MSG.view_table_matchingRows(String.valueOf(getListGrid().getTotalRows()),
String.valueOf(count)));
- }
- }
-
- @Override
- public void redraw() {
- super.redraw();
- refresh();//is table so need to call this to reload
- }
-}
-
-/** Bundles a ResourceSelector instance with labeling in Canvas for display.
- * Also modifies the AssignedGrid to listen for AvailbleGrid completion and act
accordingly.
- */
-//class AlertResourceSelectorRegion extends LocatableVLayout {
-final class AlertResourceSelectorRegion extends LocatableVLayout {
- public AlertResourceSelectorRegion(String locatorId, Integer[] assigned) {
- super(locatorId);
- this.currentlyAssignedIds = assigned;
- }
-
- private PortletAlertSelector selector = null;
-
- private Integer[] currentlyAssignedIds;
-
- public Integer[] getCurrentlyAssignedIds() {
- return currentlyAssignedIds;
- }
- public Integer[] getListGridValues() {
- Integer[] listGridValues = new Integer[0];
- if (null != selector) {
- listGridValues = selector.getAssignedListGridValues();
+ return new GroupAlertsPortlet(locatorId, groupId);
}
- return listGridValues;
}
- public Canvas getCanvas() {
- if (selector == null) {
- selector = new
PortletAlertSelector(extendLocatorId("AlertSelector"),
this.currentlyAssignedIds,
- ResourceType.ANY_PLATFORM_TYPE, false);
- }
- return selector;
- }
-
- public void setCurrentlyAssignedIds(Integer[] currentlyAssignedIds) {
- this.currentlyAssignedIds = currentlyAssignedIds;
- }
}
\ No newline at end of file
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/groups/GroupAlertsPortlet3.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/groups/GroupAlertsPortlet3.java
deleted file mode 100644
index 2a2b3ac..0000000
---
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/groups/GroupAlertsPortlet3.java
+++ /dev/null
@@ -1,378 +0,0 @@
-/*
- * 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.coregui.client.dashboard.portlets.groups;
-
-import java.util.List;
-
-import com.allen_sauer.gwt.log.client.Log;
-import com.google.gwt.user.client.History;
-import com.google.gwt.user.client.Timer;
-import com.google.gwt.user.client.rpc.AsyncCallback;
-import com.smartgwt.client.widgets.Canvas;
-import com.smartgwt.client.widgets.HTMLFlow;
-import com.smartgwt.client.widgets.form.DynamicForm;
-import com.smartgwt.client.widgets.form.events.SubmitValuesEvent;
-import com.smartgwt.client.widgets.form.events.SubmitValuesHandler;
-import com.smartgwt.client.widgets.form.fields.CheckboxItem;
-import com.smartgwt.client.widgets.form.fields.FormItem;
-import com.smartgwt.client.widgets.form.fields.LinkItem;
-import com.smartgwt.client.widgets.form.fields.SelectItem;
-import com.smartgwt.client.widgets.form.fields.StaticTextItem;
-import com.smartgwt.client.widgets.layout.VLayout;
-
-import org.rhq.core.domain.alert.Alert;
-import org.rhq.core.domain.alert.AlertPriority;
-import org.rhq.core.domain.configuration.Configuration;
-import org.rhq.core.domain.configuration.PropertySimple;
-import org.rhq.core.domain.criteria.AlertCriteria;
-import org.rhq.core.domain.dashboard.DashboardPortlet;
-import org.rhq.core.domain.util.PageControl;
-import org.rhq.core.domain.util.PageList;
-import org.rhq.core.domain.util.PageOrdering;
-import org.rhq.enterprise.gui.coregui.client.ImageManager;
-import
org.rhq.enterprise.gui.coregui.client.components.measurement.CustomConfigMeasurementRangeEditor;
-import org.rhq.enterprise.gui.coregui.client.dashboard.AutoRefreshPortlet;
-import org.rhq.enterprise.gui.coregui.client.dashboard.AutoRefreshPortletUtil;
-import org.rhq.enterprise.gui.coregui.client.dashboard.CustomSettingsPortlet;
-import org.rhq.enterprise.gui.coregui.client.dashboard.Portlet;
-import org.rhq.enterprise.gui.coregui.client.dashboard.PortletViewFactory;
-import org.rhq.enterprise.gui.coregui.client.dashboard.PortletWindow;
-import
org.rhq.enterprise.gui.coregui.client.dashboard.portlets.PortletConfigurationEditorComponent;
-import
org.rhq.enterprise.gui.coregui.client.dashboard.portlets.PortletConfigurationEditorComponent.Constant;
-import org.rhq.enterprise.gui.coregui.client.gwt.AlertGWTServiceAsync;
-import org.rhq.enterprise.gui.coregui.client.gwt.GWTServiceLookup;
-import
org.rhq.enterprise.gui.coregui.client.inventory.common.detail.summary.AbstractActivityView;
-import org.rhq.enterprise.gui.coregui.client.resource.disambiguation.ReportDecorator;
-import org.rhq.enterprise.gui.coregui.client.util.GwtRelativeDurationConverter;
-import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableCanvas;
-import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableDynamicForm;
-import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableVLayout;
-
-/**This portlet allows the end user to customize the:
- * i)range
- * ii)priority
- * iii)etc.
- * of alerts to display for the given group
- *
- * @author Simeon Pinder
- */
-public class GroupAlertsPortlet3 extends LocatableVLayout implements
CustomSettingsPortlet, AutoRefreshPortlet {
- private int groupId = -1;
- protected LocatableCanvas recentAlertsContent = new
LocatableCanvas(extendLocatorId("RecentAlerts"));
- private static AlertGWTServiceAsync alertService =
GWTServiceLookup.getAlertService();
- private boolean currentlyLoading = false;
- private Configuration portletConfig = null;
- private DashboardPortlet storedPortlet;
-
- public GroupAlertsPortlet3(String locatorId) {
- super(locatorId);
- //figure out which page we're loading
- String currentPage = History.getToken();
- String[] elements = currentPage.split("/");
- int currentGroupIdentifier = Integer.valueOf(elements[1]);
- this.groupId = currentGroupIdentifier;
- initializeUi();
- }
-
- @Override
- protected void onInit() {
- super.onInit();
- loadData();
- }
-
- /**Defines layout for the Activity page.
- */
- protected void initializeUi() {
- setPadding(5);
- setMembersMargin(5);
- addMember(recentAlertsContent);
- }
-
- // A non-displayed, persisted identifier for the portlet
- public static final String KEY = "GroupAlerts";
- // A default displayed, persisted name for the portlet
- public static final String NAME = "Group: Alerts";
- public static final String ID = "id";
-
- // set on initial configuration, the window for this portlet view.
- private PortletWindow portletWindow;
- //instance ui widgets
-
- private Timer refreshTimer;
-
- /** Responsible for initialization and lazy configuration of the portlet values
- */
- public void configure(PortletWindow portletWindow, DashboardPortlet storedPortlet) {
- //populate portlet configuration details
- if (null == this.portletWindow && null != portletWindow) {
- this.portletWindow = portletWindow;
- }
-
- if ((null == storedPortlet) || (null == storedPortlet.getConfiguration())) {
- return;
- }
- this.storedPortlet = storedPortlet;
- portletConfig = storedPortlet.getConfiguration();
-
- //lazy init any elements not yet configured.
- for (String key :
PortletConfigurationEditorComponent.CONFIG_PROPERTY_INITIALIZATION.keySet()) {
- if (portletConfig.getSimple(key) == null) {
- portletConfig.put(new PropertySimple(key,
-
PortletConfigurationEditorComponent.CONFIG_PROPERTY_INITIALIZATION.get(key)));
- }
- }
- }
-
- public Canvas getHelpCanvas() {
- return new HTMLFlow(MSG.view_portlet_help_recentAlerts());
- }
-
- public static final class Factory implements PortletViewFactory {
- public static PortletViewFactory INSTANCE = new Factory();
-
- public final Portlet getInstance(String locatorId) {
- return new GroupAlertsPortlet3(locatorId);
- }
- }
-
- /** Fetches alerts and updates the DynamicForm instance with the latest
- * alert information.
- */
- private void getRecentAlerts() {
- final int groupId = this.groupId;
- currentlyLoading = false;
- //fetches last five alerts for this resource
- AlertCriteria criteria = new AlertCriteria();
- //filter priority
- PropertySimple property = portletConfig.getSimple(Constant.ALERT_PRIORITY);
- if (property != null) {
- String currentSetting = property.getStringValue();
- String[] parsedValues = currentSetting.trim().split(",");
- if (currentSetting.trim().isEmpty() || parsedValues.length == 3) {
- //all alert priorities assumed
- } else {
- AlertPriority[] filterPriorities = new
AlertPriority[parsedValues.length];
- int indx = 0;
- for (String priority : parsedValues) {
- AlertPriority p = AlertPriority.valueOf(priority);
- filterPriorities[indx++] = p;
- }
- criteria.addFilterPriorities(filterPriorities);
- }
- }
- PageControl pc = new PageControl();
- //result sort order
- property = portletConfig.getSimple(Constant.RESULT_SORT_ORDER);
- if (property != null) {
- String currentSetting = property.getStringValue();
- if (currentSetting.trim().isEmpty() ||
currentSetting.equalsIgnoreCase(PageOrdering.DESC.name())) {
- criteria.addSortCtime(PageOrdering.DESC);
- pc.setPrimarySortOrder(PageOrdering.DESC);
- } else {
- criteria.addSortCtime(PageOrdering.ASC);
- pc.setPrimarySortOrder(PageOrdering.ASC);
- }
- }
- //result timeframe if enabled
- property = portletConfig.getSimple(Constant.METRIC_RANGE_ENABLE);
- if (Boolean.valueOf(property.getBooleanValue())) {//then proceed setting
- property = portletConfig.getSimple(Constant.METRIC_RANGE);
- if (property != null) {
- String currentSetting = property.getStringValue();
- String[] range = currentSetting.split(",");
- criteria.addFilterStartTime(Long.valueOf(range[0]));
- criteria.addFilterEndTime(Long.valueOf(range[1]));
- }
- }
-
- //result count
- property = portletConfig.getSimple(Constant.RESULT_COUNT);
- if (property != null) {
- String currentSetting = property.getStringValue();
- if (currentSetting.trim().isEmpty() ||
currentSetting.equalsIgnoreCase("5")) {
- //PageControl pageControl = new PageControl(0, 5);
- pc.setPageSize(5);
- } else {
- //PageControl pageControl = new PageControl(0,
Integer.valueOf(currentSetting));
- pc.setPageSize(Integer.valueOf(currentSetting));
- }
- }
- criteria.setPageControl(pc);
- criteria.addFilterResourceGroupIds(groupId);
- alertService.findAlertsByCriteria(criteria, new
AsyncCallback<PageList<Alert>>() {
- @Override
- public void onSuccess(PageList<Alert> result) {
- VLayout column = new VLayout();
- column.setHeight(10);
- if (!result.isEmpty()) {
- int rowNum = 0;
- for (Alert alert : result) {
- // alert history records do not have a usable locatorId,
we'll use rownum, which is unique and
- // may be repeatable.
- LocatableDynamicForm row = new
LocatableDynamicForm(recentAlertsContent.extendLocatorId(String
- .valueOf(rowNum++)));
- row.setNumCols(3);
-
- StaticTextItem iconItem =
AbstractActivityView.newTextItemIcon(ImageManager.getAlertIcon(alert
- .getAlertDefinition().getPriority()),
alert.getAlertDefinition().getPriority()
- .getDisplayName());
- LinkItem link =
AbstractActivityView.newLinkItem(alert.getAlertDefinition().getName() + ": ",
- ReportDecorator.GWT_GROUP_URL + groupId +
"/Alerts/History/" + alert.getId());
- StaticTextItem time =
AbstractActivityView.newTextItem(GwtRelativeDurationConverter
- .format(alert.getCtime()));
- row.setItems(iconItem, link, time);
-
- column.addMember(row);
- }
- //link to more details
- LocatableDynamicForm row = new
LocatableDynamicForm(recentAlertsContent.extendLocatorId(String
- .valueOf(rowNum++)));
- AbstractActivityView.addSeeMoreLink(row,
ReportDecorator.GWT_GROUP_URL + groupId
- + "/Alerts/History/", column);
- } else {
- LocatableDynamicForm row =
AbstractActivityView.createEmptyDisplayRow(recentAlertsContent
- // .extendLocatorId("None"),
AbstractActivityView.RECENT_ALERTS_NONE);
- .extendLocatorId("None"), "No results found using
criteria specified.");
- column.addMember(row);
- }
- for (Canvas child : recentAlertsContent.getChildren()) {
- child.destroy();
- }
- recentAlertsContent.addChild(column);
- recentAlertsContent.markForRedraw();
- }
-
- @Override
- public void onFailure(Throwable caught) {
- Log.debug("Error retrieving recent alerts for group [" +
groupId + "]:" + caught.getMessage());
- }
- });
- }
-
- protected void loadData() {
- currentlyLoading = true;
- getRecentAlerts();
- }
-
- @Override
- public DynamicForm getCustomSettingsForm() {
- LocatableDynamicForm customSettings = new
LocatableDynamicForm(extendLocatorId("customSettings"));
- LocatableVLayout page = new
LocatableVLayout(customSettings.extendLocatorId("page"));
- //build editor form container
- final LocatableDynamicForm form = new
LocatableDynamicForm(page.extendLocatorId("alert-filter"));
- form.setMargin(5);
-
- //add label about what configuration affects
-
- //add alert priority selector
- final SelectItem alertPrioritySelector = PortletConfigurationEditorComponent
- .getAlertPriorityEditor(portletConfig);
- //add sort priority selector
- // final SelectItem resultSortSelector =
PortletConfigurationEditorComponent
- // .getResulSortOrderEditor(portletConfig);
- //add result count selector
- final SelectItem resultCountSelector =
PortletConfigurationEditorComponent.getResultCountEditor(portletConfig);
- //add range selector
- final CustomConfigMeasurementRangeEditor measurementRangeEditor =
PortletConfigurationEditorComponent
- .getMeasurementRangeEditor(portletConfig);
- //TODO: spinder 3/10/11 renable sort selector once it's working in criteria
- // form.setItems(alertPrioritySelector, resultSortSelector,
resultCountSelector);
- form.setItems(alertPrioritySelector, resultCountSelector);
-
- //submit handler
- customSettings.addSubmitValuesHandler(new SubmitValuesHandler() {
-
- @Override
- public void onSubmitValues(SubmitValuesEvent event) {
- //alert severity
- String selectedValue = alertPrioritySelector.getValue().toString();
- if ((selectedValue.trim().isEmpty()) ||
(selectedValue.split(",").length == 3)) {//then no alertPriority specified
- portletConfig.put(new PropertySimple(Constant.ALERT_PRIORITY,
""));
- } else {//some subset of available alertPriorities will be used
- portletConfig.put(new PropertySimple(Constant.ALERT_PRIORITY,
selectedValue));
- }
- // //result sort order
- // selectedValue =
resultSortSelector.getValue().toString();
- // if ((selectedValue.trim().isEmpty()) ||
(selectedValue.equalsIgnoreCase(PageOrdering.DESC.name()))) {//then desc
- // portletConfig.put(new
PropertySimple(Constant.RESULT_SORT_ORDER, PageOrdering.DESC));
- // } else {
- // portletConfig.put(new
PropertySimple(Constant.RESULT_SORT_ORDER, PageOrdering.ASC));
- // }
- //result count
- selectedValue = resultCountSelector.getValue().toString();
- if ((selectedValue.trim().isEmpty()) ||
(selectedValue.equalsIgnoreCase(Constant.RESULT_COUNT_DEFAULT))) {//then 5
- portletConfig.put(new PropertySimple(Constant.RESULT_COUNT,
Constant.RESULT_COUNT_DEFAULT));
- } else {
- portletConfig.put(new PropertySimple(Constant.RESULT_COUNT,
selectedValue));
- }
-
- //alert time range filter. Check for enabled and then persist property.
Dealing with compound widget.
- FormItem item =
measurementRangeEditor.getItem(CustomConfigMeasurementRangeEditor.ENABLE_RANGE_ITEM);
- CheckboxItem itemC = (CheckboxItem) item;
- selectedValue = String.valueOf(itemC.getValueAsBoolean());
- if (!selectedValue.trim().isEmpty()) {//then call
- portletConfig.put(new PropertySimple(Constant.METRIC_RANGE_ENABLE,
selectedValue));
- }
-
- //alert time advanced time filter enabled.
- selectedValue = String.valueOf(measurementRangeEditor.isAdvanced());
- if ((selectedValue != null) && (!selectedValue.trim().isEmpty()))
{
- portletConfig.put(new
PropertySimple(Constant.METRIC_RANGE_BEGIN_END_FLAG, selectedValue));
- }
-
- //alert time frame
- List<Long> begEnd = measurementRangeEditor.getBeginEndTimes();
- if (begEnd.get(0) != 0) {//advanced settings
- portletConfig.put(new PropertySimple(Constant.METRIC_RANGE,
(begEnd.get(0) + "," + begEnd.get(1))));
- }
-
- //persist
- storedPortlet.setConfiguration(portletConfig);
- configure(portletWindow, storedPortlet);
- loadData();
- }
- });
- form.markForRedraw();
- page.addMember(measurementRangeEditor);
- page.addMember(form);
- customSettings.addChild(page);
- return customSettings;
- }
-
- public void startRefreshCycle() {
- refreshTimer = AutoRefreshPortletUtil.startRefreshCycle(this, this,
refreshTimer);
- }
-
- @Override
- protected void onDestroy() {
- AutoRefreshPortletUtil.onDestroy(this, refreshTimer);
-
- super.onDestroy();
- }
-
- public boolean isRefreshing() {
- return this.currentlyLoading;
- }
-
- @Override
- public void redraw() {
- super.redraw();
- loadData();
- }
-}
\ No newline at end of file
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/recent/alerts/AbstractRecentAlertsPortlet.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/recent/alerts/AbstractRecentAlertsPortlet.java
new file mode 100644
index 0000000..013e5be
--- /dev/null
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/recent/alerts/AbstractRecentAlertsPortlet.java
@@ -0,0 +1,376 @@
+package org.rhq.enterprise.gui.coregui.client.dashboard.portlets.recent.alerts;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+import com.google.gwt.user.client.Timer;
+import com.smartgwt.client.data.DSRequest;
+import com.smartgwt.client.data.DSResponse;
+import com.smartgwt.client.types.Overflow;
+import com.smartgwt.client.widgets.Canvas;
+import com.smartgwt.client.widgets.HTMLFlow;
+import com.smartgwt.client.widgets.form.DynamicForm;
+import com.smartgwt.client.widgets.form.events.SubmitValuesEvent;
+import com.smartgwt.client.widgets.form.events.SubmitValuesHandler;
+import com.smartgwt.client.widgets.form.fields.CheckboxItem;
+import com.smartgwt.client.widgets.form.fields.FormItem;
+import com.smartgwt.client.widgets.form.fields.SelectItem;
+
+import org.rhq.core.domain.alert.Alert;
+import org.rhq.core.domain.alert.AlertPriority;
+import org.rhq.core.domain.authz.Permission;
+import org.rhq.core.domain.common.EntityContext;
+import org.rhq.core.domain.configuration.Configuration;
+import org.rhq.core.domain.configuration.PropertySimple;
+import org.rhq.core.domain.criteria.AlertCriteria;
+import org.rhq.core.domain.dashboard.DashboardPortlet;
+import org.rhq.core.domain.resource.composite.ResourcePermission;
+import org.rhq.core.domain.util.OrderingField;
+import org.rhq.core.domain.util.PageControl;
+import org.rhq.core.domain.util.PageList;
+import org.rhq.core.domain.util.PageOrdering;
+import org.rhq.enterprise.gui.coregui.client.alert.AlertDataSource;
+import org.rhq.enterprise.gui.coregui.client.alert.AlertHistoryView;
+import
org.rhq.enterprise.gui.coregui.client.components.measurement.CustomConfigMeasurementRangeEditor;
+import org.rhq.enterprise.gui.coregui.client.dashboard.AutoRefreshPortlet;
+import org.rhq.enterprise.gui.coregui.client.dashboard.AutoRefreshPortletUtil;
+import org.rhq.enterprise.gui.coregui.client.dashboard.CustomSettingsPortlet;
+import org.rhq.enterprise.gui.coregui.client.dashboard.PortletWindow;
+import
org.rhq.enterprise.gui.coregui.client.dashboard.portlets.PortletConfigurationEditorComponent;
+import
org.rhq.enterprise.gui.coregui.client.dashboard.portlets.PortletConfigurationEditorComponent.Constant;
+import org.rhq.enterprise.gui.coregui.client.util.MeasurementUtility;
+import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableDynamicForm;
+import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableVLayout;
+
+/**
+ * A base class for deriving recent alerts portlets for different entity contexts. In
this way the
+ * basic plumbing is shared, giving a consistent behavior and configuration for the
concrete portlets.
+ *
+ * @author Jay Shaughnessy
+ * @author Simeon Pinder
+ */
+public abstract class AbstractRecentAlertsPortlet extends AlertHistoryView implements
CustomSettingsPortlet,
+ AutoRefreshPortlet {
+
+ // set on initial configuration, the window for this portlet view.
+ private PortletWindow portletWindow;
+
+ private AlertsPortletDataSource dataSource;
+
+ // autorefresh timer
+ private Timer refreshTimer;
+
+ public AbstractRecentAlertsPortlet(String locatorId, EntityContext entityContext) {
+ super(locatorId, entityContext);
+
+ setShowFilterForm(false); //disable filter form for portlet
+ setOverflow(Overflow.VISIBLE);
+ }
+
+ public Timer getRefreshTimer() {
+ return refreshTimer;
+ }
+
+ public void setRefreshTimer(Timer refreshTimer) {
+ this.refreshTimer = refreshTimer;
+ }
+
+ public PortletWindow getPortletWindow() {
+ return portletWindow;
+ }
+
+ @Override
+ public AlertsPortletDataSource getDataSource() {
+ if (null == this.dataSource) {
+ this.dataSource = new AlertsPortletDataSource(getContext());
+ }
+ return this.dataSource;
+ }
+
+ @Override
+ public Canvas getHelpCanvas() {
+ return new HTMLFlow(MSG.view_portlet_help_recentAlerts());
+ }
+
+ @Override
+ public void configure(PortletWindow portletWindow, DashboardPortlet storedPortlet) {
+
+ // the portletWindow does not change, so we can hold onto it locally
+ if (null == this.portletWindow && null != portletWindow) {
+ this.portletWindow = portletWindow;
+ }
+
+ // if there is no configuration there is nothing to set
+ if ((null == storedPortlet) || (null == storedPortlet.getConfiguration())) {
+ return;
+ }
+
+ Configuration config = storedPortlet.getConfiguration();
+
+ // not sure I love the fact that this common portlet config assigns some
irrelevant/unused config props,
+ // may be better to prune the common set and add the specific properties locally
in this method
+ for (String key :
PortletConfigurationEditorComponent.CONFIG_PROPERTY_INITIALIZATION.keySet()) {
+ if (config.getSimple(key) == null) {
+ config.put(new PropertySimple(key,
PortletConfigurationEditorComponent.CONFIG_PROPERTY_INITIALIZATION
+ .get(key)));
+ }
+ }
+
+ getDataSource().setConfiguration(config);
+ }
+
+ @Override
+ public DynamicForm getCustomSettingsForm() {
+
+ LocatableDynamicForm customSettingsForm = new
LocatableDynamicForm(extendLocatorId("CustomSettings"));
+ LocatableVLayout page = new
LocatableVLayout(customSettingsForm.extendLocatorId("Page"));
+ LocatableDynamicForm filterForm = new
LocatableDynamicForm(page.extendLocatorId("Filter"));
+ filterForm.setMargin(5);
+
+ final DashboardPortlet storedPortlet = this.portletWindow.getStoredPortlet();
+ final Configuration portletConfig = storedPortlet.getConfiguration();
+
+ // alert priority selector
+ final SelectItem alertPrioritySelector = PortletConfigurationEditorComponent
+ .getAlertPriorityEditor(portletConfig);
+
+ // result count selector
+ final SelectItem resultCountSelector =
PortletConfigurationEditorComponent.getResultCountEditor(portletConfig);
+
+ // range selector
+ final CustomConfigMeasurementRangeEditor measurementRangeEditor =
PortletConfigurationEditorComponent
+ .getMeasurementRangeEditor(portletConfig);
+
+ filterForm.setItems(alertPrioritySelector, resultCountSelector);
+
+ //submit handler
+ customSettingsForm.addSubmitValuesHandler(new SubmitValuesHandler() {
+
+ @Override
+ public void onSubmitValues(SubmitValuesEvent event) {
+ // alert severity
+ String selectedValue = alertPrioritySelector.getValue().toString();
+ if ((selectedValue.trim().isEmpty())
+ || (selectedValue.split(",").length ==
AlertPriority.values().length)) {
+ // no severity filter
+ selectedValue = Constant.ALERT_PRIORITY_DEFAULT;
+ }
+ portletConfig.put(new PropertySimple(Constant.ALERT_PRIORITY,
selectedValue));
+
+ // result count
+ selectedValue = resultCountSelector.getValue().toString();
+ if (selectedValue.trim().isEmpty()) {
+ selectedValue = Constant.RESULT_COUNT_DEFAULT;
+ }
+ portletConfig.put(new PropertySimple(Constant.RESULT_COUNT,
selectedValue));
+
+ // time range settings
+ saveMeasurementRangeEditorSettings(measurementRangeEditor,
portletConfig);
+
+ // persist and reload portlet
+ storedPortlet.setConfiguration(portletConfig);
+ configure(portletWindow, storedPortlet);
+ }
+ });
+
+ page.addMember(measurementRangeEditor);
+ page.addMember(filterForm);
+ customSettingsForm.addChild(page);
+
+ return customSettingsForm;
+ }
+
+ /**
+ * Takes the current value of the widget and persists it into the configuration
object passed in.
+ *
+ * @param measurementRangeEditor
+ * @param portletConfig
+ * returns populated configuration object.
+ */
+ private void saveMeasurementRangeEditorSettings(final
CustomConfigMeasurementRangeEditor measurementRangeEditor,
+ Configuration portletConfig) {
+ String selectedValue = null;
+ if ((measurementRangeEditor != null) && (portletConfig != null)) {
+ //time range filter. Check for enabled and then persist property. Dealing
with compound widget.
+ FormItem item =
measurementRangeEditor.getItem(CustomConfigMeasurementRangeEditor.ENABLE_RANGE_ITEM);
+ CheckboxItem itemC = (CheckboxItem) item;
+ boolean persistTimeRangeSettings = itemC.getValueAsBoolean();
+ if (persistTimeRangeSettings) {//retrieve values and persist
+ selectedValue = String.valueOf(itemC.getValueAsBoolean());
+ if (!selectedValue.trim().isEmpty()) {//then call
+ portletConfig.put(new PropertySimple(Constant.METRIC_RANGE_ENABLE,
selectedValue));
+ }
+
+ //time advanced time filter enabled.
+ boolean isAdvanceTimeSetting = false;
+ selectedValue = String.valueOf(measurementRangeEditor.isAdvanced());
+ if ((selectedValue != null) && (!selectedValue.trim().isEmpty()))
{
+ portletConfig.put(new
PropertySimple(Constant.METRIC_RANGE_BEGIN_END_FLAG, selectedValue));
+ isAdvanceTimeSetting = Boolean.valueOf(selectedValue);
+ }
+
+ //time frame
+ List<Long> begEnd = measurementRangeEditor.getBeginEndTimes();
+ if (isAdvanceTimeSetting) {//advanced settings
+ portletConfig.put(new PropertySimple(Constant.METRIC_RANGE,
(begEnd.get(0) + "," + begEnd.get(1))));
+ } else {
+ //save not advanced time range
+ portletConfig.put(new PropertySimple(Constant.METRIC_RANGE_LASTN,
measurementRangeEditor
+ .getMetricRangePreferences().lastN));
+ portletConfig.put(new PropertySimple(Constant.METRIC_RANGE_UNIT,
measurementRangeEditor
+ .getMetricRangePreferences().unit));
+ }
+ } else {//if disabled, reset time defaults
+ portletConfig.put(new PropertySimple(Constant.METRIC_RANGE_ENABLE,
false));
+ portletConfig.put(new
PropertySimple(Constant.METRIC_RANGE_BEGIN_END_FLAG, false));
+ List<Long> rangeArray =
MeasurementUtility.calculateTimeFrame(Integer
+ .valueOf(Constant.METRIC_RANGE_LASTN_DEFAULT),
Integer.valueOf(Constant.METRIC_RANGE_UNIT_DEFAULT));
+ // String[] range =
{String.valueOf(rangeArray.get(0)),String.valueOf(rangeArray.get(1))};
+ portletConfig.put(new PropertySimple(Constant.METRIC_RANGE,
+ (String.valueOf(rangeArray.get(0)) + "," +
String.valueOf(rangeArray.get(1)))));
+ }
+ }
+ }
+
+ @Override
+ protected void setupTableInteractions(boolean hasWriteAccess) {
+ if (!hasWriteAccess) {
+ Set<Permission> globalPerm =
this.getPortletWindow().getGlobalPermissions();
+ ResourcePermission resPerm =
this.getPortletWindow().getResourcePermissions();
+ hasWriteAccess = (globalPerm.contains(Permission.MANAGE_INVENTORY) || (null
!= resPerm && resPerm.isAlert()));
+ }
+ super.setupTableInteractions(hasWriteAccess);
+ }
+
+ public void startRefreshCycle() {
+ refreshTimer = AutoRefreshPortletUtil.startRefreshCycle(this, this,
refreshTimer);
+ }
+
+ public boolean isRefreshing() {
+ // TODO: actually keep track of when the portlet is refreshing data
+ return false;
+ }
+
+ @Override
+ protected void onDestroy() {
+ AutoRefreshPortletUtil.onDestroy(this, refreshTimer);
+
+ super.onDestroy();
+ }
+
+ static public class AlertsPortletDataSource extends AlertDataSource {
+ private Configuration configuration;
+
+ public AlertsPortletDataSource(EntityContext entityContext) {
+ this(entityContext, null);
+ }
+
+ public AlertsPortletDataSource(EntityContext entityContext, Configuration
configuration) {
+ super(entityContext);
+ this.configuration = configuration;
+ }
+
+ public Configuration getConfiguration() {
+ return configuration;
+ }
+
+ public void setConfiguration(Configuration configuration) {
+ this.configuration = configuration;
+ }
+
+ /* (non-Javadoc)
+ * This override allows us to set the total rows to the number of recent alerts
configured for
+ * the portlet. This sets the counter appropriately and stops further queries to
the server.
+ *
+ * @see
org.rhq.enterprise.gui.coregui.client.alert.AlertDataSource#dataRetrieved(org.rhq.core.domain.util.PageList,
com.smartgwt.client.data.DSResponse, com.smartgwt.client.data.DSRequest)
+ */
+ @Override
+ protected void dataRetrieved(PageList<Alert> result, DSResponse response,
DSRequest request) {
+ super.dataRetrieved(result, response, request);
+
+ response.setTotalRows(result.size());
+ }
+
+ @Override
+ protected AlertCriteria getFetchCriteria(DSRequest request) {
+ AlertCriteria criteria = new AlertCriteria();
+
+ // result count
+ String currentSetting =
this.configuration.getSimpleValue(Constant.RESULT_COUNT,
+ Constant.RESULT_COUNT_DEFAULT);
+
+ // We have to set a PageControl override here, or RPCDataSource will apply
default paging based on the
+ // request. But, once setting a paging override the CriteriaQueryGenerator
will use it for
+ // paging *and* sorting, so we need to also ensure our desired sorting is
included in the override. So,
+ // to get the most recent alerts, apply a descending ordering on create
time.
+ int pageNumber = 0;
+ int pageSize = Integer.valueOf(currentSetting);
+ OrderingField orderingField = new OrderingField("ctime",
PageOrdering.DESC);
+ criteria.setPageControl(new PageControl(pageNumber, pageSize,
orderingField));
+
+ // filter priority
+ currentSetting = this.configuration
+ .getSimpleValue(Constant.ALERT_PRIORITY,
Constant.ALERT_PRIORITY_DEFAULT);
+ String[] parsedValues = currentSetting.trim().split(",");
+ if (!(currentSetting.trim().isEmpty() || parsedValues.length == 3)) {
+ AlertPriority[] filterPriorities = new
AlertPriority[parsedValues.length];
+ int indx = 0;
+ for (String priority : parsedValues) {
+ AlertPriority p = AlertPriority.valueOf(priority);
+ filterPriorities[indx++] = p;
+ }
+ criteria.addFilterPriorities(filterPriorities);
+ }
+
+ //result timeframe if enabled
+ currentSetting =
this.configuration.getSimpleValue(Constant.METRIC_RANGE_ENABLE, null);
+ if (Boolean.valueOf(currentSetting)) {//then proceed setting
+
+ boolean isAdvanced = false;
+ //detect type of widget[Simple|Advanced]
+ PropertySimple property =
this.configuration.getSimple(Constant.METRIC_RANGE_BEGIN_END_FLAG);
+ if (property != null) {
+ isAdvanced = property.getBooleanValue();
+ }
+ if (isAdvanced) {
+ //Advanced time settings
+ property = this.configuration.getSimple(Constant.METRIC_RANGE);
+ if (property != null) {
+ currentSetting = property.getStringValue();
+ String[] range = currentSetting.split(",");
+ criteria.addFilterStartTime(Long.valueOf(range[0]));
+ criteria.addFilterEndTime(Long.valueOf(range[1]));
+ }
+ } else {
+ //Simple time settings
+ property =
this.configuration.getSimple(Constant.METRIC_RANGE_LASTN);
+ if (property != null) {
+ int lastN = property.getIntegerValue();
+ property =
this.configuration.getSimple(Constant.METRIC_RANGE_UNIT);
+ int lastUnits = property.getIntegerValue();
+ ArrayList<Long> beginEnd =
MeasurementUtility.calculateTimeFrame(lastN, Integer
+ .valueOf(lastUnits));
+ criteria.addFilterStartTime(Long.valueOf(beginEnd.get(0)));
+ criteria.addFilterEndTime(Long.valueOf(beginEnd.get(1)));
+ }
+ }
+ }
+
+ // add any context related filters
+ switch (getEntityContext().type) {
+ case Resource:
+ criteria.addFilterResourceIds(getEntityContext().getResourceId());
+ break;
+
+ case ResourceGroup:
+ criteria.addFilterResourceGroupIds(getEntityContext().getGroupId());
+ }
+
+ criteria.fetchAlertDefinition(true);
+ criteria.fetchRecoveryAlertDefinition(true);
+
+ return criteria;
+ }
+ }
+}
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/recent/alerts/PortletAlertSelector.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/recent/alerts/PortletAlertSelector.java
deleted file mode 100644
index dae36c2..0000000
---
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/recent/alerts/PortletAlertSelector.java
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * 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.dashboard.portlets.recent.alerts;
-
-import com.google.gwt.user.client.rpc.AsyncCallback;
-import com.smartgwt.client.data.Record;
-import com.smartgwt.client.data.RecordList;
-import com.smartgwt.client.types.ListGridFieldType;
-import com.smartgwt.client.widgets.grid.ListGridField;
-import com.smartgwt.client.widgets.grid.ListGridRecord;
-
-import org.rhq.core.domain.criteria.ResourceCriteria;
-import org.rhq.core.domain.resource.Resource;
-import org.rhq.core.domain.resource.ResourceType;
-import org.rhq.core.domain.util.PageList;
-import org.rhq.enterprise.gui.coregui.client.CoreGUI;
-import org.rhq.enterprise.gui.coregui.client.gwt.GWTServiceLookup;
-import org.rhq.enterprise.gui.coregui.client.inventory.resource.ResourceDatasource;
-import
org.rhq.enterprise.gui.coregui.client.inventory.resource.selection.ResourceSelector;
-
-/**
- * @author Simeon Pinder
- */
-public class PortletAlertSelector extends ResourceSelector {
-
- public PortletAlertSelector(String locatorId, Integer[] currentlyAssignedIds,
ResourceType resourceTypeFilter,
- boolean forceResourceTypeFilter) {
- super(locatorId, resourceTypeFilter, forceResourceTypeFilter);
-
- //populate fields for grid.
- ListGridField nameField = new ListGridField("name",
MSG.common_title_name());
- ListGridField iconField = new ListGridField("icon",
MSG.common_title_icon(), 50);
- iconField.setType(ListGridFieldType.ICON);
- assignedGrid.setFields(iconField, nameField);
-
- setWidth(RecentAlertsPortlet.ALERT_RESOURCE_SELECTION_WIDTH);
-
- //retrieve the previously assigned resource ids
- if ((currentlyAssignedIds != null) && currentlyAssignedIds.length > 0)
{
- //build listgrid records
- ResourceCriteria criteria = new ResourceCriteria();
- criteria.addFilterIds(currentlyAssignedIds);
-
- GWTServiceLookup.getResourceService().findResourcesByCriteria(criteria,
- new AsyncCallback<PageList<Resource>>() {
- @Override
- public void onSuccess(PageList<Resource> result) {
- if (result.size() > 0) {
- ListGridRecord[] data = (new
ResourceDatasource()).buildRecords(result);
- assignedGrid.setData(data);
- }
- }
-
- @Override
- public void onFailure(Throwable caught) {
-
CoreGUI.getErrorHandler().handleError(MSG.view_portlet_recentAlerts_fail_msg(), caught);
- }
- });
- }
- }
-
- public Integer[] getAssignedListGridValues() {
- Integer[] listGridValues = new Integer[0];
- if ((null != assignedGrid)) {
- RecordList allRecords = assignedGrid.getDataAsRecordList();
- if (allRecords.getLength() > 0) {
- listGridValues = new Integer[allRecords.getLength()];
- for (int i = 0; i < allRecords.getLength(); i++) {
- Record record = allRecords.get(i);
- listGridValues[i] =
record.getAttributeAsInt(RecentAlertsPortlet.ID);
- }
- }
- }
- return listGridValues;
- }
-}
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/recent/alerts/RecentAlertsPortlet.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/recent/alerts/RecentAlertsPortlet.java
index fed9070..51e12b6 100644
---
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/recent/alerts/RecentAlertsPortlet.java
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/recent/alerts/RecentAlertsPortlet.java
@@ -18,542 +18,22 @@
*/
package org.rhq.enterprise.gui.coregui.client.dashboard.portlets.recent.alerts;
-import java.util.Set;
-
-import com.google.gwt.user.client.Timer;
-import com.smartgwt.client.types.Overflow;
-import com.smartgwt.client.widgets.Canvas;
-import com.smartgwt.client.widgets.HTMLFlow;
-import com.smartgwt.client.widgets.events.DoubleClickEvent;
-import com.smartgwt.client.widgets.events.DoubleClickHandler;
-import com.smartgwt.client.widgets.form.DynamicForm;
-import com.smartgwt.client.widgets.form.events.SubmitValuesEvent;
-import com.smartgwt.client.widgets.form.events.SubmitValuesHandler;
-import com.smartgwt.client.widgets.form.fields.SelectItem;
-import com.smartgwt.client.widgets.form.fields.SpacerItem;
-import com.smartgwt.client.widgets.form.fields.events.ChangeEvent;
-import com.smartgwt.client.widgets.form.fields.events.ChangeHandler;
-import com.smartgwt.client.widgets.grid.CellFormatter;
-import com.smartgwt.client.widgets.grid.ListGrid;
-import com.smartgwt.client.widgets.grid.ListGridRecord;
-import com.smartgwt.client.widgets.layout.VLayout;
-
-import org.rhq.core.domain.alert.AlertPriority;
-import org.rhq.core.domain.authz.Permission;
-import org.rhq.core.domain.configuration.PropertyList;
-import org.rhq.core.domain.configuration.PropertySimple;
-import org.rhq.core.domain.dashboard.DashboardPortlet;
-import org.rhq.core.domain.resource.ResourceType;
-import org.rhq.enterprise.gui.coregui.client.CoreGUI;
-import org.rhq.enterprise.gui.coregui.client.LinkManager;
-import org.rhq.enterprise.gui.coregui.client.alert.AlertHistoryView;
-import org.rhq.enterprise.gui.coregui.client.alert.AlertPortletDataSource;
-import org.rhq.enterprise.gui.coregui.client.dashboard.AutoRefreshPortlet;
-import org.rhq.enterprise.gui.coregui.client.dashboard.AutoRefreshPortletUtil;
-import org.rhq.enterprise.gui.coregui.client.dashboard.CustomSettingsPortlet;
+import org.rhq.core.domain.common.EntityContext;
import org.rhq.enterprise.gui.coregui.client.dashboard.Portlet;
import org.rhq.enterprise.gui.coregui.client.dashboard.PortletViewFactory;
-import org.rhq.enterprise.gui.coregui.client.dashboard.PortletWindow;
-import org.rhq.enterprise.gui.coregui.client.util.MeasurementUtility;
-import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableDynamicForm;
-import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableHLayout;
-import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableLabel;
-import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableVLayout;
-import org.rhq.enterprise.gui.coregui.client.util.selenium.SeleniumUtility;
/**
- * @author Simeon Pinder
- * @author Greg Hinkle
+ * @author Jay Shaughnessy
*/
-public class RecentAlertsPortlet extends AlertHistoryView implements
CustomSettingsPortlet, AutoRefreshPortlet {
+public class RecentAlertsPortlet extends AbstractRecentAlertsPortlet {
// A non-displayed, persisted identifier for the portlet
public static final String KEY = "RecentAlerts";
// A default displayed, persisted name for the portlet
public static final String NAME = MSG.view_portlet_defaultName_recentAlerts();
- //widget keys also used in form population
- public static final String ALERT_RANGE_DISPLAY_AMOUNT_VALUE =
"alert-range-display-amount-value";
- public static final String ALERT_RANGE_PRIORITY_VALUE =
"alert-range-priority-value";
- public static final String ALERT_RANGE_TIME_VALUE =
"alert-range-time-value";
- public static final String ALERT_RANGE_RESOURCES_VALUE =
"alert-range-resource-value";
- public static final String ALERT_RANGE_RESOURCE_IDS =
"alert-range-resource-ids";
- //configuration default information
- private static final String defaultAlertCountValue = "5";
- private static final String PRIORITY_ALL = MSG.common_label_all();
- private static final String PRIORITY_HIGH = AlertPriority.HIGH.getDisplayName();
- private static final String PRIORITY_MEDIUM = AlertPriority.MEDIUM.getDisplayName();
- private static final String PRIORITY_LOW = AlertPriority.LOW.getDisplayName();
- private static final String defaultPriorityValue = PRIORITY_ALL;
- private static final String TIME_30_MINS = "30 " +
MSG.common_label_minutes();
- private static final String TIME_HOUR = MSG.common_label_hour();
- private static final String TIME_12_HRS = "12 " +
MSG.common_label_hours();
- private static final String TIME_DAY = MSG.common_label_day();
- private static final String TIME_WEEK = MSG.common_label_week();
- private static final String TIME_MONTH = MSG.common_label_month();
- private static final String defaultTimeValue = TIME_DAY;
- public static final String RESOURCES_ALL = MSG.common_label_all_resources();
- public static final String RESOURCES_SELECTED =
MSG.common_label_selected_resources();
- public static final String defaultResourceValue = RESOURCES_ALL;
- private static final String unlimited = MSG.common_label_unlimited();
- //alert resource labels
- public static final String ALERT_LABEL_SELECTED_RESOURCES =
MSG.common_title_selected_resources();
- public static final String ALERT_LABEL_AVAILABLE_RESOURCES =
MSG.common_title_available_resources();
- public static final String ALERT_LABEL_RESOURCE_INVENTORY =
MSG.common_title_resource_inventory();
- public static final int ALERT_RESOURCE_SELECTION_WIDTH = 800;
- public static final String ID = "id";
-
- // set on initial configuration, the window for this portlet view.
- private PortletWindow portletWindow;
-
- //shared private UI elements
- private AlertResourceSelectorRegion resourceSelector;
-
- private AlertPortletDataSource dataSource;
- //instance ui widgets
- private Canvas containerCanvas;
-
- private Timer refreshTimer;
-
public RecentAlertsPortlet(String locatorId) {
- super(locatorId);
-
- //override the shared datasource
- this.dataSource = new AlertPortletDataSource();
- setDataSource(this.dataSource);
-
- setShowHeader(false);
- setShowFooter(true);
- setShowFooterRefresh(false); //disable footer refresh
- setShowFilterForm(false); //disable filter form for portlet
-
- setOverflow(Overflow.VISIBLE);
- }
-
- public void configure(PortletWindow portletWindow, DashboardPortlet storedPortlet) {
-
- if (null == this.portletWindow && null != portletWindow) {
- this.portletWindow = portletWindow;
- }
-
- if ((null == storedPortlet) || (null == storedPortlet.getConfiguration())) {
- return;
- }
-
- //Operation range property - retrieve existing value
- PropertySimple property =
storedPortlet.getConfiguration().getSimple(ALERT_RANGE_DISPLAY_AMOUNT_VALUE);
- if ((property != null) && (property.getStringValue() != null)) {
- //retrieve and translate to int
- String retrieved = property.getStringValue();
- int translatedAlertRangeSelection =
translatedAlertRangeSelection(retrieved);
- getDataSource().setAlertRangeCompleted(translatedAlertRangeSelection);
- } else {//create setting
- storedPortlet.getConfiguration().put(
- new PropertySimple(ALERT_RANGE_DISPLAY_AMOUNT_VALUE,
defaultAlertCountValue));
-
getDataSource().setAlertRangeCompleted(Integer.parseInt(defaultAlertCountValue));
- }
- //Operation priority property setting
- property =
storedPortlet.getConfiguration().getSimple(ALERT_RANGE_PRIORITY_VALUE);
- if ((property != null) && (property.getStringValue() != null)) {
- //retrieve and translate to int
- String retrieved = property.getStringValue();
- int translatedPriorityIndex = translatedPriorityToValidIndex(retrieved);
- getDataSource().setAlertPriorityIndex(translatedPriorityIndex);
- } else {//create setting
- storedPortlet.getConfiguration().put(new
PropertySimple(ALERT_RANGE_PRIORITY_VALUE, defaultPriorityValue));
-
getDataSource().setAlertPriorityIndex(translatedPriorityToValidIndex(PRIORITY_ALL));
- }
-
- //Range to time that alerts will be shown for
- property = storedPortlet.getConfiguration().getSimple(ALERT_RANGE_TIME_VALUE);
- if ((property != null) && (property.getStringValue() != null)) {
- //retrieve and translate to int
- String retrieved = property.getStringValue();
- long translatedRange = translateTimeToValidRange(retrieved);
- getDataSource().setAlertTimeRange(translatedRange);
- } else {//create setting
- storedPortlet.getConfiguration().put(new
PropertySimple(ALERT_RANGE_TIME_VALUE, defaultTimeValue));
-
getDataSource().setAlertTimeRange(translateTimeToValidRange(defaultTimeValue));
- }
-
- //Range of resources to be included in the query
- property =
storedPortlet.getConfiguration().getSimple(ALERT_RANGE_RESOURCES_VALUE);
- if ((property != null) && (property.getStringValue() != null)) {
- //retrieve and translate to int
- String retrieved = property.getStringValue();
- if (retrieved.trim().equalsIgnoreCase(RESOURCES_SELECTED)) {
- getDataSource().setAlertResourcesToUse(RESOURCES_SELECTED);
- } else {
- getDataSource().setAlertResourcesToUse(RESOURCES_ALL);
- }
- } else {//create setting
- storedPortlet.getConfiguration().put(new
PropertySimple(ALERT_RANGE_RESOURCES_VALUE, defaultResourceValue));
- getDataSource().setAlertResourcesToUse(RESOURCES_ALL);
- }
-
- //resource ids to be conditionally included in the query
- Integer[] filterResourceIds = null;
- filterResourceIds = getDataSource().extractFilterResourceIds(storedPortlet,
filterResourceIds);
- //no defaults
-
- if (filterResourceIds != null) {
- getDataSource().setAlertFilterResourceId(filterResourceIds);
- }
-
- //conditionally display the selected resources ui
- if (containerCanvas != null) {
- //empty out earlier canvas
- for (Canvas c : containerCanvas.getChildren()) {
- c.destroy();
- }
- if ((resourceSelector != null) &&
getDataSource().getAlertResourcesToUse().equals(RESOURCES_SELECTED)) {
- containerCanvas.addChild(resourceSelector.getCanvas());
- } else {
- containerCanvas.addChild(new Canvas());
- }
- }
- }
-
- private int translatedAlertRangeSelection(String retrieved) {
- int translated = -1;
- if ((retrieved != null) && (!retrieved.trim().isEmpty())) {
- if (retrieved.equalsIgnoreCase(unlimited)) {
- translated = -1;
- } else {
- translated = Integer.parseInt(retrieved);//default to all
- }
- } else {//default to defaultValue
- if (defaultAlertCountValue.equalsIgnoreCase(unlimited)) {
- translated = -1;
- } else {
- translated = Integer.parseInt(defaultAlertCountValue);
- }
- }
- return translated;
- }
-
- private int translatedPriorityToValidIndex(String retrieved) {
- int translatedPriority = 0;//default to all
- if ((retrieved != null) && (!retrieved.trim().isEmpty())) {
- if (retrieved.equalsIgnoreCase(PRIORITY_HIGH)) {
- translatedPriority = 3;
- } else if (retrieved.equalsIgnoreCase(PRIORITY_MEDIUM)) {
- translatedPriority = 2;
- } else if (retrieved.equalsIgnoreCase(PRIORITY_LOW)) {
- translatedPriority = 1;
- } else {
- translatedPriority = 0;//default to all
- }
- }
- return translatedPriority;
- }
-
- /**Translates the UI selection options into time values for alert query.
- *
- * @param retrieved
- * @return long value mapping to string passed in.
- */
- private long translateTimeToValidRange(String retrieved) {
- long translated = 0;//default to ALL
- if ((retrieved != null) && (!retrieved.trim().isEmpty())) {
- if (retrieved.equalsIgnoreCase(TIME_30_MINS)) {
- translated = MeasurementUtility.MINUTES * 30;
- } else if (retrieved.equalsIgnoreCase(TIME_HOUR)) {
- translated = MeasurementUtility.HOURS;
- } else if (retrieved.equalsIgnoreCase(TIME_12_HRS)) {
- translated = MeasurementUtility.HOURS * 12;
- } else if (retrieved.equalsIgnoreCase(TIME_DAY)) {
- translated = MeasurementUtility.DAYS;
- } else if (retrieved.equalsIgnoreCase(TIME_WEEK)) {
- translated = MeasurementUtility.WEEKS;
- } else if (retrieved.equalsIgnoreCase(TIME_MONTH)) {
- translated = MeasurementUtility.DAYS * 28;//replicated from old struts
def.
- } else {
- translated = MeasurementUtility.DAYS;//default to day otherwise.
- }
- }
- return translated;
- }
-
- public Canvas getHelpCanvas() {
- return new HTMLFlow(MSG.view_portlet_help_recentAlerts());
- }
-
- public DynamicForm getCustomSettingsForm() {
- //root dynamic form instance
- final LocatableDynamicForm form = new
LocatableDynamicForm(extendLocatorId("custom-settings"));
- form.setWidth(RecentAlertsPortlet.ALERT_RESOURCE_SELECTION_WIDTH + 40);//largest
widget display + 40 for buttons
- form.setHeight(400);
- form.setMargin(5);
-
- final DashboardPortlet storedPortlet = portletWindow.getStoredPortlet();
-
- //vertical container
- VLayout column = new VLayout();
-
- //label
- LocatableLabel alertRangeLabel = new
LocatableLabel(extendLocatorId("DynamicForm_Label_Alert_Range"),
"<b>"
- + MSG.common_title_alert_range() + "</b>");
-
- //horizontal layout
- LocatableHLayout row = new
LocatableHLayout(extendLocatorId("alert-range-settings-row-1"));
- row.setMembersMargin(10);
-
- //-------------combobox for number of completed scheduled ops to display on the
dashboard
- final SelectItem alertRangeLastComboBox = new
SelectItem(ALERT_RANGE_DISPLAY_AMOUNT_VALUE);
- alertRangeLastComboBox.setTitle(MSG.view_measureRange_last());
- alertRangeLastComboBox.setType("selection");
- alertRangeLastComboBox.setWrapTitle(false);
- //define acceptable values for display amount
- String[] acceptableDisplayValues = { "5", "10",
MSG.common_label_unlimited() };
- alertRangeLastComboBox.setValueMap(acceptableDisplayValues);
- //set width of dropdown display region
- alertRangeLastComboBox.setWidth(100);
- alertRangeLastComboBox.addChangeHandler(new ChangeHandler() {
- public void onChange(ChangeEvent event) {
- String selectedItem = "" + event.getValue();
- //stuff into the master form for retrieval
- form.setValue(ALERT_RANGE_DISPLAY_AMOUNT_VALUE, selectedItem);
- }
- });
-
- //default selected value to 'unlimited'(live lists) and check both
combobox settings here.
- String selectedValue = defaultAlertCountValue;
- if (storedPortlet != null) {
- //if property exists retrieve it
- if
(storedPortlet.getConfiguration().getSimple(ALERT_RANGE_DISPLAY_AMOUNT_VALUE) != null) {
- selectedValue =
storedPortlet.getConfiguration().getSimple(ALERT_RANGE_DISPLAY_AMOUNT_VALUE)
- .getStringValue();
- } else {//insert default value
- storedPortlet.getConfiguration().put(
- new PropertySimple(ALERT_RANGE_DISPLAY_AMOUNT_VALUE,
defaultAlertCountValue));
- }
- }
- //prepopulate the combobox with the previously stored selection
- alertRangeLastComboBox.setDefaultValue(selectedValue);
-
- //-------------combobox for number of completed scheduled ops to display on the
dashboard
- final SelectItem alertRangePriorityComboBox = new
SelectItem(ALERT_RANGE_PRIORITY_VALUE);
- alertRangePriorityComboBox.setTitle("");
- alertRangePriorityComboBox.setHint("<nobr> <b> " +
MSG.view_portlet_recentAlerts_config_priority_label()
- + "</b></nobr>");
- alertRangePriorityComboBox.setType("selection");
- //define acceptable values for display amount
- String[] acceptablePriorityDisplayValues = { PRIORITY_ALL, PRIORITY_HIGH,
PRIORITY_MEDIUM, PRIORITY_LOW };
- alertRangePriorityComboBox.setValueMap(acceptablePriorityDisplayValues);
- //set width of dropdown display region
- alertRangePriorityComboBox.setWidth(100);
- alertRangePriorityComboBox.addChangeHandler(new ChangeHandler() {
- public void onChange(ChangeEvent event) {
- String selectedItem = "" + event.getValue();
- //stuff into the master form for retrieval
- form.setValue(ALERT_RANGE_PRIORITY_VALUE, selectedItem);
- }
- });
-
- //default selected value to 'unlimited'(live lists) and check both
combobox settings here.
- selectedValue = defaultPriorityValue;
- if (storedPortlet != null) {
- //if property exists retrieve it
- if (storedPortlet.getConfiguration().getSimple(ALERT_RANGE_PRIORITY_VALUE) !=
null) {
- selectedValue =
storedPortlet.getConfiguration().getSimple(ALERT_RANGE_PRIORITY_VALUE).getStringValue();
- } else {//insert default value
- storedPortlet.getConfiguration().put(
- new PropertySimple(ALERT_RANGE_PRIORITY_VALUE,
defaultPriorityValue));
- }
- }
- //prepopulate the combobox with the previously stored selection
- alertRangePriorityComboBox.setDefaultValue(selectedValue);
- row.addMember(alertRangeLabel);
- DynamicForm wrappedRange = new DynamicForm();
- wrappedRange.setFields(alertRangeLastComboBox);
- row.addMember(wrappedRange);
-
- DynamicForm wrappedPriority = new DynamicForm();
- wrappedPriority.setFields(alertRangePriorityComboBox);
- row.addMember(wrappedPriority);
-
- //horizontal layout
- LocatableHLayout row2 = new
LocatableHLayout(extendLocatorId("alert-range-settings-row-2"));
-
- LocatableLabel alertRangeSpanLabel = new
LocatableLabel(extendLocatorId("range-span-label"), "<b>"
- + MSG.view_portlet_recentAlerts_config_when() + "<b>");
- //------------- Build second combobox for timeframe for problem resources
search.
- final SelectItem alertRangeTimeComboBox = new
SelectItem(ALERT_RANGE_TIME_VALUE);
- alertRangeTimeComboBox.setTitle("");
- alertRangeTimeComboBox.setHint("");
- alertRangeTimeComboBox.setType("selection");
- String[] acceptableTimeDisplayValues = { TIME_30_MINS, TIME_HOUR, TIME_12_HRS,
TIME_DAY, TIME_WEEK, TIME_MONTH };
- alertRangeTimeComboBox.setValueMap(acceptableTimeDisplayValues);
- alertRangeTimeComboBox.setWidth(100);
- alertRangeTimeComboBox.addChangeHandler(new ChangeHandler() {
- public void onChange(ChangeEvent event) {
- String selectedItem = "" + event.getValue();
- //stuff into the master form for retrieval
- form.setValue(ALERT_RANGE_TIME_VALUE, selectedItem);
- }
- });
-
- //set to default
- selectedValue = defaultTimeValue;
- if (storedPortlet != null) {
- //if property exists retrieve it
- if (storedPortlet.getConfiguration().getSimple(ALERT_RANGE_TIME_VALUE) !=
null) {
- selectedValue =
storedPortlet.getConfiguration().getSimple(ALERT_RANGE_TIME_VALUE).getStringValue();
- } else {//insert default value
- storedPortlet.getConfiguration().put(new
PropertySimple(ALERT_RANGE_TIME_VALUE, defaultTimeValue));
- }
- }
- //prepopulate the combobox with the previously stored selection
- alertRangeTimeComboBox.setDefaultValue(selectedValue);
- DynamicForm timeSelectionWrapper = new DynamicForm();
- timeSelectionWrapper.setFields(alertRangeTimeComboBox);
-
- // build resource selection drop down
- //------------- Build second combobox for timeframe for problem resources
search.
- final SelectItem alertResourcesComboBox = new
SelectItem(ALERT_RANGE_RESOURCES_VALUE);
- alertResourcesComboBox.setTitle(MSG.common_val_for());
- alertResourcesComboBox.setHint("");
- alertResourcesComboBox.setType("selection");
- String[] acceptableResourceDisplayValues = { RESOURCES_ALL, RESOURCES_SELECTED
};
- alertResourcesComboBox.setValueMap(acceptableResourceDisplayValues);
- alertResourcesComboBox.setWidth(150);
- alertResourcesComboBox.addChangeHandler(new ChangeHandler() {
- public void onChange(ChangeEvent event) {
- String selectedItem = "" + event.getValue();
- //stuff into the master form for retrieval
- form.setValue(ALERT_RANGE_RESOURCES_VALUE, selectedItem);
- //empty out earlier canvas
- for (Canvas c : containerCanvas.getChildren()) {
- c.destroy();
- }
- if (selectedItem.equals(RESOURCES_SELECTED)) {
- containerCanvas.addChild(resourceSelector.getCanvas());
- } else {
- containerCanvas.addChild(new Canvas());
- }
- }
- });
-
- //set to default
- selectedValue = defaultResourceValue;
- if (storedPortlet != null) {
- //if property exists retrieve it
- if (storedPortlet.getConfiguration().getSimple(ALERT_RANGE_RESOURCES_VALUE)
!= null) {
- selectedValue =
storedPortlet.getConfiguration().getSimple(ALERT_RANGE_RESOURCES_VALUE)
- .getStringValue();
- } else {//insert default value
- storedPortlet.getConfiguration().put(
- new PropertySimple(ALERT_RANGE_RESOURCES_VALUE,
defaultResourceValue));
- }
- }
- //prepopulate the combobox with the previously stored selection
- alertResourcesComboBox.setDefaultValue(selectedValue);
- DynamicForm resourceSelectionWrapper = new DynamicForm();
- resourceSelectionWrapper.setFields(alertResourcesComboBox);
-
- alertRangeSpanLabel.setWrap(false);
- alertRangeSpanLabel.setWidth(150);
- row2.addMember(alertRangeSpanLabel);
- row2.addMember(timeSelectionWrapper);
- row2.addMember(resourceSelectionWrapper);
-
- //if portlet config setting exist, then retrieve
- Integer[] alertFilterResourceIds = null;
- alertFilterResourceIds = getDataSource().extractFilterResourceIds(storedPortlet,
alertFilterResourceIds);
-
- LocatableHLayout resourceSelectionRegion = new
LocatableHLayout(extendLocatorId("selection-canvas"));
- resourceSelector = new
AlertResourceSelectorRegion(extendLocatorId("ResourcesWithAlerts"),
- alertFilterResourceIds);
- resourceSelectionRegion.setWidth100();
-
- if (alertFilterResourceIds != null) {
- getDataSource().setAlertFilterResourceId(alertFilterResourceIds);
- resourceSelector.setCurrentlyAssignedIds(alertFilterResourceIds);
- }
-
- //instantiate canvas area to display empty or rich resource selection based on
dropdown selection
- containerCanvas = new Canvas();
- String previousAlertFilterChoice =
storedPortlet.getConfiguration().getSimple(ALERT_RANGE_RESOURCES_VALUE)
- .getStringValue();
-
- //reload the ResourceSelectionRegion if user has chosen to focus on specific
resources with alerts
- if (previousAlertFilterChoice.equals(RESOURCES_SELECTED)) {
- containerCanvas.addChild(resourceSelector.getCanvas());
- } else {// define empty canvas
- containerCanvas.addChild(new Canvas());
- }
-
- //add contain resource selection region.
- resourceSelectionRegion.addMember(containerCanvas);
-
- //finish construction of the layout
- column.addMember(row);
- column.addMember(row2);
- SpacerItem verticalSpace = new SpacerItem();
- verticalSpace.setHeight(20);
- DynamicForm spacerWrapper = new DynamicForm();
- spacerWrapper.setItems(verticalSpace);
- column.addMember(spacerWrapper);
- column.addMember(resourceSelectionRegion);
- form.addChild(column);
-
- //submit handler
- form.addSubmitValuesHandler(new SubmitValuesHandler() {
- @Override
- public void onSubmitValues(SubmitValuesEvent event) {
- //no need to insert validation here as user not allowed to enter values
- parseFormAndPopulateConfiguration(form, storedPortlet,
ALERT_RANGE_DISPLAY_AMOUNT_VALUE,
- ALERT_RANGE_PRIORITY_VALUE, ALERT_RANGE_RESOURCES_VALUE,
ALERT_RANGE_TIME_VALUE);
-
- //retrieve alert-resource-selection property
- PropertySimple prop =
storedPortlet.getConfiguration().getSimple(ALERT_RANGE_RESOURCES_VALUE);
-
- //check to see if "Selected Resources" or "All
Resources"
- if (prop != null &&
RESOURCES_SELECTED.equals(prop.getStringValue())) {
- //retrieve currentlyAssignedIds
- Integer[] valuesToPersist = resourceSelector.getListGridValues();
- resourceSelector.setCurrentlyAssignedIds(valuesToPersist);
-
- //build property list of ids to persist
- PropertyList list = new PropertyList(ALERT_RANGE_RESOURCE_IDS);
- for (int rid : resourceSelector.getCurrentlyAssignedIds()) {
- list.add(new PropertySimple(ALERT_RANGE_RESOURCE_IDS, rid));
- }
- storedPortlet.getConfiguration().put(new
PropertyList(ALERT_RANGE_RESOURCE_IDS, list));
-
getDataSource().setAlertFilterResourceId(resourceSelector.getCurrentlyAssignedIds());
- }
-
- configure(portletWindow, storedPortlet);
-
- refresh();//reload form with new data selections
- markForRedraw();
- }
- });
-
- return form;
- }
-
- /**Iterates over DynamicForm instance to check for properties passed in and if they
have been set
- * to put that property into the DashboardPortlet configuration.
- *
- * @param form Dynamic form storing user selections
- * @param portlet Container for configuration changes
- * @param properties Variable list of keys used to verify or populate properties.
- */
- private void parseFormAndPopulateConfiguration(final DynamicForm form,
DashboardPortlet storedPortlet,
- String... properties) {
- if ((form != null) && (storedPortlet != null)) {
- for (String property : properties) {
- if (form.getValue(property) != null) {//if new value supplied
- storedPortlet.getConfiguration().put(new PropertySimple(property,
form.getValue(property)));
- }
- }
- }
- }
-
- public AlertPortletDataSource getDataSource() {
- return dataSource;
+ super(locatorId, EntityContext.forSubsystemView());
}
public static final class Factory implements PortletViewFactory {
@@ -565,102 +45,4 @@ public class RecentAlertsPortlet extends AlertHistoryView implements
CustomSetti
}
}
- public void startRefreshCycle() {
- refreshTimer = AutoRefreshPortletUtil.startRefreshCycle(this, this,
refreshTimer);
- }
-
- @Override
- protected void onDestroy() {
- AutoRefreshPortletUtil.onDestroy(this, refreshTimer);
-
- super.onDestroy();
- }
-
- public boolean isRefreshing() {
- return false;
- }
-
- @Override
- protected void setupTableInteractions(boolean hasWriteAccess) {
- // The portlet is a "subsystem" view. Meaning the alerts displayed can
be from any accessible group for
- // the user. This means the user can have varying permissions on the underlying
groups and/or resources,
- // which makes button enablement tricky. So, for the portlet don't even show
the buttons unless the user
- // is inventory manager. Other users will just have to navigate to the alert in
question in order to
- // manipulate it.
-
- //determine if the user is inventory manager and if so render the buttons
- Set<Permission> permissions = this.portletWindow.getGlobalPermissions();
- if ((null != permissions) &&
permissions.contains(Permission.MANAGE_INVENTORY)) {
- super.setupTableInteractions(true);
- }
- }
-
- protected CellFormatter getDetailsLinkColumnCellFormatter() {
- return new CellFormatter() {
- public String format(Object value, ListGridRecord record, int i, int i1) {
- Integer recordId = getId(record);
- Integer resourceId = record.getAttributeAsInt("resourceId");
- String detailsUrl = LinkManager.getSubsystemAlertHistoryLink(resourceId,
recordId);
- return SeleniumUtility.getLocatableHref(detailsUrl, value.toString(),
null);
- }
- };
- }
-
- @Override
- protected void configureTable() {
- // TODO Auto-generated method stub
- super.configureTable();
-
- setListGridDoubleClickHandler(new DoubleClickHandler() {
- @Override
- public void onDoubleClick(DoubleClickEvent event) {
- ListGrid listGrid = (ListGrid) event.getSource();
- ListGridRecord[] selectedRows = listGrid.getSelection();
- if (selectedRows != null && selectedRows.length == 1) {
- Integer recordId = getId(selectedRows[0]);
- Integer resourceId =
selectedRows[0].getAttributeAsInt("resourceId");
- CoreGUI.goToView(LinkManager.getSubsystemAlertHistoryLink(resourceId,
recordId));
- }
- }
- });
- }
-
-}
-
-/** Bundles a ResourceSelector instance with labelling in Canvas for display.
- * Also modifies the AssignedGrid to listen for AvailbleGrid completion and act
accordingly.
- */
-class AlertResourceSelectorRegion extends LocatableVLayout {
- public AlertResourceSelectorRegion(String locatorId, Integer[] assigned) {
- super(locatorId);
- this.currentlyAssignedIds = assigned;
- }
-
- private PortletAlertSelector selector = null;
-
- private Integer[] currentlyAssignedIds;
-
- public Integer[] getCurrentlyAssignedIds() {
- return currentlyAssignedIds;
- }
-
- public Integer[] getListGridValues() {
- Integer[] listGridValues = new Integer[0];
- if (null != selector) {
- listGridValues = selector.getAssignedListGridValues();
- }
- return listGridValues;
- }
-
- public Canvas getCanvas() {
- if (selector == null) {
- selector = new
PortletAlertSelector(extendLocatorId("AlertSelector"),
this.currentlyAssignedIds,
- ResourceType.ANY_PLATFORM_TYPE, false);
- }
- return selector;
- }
-
- public void setCurrentlyAssignedIds(Integer[] currentlyAssignedIds) {
- this.currentlyAssignedIds = currentlyAssignedIds;
- }
}
\ No newline at end of file
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/resource/ResourceAlertsPortlet.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/resource/ResourceAlertsPortlet.java
index ff3a9939..c43068f 100644
---
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/resource/ResourceAlertsPortlet.java
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/resource/ResourceAlertsPortlet.java
@@ -19,26 +19,17 @@
package org.rhq.enterprise.gui.coregui.client.dashboard.portlets.resource;
import com.google.gwt.user.client.History;
-import com.smartgwt.client.widgets.Canvas;
-import org.rhq.core.domain.configuration.PropertySimple;
-import org.rhq.core.domain.dashboard.DashboardPortlet;
-import org.rhq.core.domain.resource.ResourceType;
-import org.rhq.enterprise.gui.coregui.client.CoreGUI;
-import org.rhq.enterprise.gui.coregui.client.Messages;
-import org.rhq.enterprise.gui.coregui.client.alert.AlertPortletConfigurationDataSource;
+import org.rhq.core.domain.common.EntityContext;
import org.rhq.enterprise.gui.coregui.client.dashboard.Portlet;
import org.rhq.enterprise.gui.coregui.client.dashboard.PortletViewFactory;
-import org.rhq.enterprise.gui.coregui.client.dashboard.PortletWindow;
-import
org.rhq.enterprise.gui.coregui.client.dashboard.portlets.PortletConfigurationEditorComponent;
-import
org.rhq.enterprise.gui.coregui.client.dashboard.portlets.groups.GroupAlertsPortlet;
-import
org.rhq.enterprise.gui.coregui.client.dashboard.portlets.recent.alerts.PortletAlertSelector;
-import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableVLayout;
+import
org.rhq.enterprise.gui.coregui.client.dashboard.portlets.recent.alerts.AbstractRecentAlertsPortlet;
/**
+ * @author Jay Shaughnessy
* @author Simeon Pinder
*/
-public class ResourceAlertsPortlet extends GroupAlertsPortlet {
+public class ResourceAlertsPortlet extends AbstractRecentAlertsPortlet {
// A non-displayed, persisted identifier for the portlet
public static final String KEY = "ResourceAlerts";
@@ -47,138 +38,34 @@ public class ResourceAlertsPortlet extends GroupAlertsPortlet {
private int resourceId;
- public ResourceAlertsPortlet(String locatorId) {
- super(locatorId);
+ public ResourceAlertsPortlet(String locatorId, int resourceId) {
- //override the shared datasource
- //figure out which page we're loading
- String currentPage = History.getToken();
- String[] elements = currentPage.split("/");
- this.resourceId = Integer.valueOf(elements[1]);
- }
-
- /**Defines layout for the portlet page.
- */
- protected void initializeUi() {
- //initalize the datasource
- Integer[] resourceIds = new Integer[1];
- resourceIds[0] = this.resourceId;
- this.dataSource = new AlertPortletConfigurationDataSource(storedPortlet,
portletConfig, null, resourceIds);
- setDataSource(this.dataSource);
-
- setShowHeader(false);
- setShowFooter(true);
- setShowFooterRefresh(false); //disable footer refresh
- setShowFilterForm(false); //disable filter form for portlet
-
- getListGrid().setEmptyMessage(MSG.view_portlet_results_empty());
- }
+ super(locatorId, EntityContext.forResource(resourceId));
- @Override
- protected void onInit() {
- super.onInit();
- initializeUi();
+ this.resourceId = resourceId;
}
- /** Responsible for initialization and lazy configuration of the portlet values
- */
- public void configure(PortletWindow portletWindow, DashboardPortlet storedPortlet) {
- //populate portlet configuration details
- if (null == this.portletWindow && null != portletWindow) {
- this.portletWindow = portletWindow;
- }
-
- if ((null == storedPortlet) || (null == storedPortlet.getConfiguration())) {
- return;
- }
- this.storedPortlet = storedPortlet;
- portletConfig = storedPortlet.getConfiguration();
-
- if (!portletConfigInitialized) {
- Integer[] resourceIds = new Integer[1];
- resourceIds[0] = this.resourceId;
- this.dataSource = new AlertPortletConfigurationDataSource(storedPortlet,
portletConfig, null, resourceIds);
- setDataSource(this.dataSource);
- portletConfigInitialized = true;
- }
-
- //lazy init any elements not yet configured.
- for (String key :
PortletConfigurationEditorComponent.CONFIG_PROPERTY_INITIALIZATION.keySet()) {
- if (portletConfig.getSimple(key) == null) {
- portletConfig.put(new PropertySimple(key,
-
PortletConfigurationEditorComponent.CONFIG_PROPERTY_INITIALIZATION.get(key)));
- }
- }
-
- //resource ids to be conditionally included in the query
- Integer[] filterResourceIds = null;
- filterResourceIds = getDataSource().extractFilterResourceIds(storedPortlet,
filterResourceIds);
- //no defaults
-
- if (filterResourceIds != null) {
- getDataSource().setAlertFilterResourceId(filterResourceIds);
- }
-
- // //conditionally display the selected resources ui
- // if (containerCanvas != null) {
- // //empty out earlier canvas
- // for (Canvas c : containerCanvas.getChildren()) {
- // c.destroy();
- // }
- // if ((resourceSelector != null) &&
getDataSource().getAlertResourcesToUse().equals(RESOURCES_SELECTED)) {
- // containerCanvas.addChild(resourceSelector.getCanvas());
- // } else {
- // containerCanvas.addChild(new Canvas());
- // }
- // }
-
+ public int getResourceId() {
+ return resourceId;
}
public static final class Factory implements PortletViewFactory {
public static PortletViewFactory INSTANCE = new Factory();
+ /* (non-Javadoc)
+ * TODO: This factory ASSUMES the user is currently navigated to a resource
detail view, and generates a portlet
+ * for that resource. It will fail in other scenarios. This mechanism
should be improved such that the
+ * factory method can take an EntityContext explicitly indicating, in this
case, the resource.
+ * @see
org.rhq.enterprise.gui.coregui.client.dashboard.PortletViewFactory#getInstance(java.lang.String)
+ */
public final Portlet getInstance(String locatorId) {
- return new ResourceAlertsPortlet(locatorId);
- }
- }
-}
-
-/** Bundles a ResourceSelector instance with labeling in Canvas for display.
- * Also modifies the AssignedGrid to listen for AvailbleGrid completion and act
accordingly.
- */
-class AlertResourceSelectorRegion extends LocatableVLayout {
- public AlertResourceSelectorRegion(String locatorId, Integer[] assigned) {
- super(locatorId);
- this.currentlyAssignedIds = assigned;
- }
-
- private static final Messages MSG = CoreGUI.getMessages();
- private PortletAlertSelector selector = null;
+ String currentPage = History.getToken();
+ String[] elements = currentPage.split("/");
+ int resourceId = Integer.valueOf(elements[1]);
- private Integer[] currentlyAssignedIds;
-
- public Integer[] getCurrentlyAssignedIds() {
- return currentlyAssignedIds;
- }
-
- public Integer[] getListGridValues() {
- Integer[] listGridValues = new Integer[0];
- if (null != selector) {
- listGridValues = selector.getAssignedListGridValues();
+ return new ResourceAlertsPortlet(locatorId, resourceId);
}
- return listGridValues;
}
- public Canvas getCanvas() {
- if (selector == null) {
- selector = new
PortletAlertSelector(extendLocatorId("AlertSelector"),
this.currentlyAssignedIds,
- ResourceType.ANY_PLATFORM_TYPE, false);
- }
- return selector;
- }
-
- public void setCurrentlyAssignedIds(Integer[] currentlyAssignedIds) {
- this.currentlyAssignedIds = currentlyAssignedIds;
- }
}
\ No newline at end of file