1 package de.tivsource.page.user.actions.appointment;
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.appointment.AppointmentDaoLocal;
16 import de.tivsource.page.dao.page.PageDaoLocal;
17 import de.tivsource.page.dao.property.PropertyDaoLocal;
18 import de.tivsource.page.entity.appointment.Appointment;
19 import de.tivsource.page.entity.page.Page;
20 import de.tivsource.page.user.actions.EmptyAction;
21 import de.tivsource.page.user.interfaces.Pagination;
22
23
24
25
26
27
28 @TilesDefinitions({
29 @TilesDefinition(name="appointmentList", extend = "userTemplate", putAttributes = {
30 @TilesPutAttribute(name = "content", value = "/WEB-INF/tiles/active/view/appointment/appointment_list.jsp")
31 })
32 })
33 public class IndexAction extends EmptyAction implements Pagination {
34
35
36
37
38 private static final long serialVersionUID = 3719136247417859740L;
39
40
41
42
43 private static final Logger LOGGER = LogManager.getLogger(IndexAction.class);
44
45
46
47
48 private static final Integer TO = 7;
49
50 @InjectEJB(name = "PageDao")
51 private PageDaoLocal pageDaoLocal;
52
53 @InjectEJB(name="PropertyDao")
54 private PropertyDaoLocal propertyDaoLocal;
55
56 @InjectEJB(name="AppointmentDao")
57 private AppointmentDaoLocal appointmentDaoLocal;
58
59 private List<Appointment> appointments;
60
61 private Page page;
62
63 private Integer next;
64 private Integer previous;
65 private Integer current;
66
67
68
69
70 private Integer from;
71
72
73
74
75 private Integer pagination;
76
77
78
79
80 private Integer dbQuantity;
81
82
83
84
85 private Integer maxPages;
86
87 @Override
88 public void prepare() {
89
90 page = pageDaoLocal.findByTechnical("appointment");
91 }
92
93 @Override
94 @Actions({
95 @Action(value = "index", results = {
96 @Result(name = "success", type = "tiles", location = "appointmentList"),
97 @Result(name = "input", type = "redirectAction", location = "index.html", params={"namespace", "/"}),
98 @Result(name = "error", type = "redirectAction", location = "index.html", params={"namespace", "/"})
99 })
100 })
101 public String execute() throws Exception {
102 LOGGER.info("execute() aufgerufen.");
103
104
105 this.getLanguageFromActionContext();
106
107
108 this.getDBCount();
109
110
111 if(pagination == null) {
112 pagination = 1;
113 }
114
115
116 if(pagination > maxPages) {
117 pagination = 1;
118 }
119
120
121 this.calculate();
122
123
124 appointments = appointmentDaoLocal.findAllVisible(from, TO);
125 return SUCCESS;
126
127 }
128
129 @Override
130 public Page getPage() {
131 return page;
132 }
133
134 @Override
135 public Integer getNext() {
136 return next;
137 }
138
139 @Override
140 public Integer getPrevious() {
141 return previous;
142 }
143
144 @Override
145 public Integer getCurrent() {
146 return current;
147 }
148
149 @Override
150 public void setPage(Integer extpage) {
151 pagination = extpage;
152 }
153
154 public List<Appointment> getAppointments() {
155 return appointments;
156 }
157
158 private void getDBCount() {
159 LOGGER.debug("getDBCount() aufgerufen.");
160 dbQuantity = appointmentDaoLocal.countAllVisible();
161 LOGGER.debug("DbQuantity: " + dbQuantity);
162
163 maxPages = (dbQuantity % TO == 0) ? (dbQuantity / TO) : (dbQuantity / TO) + 1;
164 LOGGER.debug("MaxPages: " + maxPages);
165 }
166
167
168
169
170
171 private void calculate() {
172 if(pagination == 1) {
173 previous = null;
174 next = (2 <= maxPages) ? 2 : null;
175 from = 0;
176 current = pagination;
177 } else {
178 previous = pagination -1;
179 next = (pagination + 1 <= maxPages) ? pagination + 1 : null;
180 from = (pagination - 1) * TO;
181 current = pagination;
182 }
183 }
184
185
186 }