View Javadoc

1   package de.tivsource.page.admin.actions.locations.event;
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  
13  import de.tivsource.ejb3plugin.InjectEJB;
14  import de.tivsource.page.admin.actions.EmptyAction;
15  import de.tivsource.page.common.css.CSSGroup;
16  import de.tivsource.page.dao.cssgroup.CSSGroupDaoLocal;
17  import de.tivsource.page.dao.event.EventDaoLocal;
18  import de.tivsource.page.dao.location.LocationDaoLocal;
19  import de.tivsource.page.dao.picture.PictureDaoLocal;
20  import de.tivsource.page.dao.property.PropertyDaoLocal;
21  import de.tivsource.page.entity.enumeration.Language;
22  import de.tivsource.page.entity.event.Event;
23  import de.tivsource.page.entity.location.Location;
24  import de.tivsource.page.entity.picture.Picture;
25  
26  /**
27   * 
28   * @author Marc Michele
29   *
30   */
31  public class EditAction extends EmptyAction {
32  
33  	/**
34  	 * Serial Version UID.
35  	 */
36      private static final long serialVersionUID = -6472541996524122642L;
37  
38      /**
39       * Statischer Logger der Klasse.
40       */
41      private static final Logger LOGGER = LogManager.getLogger(EditAction.class);
42  
43      @InjectEJB(name = "CSSGroupDao")
44      private CSSGroupDaoLocal cssGroupDaoLocal;
45  
46      @InjectEJB(name="EventDao")
47      private EventDaoLocal eventDaoLocal;
48  
49      @InjectEJB(name="LocationDao")
50      private LocationDaoLocal locationDaoLocal;
51  
52      @InjectEJB(name="PictureDao")
53      private PictureDaoLocal pictureDaoLocal;
54  
55      @InjectEJB(name="PropertyDao")
56      private PropertyDaoLocal propertyDaoLocal;
57  
58      private Event event;
59  
60      private String lang;
61  
62      private List<Location> locationList;
63  
64      private List<Picture> pictureList;
65  
66      private List<CSSGroup> cssGroupList;
67  
68      public Event getEvent() {
69          return event;
70      }
71  
72      public void setEvent(Event event) {
73          this.event = event;
74      }
75  
76      public String getLang() {
77          return lang;
78      }
79  
80      public void setLang(String lang) {
81          this.lang = lang;
82      }
83  
84      @Override
85      public void prepare() {
86          super.prepare();
87          locationList = locationDaoLocal.findAll(0, locationDaoLocal.countAll());
88          pictureList = pictureDaoLocal.findAll(propertyDaoLocal.findByKey("gallery.uuid.for.event.picture").getValue());
89          cssGroupList = cssGroupDaoLocal.findAll(0, cssGroupDaoLocal.countAll());
90      }
91  
92      @Override
93      @Actions({
94          @Action(
95          		value = "edit", 
96          		results = { 
97          				@Result(name = "success", type = "redirectAction", location = "index.html"),
98          				@Result(name = "input",   type = "tiles", location = "eventEditForm"),
99          				@Result(name = "error",   type = "tiles", location = "eventEditError")
100         				}
101         )
102     })
103     public String execute() throws Exception {
104     	LOGGER.info("execute() aufgerufen.");
105 
106         String remoteUser    = ServletActionContext.getRequest().getRemoteUser();
107         String remoteAddress = ServletActionContext.getRequest().getRemoteAddr();
108     	
109     	if(event != null) {
110     		LOGGER.info("UUID des Events: " + event.getUuid());
111     		Event dbEvent = eventDaoLocal.findByUuid(event.getUuid());
112 
113             if(lang.contentEquals(new StringBuffer("EN"))) {
114                 event.getDescriptionMap().put(Language.DE, dbEvent.getDescriptionObject(Language.DE));
115                 String noLineBreaks = event.getDescription(Language.EN).replaceAll("(\\r|\\n)", "");
116                 dbEvent.getDescriptionMap().get(Language.EN).setDescription(noLineBreaks);
117                 dbEvent.getDescriptionMap().get(Language.EN).setKeywords(event.getKeywords(Language.EN));
118                 dbEvent.getDescriptionMap().get(Language.EN).setName(event.getName(Language.EN));
119             } else {
120         	    String noLineBreaks = event.getDescription(Language.DE).replaceAll("(\\r|\\n)", "");
121         	    dbEvent.getDescriptionMap().get(Language.DE).setDescription(noLineBreaks);
122                 dbEvent.getDescriptionMap().get(Language.DE).setKeywords(event.getKeywords(Language.DE));;
123                 dbEvent.getDescriptionMap().get(Language.DE).setName(event.getName(Language.DE));
124             }
125     		
126     		dbEvent.setBeginning(event.getBeginning());
127     		dbEvent.setDeadline(event.getDeadline());
128     		dbEvent.setEnding(event.getEnding());
129     		dbEvent.setModifiedAddress(remoteAddress);
130     		dbEvent.setLocation(locationDaoLocal.findByUuidWidthEvents(event.getLocation().getUuid()));
131     		dbEvent.setModified(new Date());
132     		dbEvent.setModifiedBy(remoteUser);
133     		dbEvent.setPrice(event.getPrice());
134     		dbEvent.setReservation(event.getReservation());
135     		dbEvent.setVisible(event.getVisible());
136     		dbEvent.setPicture(event.getPicture());
137     		dbEvent.setPiwikGoal(event.getPiwikGoal());
138     		dbEvent.setMaxReservations(event.getMaxReservations());
139     		dbEvent.setMaxPersons(event.getMaxPersons());
140     		dbEvent.setPictureOnPage(event.getPictureOnPage());
141     		dbEvent.setTimeSelection(event.getTimeSelection());
142     		dbEvent.setCssGroup(event.getCssGroup());
143 
144     		eventDaoLocal.merge(dbEvent);
145             return SUCCESS;
146     	}
147     	else {
148     		return ERROR;
149     	}
150 
151     }// Ende execute()
152 
153     public List<Location> getLocationList() {
154         return locationList;
155     }// Ende getLocationList()
156 
157     public List<Picture> getPictureList() {
158         return pictureList;
159     }// Ende getPictureList()
160 
161     public List<CSSGroup> getCssGroupList() {
162         LOGGER.info("getCssGroupList() aufgerufen.");
163         LOGGER.info("Anzahl der CSS-Gruppen in der Liste: " + cssGroupList.size());
164         return cssGroupList;
165     }// Ende getCssGroupList()
166 
167 }// Ende class