IoT CAS Frameworks/IOT_Server/Server_Admin_Framework/source/ConsumerAPI/src/java/AV_Action/AV_GetAggregatedMetricValue.java
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        StringBuffer result = new StringBuffer();
        String customername = null;
        String service = null;
        String deviceid = null;
        String metrictype = null;
        String timeperiod = null;
        String metricvalue = null;
        String resourcetype = null;
        String slot = null;
        int selectedYear = 0;
        String selectedMonth = null;
        int selectedWeek = 0;
        int selectedDate = 0;
        int selectedHour = 0;
        try {
            customername = request.getParameter("customer");
            service = request.getParameter("service");
            deviceid = request.getParameter("resourceid");
            metrictype = request.getParameter("metrictype");
            resourcetype = request.getParameter("resourcetype");
            timeperiod = request.getParameter("timeperiod");
            slot = request.getParameter("slot");
            selectedYear = Integer.valueOf(request.getParameter("year"));
            selectedMonth = request.getParameter("month");
            selectedWeek = Integer.valueOf(request.getParameter("week"));
            selectedDate = Integer.valueOf(request.getParameter("date"));
            String tmp = request.getParameter("hour");
            if (tmp != null) {
                if (!(tmp.equals("null"))) {
                    selectedHour = Integer.valueOf(tmp);
                }
            }

            metricvalue = GetAggregatedMetricValue.getAggregatedMetricValue(request, customername, service, deviceid, metrictype, resourcetype, timeperiod, slot, selectedYear, selectedMonth, selectedWeek, selectedDate, selectedHour);
            if (metricvalue == null) {
                log.debug("No data found");
                result.append("{\"error\":\"error\"}");
            } else {
                if (metricvalue.equals("null")) {
                    metricvalue = "[" + metricvalue + "]";
                } else {
                    metricvalue = "[" + metricvalue + "]";
                }
                String callback = request.getParameter("callback");
                result.append(callback + "('" + metricvalue + "')");
            }
            //System.out.println("Response==>" + result);
        } catch (Exception ex) {
            ex.printStackTrace();
            log.error("Error while performing action", ex);
        }
        try {
            response.getWriter().write(result.toString());
        } catch (Exception ex) {
            log.debug("exception while writing output", ex);
        } finally {
            try {
                customername = null;
                service = null;
                deviceid = null;
                metrictype = null;
                timeperiod = null;
                result = null;
                slot = null;
                selectedMonth = null;
                if (out != null) {
                    out.close();
                    out = null;
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
/**
     * Processes requests for both HTTP
     * <code>GET</code> and
     * <code>POST</code> methods.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
Processes requests for both HTTP
GET and
POST methods.

@param request servlet request
@param response servlet response
@throws ServletException if a servlet-specific error occurs
@throws IOException if an I/O error occurs
Processes requests for both HTTP GET and POST methods . @param request servlet request @param response servlet response @throws ServletException if a servlet - specific error occurs @throws IOException if an I / O error occurs
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        StringBuffer result = new StringBuffer();
        String customername = null;
        String service = null;
        String deviceid = null;
        String metrictype = null;
        String timeperiod = null;
        String metricvalue = null;
        String resourcetype = null;
        String slot = null;
        int selectedYear = 0;
        String selectedMonth = null;
        int selectedWeek = 0;
        int selectedDate = 0;
        int selectedHour = 0;
        try {
            customername = request.getParameter("customer");
            service = request.getParameter("service");
            deviceid = request.getParameter("resourceid");
            metrictype = request.getParameter("metrictype");
            resourcetype = request.getParameter("resourcetype");
            timeperiod = request.getParameter("timeperiod");
            slot = request.getParameter("slot");
            selectedYear = Integer.valueOf(request.getParameter("year"));
            selectedMonth = request.getParameter("month");
            selectedWeek = Integer.valueOf(request.getParameter("week"));
            selectedDate = Integer.valueOf(request.getParameter("date"));
            String tmp = request.getParameter("hour");
            if (tmp != null) {
                if (!(tmp.equals("null"))) {
                    selectedHour = Integer.valueOf(tmp);
                }
            }
            metricvalue = GetAggregatedMetricValue.getAggregatedMetricValue(request, customername, service, deviceid, metrictype, resourcetype, timeperiod, slot, selectedYear, selectedMonth, selectedWeek, selectedDate, selectedHour);
            if (metricvalue == null) {
                log.debug("No data found");
                result.append("{\"error\":\"error\"}");
            } else {
                if (metricvalue.equals("null")) {
                    metricvalue = "[" + metricvalue + "]";
                } else {
                    metricvalue = "[" + metricvalue + "]";
                }
                String callback = request.getParameter("callback");
                result.append(callback + "('" + metricvalue + "')");
            }
        } catch (Exception ex) {
            ex.printStackTrace();
            log.error("Error while performing action", ex);
        }
        try {
            response.getWriter().write(result.toString());
        } catch (Exception ex) {
            log.debug("exception while writing output", ex);
        } finally {
            try {
                customername = null;
                service = null;
                deviceid = null;
                metrictype = null;
                timeperiod = null;
                result = null;
                slot = null;
                selectedMonth = null;
                if (out != null) {
                    out.close();
                    out = null;
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
protected void processRequest ( HttpServletRequest request , HttpServletResponse response ) throws ServletException , IOException { response . setContentType ( "text/html;charset=UTF-8" ) ; PrintWriter out = response . getWriter ( ) ; StringBuffer result = new StringBuffer ( ) ; String customername = null ; String service = null ; String deviceid = null ; String metrictype = null ; String timeperiod = null ; String metricvalue = null ; String resourcetype = null ; String slot = null ; int selectedYear = 0 ; String selectedMonth = null ; int selectedWeek = 0 ; int selectedDate = 0 ; int selectedHour = 0 ; try { customername = request . getParameter ( "customer" ) ; service = request . getParameter ( "service" ) ; deviceid = request . getParameter ( "resourceid" ) ; metrictype = request . getParameter ( "metrictype" ) ; resourcetype = request . getParameter ( "resourcetype" ) ; timeperiod = request . getParameter ( "timeperiod" ) ; slot = request . getParameter ( "slot" ) ; selectedYear = Integer . valueOf ( request . getParameter ( "year" ) ) ; selectedMonth = request . getParameter ( "month" ) ; selectedWeek = Integer . valueOf ( request . getParameter ( "week" ) ) ; selectedDate = Integer . valueOf ( request . getParameter ( "date" ) ) ; String tmp = request . getParameter ( "hour" ) ; if ( tmp != null ) { if ( ! ( tmp . equals ( "null" ) ) ) { selectedHour = Integer . valueOf ( tmp ) ; } } metricvalue = GetAggregatedMetricValue . getAggregatedMetricValue ( request , customername , service , deviceid , metrictype , resourcetype , timeperiod , slot , selectedYear , selectedMonth , selectedWeek , selectedDate , selectedHour ) ; if ( metricvalue == null ) { log . debug ( "No data found" ) ; result . append ( "{\"error\":\"error\"}" ) ; } else { if ( metricvalue . equals ( "null" ) ) { metricvalue = "[" + metricvalue + "]" ; } else { metricvalue = "[" + metricvalue + "]" ; } String callback = request . getParameter ( "callback" ) ; result . append ( callback + "('" + metricvalue + "')" ) ; } } catch ( Exception ex ) { ex . printStackTrace ( ) ; log . error ( "Error while performing action" , ex ) ; } try { response . getWriter ( ) . write ( result . toString ( ) ) ; } catch ( Exception ex ) { log . debug ( "exception while writing output" , ex ) ; } finally { try { customername = null ; service = null ; deviceid = null ; metrictype = null ; timeperiod = null ; result = null ; slot = null ; selectedMonth = null ; if ( out != null ) { out . close ( ) ; out = null ; } } catch ( Exception e ) { e . printStackTrace ( ) ; } } }
Processes requests for both HTTP
 <code>GET</code> and
 <code>POST</code> methods.
Processes requests for both HTTP <code > GET< / code > and <code > POST< / code > methods .
//System.out.println("Response==>" + result);