1 package de.tivsource.page.admin.actions.others.gallery;
2
3 import java.util.Arrays;
4 import java.util.Date;
5 import java.util.List;
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.gallery.GalleryDaoLocal;
22 import de.tivsource.page.dao.picture.PictureDaoLocal;
23 import de.tivsource.page.entity.enumeration.Language;
24 import de.tivsource.page.entity.gallery.Gallery;
25 import de.tivsource.page.entity.picture.Picture;
26 import de.tivsource.page.enumeration.GalleryType;
27
28
29
30
31
32
33 @TilesDefinitions({
34 @TilesDefinition(name="galleryEditForm", 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/others.jsp"),
37 @TilesPutAttribute(name = "content", value = "/WEB-INF/tiles/active/view/gallery/edit_form.jsp")
38 }),
39 @TilesDefinition(name="galleryEditError", extend = "adminTemplate", putAttributes = {
40 @TilesPutAttribute(name = "navigation", value = "/WEB-INF/tiles/active/navigation/others.jsp"),
41 @TilesPutAttribute(name = "content", value = "/WEB-INF/tiles/active/view/gallery/edit_error.jsp")
42 })
43 })
44 public class EditAction extends EmptyAction {
45
46
47
48
49 private static final long serialVersionUID = -5770235481070099665L;
50
51
52
53
54 private static final Logger LOGGER = LogManager.getLogger(EditAction.class);
55
56 @InjectEJB(name = "CSSGroupDao")
57 private CSSGroupDaoLocal cssGroupDaoLocal;
58
59 @InjectEJB(name="GalleryDao")
60 private GalleryDaoLocal galleryDaoLocal;
61
62 @InjectEJB(name="PictureDao")
63 private PictureDaoLocal pictureDaoLocal;
64
65 private Gallery gallery;
66
67 private String lang = "DE";
68
69 private List<Picture> pictureList;
70
71 private List<CSSGroup> cssGroupList;
72
73 public Gallery getGallery() {
74 return gallery;
75 }
76
77 public void setGallery(Gallery gallery) {
78 this.gallery = gallery;
79 }
80
81 public String getLang() {
82 return lang;
83 }
84
85 public void setLang(String lang) {
86 this.lang = lang;
87 }
88
89 @Override
90 public void prepare() {
91 super.prepare();
92 cssGroupList = cssGroupDaoLocal.findAll(0, cssGroupDaoLocal.countAll());
93 }
94
95 @Override
96 @Actions({
97 @Action(
98 value = "edit",
99 results = {
100 @Result(name = "success", type = "redirectAction", location = "index.html"),
101 @Result(name = "input", type = "tiles", location = "galleryEditForm"),
102 @Result(name = "error", type = "tiles", location = "galleryEditError")
103 }
104 )
105 })
106 public String execute() throws Exception {
107 LOGGER.info("execute() aufgerufen.");
108
109 String remoteUser = ServletActionContext.getRequest().getRemoteUser();
110 String remoteAddress = ServletActionContext.getRequest().getRemoteAddr();
111
112 if(gallery != null) {
113 LOGGER.info("UUID des Events: " + gallery.getUuid());
114 Gallery dbGallery = galleryDaoLocal.findByUuid(gallery.getUuid());
115 pictureList = pictureDaoLocal.findAll(gallery.getUuid());
116
117 if(lang.contentEquals(new StringBuffer("EN"))) {
118 gallery.getDescriptionMap().put(Language.DE, dbGallery.getDescriptionObject(Language.DE));
119 String noLineBreaks = gallery.getDescription(Language.EN).replaceAll("(\\r|\\n)", "");
120 dbGallery.getDescriptionMap().get(Language.EN).setDescription(noLineBreaks);
121 dbGallery.getDescriptionMap().get(Language.EN).setKeywords(gallery.getKeywords(Language.EN));
122 dbGallery.getDescriptionMap().get(Language.EN).setName(gallery.getName(Language.EN));
123 } else {
124 String noLineBreaks = gallery.getDescription(Language.DE).replaceAll("(\\r|\\n)", "");
125 dbGallery.getDescriptionMap().get(Language.DE).setDescription(noLineBreaks);
126 dbGallery.getDescriptionMap().get(Language.DE).setKeywords(gallery.getKeywords(Language.DE));;
127 dbGallery.getDescriptionMap().get(Language.DE).setName(gallery.getName(Language.DE));
128 }
129
130 dbGallery.setModifiedAddress(remoteAddress);
131 dbGallery.setModified(new Date());
132 dbGallery.setModifiedBy(remoteUser);
133 dbGallery.setVisible(gallery.getVisible());
134 dbGallery.setOrderNumber(gallery.getOrderNumber());
135 dbGallery.setTechnical(gallery.getTechnical());
136 dbGallery.setPicture(gallery.getPicture());
137 dbGallery.setPictureOnPage(gallery.getPictureOnPage());
138 dbGallery.setType(gallery.getType());
139 dbGallery.setCssGroup(gallery.getCssGroup());
140
141 galleryDaoLocal.merge(dbGallery);
142 return SUCCESS;
143 }
144 else {
145 return ERROR;
146 }
147
148 }
149
150 public List<GalleryType> getGalleryTypeList() {
151 return Arrays.asList(GalleryType.values());
152 }
153
154 public List<Picture> getPictureList() {
155 return pictureList;
156 }
157
158 public List<CSSGroup> getCssGroupList() {
159 LOGGER.info("getCssGroupList() aufgerufen.");
160 LOGGER.info("Anzahl der CSS-Gruppen in der Liste: " + cssGroupList.size());
161 return cssGroupList;
162 }
163
164 }