From: <rp...@hy...> - 2008-07-16 03:44:58
|
Author: rpack Date: 2008-07-15 20:44:56 -0700 (Tue, 15 Jul 2008) New Revision: 10204 URL: http://svn.hyperic.org/?view=rev&root=Hyperic+HQ&revision=10204 Modified: trunk/src/org/hyperic/hq/ui/service/RESTService.java Log: Refactored parameter names, Extracted propkeys into KeyContstants, added stub for alertsummary widget Modified: trunk/src/org/hyperic/hq/ui/service/RESTService.java =================================================================== --- trunk/src/org/hyperic/hq/ui/service/RESTService.java 2008-07-16 03:44:10 UTC (rev 10203) +++ trunk/src/org/hyperic/hq/ui/service/RESTService.java 2008-07-16 03:44:56 UTC (rev 10204) @@ -11,14 +11,13 @@ import org.apache.tapestry.IRequestCycle; import org.apache.tapestry.engine.ILink; import org.apache.tapestry.services.ServiceConstants; -import org.hyperic.hq.auth.shared.SessionNotFoundException; -import org.hyperic.hq.auth.shared.SessionTimeoutException; import org.hyperic.hq.authz.server.session.AuthzSubject; import org.hyperic.hq.authz.shared.PermissionException; import org.hyperic.hq.bizapp.server.session.DashboardPortletBossEJBImpl; import org.hyperic.hq.bizapp.shared.AuthzBoss; import org.hyperic.hq.bizapp.shared.DashboardPortletBossLocal; import org.hyperic.hq.ui.Constants; +import org.hyperic.hq.ui.KeyConstants; import org.hyperic.hq.ui.WebUser; import org.hyperic.hq.ui.server.session.DashboardConfig; import org.hyperic.hq.ui.server.session.DashboardManagerEJBImpl; @@ -42,6 +41,13 @@ public static final String SERVICE_NAME = "api"; + public String getName() { + return SERVICE_NAME; + } + + /** + * Generates the service urls + */ public ILink getLink(boolean post, Object parameter) { Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put(ServiceConstants.SERVICE, getName()); @@ -52,16 +58,16 @@ } /** - * Supports service version 1.0+ + * The Service method. Supports services of version 1.0+ */ public void service(IRequestCycle cycle) throws IOException { - Double serviceVersion = Double.parseDouble(cycle.getParameter(SERVICE_VERSION_PARAM)); - String widgetID = cycle.getParameter(PARAM_SERVICE_ID); + Double serviceVersion = Double.parseDouble(cycle.getParameter(PARAM_SERVICE_VERSION)); + String servicePointId = cycle.getParameter(PARAM_SERVICE_ID); if (SERVICE_VERSION_1_0 == serviceVersion) { - if (widgetID.equalsIgnoreCase(SERVICE_ID_CHART_WIDGET)) { + if (servicePointId.equalsIgnoreCase(SERVICE_ID_CHART_WIDGET)) { _response.getWriter().write(serviceChartWidget(cycle)); - } else if (widgetID.equalsIgnoreCase(SERVICE_ID_ALERT_SUM_WIDGET)) { + } else if (servicePointId.equalsIgnoreCase(SERVICE_ID_ALERT_SUM_WIDGET)) { _response.getWriter().write(serviceAlertSummaryWidget(cycle)); } } @@ -70,12 +76,36 @@ /** * Service for the AlertSummary Widget * - * @param cycle - * @return + * @param cycle the service parameters + * @return the service JSON response */ private String serviceAlertSummaryWidget(IRequestCycle cycle) { - return ""; + String configParam = cycle.getParameter(PARAM_CONFIG); + String pageNumberParam = cycle.getParameter(PARAM_PAGE_NUM); + String regexFilterParam = cycle.getParameter(PARAM_REGEX_FILTER); + String resourceIdParam = cycle.getParameter(PARAM_RESOURCE_ID); + String res = EMPTY_RESPONSE; // default to an empty response + + if (configParam != null) { + // config + if (resourceIdParam != null) { + // set the resource configuration property + } + } else if (resourceIdParam != null) { + // get alert data + + } else { + if (regexFilterParam != null) { + // set filter + } + if (pageNumberParam != null) { + // request next page + } + // get groups + } + + return res; } /** @@ -87,17 +117,19 @@ */ private String serviceChartWidget(IRequestCycle cycle) throws IOException { //Get the service parameters + String metricTemplIdParam = cycle.getParameter(PARAM_METRIC_TEMPLATE_ID); + String timeRangeParam = cycle.getParameter(PARAM_TIME_RANGE); + String configParam = cycle.getParameter(PARAM_CONFIG); + String rpTemp = cycle.getParameter(PARAM_RESOURCE_ID); + Integer resourceIdParam = null; - if (cycle.getParameter(PARAM_RESOURCE_ID) != null) { - resourceIdParam = Integer.valueOf((String) (cycle.getParameter(PARAM_RESOURCE_ID))); + if (rpTemp != null) { + resourceIdParam = Integer.valueOf(rpTemp); } - String metricTemplIdParam = cycle.getParameter(PARAM_METRIC_TEMPLATE_ID); - String timeRangeParam = cycle.getParameter(PARAM_TIME_RANGE); - String configParam = cycle.getParameter(PARAM_CONFIG); - + //Get the AuthzSubject - WebUser user = (WebUser) _request.getSession().getAttribute(Constants.WEBUSER_SES_ATTR); - AuthzBoss boss = ContextUtils.getAuthzBoss(_servletContext); + WebUser user = (WebUser) _request.getSession().getAttribute(Constants.WEBUSER_SES_ATTR); + AuthzBoss boss = ContextUtils.getAuthzBoss(_servletContext); AuthzSubject me = null; try { me = boss.findSubjectById(user.getSessionId(), user.getSubject().getId()); @@ -108,7 +140,8 @@ // Load the current dashboard DashboardManagerLocal dashManager = DashboardManagerEJBImpl.getOne(); - Integer selectedDashboard = SessionUtils.getIntegerAttribute(_request.getSession(), Constants.SELECTED_DASHBOARD_ID, null); + Integer selectedDashboard = SessionUtils.getIntegerAttribute(_request.getSession(), + Constants.SELECTED_DASHBOARD_ID, null); ArrayList<DashboardConfig> dashboardList = null; try { dashboardList = (ArrayList<DashboardConfig>) dashManager.getDashboards(me); @@ -116,15 +149,16 @@ log.debug(e.getLocalizedMessage()); return ERROR_GENERIC; } + // Get the configuration for the current dashboard DashboardConfig dashConfig = DashboardUtils.findDashboard(dashboardList, selectedDashboard); ConfigResponse config = dashConfig.getConfig(); String res; - + if (resourceIdParam != null && metricTemplIdParam != null) { // Get the timerange for the chart - String timeRange = config.getValue(".dashContent.charts.range"); + String timeRange = config.getValue(KeyConstants.USER_DASHBOARD_CHART_RANGE); long end = System.currentTimeMillis(); long start; if (timeRange.equalsIgnoreCase("1h")) { @@ -136,9 +170,9 @@ } else if (timeRange.equalsIgnoreCase("1w")) { start = 604800000l; //1w } else { - start = 3600000l; //default to 1h + start = 86400000l; //default to 1d } - + // Get chart metric data, given the RID and MTIDs try { ArrayList<Integer> mtids = new ArrayList<Integer>(); @@ -156,7 +190,7 @@ } } else if (configParam != null) { if (timeRangeParam != null) { - config.setValue(".dashContent.charts.tr", timeRangeParam); + config.setValue(KeyConstants.USER_DASHBOARD_CHART_RANGE, timeRangeParam); //update the crispo try { ConfigurationProxy.getInstance().setDashboardPreferences(_request.getSession(), user, boss, config); @@ -167,22 +201,19 @@ res = EMPTY_RESPONSE; } else { try { - res = new JSONObject().put("tr", config.getValue(".dashContent.charts.tr")).toString(); + res = new JSONObject().put("tr", config.getValue(KeyConstants.USER_DASHBOARD_CHART_RANGE)).toString(); } catch (JSONException e) { log.debug(e.getLocalizedMessage()); res = ERROR_GENERIC; } } } else { - // Get the list of saved charts for this user - res = config.getValue(".dashContent.charts"); + // Get the list of saved charts for this dashboard + res = config.getValue(KeyConstants.USER_DASHBOARD_CHARTS); if (res == null) res = EMPTY_RESPONSE; // no saved charts } return res; } - public String getName() { - return SERVICE_NAME; - } } |