View Javadoc

1   package de.tivsource.page.admin.actions.locations.location;
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.cssgroup.CSSGroupDaoLocal;
21  import de.tivsource.page.dao.location.LocationDaoLocal;
22  import de.tivsource.page.dao.picture.PictureDaoLocal;
23  import de.tivsource.page.dao.property.PropertyDaoLocal;
24  import de.tivsource.page.entity.enumeration.Language;
25  import de.tivsource.page.entity.location.Location;
26  import de.tivsource.page.entity.picture.Picture;
27  
28  /**
29   * 
30   * @author Marc Michele
31   *
32   */
33  @TilesDefinitions({
34    @TilesDefinition(name="locationAddForm",  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/locations.jsp"),
37      @TilesPutAttribute(name = "content",    value = "/WEB-INF/tiles/active/view/location/add_form.jsp")
38    }),
39    @TilesDefinition(name="locationAddError", extend = "adminTemplate", putAttributes = {
40      @TilesPutAttribute(name = "navigation", value = "/WEB-INF/tiles/active/navigation/locations.jsp"),
41      @TilesPutAttribute(name = "content",    value = "/WEB-INF/tiles/active/view/location/add_error.jsp")
42    })
43  })
44  public class AddAction extends EmptyAction {
45  
46  	/**
47  	 * Serial Version UID.
48  	 */
49      private static final long serialVersionUID = 7586573485098206790L;
50  
51      /**
52  	 * Statischer Logger der Klasse.
53  	 */
54      private static final Logger LOGGER = LogManager.getLogger(AddAction.class);
55  
56      @InjectEJB(name = "CSSGroupDao")
57      private CSSGroupDaoLocal cssGroupDaoLocal;
58  
59      @InjectEJB(name="LocationDao")
60      private LocationDaoLocal locationDaoLocal;
61  
62      @InjectEJB(name="PictureDao")
63      private PictureDaoLocal pictureDaoLocal;
64  
65      @InjectEJB(name="PropertyDao")
66      private PropertyDaoLocal propertyDaoLocal;
67  
68      private Location location;
69  
70      private List<Picture> pictureList;
71  
72      private List<CSSGroup> cssGroupList;
73  
74  	public Location getLocation() {
75          return location;
76      }
77  
78      public void setLocation(Location location) {
79          this.location = location;
80      }
81  
82      @Override
83      public void prepare() {
84          super.prepare();
85          pictureList = pictureDaoLocal.findAll(propertyDaoLocal.findByKey("gallery.uuid.for.location.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 = "locationAddForm"),
96                  @Result(name = "error", type="tiles", location = "locationAddError")
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(location != null) {
107     	    location.setUuid(UUID.randomUUID().toString());
108     	    location.setModified(new Date());
109     	    location.setCreated(new Date());
110     	    location.setModifiedBy(remoteUser);
111     	    location.setModifiedAddress(remoteAddress);
112     	    
113     	    location.getDescriptionMap().get(Language.DE).setLanguage(Language.DE);
114     	    location.getDescriptionMap().get(Language.DE).setNamingItem(location);
115     	    location.getDescriptionMap().get(Language.DE).setUuid(UUID.randomUUID().toString());
116     	    String noLineBreaks = location.getDescription(Language.DE).replaceAll("(\\r|\\n)", "");
117     	    location.getDescriptionMap().get(Language.DE).setDescription(noLineBreaks);
118     	    
119             location.getDescriptionMap().get(Language.EN).setDescription(location.getDescriptionMap().get(Language.DE).getDescription());
120             location.getDescriptionMap().get(Language.EN).setKeywords(location.getDescriptionMap().get(Language.DE).getKeywords());
121             location.getDescriptionMap().get(Language.EN).setLanguage(Language.EN);
122             location.getDescriptionMap().get(Language.EN).setName(location.getDescriptionMap().get(Language.DE).getName());
123             location.getDescriptionMap().get(Language.EN).setNamingItem(location);
124             location.getDescriptionMap().get(Language.EN).setUuid(UUID.randomUUID().toString());
125 
126             /*
127 
128             // Pfad in dem die Bild Datei gespeichert wird.
129             String uploadPath = "/var/www/html/uploads/";
130 
131             // Name der Bild Datei die erstellt werden soll. 
132             String pictureSaveName = DigestUtils.shaHex("Hier ist das Geheimniss."
133                 + picture.getName() + new Date() + "Noch ein bischen.")
134                 + ".png";
135             
136             
137 
138             File fullPictureFileToCreate = new File(uploadPath, pictureSaveName);
139             // Wenn die Datei noch nicht existiert wird Sie erstellt.
140             if (!fullPictureFileToCreate.exists()) {
141                 savePictureFile(picture, fullPictureFileToCreate);
142             }
143 
144             location.setPicture(pictureSaveName);
145             */
146             
147     		locationDaoLocal.merge(location);
148             return SUCCESS;
149     	}
150     	else {
151     		return ERROR;
152     	}
153 
154     }// Ende execute()
155 
156     public List<Picture> getPictureList() {
157         return pictureList;
158     }// Ende getPictureList()
159 
160     public List<CSSGroup> getCssGroupList() {
161         LOGGER.info("getCssGroupList() aufgerufen.");
162         LOGGER.info("Anzahl der CSS-Gruppen in der Liste: " + cssGroupList.size());
163         return cssGroupList;
164     }// Ende getCssGroupList()
165 
166 }// Ende class