View Javadoc

1   package de.tivsource.page.admin.actions.others.appointment;
2   
3   import java.util.Date;
4   import java.util.List;
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  import org.apache.struts2.tiles.annotation.TilesDefinition;
13  import org.apache.struts2.tiles.annotation.TilesDefinitions;
14  import org.apache.struts2.tiles.annotation.TilesPutAttribute;
15  
16  import de.tivsource.ejb3plugin.InjectEJB;
17  import de.tivsource.page.admin.actions.EmptyAction;
18  import de.tivsource.page.common.css.CSSGroup;
19  import de.tivsource.page.dao.appointment.AppointmentDaoLocal;
20  import de.tivsource.page.dao.cssgroup.CSSGroupDaoLocal;
21  import de.tivsource.page.dao.picture.PictureDaoLocal;
22  import de.tivsource.page.dao.property.PropertyDaoLocal;
23  import de.tivsource.page.entity.appointment.Appointment;
24  import de.tivsource.page.entity.enumeration.Language;
25  import de.tivsource.page.entity.picture.Picture;
26  
27  /**
28   * 
29   * @author Marc Michele
30   *
31   */
32  @TilesDefinitions({
33    @TilesDefinition(name="appointmentEditForm",  extend = "adminTemplate", putAttributes = {
34      @TilesPutAttribute(name = "meta",       value = "/WEB-INF/tiles/active/meta/chosen.jsp"),
35      @TilesPutAttribute(name = "navigation", value = "/WEB-INF/tiles/active/navigation/others.jsp"),
36      @TilesPutAttribute(name = "content",    value = "/WEB-INF/tiles/active/view/appointment/edit_form.jsp")
37    }),
38    @TilesDefinition(name="appointmentEditError", extend = "adminTemplate", putAttributes = {
39      @TilesPutAttribute(name = "navigation", value = "/WEB-INF/tiles/active/navigation/others.jsp"),
40      @TilesPutAttribute(name = "content",    value = "/WEB-INF/tiles/active/view/appointment/edit_error.jsp")
41    })
42  })
43  public class EditAction extends EmptyAction {
44  
45  	/**
46  	 * Serial Version UID.
47  	 */
48      private static final long serialVersionUID = 7633432653598001392L;
49  
50      /**
51       * Statischer Logger der Klasse.
52       */
53      private static final Logger LOGGER = LogManager.getLogger(EditAction.class);
54  
55      @InjectEJB(name="AppointmentDao")
56      private AppointmentDaoLocal appointmentDaoLocal;
57  
58      @InjectEJB(name = "CSSGroupDao")
59      private CSSGroupDaoLocal cssGroupDaoLocal;
60  
61      @InjectEJB(name="PictureDao")
62      private PictureDaoLocal pictureDaoLocal;
63  
64      @InjectEJB(name="PropertyDao")
65      private PropertyDaoLocal propertyDaoLocal;
66  
67      private Appointment appointment;
68  
69      private String lang = "DE";
70  
71      private List<Picture> pictureList;
72  
73      private List<CSSGroup> cssGroupList;
74  
75      public Appointment getAppointment() {
76          return appointment;
77      }
78  
79  	public void setAppointment(Appointment appointment) {
80          this.appointment = appointment;
81      }
82  	
83      public String getLang() {
84          return lang;
85      }
86  
87      public void setLang(String lang) {
88          this.lang = lang;
89      }
90  
91      @Override
92      public void prepare() {
93          super.prepare();
94          pictureList = pictureDaoLocal.findAll(propertyDaoLocal.findByKey("gallery.uuid.for.appointment.picture").getValue());
95          cssGroupList = cssGroupDaoLocal.findAll(0, cssGroupDaoLocal.countAll());
96      }
97  
98      @Override
99      @Actions({
100         @Action(
101         		value = "edit", 
102         		results = { 
103         				@Result(name = "success", type = "redirectAction", location = "index.html"),
104         				@Result(name = "input",   type = "tiles", location = "appointmentEditForm"),
105         				@Result(name = "error",   type = "tiles", location = "appointmentEditError")
106         				}
107         )
108     })
109     public String execute() throws Exception {
110     	LOGGER.info("execute() aufgerufen.");
111 
112         String remoteUser    = ServletActionContext.getRequest().getRemoteUser();
113         String remoteAddress = ServletActionContext.getRequest().getRemoteAddr();
114 
115     	if(appointment != null) {
116     		LOGGER.info("Appointment UUID: " + appointment.getUuid());
117     		Appointment dbAppointment = appointmentDaoLocal.findByUuid(appointment.getUuid());
118     		
119 
120             if(lang.contentEquals(new StringBuffer("EN"))) {
121                 appointment.getContentMap().put(Language.DE, dbAppointment.getContentObject(Language.DE));
122                 dbAppointment.getContentMap().get(Language.EN).setContent(appointment.getContent(Language.EN));
123                 dbAppointment.getContentMap().get(Language.EN).setModified(new Date());
124 
125                 appointment.getDescriptionMap().put(Language.DE, dbAppointment.getDescriptionObject(Language.DE));
126                 String noLineBreaks = appointment.getDescription(Language.EN).replaceAll("(\\r|\\n)", "");
127                 dbAppointment.getDescriptionMap().get(Language.EN).setDescription(noLineBreaks);
128                 dbAppointment.getDescriptionMap().get(Language.EN).setKeywords(appointment.getKeywords(Language.EN));
129                 dbAppointment.getDescriptionMap().get(Language.EN).setName(appointment.getName(Language.EN));
130             } else {
131                 dbAppointment.getContentMap().get(Language.DE).setContent(appointment.getContent(Language.DE));
132                 dbAppointment.getContentMap().get(Language.DE).setModified(new Date());
133 
134                 String noLineBreaks = appointment.getDescription(Language.DE).replaceAll("(\\r|\\n)", "");
135                 dbAppointment.getDescriptionMap().get(Language.DE).setDescription(noLineBreaks);
136                 dbAppointment.getDescriptionMap().get(Language.DE).setKeywords(appointment.getKeywords(Language.DE));;
137                 dbAppointment.getDescriptionMap().get(Language.DE).setName(appointment.getName(Language.DE));
138             }
139 
140 
141             dbAppointment.setPointInTime(appointment.getPointInTime());
142             dbAppointment.setBooking(appointment.getBooking());
143             dbAppointment.setBookingUrl(appointment.getBookingUrl());
144             dbAppointment.setHasVenue(appointment.getHasVenue());
145             dbAppointment.setVenue(appointment.getVenue());
146             dbAppointment.setVisibleFrom(appointment.getVisibleFrom());
147     		dbAppointment.setModified(new Date());
148     		dbAppointment.setVisible(appointment.getVisible());
149     		dbAppointment.setModifiedBy(remoteUser);
150     		dbAppointment.setModifiedAddress(remoteAddress);
151     		dbAppointment.setPicture(appointment.getPicture());
152     		dbAppointment.setPictureOnPage(appointment.getPictureOnPage());
153     		dbAppointment.setCssGroup(appointment.getCssGroup());
154 
155 
156     		appointmentDaoLocal.merge(dbAppointment);
157             return SUCCESS;
158     	}
159     	else {
160     		return ERROR;
161     	}
162 
163     }// Ende execute()
164 
165 	public List<Picture> getPictureList() {
166 	    return pictureList;
167 	}// Ende getPictureList()
168 
169     public List<CSSGroup> getCssGroupList() {
170         LOGGER.info("getCssGroupList() aufgerufen.");
171         LOGGER.info("Anzahl der CSS-Gruppen in der Liste: " + cssGroupList.size());
172         return cssGroupList;
173     }// Ende getCssGroupList()
174 
175 }// Ende class