View Javadoc

1   package de.tivsource.page.admin.actions.locations.location;
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.cssgroup.CSSGroupDaoLocal;
20  import de.tivsource.page.dao.location.LocationDaoLocal;
21  import de.tivsource.page.dao.picture.PictureDaoLocal;
22  import de.tivsource.page.dao.property.PropertyDaoLocal;
23  import de.tivsource.page.entity.enumeration.Language;
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  @TilesDefinitions({
33    @TilesDefinition(name="locationEditForm", 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/locations.jsp"),
36      @TilesPutAttribute(name = "content",    value = "/WEB-INF/tiles/active/view/location/edit_form.jsp")
37    }),
38    @TilesDefinition(name="locationEditError", extend = "adminTemplate", putAttributes = {
39      @TilesPutAttribute(name = "navigation", value = "/WEB-INF/tiles/active/navigation/locations.jsp"),
40      @TilesPutAttribute(name = "content",    value = "/WEB-INF/tiles/active/view/location/edit_error.jsp")
41    })
42  })
43  public class EditAction extends EmptyAction {
44  
45  	/**
46  	 * Serial Version UID.
47  	 */
48      private static final long serialVersionUID = -1781888752368914342L;
49  
50      /**
51  	 * Statischer Logger der Klasse.
52  	 */
53      private static final Logger LOGGER = LogManager.getLogger(EditAction.class);
54  
55      @InjectEJB(name = "CSSGroupDao")
56      private CSSGroupDaoLocal cssGroupDaoLocal;
57  
58      @InjectEJB(name="LocationDao")
59      private LocationDaoLocal locationDaoLocal;
60  
61      @InjectEJB(name="PictureDao")
62      private PictureDaoLocal pictureDaoLocal;
63  
64      @InjectEJB(name="PropertyDao")
65      private PropertyDaoLocal propertyDaoLocal;
66  
67      private Location location;
68  
69      private String lang;
70  
71      private List<Picture> pictureList;
72  
73      private List<CSSGroup> cssGroupList;
74  
75      public Location getLocation() {
76          return location;
77      }
78  
79      public void setLocation(Location location) {
80          this.location = location;
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.location.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 = "locationEditForm"),
105                 @Result(name = "error",   type = "tiles", location = "locationEditError")
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(location != null) {
116     		LOGGER.info(location.getUuid());
117     		Location dbLocation = locationDaoLocal.findByUuid(location.getUuid());
118 
119             if(lang.contentEquals(new StringBuffer("EN"))) {
120                 location.getDescriptionMap().put(Language.DE, dbLocation.getDescriptionObject(Language.DE));
121                 String noLineBreaks = location.getDescription(Language.EN).replaceAll("(\\r|\\n)", "");
122                 dbLocation.getDescriptionMap().get(Language.EN).setDescription(noLineBreaks);
123                 dbLocation.getDescriptionMap().get(Language.EN).setKeywords(location.getKeywords(Language.EN));
124                 dbLocation.getDescriptionMap().get(Language.EN).setName(location.getName(Language.EN));
125             } else {
126             	String noLineBreaks = location.getDescription(Language.DE).replaceAll("(\\r|\\n)", "");
127                 dbLocation.getDescriptionMap().get(Language.DE).setDescription(noLineBreaks);
128                 dbLocation.getDescriptionMap().get(Language.DE).setKeywords(location.getKeywords(Language.DE));;
129                 dbLocation.getDescriptionMap().get(Language.DE).setName(location.getName(Language.DE));
130             }
131 
132     		dbLocation.setModified(new Date());
133     		dbLocation.setVisible(location.getVisible());
134     		dbLocation.setModifiedBy(remoteUser);
135     		dbLocation.setModifiedAddress(remoteAddress);
136 
137     		dbLocation.getAddress().setCity(location.getAddress().getCity());
138     		dbLocation.getAddress().setCountry(location.getAddress().getCountry());
139     		dbLocation.getAddress().setStreet(location.getAddress().getStreet());
140     		dbLocation.getAddress().setZip(location.getAddress().getZip());
141 
142     		dbLocation.getContactDetails().setEmail(location.getContactDetails().getEmail());
143     		dbLocation.getContactDetails().setFax(location.getContactDetails().getFax());
144     		dbLocation.getContactDetails().setHomepage(location.getContactDetails().getHomepage());
145     		dbLocation.getContactDetails().setMobile(location.getContactDetails().getMobile());
146     		dbLocation.getContactDetails().setTelephone(location.getContactDetails().getTelephone());
147 
148     		dbLocation.setEvent(location.getEvent());
149     		dbLocation.setLatitude(location.getLatitude());
150     		dbLocation.setLongitude(location.getLongitude());
151     		dbLocation.setPicture(location.getPicture());
152     		dbLocation.setOrder(location.getOrder());
153     		dbLocation.setPictureOnPage(location.getPictureOnPage());
154     		dbLocation.setInLocationList(location.getInLocationList());
155     		dbLocation.setCssGroup(location.getCssGroup());
156 
157 
158     		locationDaoLocal.merge(dbLocation);
159             return SUCCESS;
160     	}
161     	else {
162     		return ERROR;
163     	}
164 
165     }// Ende execute()
166 
167     public List<Picture> getPictureList() {
168         return pictureList;
169     }// Ende getPictureList()
170 
171     public List<CSSGroup> getCssGroupList() {
172         LOGGER.info("getCssGroupList() aufgerufen.");
173         LOGGER.info("Anzahl der CSS-Gruppen in der Liste: " + cssGroupList.size());
174         return cssGroupList;
175     }// Ende getCssGroupList()
176 
177 }// Ende class