com.ugam.collage.plus.controller.people_count.TrackUpdatesController.java Source code

Java tutorial

Introduction

Here is the source code for com.ugam.collage.plus.controller.people_count.TrackUpdatesController.java

Source

/**
 * Class Name:         TrackUpdatesController
 *
 * Created By:         Divya.k3
 * Created On:         6:53:46 PM, Oct 15, 2014
 *
 * Modified By:         Divya.k3
 * Modified On:         6:53:46 PM, Oct 15, 2014
 *
 * Description:
 *
 * Copyright (c) 2013 Ugam Interactive. All rights reserved.
 *
 * Use is subject to license terms.
 */

package com.ugam.collage.plus.controller.people_count;

import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ugam.collage.plus.auth.service.AuthService;
import com.ugam.collage.plus.service.people_count.TrackUpdatesService;
import com.ugam.collage.plus.vo.PeopleDetailsVo;
import com.ugam.collage.plus.vo.ReportTrackVo;
import com.ugam.collage.plus.vo.ResponseTrackVo;
import com.ugam.collage.plus.vo.TsCommentsVo;

@Controller
@RequestMapping(value = "/secure/people-count/track-updates")
public class TrackUpdatesController {

    private static final Logger logger = LoggerFactory.getLogger(TrackUpdatesController.class);

    @Autowired
    private AuthService authService;

    @Autowired
    TrackUpdatesService trackUpdatesService;

    @RequestMapping(value = "/all", method = RequestMethod.GET)
    public String manage(Locale locale, HttpServletRequest httpServletRequest, Model model) {

        logger.debug("Loading Track Updates Page");

        List<String> accesslevels = authService.userAccessLevels();
        if (accesslevels.contains("L3")) {

            return "track-updates";
        } else {
            return "error-not-authorized";
        }
    }

    @RequestMapping(value = "/getReportingsTrackDetails/{yearId}/{monthId}/", method = RequestMethod.GET, headers = "Accept=application/json")
    public @ResponseBody List<TsCommentsVo> getReportingsTrackDetails(@PathVariable Integer yearId,
            @PathVariable Integer monthId, Locale locale, Model model) {

        logger.info("getReportingsTrackDetails");

        List<TsCommentsVo> tsCommentsVoList = trackUpdatesService.getReportingsTrackDetails(yearId, monthId);

        return tsCommentsVoList;
    }

    @RequestMapping(value = "/updateReportingsTrackDetails", method = RequestMethod.POST, headers = "Accept=application/json")
    public @ResponseBody Map<String, Object> updateReportingsTrackDetails(HttpServletRequest httpServletRequest,
            @RequestBody ReportTrackVo reportTractdetail, Model model) {

        Map<String, Object> returnData = new HashMap<>();
        try {
            trackUpdatesService.updateReportingsTrackDetails(reportTractdetail);
            returnData.put("success", "true");
            returnData.put("message", "Saved Successfully");

        } catch (Exception e) {
            returnData.put("success", "false");
            returnData.put("message", "Error in Adding Data from UI - " + e.getLocalizedMessage());
            logger.error("Error Adding Data from UI", e);
        }

        return returnData;

    }

    @RequestMapping(value = "/getResponseTrackDetails/{yearId}/{monthId}/", method = RequestMethod.GET, headers = "Accept=application/json")
    public @ResponseBody List<ResponseTrackVo> getResponseTrackDetails(@PathVariable Integer yearId,
            @PathVariable Integer monthId, Locale locale, Model model) {

        logger.info("getResponseTrackDetails");

        List<ResponseTrackVo> responseTrackVoList = trackUpdatesService.getResponseTrackDetails(yearId, monthId);

        return responseTrackVoList;
    }
}