1 package de.tivsource.page.admin.actions.others.linkentry;
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 import org.apache.struts2.tiles.annotation.TilesDefinition;
12 import org.apache.struts2.tiles.annotation.TilesDefinitions;
13 import org.apache.struts2.tiles.annotation.TilesPutAttribute;
14
15 import de.tivsource.ejb3plugin.InjectEJB;
16 import de.tivsource.page.admin.actions.EmptyAction;
17 import de.tivsource.page.common.menuentry.LinkEntry;
18 import de.tivsource.page.dao.linkentry.LinkEntryDaoLocal;
19
20
21
22
23
24
25 @TilesDefinitions({
26 @TilesDefinition(name="linkEntryDeleteForm", extend = "adminTemplate", putAttributes = {
27 @TilesPutAttribute(name = "meta", value = "/WEB-INF/tiles/active/meta/chosen.jsp"),
28 @TilesPutAttribute(name = "navigation", value = "/WEB-INF/tiles/active/navigation/others.jsp"),
29 @TilesPutAttribute(name = "content", value = "/WEB-INF/tiles/active/view/linkentry/delete_form.jsp")
30 }),
31 @TilesDefinition(name="linkEntryDeleteError", extend = "adminTemplate", putAttributes = {
32 @TilesPutAttribute(name = "meta", value = "/WEB-INF/tiles/active/meta/chosen.jsp"),
33 @TilesPutAttribute(name = "navigation", value = "/WEB-INF/tiles/active/navigation/others.jsp"),
34 @TilesPutAttribute(name = "content", value = "/WEB-INF/tiles/active/view/linkentry/delete_error.jsp")
35 })
36 })
37 public class DeleteAction extends EmptyAction {
38
39
40
41
42 private static final long serialVersionUID = 2784414111723220045L;
43
44
45
46
47 private static final Logger LOGGER = LogManager.getLogger(DeleteAction.class);
48
49 @InjectEJB(name="LinkEntryDao")
50 private LinkEntryDaoLocal linkEntryDaoLocal;
51
52 private LinkEntry linkEntry;
53
54 public LinkEntry getLinkEntry() {
55 return linkEntry;
56 }
57
58 public void setLinkEntry(LinkEntry linkEntry) {
59 this.linkEntry = linkEntry;
60 }
61
62 @Override
63 @Actions({
64 @Action(
65 value = "delete",
66 results = {
67 @Result(name = "success", type = "redirectAction", location = "index.html"),
68 @Result(name = "input", type="tiles", location = "linkEntryDeleteForm"),
69 @Result(name = "error", type="tiles", location = "linkEntryDeleteError")
70 }
71 )
72 })
73 public String execute() throws Exception {
74 LOGGER.info("execute() aufgerufen.");
75
76 String remoteUser = ServletActionContext.getRequest().getRemoteUser();
77 String remoteAddress = ServletActionContext.getRequest().getRemoteAddr();
78
79 if(linkEntry != null) {
80 LinkEntry dbLinkEntry = linkEntryDaoLocal.findByUuid(linkEntry.getUuid());
81 dbLinkEntry.setModified(new Date());
82 dbLinkEntry.setModifiedBy(remoteUser);
83 dbLinkEntry.setModifiedAddress(remoteAddress);
84 linkEntryDaoLocal.merge(dbLinkEntry);
85 linkEntryDaoLocal.delete(dbLinkEntry);
86 return SUCCESS;
87 }
88 else {
89 return ERROR;
90 }
91
92
93 }
94
95 }