1 package de.tivsource.page.user.actions.feedback;
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.dao.feedback.FeedbackOptionDaoLocal;
16 import de.tivsource.page.dao.page.PageDaoLocal;
17 import de.tivsource.page.dao.property.PropertyDaoLocal;
18 import de.tivsource.page.entity.feedback.Feedback;
19 import de.tivsource.page.entity.feedback.FeedbackOption;
20 import de.tivsource.page.entity.page.Page;
21 import de.tivsource.page.user.actions.EmptyAction;
22
23
24
25
26
27
28 @TilesDefinitions({
29 @TilesDefinition(name="feedbackForm", extend = "userTemplate", putAttributes = {
30 @TilesPutAttribute(name = "meta", value = "/WEB-INF/tiles/active/meta/feedback_form.jsp"),
31 @TilesPutAttribute(name = "twitter", value = "/WEB-INF/tiles/active/twitter/feedback_form.jsp"),
32 @TilesPutAttribute(name = "content", value = "/WEB-INF/tiles/active/view/feedback/feedback_form.jsp")
33 })
34 })
35 public class IndexAction extends EmptyAction {
36
37
38
39
40 private static final long serialVersionUID = -3520284340434098206L;
41
42
43
44
45 private static final Logger LOGGER = LogManager.getLogger(IndexAction.class);
46
47 @InjectEJB(name = "PageDao")
48 private PageDaoLocal pageDaoLocal;
49
50 @InjectEJB(name = "FeedbackOptionDao")
51 private FeedbackOptionDaoLocal feedbackOptionDaoLocal;
52
53 @InjectEJB(name="PropertyDao")
54 private PropertyDaoLocal propertyDaoLocal;
55
56 private Feedback feedback;
57
58 private Integer uncheckCashpoint;
59
60 private Integer uncheckVoucher;
61
62 private Page page;
63
64 private List<FeedbackOption> options;
65
66 public Feedback getFeedback() {
67 return feedback;
68 }
69
70 public Boolean getCashpoint() {
71 if(feedback.getCashpoint() != null) {
72 return true;
73 }
74 return false;
75 }
76
77 public void setCashpoint(Integer uncheckCashpoint) {
78 this.uncheckCashpoint = uncheckCashpoint;
79 }
80
81 public Boolean getVoucher() {
82 if(feedback.getVoucher() != null) {
83 return true;
84 }
85 return false;
86 }
87
88 public void setVoucher(Integer uncheckVoucher) {
89 this.uncheckVoucher = uncheckVoucher;
90 }
91
92 @Override
93 public void prepare() {
94 LOGGER.info("prepare() aufgerufen.");
95
96 page = pageDaoLocal.findByTechnical("feedback");
97
98
99 this.getLanguageFromActionContext();
100
101 options = feedbackOptionDaoLocal.findAllVisible(0, feedbackOptionDaoLocal.countAllVisible());
102 }
103
104 @Override
105 @Actions({
106 @Action(value = "index", results = {
107 @Result(name = "success", type = "tiles", location = "feedbackForm"),
108 @Result(name = "input", type = "tiles", location = "feedbackForm"),
109 @Result(name = "error", type = "redirectAction", location = "index.html", params={"namespace", "/"})
110 })
111 })
112 public String execute() throws Exception {
113 LOGGER.info("execute() aufgerufen.");
114
115
116 boolean moduleEnabled = propertyDaoLocal.findByKey("module.feedback").getValue().equals("true") ? true : false;
117
118
119 if(moduleEnabled) {
120
121 initFeedbackObject();
122 return SUCCESS;
123 } else {
124 return ERROR;
125 }
126
127 }
128
129 @Override
130 public Page getPage() {
131 return page;
132 }
133
134 public List<FeedbackOption> getOptions() {
135 return options;
136 }
137
138 private void initFeedbackObject() {
139 feedback = new Feedback();
140 if(isValidCashpoint()) {
141 feedback.setCashpoint(uncheckCashpoint.toString());
142 }
143 if(isValidVoucher()) {
144 feedback.setVoucher(uncheckVoucher.toString());
145 }
146 }
147
148 private Boolean isValidCashpoint() {
149
150 if(uncheckCashpoint != null && uncheckCashpoint > 0) {
151 return true;
152 }
153 return false;
154 }
155
156 private Boolean isValidVoucher() {
157
158 if(uncheckVoucher != null && uncheckVoucher > 0) {
159 return true;
160 }
161 return false;
162 }
163
164
165
166 }