View Javadoc

1   /**
2    * Copyright 2011 The Kuali Foundation Licensed under the
3    * Educational Community License, Version 2.0 (the "License"); you may
4    * not use this file except in compliance with the License. You may
5    * obtain a copy of the License at
6    *
7    * http://www.osedu.org/licenses/ECL-2.0
8    *
9    * Unless required by applicable law or agreed to in writing,
10   * software distributed under the License is distributed on an "AS IS"
11   * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12   * or implied. See the License for the specific language governing
13   * permissions and limitations under the License.
14   */
15  
16  package org.kuali.mobility.alerts.controllers;
17  
18  import java.util.List;
19  
20  import javax.servlet.http.HttpServletRequest;
21  
22  import org.kuali.mobility.alerts.entity.Alert;
23  import org.kuali.mobility.alerts.service.AlertsService;
24  import org.kuali.mobility.campus.service.CampusService;
25  import org.kuali.mobility.security.user.api.User;
26  import org.kuali.mobility.shared.Constants;
27  import org.springframework.beans.factory.annotation.Autowired;
28  import org.springframework.stereotype.Controller;
29  import org.springframework.ui.Model;
30  import org.springframework.web.bind.annotation.RequestMapping;
31  import org.springframework.web.bind.annotation.RequestMethod;
32  import org.springframework.web.bind.annotation.ResponseBody;
33  
34  import flexjson.JSONSerializer;
35  
36  @Controller
37  @RequestMapping("/alerts")
38  public class AlertsController {
39  
40  	@Autowired
41  	private AlertsService alertsService;
42  
43  	@Autowired
44  	private CampusService campusService;
45  
46  	@RequestMapping(method = RequestMethod.GET)
47  	public String getList(HttpServletRequest request, Model uiModel) {
48  		User user = (User) request.getSession().getAttribute(Constants.KME_USER_KEY);
49  		if (user.getViewCampus() != null) {
50  			if (campusService.needToSelectDifferentCampusForTool("alerts", user.getViewCampus())) {
51  				return "redirect:/campus?toolName=alerts";
52  			}
53  		}
54  		return "alerts/list";
55  	}
56  
57  	@Deprecated
58  	@RequestMapping(method = RequestMethod.GET, headers = "Accept=application/json")
59  	@ResponseBody
60  	public String getListJson(HttpServletRequest request, Model uiModel) {
61  		User user = (User) request.getSession().getAttribute(Constants.KME_USER_KEY);
62  		List<Alert> alerts = alertsService.findAlertsByCampus(user.getViewCampus());
63  
64  		return new JSONSerializer().exclude("*.class").deepSerialize(alerts);
65  	}
66  
67  	public AlertsService getAlertsService() {
68  		return alertsService;
69  	}
70  
71  	public void setAlertsService(AlertsService alertsService) {
72  		this.alertsService = alertsService;
73  	}
74  
75  	public CampusService getCampusService() {
76  		return campusService;
77  	}
78  
79  	public void setCampusService(CampusService campusService) {
80  		this.campusService = campusService;
81  	}
82  }