1 package de.tivsource.page.admin.actions.locations.location;
2
3
4 import java.util.Date;
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.location.LocationDaoLocal;
16 import de.tivsource.page.entity.location.Location;
17
18
19
20
21
22
23 public class OpeningHourDeleteAction extends EmptyAction {
24
25
26
27
28 private static final long serialVersionUID = -3637008080563139796L;
29
30
31
32
33 private static final Logger LOGGER = LogManager.getLogger(OpeningHourDeleteAction.class);
34
35 @InjectEJB(name="LocationDao")
36 private LocationDaoLocal locationDaoLocal;
37
38 private Location location;
39
40 private String uncheckLocation;
41
42 private Integer openingHoursIndex;
43
44 public Location getLocation() {
45 return location;
46 }
47
48 public void setLocationUuid(String location) {
49 this.uncheckLocation = location;
50 }
51
52 public void setOpeningHours(Integer openingHoursIndex) {
53 this.openingHoursIndex = openingHoursIndex;
54 }
55
56 @Override
57 @Actions({
58 @Action(
59 value = "openingHourDelete",
60 results = {
61 @Result(name = "success", type = "redirect", params={"locationUuid", "%{location.uuid}", "location", "overview.html", "namespace", "/location"}),
62 @Result(name = "input", type="tiles", location = "openingHourDeleteForm"),
63 @Result(name = "error", type="tiles", location = "openingHourDeleteError")
64 }
65 )
66 })
67 public String execute() throws Exception {
68 LOGGER.info("execute() aufgerufen.");
69
70 this.loadPageParameter();
71
72 String remoteUser = ServletActionContext.getRequest().getRemoteUser();
73 String remoteAddress = ServletActionContext.getRequest().getRemoteAddr();
74
75 if(location != null) {
76
77 Location dbLocation = locationDaoLocal.findByUuid(location.getUuid());
78 dbLocation.setModified(new Date());
79 dbLocation.setModifiedBy(remoteUser);
80 dbLocation.setModifiedAddress(remoteAddress);
81 locationDaoLocal.merge(dbLocation);
82
83 locationDaoLocal.removeOpeningHour(openingHoursIndex, location.getUuid());
84
85
86 return SUCCESS;
87 }
88 else {
89 return ERROR;
90 }
91
92 }
93
94 private void loadPageParameter() {
95
96 if( uncheckLocation != null && uncheckLocation != "" && uncheckLocation.length() > 0) {
97 location = locationDaoLocal.findByUuid(uncheckLocation);
98 }
99
100 }
101
102 }