View Javadoc

1   package de.tivsource.page.admin.actions.others.news;
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  
13  import de.tivsource.ejb3plugin.InjectEJB;
14  import de.tivsource.page.admin.actions.EmptyAction;
15  import de.tivsource.page.common.css.CSSGroup;
16  import de.tivsource.page.dao.cssgroup.CSSGroupDaoLocal;
17  import de.tivsource.page.dao.news.NewsDaoLocal;
18  import de.tivsource.page.dao.picture.PictureDaoLocal;
19  import de.tivsource.page.dao.property.PropertyDaoLocal;
20  import de.tivsource.page.entity.enumeration.Language;
21  import de.tivsource.page.entity.news.News;
22  import de.tivsource.page.entity.picture.Picture;
23  
24  /**
25   * 
26   * @author Marc Michele
27   *
28   */
29  public class EditAction extends EmptyAction {
30  
31  	/**
32  	 * Serial Version UID.
33  	 */
34  	private static final long serialVersionUID = 2928952499252570880L;
35  
36  	/**
37       * Statischer Logger der Klasse.
38       */
39      private static final Logger LOGGER = LogManager.getLogger(EditAction.class);
40  
41      @InjectEJB(name = "CSSGroupDao")
42      private CSSGroupDaoLocal cssGroupDaoLocal;
43  
44      @InjectEJB(name="NewsDao")
45      private NewsDaoLocal newsDaoLocal;
46  
47      @InjectEJB(name="PictureDao")
48      private PictureDaoLocal pictureDaoLocal;
49  
50      @InjectEJB(name="PropertyDao")
51      private PropertyDaoLocal propertyDaoLocal;
52  
53      private News news;
54  
55      private String lang;
56  
57      private List<Picture> pictureList;
58      
59      private List<CSSGroup> cssGroupList;
60  
61      public News getNews() {
62          return news;
63      }
64  
65  	public void setNews(News news) {
66          this.news = news;
67      }
68  	
69      public String getLang() {
70          return lang;
71      }
72  
73      public void setLang(String lang) {
74          this.lang = lang;
75      }
76  
77      @Override
78      public void prepare() {
79          super.prepare();
80          pictureList = pictureDaoLocal.findAll(propertyDaoLocal.findByKey("gallery.uuid.for.news.picture").getValue());
81          cssGroupList = cssGroupDaoLocal.findAll(0, cssGroupDaoLocal.countAll());
82      }
83  
84      @Override
85      @Actions({
86          @Action(
87          		value = "edit", 
88          		results = { 
89          				@Result(name = "success", type = "redirectAction", location = "index.html"),
90          				@Result(name = "input",   type = "tiles", location = "newsEditForm"),
91          				@Result(name = "error",   type = "tiles", location = "newsEditError")
92          				}
93          )
94      })
95      public String execute() throws Exception {
96      	LOGGER.info("execute() aufgerufen.");
97  
98          String remoteUser    = ServletActionContext.getRequest().getRemoteUser();
99          String remoteAddress = ServletActionContext.getRequest().getRemoteAddr();
100 
101     	if(news != null) {
102     		LOGGER.info("News UUID: " + news.getUuid());
103     		News dbNews = newsDaoLocal.findByUuid(news.getUuid());
104     		
105 
106             if(lang.contentEquals(new StringBuffer("EN"))) {
107                 news.getContentMap().put(Language.DE, dbNews.getContentObject(Language.DE));
108                 dbNews.getContentMap().get(Language.EN).setContent(news.getContent(Language.EN));
109                 dbNews.getContentMap().get(Language.EN).setModified(new Date());
110 
111                 news.getDescriptionMap().put(Language.DE, dbNews.getDescriptionObject(Language.DE));
112                 String noLineBreaks = news.getDescription(Language.EN).replaceAll("(\\r|\\n)", "");
113                 dbNews.getDescriptionMap().get(Language.EN).setDescription(noLineBreaks);
114                 dbNews.getDescriptionMap().get(Language.EN).setKeywords(news.getKeywords(Language.EN));
115                 dbNews.getDescriptionMap().get(Language.EN).setName(news.getName(Language.EN));
116             } else {
117                 dbNews.getContentMap().get(Language.DE).setContent(news.getContent(Language.DE));
118                 dbNews.getContentMap().get(Language.DE).setModified(new Date());
119 
120                 String noLineBreaks = news.getDescription(Language.DE).replaceAll("(\\r|\\n)", "");
121                 dbNews.getDescriptionMap().get(Language.DE).setDescription(noLineBreaks);
122                 dbNews.getDescriptionMap().get(Language.DE).setKeywords(news.getKeywords(Language.DE));;
123                 dbNews.getDescriptionMap().get(Language.DE).setName(news.getName(Language.DE));
124             }
125 
126 
127     		dbNews.setModified(new Date());
128     		dbNews.setVisible(news.getVisible());
129     		dbNews.setModifiedBy(remoteUser);
130     		dbNews.setModifiedAddress(remoteAddress);
131     		dbNews.setPicture(news.getPicture());
132     		dbNews.setReleaseDate(news.getReleaseDate());
133     		dbNews.setPictureOnPage(news.getPictureOnPage());
134     		dbNews.setCssGroup(news.getCssGroup());
135 
136     		newsDaoLocal.merge(dbNews);
137             return SUCCESS;
138     	}
139     	else {
140     		return ERROR;
141     	}
142 
143     }// Ende execute()
144 
145     public List<Picture> getPictureList() {
146         return pictureList;
147     }
148 
149     public List<CSSGroup> getCssGroupList() {
150         LOGGER.info("getCssGroupList() aufgerufen.");
151         LOGGER.info("Anzahl der CSS-Gruppen in der Liste: " + cssGroupList.size());
152         return cssGroupList;
153     }
154 
155 }// Ende class