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