1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.mobility.conference.controllers;
17
18 import java.io.UnsupportedEncodingException;
19 import java.sql.Timestamp;
20 import java.text.DateFormat;
21 import java.text.SimpleDateFormat;
22 import java.util.Date;
23 import java.util.List;
24
25 import org.kuali.mobility.conference.entity.Attendee;
26 import org.kuali.mobility.conference.entity.ContentBlock;
27 import org.kuali.mobility.conference.entity.MenuItem;
28 import org.kuali.mobility.conference.entity.Session;
29 import org.kuali.mobility.conference.entity.SessionFeedback;
30 import org.kuali.mobility.conference.service.ConferenceService;
31 import org.kuali.mobility.email.service.EmailService;
32 import org.springframework.beans.factory.annotation.Autowired;
33 import org.springframework.stereotype.Controller;
34 import org.springframework.ui.Model;
35 import org.springframework.web.bind.annotation.ModelAttribute;
36 import org.springframework.web.bind.annotation.PathVariable;
37 import org.springframework.web.bind.annotation.RequestMapping;
38 import org.springframework.web.bind.annotation.RequestMethod;
39 import org.springframework.web.bind.annotation.RequestParam;
40 import org.springframework.web.bind.annotation.ResponseBody;
41
42 import flexjson.JSONSerializer;
43
44 @Controller
45 @RequestMapping("/conference")
46 public class ConferenceController {
47
48 @Autowired
49 private ConferenceService conferenceService;
50
51 @Autowired
52 private EmailService emailService;
53
54 public void setConferenceService(ConferenceService conferenceService) {
55 this.conferenceService = conferenceService;
56 }
57
58 @RequestMapping(method = RequestMethod.GET)
59 public String index(Model uiModel) {
60 Date d = new Date();
61 DateFormat formatter = new SimpleDateFormat("MMddyy");
62 String today = formatter.format(d);
63 if ("092811".equals(today) || "092911".equals(today) || "093011".equals(today) || "100111".equals(today)) {
64 } else {
65 today = "";
66 }
67
68
69
70 return "conference/index";
71 }
72
73 @RequestMapping(method = RequestMethod.GET, headers = "Accept=application/json")
74 @ResponseBody
75 public String getMenuJson(@RequestParam(value="lang", required = false) String lang) {
76 List<MenuItem> menuItems = conferenceService.findAllMenuItems(lang);
77 return new JSONSerializer().exclude("*.class").deepSerialize(menuItems);
78 }
79
80 @RequestMapping(value = "/welcome", method = RequestMethod.GET)
81 public String welcome(Model uiModel) {
82 List<ContentBlock> contentBlocks = conferenceService.findAllContentBlocks();
83 uiModel.addAttribute("contentBlocks", contentBlocks);
84 return "conference/welcome";
85 }
86
87 @RequestMapping(value = "/featuredSpeakers", method = RequestMethod.GET)
88 public String featuredSpeakers(Model uiModel) {
89 List<ContentBlock> contentBlocks = conferenceService.findFeaturedSpeakers();
90 uiModel.addAttribute("contentBlocks", contentBlocks);
91 return "conference/featuredSpeakers";
92 }
93
94 @RequestMapping(value = "/attendeeGroups", method = RequestMethod.GET)
95 public String attendeeGroups(Model uiModel) {
96 return attendees("A", "Z", uiModel);
97
98 }
99
100 @RequestMapping(value = "/attendees", method = RequestMethod.GET)
101 public String attendees(@RequestParam(value="start", required=true) String start, @RequestParam(value="end", required=true) String end, Model uiModel) {
102 List<Attendee> attendees = conferenceService.findAllAttendees(start.charAt(0), end.charAt(0));
103 uiModel.addAttribute("attendees", attendees);
104 return "conference/attendees";
105 }
106
107 @RequestMapping(value = "/attendeeDetails/{id}", method = RequestMethod.GET)
108 public String attendeeDetails(@PathVariable("id") String id, Model uiModel) {
109 Attendee attendee = conferenceService.findAttendeeById(id);
110 uiModel.addAttribute("attendee", attendee);
111 return "conference/attendeeDetails";
112 }
113
114 @RequestMapping(value = "/sessions", method = RequestMethod.GET)
115 public String sessions(@RequestParam(value="date", required=false) String date, Model uiModel) {
116 List<Session> sessions = conferenceService.findAllSessions(date);
117 uiModel.addAttribute("sessions", sessions);
118 return "conference/sessions";
119 }
120
121 @RequestMapping(value = "/sessionDetails/{id}", method = RequestMethod.GET)
122 public String sessionDetails(@PathVariable("id") String id, Model uiModel) throws UnsupportedEncodingException {
123 Session session = conferenceService.findSessionById(id);
124 uiModel.addAttribute("session", session);
125 uiModel.addAttribute("sessionFeedback", new SessionFeedback());
126 return "conference/sessionDetails";
127 }
128
129 @RequestMapping(value = "/sessionFeedback", method = RequestMethod.POST)
130 public String submitFeedback(Model uiModel, @ModelAttribute("sessionFeedback") SessionFeedback sessionFeedback) {
131 sessionFeedback.setTimePosted(new Timestamp(System.currentTimeMillis()));
132 sendEmail(sessionFeedback);
133 return "conference/sessionFeedbackThanks";
134 }
135
136 @RequestMapping(value = "/sessionSpeakerDetails", method = RequestMethod.GET)
137 public String sessionSpeakerDetails(Model uiModel, @RequestParam(required = true) int id) {
138 List<Session> sessions = conferenceService.findAllSessions("");
139 uiModel.addAttribute("session", sessions.get(id));
140 return "conference/sessionSpeakerDetails";
141 }
142
143 private void sendEmail(SessionFeedback f) {
144 try {
145 emailService.sendEmail(f.toString(), "SWITC Feedback; "+f.getSessionId()+":"+f.getRating(), conferenceService.getToEmailAddress(), conferenceService.getFromEmailAddress());
146 } catch (Exception e) {}
147 }
148
149 }