1 package de.tivsource.page.admin.actions.system.property;
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.property.PropertyDaoLocal;
15 import de.tivsource.page.entity.property.Property;
16
17
18
19
20
21
22 public class EditAction extends EmptyAction {
23
24
25
26
27 private static final long serialVersionUID = 8810065390227066052L;
28
29
30
31
32 private static final Logger LOGGER = LogManager.getLogger(EditAction.class);
33
34 @InjectEJB(name="PropertyDao")
35 private PropertyDaoLocal propertyDaoLocal;
36
37 private Property property;
38
39 public Property getProperty() {
40 return property;
41 }
42
43 public void setProperty(Property property) {
44 this.property = property;
45 }
46
47 @Override
48 @Actions({
49 @Action(
50 value = "edit",
51 results = {
52 @Result(name = "success", type = "redirectAction", location = "index.html"),
53 @Result(name = "input", type = "tiles", location = "propertyEditForm"),
54 @Result(name = "error", type = "tiles", location = "propertyEditError")
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(property != null) {
65 LOGGER.info(property.getKey());
66 Property dbProperty = propertyDaoLocal.findByKey(property.getKey());
67 dbProperty.setValue(property.getValue());
68 dbProperty.setModified(new Date());
69 dbProperty.setModifiedBy(remoteUser);
70 dbProperty.setModifiedAddress(remoteAddress);
71 propertyDaoLocal.merge(dbProperty);
72 return SUCCESS;
73 }
74 else {
75 return ERROR;
76 }
77
78 }
79
80 }