1 package de.tivsource.page.user.actions.event;
2
3 import java.util.ArrayList;
4 import java.util.Calendar;
5 import java.util.Date;
6 import java.util.List;
7 import java.util.regex.Pattern;
8
9 import org.apache.logging.log4j.LogManager;
10 import org.apache.logging.log4j.Logger;
11 import org.apache.struts2.ServletActionContext;
12 import org.apache.struts2.convention.annotation.Action;
13 import org.apache.struts2.convention.annotation.Actions;
14 import org.apache.struts2.convention.annotation.Result;
15 import org.apache.struts2.tiles.annotation.TilesDefinition;
16 import org.apache.struts2.tiles.annotation.TilesDefinitions;
17 import org.apache.struts2.tiles.annotation.TilesPutAttribute;
18
19 import de.tivsource.ejb3plugin.InjectEJB;
20 import de.tivsource.page.dao.event.EventDaoLocal;
21 import de.tivsource.page.dao.page.PageDaoLocal;
22 import de.tivsource.page.dao.property.PropertyDaoLocal;
23 import de.tivsource.page.entity.enumeration.Language;
24 import de.tivsource.page.entity.event.Event;
25 import de.tivsource.page.entity.page.Page;
26 import de.tivsource.page.user.actions.EmptyAction;
27
28
29
30
31
32
33 @TilesDefinitions({
34 @TilesDefinition(name="event", extend = "userTemplate", putAttributes = {
35 @TilesPutAttribute(name = "meta", value = "/WEB-INF/tiles/active/meta/event.jsp"),
36 @TilesPutAttribute(name = "twitter", value = "/WEB-INF/tiles/active/twitter/event.jsp"),
37 @TilesPutAttribute(name = "content", value = "/WEB-INF/tiles/active/view/event/event.jsp")
38 }),
39 @TilesDefinition(name="eventDeadline", extend = "userTemplate", putAttributes = {
40 @TilesPutAttribute(name = "meta", value = "/WEB-INF/tiles/active/meta/event.jsp"),
41 @TilesPutAttribute(name = "twitter", value = "/WEB-INF/tiles/active/twitter/event.jsp"),
42 @TilesPutAttribute(name = "content", value = "/WEB-INF/tiles/active/view/event/event_deadline.jsp")
43 })
44 })
45 public class IndexAction extends EmptyAction {
46
47
48
49
50 private static final long serialVersionUID = 3286347439057757386L;
51
52
53
54
55 private static final Logger LOGGER = LogManager.getLogger(IndexAction.class);
56
57 @InjectEJB(name = "PageDao")
58 private PageDaoLocal pageDaoLocal;
59
60 @InjectEJB(name="PropertyDao")
61 private PropertyDaoLocal propertyDaoLocal;
62
63 @InjectEJB(name="EventDao")
64 private EventDaoLocal eventDaoLocal;
65
66
67
68
69 private String eventUuid;
70
71 private Event event;
72
73 private Page page;
74
75 @Override
76 public Page getPage() {
77 if(page == null) {
78 setUpPage();
79 }
80 return page;
81 }
82
83 public Event getEvent() {
84 return event;
85 }
86
87 public List<Date> getTimes() {
88 List<Date> times = new ArrayList<Date>();
89
90
91 Calendar calendarStart = Calendar.getInstance();
92 calendarStart.setTime(event.getBeginning());
93 times.add(calendarStart.getTime());
94
95
96 Calendar calendar = Calendar.getInstance();
97 calendar.setTime(event.getEnding());
98 calendar.add(Calendar.MINUTE, -30);
99 Date end = calendar.getTime();
100
101
102 Date time = event.getBeginning();
103 while (time.before(end)) {
104 Calendar calendarTime = Calendar.getInstance();
105 calendarTime.setTime(time);
106 calendarTime.add(Calendar.MINUTE, 15);
107 time = calendarTime.getTime();
108 times.add(time);
109 }
110
111 return times;
112 }
113
114 @Override
115 @Actions({
116 @Action(value = "*/index", results = {
117 @Result(name = "success", type = "tiles", location = "event"),
118 @Result(name = "input", type = "tiles", location = "eventDeadline"),
119 @Result(name = "error", type = "redirectAction", location = "index.html", params={"namespace", "/"})
120 })
121 })
122 public String execute() throws Exception {
123 LOGGER.info("execute() aufgerufen.");
124
125
126 boolean moduleEnabled = propertyDaoLocal.findByKey("module.event").getValue().equals("true") ? true : false;
127
128
129 if(moduleEnabled) {
130
131 this.getLanguageFromActionContext();
132
133
134 eventUuid = ServletActionContext.getRequest().getServletPath();
135 LOGGER.info("EventUuid: " + eventUuid);
136 eventUuid = eventUuid.replaceAll("/index.html", "");
137 eventUuid = eventUuid.replaceAll("/event/", "");
138 LOGGER.info("EventUuid: " + eventUuid);
139
140
141
142
143
144 if (isValid(eventUuid) && eventDaoLocal.isEvent(eventUuid)) {
145 LOGGER.info("gültige Event Uuid.");
146 event = eventDaoLocal.findByUuid(eventUuid);
147
148 setUpPage();
149 Date now = new Date();
150 if(event.getDeadline().after(now)) {
151 return SUCCESS;
152 } else if (event.getBeginning().before(now)) {
153 return ERROR;
154 } else {
155 return INPUT;
156 }
157 }
158
159 return ERROR;
160 } else {
161
162 return ERROR;
163 }
164 }
165
166
167
168 private Boolean isValid(String input) {
169 if (Pattern.matches("[abcdef0-9-]*", input)) {
170 return true;
171 } else {
172 return false;
173 }
174 }
175
176 private void setUpPage() {
177 page = new Page();
178 page.setTechnical(event.getName(Language.DE));
179 page.setDescriptionMap(event.getDescriptionMap());
180 page.setPicture(event.getPicture());
181 page.setPictureOnPage(event.getPictureOnPage());
182 page.setCssGroup(event.getCssGroup());
183 }
184
185 }