1 package de.tivsource.page.user.actions.companion;
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.companion.CompanionDaoLocal;
16 import de.tivsource.page.dao.companion.CompanionGroupDaoLocal;
17 import de.tivsource.page.dao.page.PageDaoLocal;
18 import de.tivsource.page.dao.property.PropertyDaoLocal;
19 import de.tivsource.page.entity.companion.Companion;
20 import de.tivsource.page.entity.companion.CompanionGroup;
21 import de.tivsource.page.entity.page.Page;
22 import de.tivsource.page.user.actions.EmptyAction;
23
24
25
26
27
28
29 @TilesDefinitions({
30 @TilesDefinition(name="companion", extend = "userTemplate", putAttributes = {
31 @TilesPutAttribute(name = "content", value = "/WEB-INF/tiles/active/view/companion/companion.jsp")
32 })
33 })
34 public class IndexAction extends EmptyAction {
35
36
37
38
39 private static final long serialVersionUID = -3953411070248396460L;
40
41
42
43
44 private static final Logger LOGGER = LogManager.getLogger(IndexAction.class);
45
46 @InjectEJB(name="PageDao")
47 private PageDaoLocal pageDaoLocal;
48
49 @InjectEJB(name="PropertyDao")
50 private PropertyDaoLocal propertyDaoLocal;
51
52 @InjectEJB(name="CompanionDao")
53 private CompanionDaoLocal companionDaoLocal;
54
55 @InjectEJB(name="CompanionGroupDao")
56 private CompanionGroupDaoLocal companionGroupDaoLocal;
57
58 private Page page;
59
60 @Override
61 public void prepare() {
62
63 page = pageDaoLocal.findByTechnical("companion");
64 }
65
66 @Override
67 @Actions({
68 @Action(
69 value = "index",
70 results = {
71 @Result(name = "success", type="tiles", location = "companion"),
72 @Result(name = "error", type = "redirectAction", location = "index.html", params={"namespace", "/"})
73 }
74 )
75 })
76 public String execute() throws Exception {
77 LOGGER.info("execute() aufgerufen.");
78
79
80 boolean moduleEnabled = propertyDaoLocal.findByKey("module.companion").getValue().equals("true") ? true : false;
81
82
83 if(moduleEnabled) {
84
85 this.getLanguageFromActionContext();
86 return SUCCESS;
87 } else {
88
89 return ERROR;
90 }
91 }
92
93 public Page getPage() {
94 return page;
95 }
96
97 public List<Companion> getList() {
98 return companionDaoLocal.findAllVisible(0, companionDaoLocal.countAllVisible());
99 }
100
101 public List<CompanionGroup> getCompanionGroup() {
102 return companionGroupDaoLocal.findAllVisible(0, companionGroupDaoLocal.countAllVisible());
103 }
104
105 }