1 package de.tivsource.page.admin.actions.locations.feedbackoption;
2
3 import java.util.Date;
4 import java.util.UUID;
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
13 import de.tivsource.ejb3plugin.InjectEJB;
14 import de.tivsource.page.admin.actions.EmptyAction;
15 import de.tivsource.page.dao.feedback.FeedbackOptionDaoLocal;
16 import de.tivsource.page.entity.enumeration.Language;
17 import de.tivsource.page.entity.feedback.FeedbackOption;
18 import de.tivsource.page.entity.feedback.FeedbackOptionDescription;
19
20
21
22
23
24
25 public class AddAction extends EmptyAction {
26
27
28
29
30 private static final long serialVersionUID = -8084324674723975703L;
31
32
33
34
35 private static final Logger LOGGER = LogManager.getLogger(AddAction.class);
36
37 @InjectEJB(name="FeedbackOptionDao")
38 private FeedbackOptionDaoLocal feedbackOptionDaoLocal;
39
40 private FeedbackOption feedbackOption;
41
42 public FeedbackOption getFeedbackOption() {
43 return feedbackOption;
44 }
45
46 public void setFeedbackOption(FeedbackOption feedbackOption) {
47 this.feedbackOption = feedbackOption;
48 }
49
50 @Override
51 @Actions({
52 @Action(
53 value = "add",
54 results = {
55 @Result(name = "success", type = "redirectAction", location = "index.html"),
56 @Result(name = "input", type="tiles", location = "manualAddForm"),
57 @Result(name = "error", type="tiles", location = "manualAddError")
58 }
59 )
60 })
61 public String execute() throws Exception {
62 LOGGER.info("execute() aufgerufen.");
63
64 String remoteUser = ServletActionContext.getRequest().getRemoteUser();
65 String remoteAddress = ServletActionContext.getRequest().getRemoteAddr();
66
67 if(feedbackOption != null) {
68 feedbackOption.setUuid(UUID.randomUUID().toString());
69 feedbackOption.setModified(new Date());
70 feedbackOption.setCreated(new Date());
71 feedbackOption.setModifiedBy(remoteUser);
72 feedbackOption.setModifiedAddress(remoteAddress);
73
74 feedbackOption.getDescriptionMap().get(Language.DE).setUuid(UUID.randomUUID().toString());
75 feedbackOption.getDescriptionMap().get(Language.DE).setFeedbackOption(feedbackOption);
76 feedbackOption.getDescriptionMap().get(Language.DE).setLanguage(Language.DE);
77 String noLineBreaks = feedbackOption.getDescription(Language.DE).replaceAll("(\\r|\\n)", "");
78 feedbackOption.getDescriptionMap().get(Language.DE).setDescription(noLineBreaks);
79
80
81 FeedbackOptionDescription feedbackOptionDescription = new FeedbackOptionDescription();
82 feedbackOptionDescription.setUuid(UUID.randomUUID().toString());
83 feedbackOptionDescription.setFeedbackOption(feedbackOption);
84 feedbackOptionDescription.setLanguage(Language.EN);
85 feedbackOptionDescription.setHints(feedbackOption.getDescriptionMap().get(Language.DE).getHints());
86 feedbackOptionDescription.setDescription(feedbackOption.getDescriptionMap().get(Language.DE).getDescription());
87 feedbackOptionDescription.setKeywords(feedbackOption.getDescriptionMap().get(Language.DE).getKeywords());
88 feedbackOptionDescription.setName(feedbackOption.getDescriptionMap().get(Language.DE).getName());
89 feedbackOption.getDescriptionMap().put(Language.EN, feedbackOptionDescription);
90
91 feedbackOptionDaoLocal.merge(feedbackOption);
92
93 return SUCCESS;
94 }
95 else {
96 return ERROR;
97 }
98
99
100 }
101
102 }