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