1 package de.tivsource.page.user.actions.vacancy;
2
3 import java.util.regex.Pattern;
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 import org.apache.struts2.tiles.annotation.TilesDefinition;
12 import org.apache.struts2.tiles.annotation.TilesDefinitions;
13 import org.apache.struts2.tiles.annotation.TilesPutAttribute;
14
15 import de.tivsource.ejb3plugin.InjectEJB;
16 import de.tivsource.page.dao.page.PageDaoLocal;
17 import de.tivsource.page.dao.property.PropertyDaoLocal;
18 import de.tivsource.page.dao.vacancy.VacancyDaoLocal;
19 import de.tivsource.page.entity.page.Page;
20 import de.tivsource.page.entity.vacancy.Vacancy;
21 import de.tivsource.page.user.actions.EmptyAction;
22
23
24
25
26
27
28 @TilesDefinitions({
29 @TilesDefinition(name="vacancyDetail", extend = "userTemplate", putAttributes = {
30 @TilesPutAttribute(name = "meta", value = "/WEB-INF/tiles/active/meta/vacancy.jsp"),
31 @TilesPutAttribute(name = "content", value = "/WEB-INF/tiles/active/view/vacancy/vacancy_detail.jsp")
32 }),
33 @TilesDefinition(name="vacancyForm", extend = "userTemplate", putAttributes = {
34 @TilesPutAttribute(name = "meta", value = "/WEB-INF/tiles/active/meta/vacancy.jsp"),
35 @TilesPutAttribute(name = "content", value = "/WEB-INF/tiles/active/view/vacancy/vacancy_form.jsp")
36 })
37 })
38 public class VacancyAction extends EmptyAction {
39
40
41
42
43 private static final long serialVersionUID = 4241333027632203234L;
44
45
46
47
48 private static final Logger LOGGER = LogManager.getLogger(VacancyAction.class);
49
50 @InjectEJB(name = "PageDao")
51 private PageDaoLocal pageDaoLocal;
52
53 @InjectEJB(name="PropertyDao")
54 private PropertyDaoLocal propertyDaoLocal;
55
56 @InjectEJB(name="VacancyDao")
57 private VacancyDaoLocal vacancyDaoLocal;
58
59 private Page page;
60
61
62
63
64 private String vacancyUuid;
65
66 private Vacancy vacancy;
67
68 public Vacancy getVacancy() {
69 return vacancy;
70 }
71
72 @Override
73 @Actions({
74 @Action(value = "*/index", results = {
75 @Result(name = "success", type = "tiles", location = "vacancyDetail"),
76 @Result(name = "input", type = "redirectAction", location = "index.html", params={"namespace", "/"}),
77 @Result(name = "error", type = "redirectAction", location = "index.html", params={"namespace", "/"})
78 }),
79 @Action(value = "*/form", results = {
80 @Result(name = "success", type = "tiles", location = "vacancyForm"),
81 @Result(name = "input", type = "redirectAction", location = "index.html", params={"namespace", "/"}),
82 @Result(name = "error", type = "redirectAction", location = "index.html", params={"namespace", "/"})
83 })
84 })
85 public String execute() throws Exception {
86 LOGGER.info("execute() aufgerufen.");
87
88
89
90 boolean moduleEnabled = propertyDaoLocal.findByKey("module.vacancy").getValue().equals("true") ? true : false;
91
92
93 if(moduleEnabled) {
94
95 this.getLanguageFromActionContext();
96
97
98 vacancyUuid = ServletActionContext.getRequest().getServletPath();
99 LOGGER.info("VacancyUuid: " + vacancyUuid);
100 vacancyUuid = vacancyUuid.replaceAll("/form.html", "");
101 vacancyUuid = vacancyUuid.replaceAll("/index.html", "");
102 vacancyUuid = vacancyUuid.replaceAll("/vacancy/", "");
103 LOGGER.info("VacancyUuid: " + vacancyUuid);
104
105
106
107
108
109 if (isValid(vacancyUuid) && vacancyDaoLocal.isVacancy(vacancyUuid)) {
110 LOGGER.info("gültige Vacancy Uuid.");
111
112 setUpPage();
113 return SUCCESS;
114 }
115
116
117 return ERROR;
118 } else {
119
120 return ERROR;
121 }
122 }
123
124 @Override
125 public Page getPage() {
126 return page;
127 }
128
129 private Boolean isValid(String input) {
130 if (Pattern.matches("[abcdef0-9-]*", input)) {
131 return true;
132 } else {
133 return false;
134 }
135 }
136
137 private void setUpPage() {
138 vacancy = vacancyDaoLocal.findByUuid(vacancyUuid);
139 page = new Page();
140 page.setTechnical(vacancy.getTechnical());
141 page.setDescriptionMap(vacancy.getDescriptionMap());
142 page.setPicture(vacancy.getPicture());
143 page.setPictureOnPage(vacancy.getPictureOnPage());
144 page.setCssGroup(vacancy.getCssGroup());
145 page.setCreated(vacancy.getCreated());
146 page.setModified(vacancy.getModified());
147 }
148
149 }