1 package de.tivsource.page.admin.actions.locations.feedbackoption;
2
3 import java.util.Date;
4
5 import org.apache.logging.log4j.LogManager;
6 import org.apache.logging.log4j.Logger;
7 import org.apache.struts2.ServletActionContext;
8 import org.apache.struts2.convention.annotation.Action;
9 import org.apache.struts2.convention.annotation.Actions;
10 import org.apache.struts2.convention.annotation.Result;
11
12 import de.tivsource.ejb3plugin.InjectEJB;
13 import de.tivsource.page.admin.actions.EmptyAction;
14 import de.tivsource.page.dao.feedback.FeedbackOptionDaoLocal;
15 import de.tivsource.page.dao.property.PropertyDaoLocal;
16 import de.tivsource.page.entity.enumeration.Language;
17 import de.tivsource.page.entity.feedback.FeedbackOption;
18
19
20
21
22
23
24 public class EditAction extends EmptyAction {
25
26
27
28
29 private static final long serialVersionUID = -9176491578050650632L;
30
31
32
33
34 private static final Logger LOGGER = LogManager.getLogger(EditAction.class);
35
36 @InjectEJB(name="FeedbackOptionDao")
37 private FeedbackOptionDaoLocal feedbackOptionDaoLocal;
38
39 @InjectEJB(name="PropertyDao")
40 private PropertyDaoLocal propertyDaoLocal;
41
42 private FeedbackOption feedbackOption;
43
44 private String lang;
45
46
47
48
49 public FeedbackOption getFeedbackOption() {
50 return feedbackOption;
51 }
52
53
54
55
56 public void setFeedbackOption(FeedbackOption feedbackOption) {
57 this.feedbackOption = feedbackOption;
58 }
59
60 public String getLang() {
61 return lang;
62 }
63
64 public void setLang(String lang) {
65 this.lang = lang;
66 }
67
68 @Override
69 public void prepare() {
70 super.prepare();
71 }
72
73 @Override
74 @Actions({
75 @Action(
76 value = "edit",
77 results = {
78 @Result(name = "success", type = "redirectAction", location = "index.html"),
79 @Result(name = "input", type = "tiles", location = "feedbackOptionEditForm"),
80 @Result(name = "error", type = "tiles", location = "feedbackOptionEditError")
81 }
82 )
83 })
84 public String execute() throws Exception {
85 LOGGER.info("execute() aufgerufen.");
86
87 String remoteUser = ServletActionContext.getRequest().getRemoteUser();
88 String remoteAddress = ServletActionContext.getRequest().getRemoteAddr();
89
90 if(feedbackOption != null) {
91 LOGGER.info("UUID der FeedbackOption: " + feedbackOption.getUuid());
92 FeedbackOption dbFeedbackOption = feedbackOptionDaoLocal.findByUuid(feedbackOption.getUuid());
93
94 if(lang.contentEquals(new StringBuffer("EN"))) {
95 feedbackOption.getDescriptionMap().put(Language.DE, dbFeedbackOption.getDescriptionObject(Language.DE));
96 String noLineBreaks = feedbackOption.getDescription(Language.EN).replaceAll("(\\r|\\n)", "");
97 dbFeedbackOption.getDescriptionMap().get(Language.EN).setDescription(noLineBreaks);
98 dbFeedbackOption.getDescriptionMap().get(Language.EN).setKeywords(feedbackOption.getDescriptionObject(Language.EN).getKeywords());
99 dbFeedbackOption.getDescriptionMap().get(Language.EN).setName(feedbackOption.getDescriptionObject(Language.EN).getName());
100 dbFeedbackOption.getDescriptionMap().get(Language.EN).setHints(feedbackOption.getDescriptionObject(Language.EN).getHints());
101 } else {
102 String noLineBreaks = feedbackOption.getDescription(Language.DE).replaceAll("(\\r|\\n)", "");
103 dbFeedbackOption.getDescriptionMap().get(Language.DE).setDescription(noLineBreaks);
104 dbFeedbackOption.getDescriptionMap().get(Language.DE).setKeywords(feedbackOption.getDescriptionObject(Language.DE).getKeywords());;
105 dbFeedbackOption.getDescriptionMap().get(Language.DE).setName(feedbackOption.getDescriptionObject(Language.DE).getName());
106 dbFeedbackOption.getDescriptionMap().get(Language.DE).setHints(feedbackOption.getDescriptionObject(Language.DE).getHints());
107 }
108
109 dbFeedbackOption.setMapKey(feedbackOption.getMapKey());
110 dbFeedbackOption.setMaxStars(feedbackOption.getMaxStars());
111 dbFeedbackOption.setOrderNumber(feedbackOption.getOrderNumber());
112 dbFeedbackOption.setModifiedAddress(remoteAddress);
113 dbFeedbackOption.setModified(new Date());
114 dbFeedbackOption.setModifiedBy(remoteUser);
115 dbFeedbackOption.setVisible(feedbackOption.getVisible());
116
117 feedbackOptionDaoLocal.merge(dbFeedbackOption);
118 return SUCCESS;
119 }
120 else {
121 return ERROR;
122 }
123
124 }
125
126 }