modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/Footer.java | 38 +++------- modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/gwt/AlertGWTService.java | 9 ++ modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/server/gwt/AlertGWTServiceImpl.java | 8 ++ modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertManagerBean.java | 14 +++ modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertManagerLocal.java | 2 5 files changed, 48 insertions(+), 23 deletions(-)
New commits: commit ec43cd6bf1be52a0a101f85faf654610b27c6df6 Author: Joseph Marques joseph@redhat.com Date: Wed Nov 24 18:17:10 2010 -0500
BZ-657107: support querying alert count by criteria (and show in footer)
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/Footer.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/Footer.java index e6da3f3..0d94cc3 100644 --- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/Footer.java +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/Footer.java @@ -27,9 +27,7 @@ import com.smartgwt.client.widgets.events.ClickEvent; import com.smartgwt.client.widgets.events.ClickHandler; import com.smartgwt.client.widgets.toolbar.ToolStripSeparator;
-import org.rhq.core.domain.alert.Alert; import org.rhq.core.domain.criteria.AlertCriteria; -import org.rhq.core.domain.util.PageList; import org.rhq.enterprise.gui.coregui.client.alert.AlertHistoryView; import org.rhq.enterprise.gui.coregui.client.footer.FavoritesButton; import org.rhq.enterprise.gui.coregui.client.gwt.GWTServiceLookup; @@ -132,31 +130,25 @@ public class Footer extends LocatableToolStrip {
public void refreshLoggedIn() { AlertCriteria alertCriteria = new AlertCriteria(); - - // only get one record from the first page, we only really care about the count - alertCriteria.setPaging(0, 1); - - // last eight hours - alertCriteria.addFilterStartTime(System.currentTimeMillis() - (1000L * 60 * 60 * 8)); + alertCriteria.addFilterStartTime(System.currentTimeMillis() - (1000L * 60 * 60 * 8)); // last 8 hrs
//check for still logged in before submitting server side request if (UserSessionManager.isLoggedIn()) { - GWTServiceLookup.getAlertService().findAlertsByCriteria(alertCriteria, - new AsyncCallback<PageList<Alert>>() { - public void onFailure(Throwable caught) { - CoreGUI.getErrorHandler().handleError(MSG.view_core_error_1(), caught); - } - - public void onSuccess(PageList<Alert> result) { - if (result.isEmpty()) { - setContents(MSG.view_core_recentAlerts("0")); - setIcon("subsystems/alert/Alert_LOW_16.png"); - } else { - setContents(MSG.view_core_recentAlerts(Integer.toString(result.getTotalSize()))); - setIcon("subsystems/alert/Alert_HIGH_16.png"); - } + GWTServiceLookup.getAlertService().findAlertCountByCriteria(alertCriteria, new AsyncCallback<Long>() { + public void onFailure(Throwable caught) { + CoreGUI.getErrorHandler().handleError(MSG.view_core_error_1(), caught); + } + + public void onSuccess(Long result) { + if (result == 0L) { + setContents(MSG.view_core_recentAlerts("0")); + setIcon("subsystems/alert/Alert_LOW_16.png"); + } else { + setContents(MSG.view_core_recentAlerts(result.toString())); + setIcon("subsystems/alert/Alert_HIGH_16.png"); } - }); + } + }); } else {//dump request Log.debug("user not logged in. Not fetching any alerts now."); } diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/gwt/AlertGWTService.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/gwt/AlertGWTService.java index a8fd51a..af44658 100644 --- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/gwt/AlertGWTService.java +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/gwt/AlertGWTService.java @@ -40,6 +40,15 @@ public interface AlertGWTService extends RemoteService { PageList<Alert> findAlertsByCriteria(AlertCriteria criteria);
/** + * Find the count of alerts that match the specified criteria. + * + * @param criteria the criteria + * + * @return the count of alerts that match the specified criteria + */ + long findAlertCountByCriteria(AlertCriteria criteria); + + /** * Delete the alerts with the specified ids if the current user has permission to do so (i.e. either * the MANAGE_INVENTORY global permission, or the MANAGE_ALERTS permission for all corresponding resources). * If the user does not have permission for all of the specified alerts, then none of the alerts will be deleted diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/server/gwt/AlertGWTServiceImpl.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/server/gwt/AlertGWTServiceImpl.java index 9f66d19..f7a7a69 100644 --- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/server/gwt/AlertGWTServiceImpl.java +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/server/gwt/AlertGWTServiceImpl.java @@ -46,6 +46,14 @@ public class AlertGWTServiceImpl extends AbstractGWTServiceImpl implements Alert } }
+ public long findAlertCountByCriteria(AlertCriteria criteria) { + try { + return this.alertManager.findAlertCountByCriteria(getSessionSubject(), criteria); + } catch (Exception e) { + throw new RuntimeException(ThrowableUtil.getAllMessages(e)); + } + } + public int deleteAlerts(int[] alertIds) { try { return this.alertManager.deleteAlerts(getSessionSubject(), alertIds); diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertManagerBean.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertManagerBean.java index 4a27685..b38593b 100644 --- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertManagerBean.java +++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertManagerBean.java @@ -1054,4 +1054,18 @@ public class AlertManagerBean implements AlertManagerLocal, AlertManagerRemote {
return alerts; } + + public long findAlertCountByCriteria(Subject subject, AlertCriteria criteria) { + CriteriaQueryGenerator generator = new CriteriaQueryGenerator(subject, criteria); + + if (!authorizationManager.isInventoryManager(subject)) { + generator.setAuthorizationResourceFragment(CriteriaQueryGenerator.AuthorizationTokenType.RESOURCE, + "alertDefinition.resource", subject.getId()); + } + + Query countQuery = generator.getCountQuery(entityManager); + long count = (Long) countQuery.getSingleResult(); + + return count; + } } diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertManagerLocal.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertManagerLocal.java index 4c7e609..d0129b4 100644 --- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertManagerLocal.java +++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertManagerLocal.java @@ -85,6 +85,8 @@ public interface AlertManagerLocal {
String prettyPrintAlertURL(Alert alert);
+ long findAlertCountByCriteria(Subject subject, AlertCriteria criteria); + // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! // // The following are shared with the Remote Interface
rhq-commits@lists.fedorahosted.org