1 package de.tivsource.page.admin.actions.others.contententry;
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 com.opensymphony.xwork2.Preparable;
17
18 import de.tivsource.ejb3plugin.InjectEJB;
19 import de.tivsource.page.admin.actions.EmptyAction;
20 import de.tivsource.page.common.menuentry.ContentEntry;
21 import de.tivsource.page.dao.contententry.ContentEntryDaoLocal;
22 import de.tivsource.page.dao.contentitem.ContentItemDaoLocal;
23 import de.tivsource.page.dao.property.PropertyDaoLocal;
24 import de.tivsource.page.entity.contentitem.ContentItem;
25 import de.tivsource.page.entity.enumeration.Language;
26
27
28
29
30
31
32 @TilesDefinitions({
33 @TilesDefinition(name="contentEntryEditForm", 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/others.jsp"),
36 @TilesPutAttribute(name = "content", value = "/WEB-INF/tiles/active/view/contententry/edit_form.jsp")
37 }),
38 @TilesDefinition(name="contentEntryEditError", extend = "adminTemplate", putAttributes = {
39 @TilesPutAttribute(name = "meta", value = "/WEB-INF/tiles/active/meta/chosen.jsp"),
40 @TilesPutAttribute(name = "navigation", value = "/WEB-INF/tiles/active/navigation/others.jsp"),
41 @TilesPutAttribute(name = "content", value = "/WEB-INF/tiles/active/view/contententry/edit_error.jsp")
42 })
43 })
44 public class EditAction extends EmptyAction implements Preparable {
45
46
47
48
49 private static final long serialVersionUID = 413937413466123241L;
50
51
52
53
54 private static final Logger LOGGER = LogManager.getLogger(EditAction.class);
55
56 @InjectEJB(name="ContentEntryDao")
57 private ContentEntryDaoLocal contentEntryDaoLocal;
58
59 @InjectEJB(name="ContentItemDao")
60 private ContentItemDaoLocal contentItemDaoLocal;
61
62 @InjectEJB(name="PropertyDao")
63 private PropertyDaoLocal propertyDaoLocal;
64
65 private ContentEntry contentEntry;
66
67 private List<ContentItem> contentItems;
68
69 public ContentEntry getContentEntry() {
70 return contentEntry;
71 }
72
73 public void setContentEntry(ContentEntry contentEntry) {
74 this.contentEntry = contentEntry;
75 }
76
77 public List<ContentItem> getContentItems() {
78 return contentItems;
79 }
80
81 @Override
82 public void prepare() {
83 contentItems = contentItemDaoLocal.findAllUnassigned(0, contentItemDaoLocal.countAllUnassigned());
84 }
85
86 @Override
87 @Actions({
88 @Action(
89 value = "edit",
90 results = {
91 @Result(name = "success", type = "redirectAction", location = "index.html"),
92 @Result(name = "input", type = "tiles", location = "contentEntryEditForm"),
93 @Result(name = "error", type = "tiles", location = "contentEntryEditError")
94 }
95 )
96 })
97 public String execute() throws Exception {
98 LOGGER.info("execute() aufgerufen.");
99
100 String remoteUser = ServletActionContext.getRequest().getRemoteUser();
101 String remoteAddress = ServletActionContext.getRequest().getRemoteAddr();
102
103 if(contentEntry != null) {
104 LOGGER.info(contentEntry.getTechnical());
105 ContentEntry dbContentEntry = contentEntryDaoLocal.findByUuid(contentEntry.getUuid());
106 contentItems.add(dbContentEntry.getContentItem());
107 dbContentEntry.setContentItem(contentEntry.getContentItem());
108 dbContentEntry.setTechnical("CI_" + contentEntry.getContentItem().getTechnical());
109
110 dbContentEntry.getDescriptionMap().get(Language.DE).setName(contentEntry.getContentItem().getDescriptionMap().get(Language.DE).getName());
111 dbContentEntry.getDescriptionMap().get(Language.DE).setDescription(contentEntry.getContentItem().getDescriptionMap().get(Language.DE).getDescription());
112 dbContentEntry.getDescriptionMap().get(Language.DE).setKeywords(contentEntry.getContentItem().getDescriptionMap().get(Language.DE).getKeywords());
113
114 dbContentEntry.getDescriptionMap().get(Language.EN).setName(contentEntry.getContentItem().getDescriptionMap().get(Language.EN).getName());
115 dbContentEntry.getDescriptionMap().get(Language.EN).setDescription(contentEntry.getContentItem().getDescriptionMap().get(Language.EN).getDescription());
116 dbContentEntry.getDescriptionMap().get(Language.EN).setKeywords(contentEntry.getContentItem().getDescriptionMap().get(Language.EN).getKeywords());
117
118 dbContentEntry.setBottomNavigation(contentEntry.getBottomNavigation());
119 dbContentEntry.setBottomNavigationOrder(contentEntry.getBottomNavigationOrder());
120 dbContentEntry.setNavigation(contentEntry.getNavigation());
121 dbContentEntry.setNavigationOrder(contentEntry.getNavigationOrder());
122 dbContentEntry.setResponsiveNavigation(contentEntry.getResponsiveNavigation());
123 dbContentEntry.setResponsiveNavigationOrder(contentEntry.getResponsiveNavigationOrder());
124 dbContentEntry.setTopNavigation(contentEntry.getTopNavigation());
125 dbContentEntry.setTopNavigationOrder(contentEntry.getTopNavigationOrder());
126
127 dbContentEntry.setModified(new Date());
128 dbContentEntry.setVisible(contentEntry.getVisible());
129 dbContentEntry.setModifiedBy(remoteUser);
130 dbContentEntry.setModifiedAddress(remoteAddress);
131 contentEntryDaoLocal.merge(dbContentEntry);
132 return SUCCESS;
133 }
134 else {
135 return ERROR;
136 }
137
138 }
139
140 }