1 package de.tivsource.page.user.actions.request;
2
3 import java.util.List;
4
5 import org.apache.logging.log4j.LogManager;
6 import org.apache.logging.log4j.Logger;
7 import org.apache.struts2.convention.annotation.Action;
8 import org.apache.struts2.convention.annotation.Actions;
9 import org.apache.struts2.convention.annotation.Result;
10 import org.apache.struts2.tiles.annotation.TilesDefinition;
11 import org.apache.struts2.tiles.annotation.TilesDefinitions;
12 import org.apache.struts2.tiles.annotation.TilesPutAttribute;
13
14 import de.tivsource.ejb3plugin.InjectEJB;
15 import de.tivsource.page.common.captcha.Captcha;
16 import de.tivsource.page.dao.captcha.CaptchaDaoLocal;
17 import de.tivsource.page.dao.location.LocationDaoLocal;
18 import de.tivsource.page.dao.page.PageDaoLocal;
19 import de.tivsource.page.dao.property.PropertyDaoLocal;
20 import de.tivsource.page.dao.reason.ReasonDaoLocal;
21 import de.tivsource.page.entity.location.Location;
22 import de.tivsource.page.entity.page.Page;
23 import de.tivsource.page.entity.request.Reason;
24 import de.tivsource.page.user.actions.EmptyAction;
25
26
27
28
29
30
31 @TilesDefinitions({
32 @TilesDefinition(name="request", extend = "userTemplate", putAttributes = {
33 @TilesPutAttribute(name = "content", value = "/WEB-INF/tiles/active/view/request/form.jsp")
34 })
35 })
36 public class IndexAction extends EmptyAction {
37
38
39
40
41 private static final long serialVersionUID = 1509866834596943504L;
42
43
44
45
46 private static final Logger LOGGER = LogManager.getLogger(IndexAction.class);
47
48 @InjectEJB(name="CaptchaDao")
49 private CaptchaDaoLocal captchaDaoLocal;
50
51 @InjectEJB(name="PageDao")
52 private PageDaoLocal pageDaoLocal;
53
54 @InjectEJB(name="PropertyDao")
55 private PropertyDaoLocal propertyDaoLocal;
56
57 @InjectEJB(name="LocationDao")
58 private LocationDaoLocal locationDaoLocal;
59
60 @InjectEJB(name="ReasonDao")
61 private ReasonDaoLocal reasonDaoLocal;
62
63 private Page page;
64
65 private Captcha captcha;
66
67 @Override
68 public void prepare() {
69
70 page = pageDaoLocal.findByTechnical("request");
71
72 captcha = captchaDaoLocal.random();
73 }
74
75 @Override
76 @Actions({
77 @Action(
78 value = "index",
79 results = {
80 @Result(name = "success", type="tiles", location = "request"),
81 @Result(name = "error", type = "redirectAction", location = "index.html", params={"namespace", "/"})
82 }
83 )
84 })
85 public String execute() throws Exception {
86 LOGGER.info("execute() aufgerufen.");
87
88
89 boolean moduleEnabled = propertyDaoLocal.findByKey("module.request").getValue().equals("true") ? true : false;
90
91
92 if(moduleEnabled) {
93
94 this.getLanguageFromActionContext();
95 return SUCCESS;
96 }
97 return ERROR;
98 }
99
100 public Page getPage() {
101 return page;
102 }
103
104 public List<Location> getLocationList() {
105 return locationDaoLocal.findAllVisible(0, locationDaoLocal.countAllVisible());
106 }
107
108 public List<Reason> getReasonList() {
109 return reasonDaoLocal.findAllVisible(0, reasonDaoLocal.countAllVisible());
110 }
111
112
113
114
115 public Captcha getCaptcha() {
116 return captcha;
117 }
118
119 }