1 package de.tivsource.page.admin.actions.locations.location;
2
3 import java.util.Date;
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
12 import de.tivsource.ejb3plugin.InjectEJB;
13 import de.tivsource.page.admin.actions.EmptyAction;
14 import de.tivsource.page.dao.location.LocationDaoLocal;
15 import de.tivsource.page.entity.location.Location;
16
17
18
19
20
21
22 public class DeleteAction extends EmptyAction {
23
24
25
26
27 private static final long serialVersionUID = -3269503270283436128L;
28
29
30
31
32 private static final Logger LOGGER = LogManager.getLogger(DeleteAction.class);
33
34 @InjectEJB(name="LocationDao")
35 private LocationDaoLocal locationDaoLocal;
36
37 private Location location;
38
39 public Location getLocation() {
40 return location;
41 }
42
43 public void setLocation(Location location) {
44 this.location = location;
45 }
46
47 @Override
48 @Actions({
49 @Action(
50 value = "delete",
51 results = {
52 @Result(name = "success", type = "redirectAction", location = "index.html"),
53 @Result(name = "input", type="tiles", location = "locationDeleteForm"),
54 @Result(name = "error", type="tiles", location = "locationDeleteError")
55 }
56 )
57 })
58 public String execute() throws Exception {
59 LOGGER.info("execute() aufgerufen.");
60
61 String remoteUser = ServletActionContext.getRequest().getRemoteUser();
62 String remoteAddress = ServletActionContext.getRequest().getRemoteAddr();
63
64 if(location != null) {
65 Location dbLocation = locationDaoLocal.findByUuid(location.getUuid());
66 dbLocation.setModified(new Date());
67 dbLocation.setModifiedBy(remoteUser);
68 dbLocation.setModifiedAddress(remoteAddress);
69 locationDaoLocal.merge(dbLocation);
70 locationDaoLocal.delete(dbLocation);
71 return SUCCESS;
72 }
73 else {
74 return ERROR;
75 }
76
77
78 }
79
80 }