modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/ReportExporter.java | 64 ++++++----
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/report/alert/SubsystemRecentAlertsView.java | 17 --
2 files changed, 40 insertions(+), 41 deletions(-)
New commits:
commit 45d4be0c41368b3dd17956c8e86ddf0d3defc63e
Author: Mike Thompson <mithomps(a)redhat.com>
Date: Sun Apr 1 19:53:34 2012 -0700
[BZ 800453] Export Csv Reports. DRY up code.
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/ReportExporter.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/ReportExporter.java
index eb7297c..bfdda08 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/ReportExporter.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/ReportExporter.java
@@ -41,6 +41,7 @@ public class ReportExporter {
private static final String FORMAT = "csv"; //CSV is all we need right now
private String reportUrl;
+ private StringBuilder queryString;
private boolean showAllDetail;
@@ -132,13 +133,23 @@ public class ReportExporter {
this.operationRequestStatuses = operationRequestStatuses;
}
- public String determineUrl() {
- StringBuilder queryString = new StringBuilder();
+ private String buildUrl() {
+ buildQueryParameters();
+
+ // trim the last "&" off the url if exists
+ final String cleanQueryString = queryString.toString().endsWith("&") ? queryString.substring(0,queryString.toString().length() -1) : queryString.toString();
+ final String queryStringNotEndingWithQuestionMark = cleanQueryString.toString().endsWith("?") ? cleanQueryString.substring(0,cleanQueryString.toString().length() -1) : cleanQueryString.toString();
+ return URL.encode(BASE_URL + reportUrl + "." + FORMAT + "?"+ queryStringNotEndingWithQuestionMark);
+ }
+
+ private void buildQueryParameters() {
+ queryString = new StringBuilder();
if (showAllDetail) {
- queryString.append("showAllDetails=").append("true").append("&");
+ addQueryParameter("showAllDetails","true");
+
} else if (null != resourceTypeIds && !resourceTypeIds.isEmpty()) {
- queryString.append("resourceTypeId=").append(StringUtility.toString(resourceTypeIds)).append("&");
+ addQueryParameter("resourceTypeId", StringUtility.toString(resourceTypeIds));
}
if(!isEmpty(operationRequestStatuses)){
@@ -147,16 +158,16 @@ public class ReportExporter {
operationRequestStatusBuffer.append(operationRequestStatus);
operationRequestStatusBuffer.append(",");
}
-
- queryString.append("operationRequestStatus=").append(operationRequestStatusBuffer.toString()).append("&");
+ addQueryParameter("operationRequestStatus", operationRequestStatusBuffer.toString().substring(0,operationRequestStatusBuffer.toString().length() -1));
}
+
if(!isEmpty(alertPriorityFilters)){
StringBuilder alertsPriorityBuffer = new StringBuilder();
for (String alertPriority : alertPriorityFilters) {
alertsPriorityBuffer.append(alertPriority);
alertsPriorityBuffer.append(",");
}
- queryString.append("alertPriority=").append(alertsPriorityBuffer.toString()).append("&");
+ addQueryParameter("alertPriority", alertsPriorityBuffer.toString().substring(0,alertsPriorityBuffer.toString().length() -1));
}
// Drift Related
@@ -165,27 +176,27 @@ public class ReportExporter {
for (String category : driftCategories) {
driftCategoriesBuffer.append(category).append(",");
}
- queryString.append("categories=").append(driftCategoriesBuffer.toString()).append("&");
- }
- if (driftDefinition != null) {
- queryString.append("definition=").append(driftDefinition).append("&");
- }
- if (driftPath != null) {
- queryString.append("path=").append(driftDefinition).append("&");
- }
- if (driftSnapshot != null) {
- queryString.append("snapshot=").append(driftSnapshot).append("&");
+ addQueryParameter("categories", driftCategoriesBuffer.toString());
}
+ addQueryParameter("definition", driftDefinition);
+ addQueryParameter("path", driftPath);
+ addQueryParameter("snapshot", driftSnapshot);
+
// to/from Dates
- if(startDate != null){
- queryString.append("startTime=").append(startDate.getTime()).append("&");
+ addQueryParameter("startTime", startDate);
+ addQueryParameter("endTime", endDate);
+ }
+
+ private void addQueryParameter(String parameterName, String parameterValue){
+ if(parameterValue != null){
+ queryString.append(parameterName).append("=").append(parameterValue).append("&");
}
- if(endDate != null){
- queryString.append("endTime=").append(endDate.getTime()).append("&");
+ }
+ private void addQueryParameter(String parameterName, Date parameterValue){
+ if(parameterValue != null){
+ addQueryParameter(parameterName, String.valueOf(parameterValue.getTime()));
}
-
- return URL.encode(BASE_URL + reportUrl + "." + FORMAT + "?"+queryString);
}
private boolean isEmpty(String[] array) {
@@ -220,9 +231,12 @@ public class ReportExporter {
this.endDate = endDate;
}
+ /**
+ * Using the url built in buildUrl() open the RESTful CSV report in a new window.
+ */
public void export(){
- String reportUrl = determineUrl();
- Log.info("Opening Export CSV report on url: "+reportUrl);
+ String reportUrl = buildUrl();
+ Log.info("Opening Export CSV report on url: " + reportUrl);
Window.open(reportUrl, "download", null);
}
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/report/alert/SubsystemRecentAlertsView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/report/alert/SubsystemRecentAlertsView.java
index b969313..47d64ed 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/report/alert/SubsystemRecentAlertsView.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/report/alert/SubsystemRecentAlertsView.java
@@ -1,14 +1,10 @@
package org.rhq.enterprise.gui.coregui.client.report.alert;
import com.smartgwt.client.widgets.grid.ListGridRecord;
-import org.rhq.core.domain.alert.AlertPriority;
import org.rhq.enterprise.gui.coregui.client.alert.SubsystemResourceAlertView;
import org.rhq.enterprise.gui.coregui.client.components.ReportExporter;
import org.rhq.enterprise.gui.coregui.client.components.table.TableAction;
-import java.util.ArrayList;
-import java.util.List;
-
public class SubsystemRecentAlertsView extends SubsystemResourceAlertView {
public SubsystemRecentAlertsView(String locatorId, boolean hasWriteAccess) {
@@ -31,19 +27,8 @@ public class SubsystemRecentAlertsView extends SubsystemResourceAlertView {
@Override
public void executeAction(ListGridRecord[] selection, Object actionValue) {
- List<AlertPriority> alertPriorityList = new ArrayList<AlertPriority>(3);
- String[] priorities = priorityFilter.getValues();
- for (String priority : priorities) {
- if(priority.equals(AlertPriority.HIGH.getDisplayName())){
- alertPriorityList.add(AlertPriority.HIGH);
- } else if(priority.equals(AlertPriority.MEDIUM.getDisplayName())){
- alertPriorityList.add(AlertPriority.MEDIUM);
- } else if(priority.equals(AlertPriority.LOW.getDisplayName())){
- alertPriorityList.add(AlertPriority.LOW);
- }
- }
ReportExporter exporter = ReportExporter.createExporterForRecentAlerts(
- "recentAlerts", alertPriorityList.toArray(new String[alertPriorityList.size()]), fromDateFilter.getValueAsDate(), toDateFilter.getValueAsDate());
+ "recentAlerts", priorityFilter.getValues(), fromDateFilter.getValueAsDate(), toDateFilter.getValueAsDate());
exporter.export();
refreshTableInfo();
}