1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.mobility.shared.controllers;
17
18 import java.util.List;
19
20 import javax.servlet.http.Cookie;
21 import javax.servlet.http.HttpServletRequest;
22 import javax.servlet.http.HttpServletResponse;
23
24 import org.kuali.mobility.campus.entity.Campus;
25 import org.kuali.mobility.campus.service.CampusService;
26 import org.kuali.mobility.security.authn.entity.User;
27 import org.kuali.mobility.shared.Constants;
28 import org.springframework.beans.factory.annotation.Autowired;
29 import org.springframework.stereotype.Controller;
30 import org.springframework.ui.Model;
31 import org.springframework.web.bind.annotation.RequestMapping;
32 import org.springframework.web.bind.annotation.RequestMethod;
33 import org.springframework.web.bind.annotation.RequestParam;
34
35 @Controller
36 @RequestMapping("/campus")
37 public class CampusController {
38
39 @Autowired
40 private CampusService campusService;
41
42 @RequestMapping(method = RequestMethod.GET)
43 public String getList(HttpServletRequest request, Model uiModel, @RequestParam(required = true) String toolName) {
44 List<Campus> campuses = campusService.findCampusesByTool(toolName);
45 if (campuses == null || campuses.isEmpty()) {
46 User user = (User) request.getSession().getAttribute(Constants.KME_USER_KEY);
47 user.setViewCampus("ALL");
48 return "redirect:/" + toolName;
49 } else if (campuses.size() == 1) {
50 User user = (User) request.getSession().getAttribute(Constants.KME_USER_KEY);
51 user.setViewCampus(campuses.get(0).getCode());
52 return "redirect:/" + toolName;
53 }
54 uiModel.addAttribute("campuses", campuses);
55 uiModel.addAttribute("toolName", toolName);
56 return "campus";
57 }
58
59 @RequestMapping(value = "/select", method = RequestMethod.GET)
60 public String selectCampus(HttpServletRequest request, HttpServletResponse response, Model uiModel, @RequestParam(required = true) String campus, @RequestParam(required = true) String toolName) {
61 User user = (User) request.getSession().getAttribute(Constants.KME_USER_KEY);
62 user.setViewCampus(campus);
63
64 Cookie cookie = new Cookie("campusSelection", campus);
65 cookie.setMaxAge(60*60*24*365);
66 cookie.setPath(request.getContextPath());
67 response.addCookie(cookie);
68
69 return "redirect:/" + toolName;
70 }
71
72 }