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 import java.util.UUID;
7
8 import org.apache.logging.log4j.LogManager;
9 import org.apache.logging.log4j.Logger;
10 import org.apache.struts2.ServletActionContext;
11 import org.apache.struts2.convention.annotation.Action;
12 import org.apache.struts2.convention.annotation.Actions;
13 import org.apache.struts2.convention.annotation.Result;
14 import org.apache.struts2.tiles.annotation.TilesDefinition;
15 import org.apache.struts2.tiles.annotation.TilesDefinitions;
16 import org.apache.struts2.tiles.annotation.TilesPutAttribute;
17
18 import de.tivsource.ejb3plugin.InjectEJB;
19 import de.tivsource.page.admin.actions.EmptyAction;
20 import de.tivsource.page.common.css.CSSGroup;
21 import de.tivsource.page.dao.cssgroup.CSSGroupDaoLocal;
22 import de.tivsource.page.dao.gallery.GalleryDaoLocal;
23 import de.tivsource.page.dao.picture.PictureDaoLocal;
24 import de.tivsource.page.entity.enumeration.Language;
25 import de.tivsource.page.entity.gallery.Gallery;
26 import de.tivsource.page.enumeration.GalleryType;
27
28
29
30
31
32
33 @TilesDefinitions({
34 @TilesDefinition(name="galleryAddForm", 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/add_form.jsp")
38 }),
39 @TilesDefinition(name="galleryAddError", 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/add_error.jsp")
42 })
43 })
44 public class AddAction extends EmptyAction {
45
46
47
48
49 private static final long serialVersionUID = 3442711359941308571L;
50
51
52
53
54 private static final Logger LOGGER = LogManager.getLogger(AddAction.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 List<CSSGroup> cssGroupList;
68
69 public Gallery getGallery() {
70 return gallery;
71 }
72
73 public void setGallery(Gallery gallery) {
74 this.gallery = gallery;
75 }
76
77 @Override
78 public void prepare() {
79 super.prepare();
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 = "galleryAddForm"),
90 @Result(name = "error", type="tiles", location = "galleryAddError")
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(gallery != null) {
101 gallery.setUuid(UUID.randomUUID().toString());
102 gallery.setModified(new Date());
103 gallery.setCreated(new Date());
104 gallery.setModifiedBy(remoteUser);
105 gallery.setModifiedAddress(remoteAddress);
106
107 gallery.getDescriptionMap().get(Language.DE).setUuid(UUID.randomUUID().toString());
108 gallery.getDescriptionMap().get(Language.DE).setNamingItem(gallery);
109 gallery.getDescriptionMap().get(Language.DE).setLanguage(Language.DE);
110 String noLineBreaks = gallery.getDescription(Language.DE).replaceAll("(\\r|\\n)", "");
111 gallery.getDescriptionMap().get(Language.DE).setDescription(noLineBreaks);
112
113 gallery.getDescriptionMap().get(Language.EN).setUuid(UUID.randomUUID().toString());
114 gallery.getDescriptionMap().get(Language.EN).setNamingItem(gallery);
115 gallery.getDescriptionMap().get(Language.EN).setLanguage(Language.EN);
116 gallery.getDescriptionMap().get(Language.EN).setName(gallery.getDescriptionMap().get(Language.DE).getName());
117 gallery.getDescriptionMap().get(Language.EN).setDescription(gallery.getDescriptionMap().get(Language.DE).getDescription());
118 gallery.getDescriptionMap().get(Language.EN).setKeywords(gallery.getDescriptionMap().get(Language.DE).getKeywords());
119
120 galleryDaoLocal.merge(gallery);
121 return SUCCESS;
122 }
123 else {
124 return ERROR;
125 }
126
127
128 }
129
130 public List<GalleryType> getGalleryTypeList() {
131 return Arrays.asList(GalleryType.values());
132 }
133
134 public List<CSSGroup> getCssGroupList() {
135 LOGGER.info("getCssGroupList() aufgerufen.");
136 LOGGER.info("Anzahl der CSS-Gruppen in der Liste: " + cssGroupList.size());
137 return cssGroupList;
138 }
139
140 }