View Javadoc

1   package de.tivsource.page.admin.actions.locations.event;
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  
14  import de.tivsource.ejb3plugin.InjectEJB;
15  import de.tivsource.page.admin.actions.EmptyAction;
16  import de.tivsource.page.common.css.CSSGroup;
17  import de.tivsource.page.dao.cssgroup.CSSGroupDaoLocal;
18  import de.tivsource.page.dao.event.EventDaoLocal;
19  import de.tivsource.page.dao.location.LocationDaoLocal;
20  import de.tivsource.page.dao.picture.PictureDaoLocal;
21  import de.tivsource.page.dao.property.PropertyDaoLocal;
22  import de.tivsource.page.entity.enumeration.Language;
23  import de.tivsource.page.entity.event.Event;
24  import de.tivsource.page.entity.location.Location;
25  import de.tivsource.page.entity.picture.Picture;
26  
27  /**
28   * 
29   * @author Marc Michele
30   *
31   */
32  public class AddAction extends EmptyAction {
33  
34  	/**
35  	 * Serial Version UID.
36  	 */
37      private static final long serialVersionUID = 7464881886808879895L;
38  
39      /**
40       * Statischer Logger der Klasse.
41       */
42      private static final Logger LOGGER = LogManager.getLogger(AddAction.class);
43  
44      @InjectEJB(name = "CSSGroupDao")
45      private CSSGroupDaoLocal cssGroupDaoLocal;
46  
47      @InjectEJB(name="EventDao")
48      private EventDaoLocal eventDaoLocal;
49  
50      @InjectEJB(name="LocationDao")
51      private LocationDaoLocal locationDaoLocal;
52  
53      @InjectEJB(name="PictureDao")
54      private PictureDaoLocal pictureDaoLocal;
55  
56      @InjectEJB(name="PropertyDao")
57      private PropertyDaoLocal propertyDaoLocal;
58  
59      private Event event;
60  
61      private List<Location> locationList;
62  
63      private List<Picture> pictureList;
64  
65      private List<CSSGroup> cssGroupList;
66  
67      public Event getEvent() {
68          return event;
69      }
70  
71      public void setEvent(Event event) {
72          this.event = event;
73      }
74  
75      @Override
76      public void prepare() {
77          super.prepare();
78          locationList = locationDaoLocal.findAll(0, locationDaoLocal.countAll());
79          pictureList = pictureDaoLocal.findAll(propertyDaoLocal.findByKey("gallery.uuid.for.event.picture").getValue());
80          cssGroupList = cssGroupDaoLocal.findAll(0, cssGroupDaoLocal.countAll());
81      }
82  
83      @Override
84      @Actions({
85          @Action(
86          		value = "add", 
87          		results = { 
88          				@Result(name = "success", type = "redirectAction", location = "index.html"),
89          				@Result(name = "input", type="tiles", location = "eventAddForm"),
90          				@Result(name = "error", type="tiles", location = "eventAddError")
91          				}
92          )
93      })
94      public String execute() throws Exception {
95      	LOGGER.info("execute() aufgerufen.");
96  
97          String remoteUser    = ServletActionContext.getRequest().getRemoteUser();
98          String remoteAddress = ServletActionContext.getRequest().getRemoteAddr();
99  
100     	if(event != null) {
101     	    event.setUuid(UUID.randomUUID().toString());
102     	    event.setModified(new Date());
103     	    event.setCreated(new Date());
104     	    event.setModifiedBy(remoteUser);
105     	    event.setModifiedAddress(remoteAddress);
106 
107     	    // Füge Event in die Location ein
108     	    event.getLocation().getEvents().add(event);
109 
110 
111     	    event.getDescriptionMap().get(Language.DE).setUuid(UUID.randomUUID().toString());
112     	    event.getDescriptionMap().get(Language.DE).setNamingItem(event);
113     	    event.getDescriptionMap().get(Language.DE).setLanguage(Language.DE);
114     	    String noLineBreaks = event.getDescription(Language.DE).replaceAll("(\\r|\\n)", "");
115     	    event.getDescriptionMap().get(Language.DE).setDescription(noLineBreaks);
116 
117     	    event.getDescriptionMap().get(Language.EN).setUuid(UUID.randomUUID().toString());
118     	    event.getDescriptionMap().get(Language.EN).setNamingItem(event);
119     	    event.getDescriptionMap().get(Language.EN).setLanguage(Language.EN);
120     	    event.getDescriptionMap().get(Language.EN).setName(event.getDescriptionMap().get(Language.DE).getName());
121     	    event.getDescriptionMap().get(Language.EN).setDescription(event.getDescriptionMap().get(Language.DE).getDescription());
122     	    event.getDescriptionMap().get(Language.EN).setKeywords(event.getDescriptionMap().get(Language.DE).getKeywords());
123 
124     	    eventDaoLocal.merge(event);
125             return SUCCESS;
126     	}
127     	else {
128     		return ERROR;
129     	}
130     	
131     	
132     }// Ende execute()
133 
134     public List<Location> getLocationList() {
135         return locationList;
136     }// Ende getLocationList()
137 
138     public List<Picture> getPictureList() {
139         return pictureList;
140     }// Ende getPictureList()
141 
142     public List<CSSGroup> getCssGroupList() {
143         LOGGER.info("getCssGroupList() aufgerufen.");
144         LOGGER.info("Anzahl der CSS-Gruppen in der Liste: " + cssGroupList.size());
145         return cssGroupList;
146     }// Ende getCssGroupList()
147 
148 }// Ende class