1 package de.tivsource.page.admin.actions.others.appointment;
2
3 import java.util.Date;
4 import java.util.List;
5 import java.util.UUID;
6
7 import org.apache.logging.log4j.LogManager;
8 import org.apache.logging.log4j.Logger;
9 import org.apache.struts2.ServletActionContext;
10 import org.apache.struts2.convention.annotation.Action;
11 import org.apache.struts2.convention.annotation.Actions;
12 import org.apache.struts2.convention.annotation.Result;
13 import org.apache.struts2.tiles.annotation.TilesDefinition;
14 import org.apache.struts2.tiles.annotation.TilesDefinitions;
15 import org.apache.struts2.tiles.annotation.TilesPutAttribute;
16
17 import de.tivsource.ejb3plugin.InjectEJB;
18 import de.tivsource.page.admin.actions.EmptyAction;
19 import de.tivsource.page.common.css.CSSGroup;
20 import de.tivsource.page.dao.appointment.AppointmentDaoLocal;
21 import de.tivsource.page.dao.cssgroup.CSSGroupDaoLocal;
22 import de.tivsource.page.dao.picture.PictureDaoLocal;
23 import de.tivsource.page.dao.property.PropertyDaoLocal;
24 import de.tivsource.page.entity.appointment.Appointment;
25 import de.tivsource.page.entity.enumeration.Language;
26 import de.tivsource.page.entity.picture.Picture;
27
28
29
30
31
32
33 @TilesDefinitions({
34 @TilesDefinition(name="appointmentAddForm", extend = "adminTemplate", putAttributes = {
35 @TilesPutAttribute(name = "meta", value = "/WEB-INF/tiles/active/meta/chosen.jsp"),
36 @TilesPutAttribute(name = "navigation", value = "/WEB-INF/tiles/active/navigation/others.jsp"),
37 @TilesPutAttribute(name = "content", value = "/WEB-INF/tiles/active/view/appointment/add_form.jsp")
38 }),
39 @TilesDefinition(name="appointmentAddError", extend = "adminTemplate", putAttributes = {
40 @TilesPutAttribute(name = "navigation", value = "/WEB-INF/tiles/active/navigation/others.jsp"),
41 @TilesPutAttribute(name = "content", value = "/WEB-INF/tiles/active/view/appointment/add_error.jsp")
42 })
43 })
44 public class AddAction extends EmptyAction {
45
46
47
48
49 private static final long serialVersionUID = -6268903742931993162L;
50
51
52
53
54 private static final Logger LOGGER = LogManager.getLogger(AddAction.class);
55
56 @InjectEJB(name="AppointmentDao")
57 private AppointmentDaoLocal appointmentDaoLocal;
58
59 @InjectEJB(name = "CSSGroupDao")
60 private CSSGroupDaoLocal cssGroupDaoLocal;
61
62 @InjectEJB(name="PictureDao")
63 private PictureDaoLocal pictureDaoLocal;
64
65 @InjectEJB(name="PropertyDao")
66 private PropertyDaoLocal propertyDaoLocal;
67
68 private Appointment appointment;
69
70 private List<Picture> pictureList;
71
72 private List<CSSGroup> cssGroupList;
73
74 public Appointment getAppointment() {
75 return appointment;
76 }
77
78 public void setAppointment(Appointment appointment) {
79 this.appointment = appointment;
80 }
81
82 @Override
83 public void prepare() {
84 super.prepare();
85 pictureList = pictureDaoLocal.findAll(propertyDaoLocal.findByKey("gallery.uuid.for.appointment.picture").getValue());
86 cssGroupList = cssGroupDaoLocal.findAll(0, cssGroupDaoLocal.countAll());
87 }
88
89 @Override
90 @Actions({
91 @Action(
92 value = "add",
93 results = {
94 @Result(name = "success", type = "redirectAction", location = "index.html"),
95 @Result(name = "input", type="tiles", location = "appointmentAddForm"),
96 @Result(name = "error", type="tiles", location = "appointmentAddError")
97 }
98 )
99 })
100 public String execute() throws Exception {
101 LOGGER.info("execute() aufgerufen.");
102
103 String remoteUser = ServletActionContext.getRequest().getRemoteUser();
104 String remoteAddress = ServletActionContext.getRequest().getRemoteAddr();
105
106 if(appointment != null) {
107 appointment.setUuid(UUID.randomUUID().toString());
108 appointment.setModified(new Date());
109 appointment.setCreated(new Date());
110 appointment.setModifiedBy(remoteUser);
111 appointment.setModifiedAddress(remoteAddress);
112
113 appointment.getDescriptionMap().get(Language.DE).setUuid(UUID.randomUUID().toString());
114 appointment.getDescriptionMap().get(Language.DE).setNamingItem(appointment);
115 appointment.getDescriptionMap().get(Language.DE).setLanguage(Language.DE);
116 String noLineBreaks = appointment.getDescription(Language.DE).replaceAll("(\\r|\\n)", "");
117 appointment.getDescriptionMap().get(Language.DE).setDescription(noLineBreaks);
118
119 appointment.getContentMap().get(Language.DE).setUuid(UUID.randomUUID().toString());
120 appointment.getContentMap().get(Language.DE).setContentItem(appointment);
121 appointment.getContentMap().get(Language.DE).setLanguage(Language.DE);
122 appointment.getContentMap().get(Language.DE).setCreated(new Date());
123 appointment.getContentMap().get(Language.DE).setModified(new Date());
124
125 appointment.getDescriptionMap().get(Language.EN).setUuid(UUID.randomUUID().toString());
126 appointment.getDescriptionMap().get(Language.EN).setNamingItem(appointment);
127 appointment.getDescriptionMap().get(Language.EN).setLanguage(Language.EN);
128
129 appointment.getContentMap().get(Language.EN).setUuid(UUID.randomUUID().toString());
130 appointment.getContentMap().get(Language.EN).setContentItem(appointment);
131 appointment.getContentMap().get(Language.EN).setLanguage(Language.EN);
132 appointment.getContentMap().get(Language.EN).setCreated(new Date());
133 appointment.getContentMap().get(Language.EN).setModified(new Date());
134
135 appointmentDaoLocal.merge(appointment);
136
137 return SUCCESS;
138 }
139 else {
140 return ERROR;
141 }
142
143
144 }
145
146 public List<Picture> getPictureList() {
147 return pictureList;
148 }
149
150 public List<CSSGroup> getCssGroupList() {
151 LOGGER.info("getCssGroupList() aufgerufen.");
152 LOGGER.info("Anzahl der CSS-Gruppen in der Liste: " + cssGroupList.size());
153 return cssGroupList;
154 }
155
156 }