1 package de.tivsource.page.user.actions.companion;
2
3 import java.util.List;
4 import java.util.regex.Pattern;
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 import org.apache.struts2.tiles.annotation.TilesDefinition;
13 import org.apache.struts2.tiles.annotation.TilesDefinitions;
14 import org.apache.struts2.tiles.annotation.TilesPutAttribute;
15
16 import de.tivsource.ejb3plugin.InjectEJB;
17 import de.tivsource.page.dao.companion.CompanionDaoLocal;
18 import de.tivsource.page.dao.companion.CompanionGroupDaoLocal;
19 import de.tivsource.page.dao.page.PageDaoLocal;
20 import de.tivsource.page.dao.property.PropertyDaoLocal;
21 import de.tivsource.page.entity.companion.Companion;
22 import de.tivsource.page.entity.companion.CompanionGroup;
23 import de.tivsource.page.entity.page.Page;
24 import de.tivsource.page.user.actions.EmptyAction;
25
26
27
28
29
30 @TilesDefinitions({
31 @TilesDefinition(name="companionGroup", extend = "userTemplate", putAttributes = {
32 @TilesPutAttribute(name = "content", value = "/WEB-INF/tiles/active/view/companion/companion_group.jsp")
33 })
34 })
35 public class GroupAction extends EmptyAction {
36
37
38
39
40 private static final long serialVersionUID = -6773446792537275637L;
41
42
43
44
45 private static final Logger LOGGER = LogManager.getLogger(GroupAction.class);
46
47 @InjectEJB(name="PropertyDao")
48 private PropertyDaoLocal propertyDaoLocal;
49
50 @InjectEJB(name="PageDao")
51 private PageDaoLocal pageDaoLocal;
52
53 @InjectEJB(name="CompanionDao")
54 private CompanionDaoLocal companionDaoLocal;
55
56 @InjectEJB(name="CompanionGroupDao")
57 private CompanionGroupDaoLocal companionGroupDaoLocal;
58
59
60
61
62 private String pageName;
63
64 private CompanionGroup companionGroup;
65
66 private Page page;
67
68 @Override
69 public void prepare() {
70
71 page = pageDaoLocal.findByTechnical("companion");
72 }
73
74 @Override
75 @Actions({
76 @Action(value = "*/index", results = {
77 @Result(name = "success", type = "tiles", location = "companionGroup"),
78 @Result(name = "error", type = "redirectAction", location = "index.html") })
79 })
80 public String execute() throws Exception {
81 LOGGER.info("execute() aufgerufen.");
82
83
84 boolean moduleEnabled = propertyDaoLocal.findByKey("module.companion").getValue().equals("true") ? true : false;
85
86
87 if(moduleEnabled) {
88
89 this.getLanguageFromActionContext();
90
91
92 pageName = ServletActionContext.getRequest().getServletPath();
93 LOGGER.info("PageName: " + pageName);
94 pageName = pageName.replaceAll("/index.html", "");
95 pageName = pageName.replaceAll("/companion/", "");
96 LOGGER.info("PageName: " + pageName);
97
98
99
100
101
102 if (isValid(pageName) && companionGroupDaoLocal.isCompanionGroupTechnical(pageName)) {
103 companionGroup = companionGroupDaoLocal.findByTechnical(pageName);
104 return SUCCESS;
105 }
106
107
108 return ERROR;
109 } else {
110
111 return ERROR;
112 }
113 }
114
115 public Page getPage() {
116 return page;
117 }
118
119 public CompanionGroup getCompanionGroup() {
120 return companionGroup;
121 }
122
123 public List<CompanionGroup> getGroupList() {
124 return companionGroupDaoLocal.findAllVisible(0, companionGroupDaoLocal.countAllVisible());
125 }
126
127 public List<Companion> getList() {
128 return companionDaoLocal.findAllVisible(0, companionDaoLocal.countAllVisible(), companionGroup);
129 }
130
131 private Boolean isValid(String input) {
132 if (Pattern.matches("[a-z]*", input)) {
133 return true;
134 } else {
135 return false;
136 }
137 }
138
139 }