View Javadoc

1   package de.tivsource.page.admin.actions.others.vacancy;
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.dao.vacancy.VacancyDaoLocal;
25  import de.tivsource.page.entity.enumeration.Language;
26  import de.tivsource.page.entity.location.Location;
27  import de.tivsource.page.entity.picture.Picture;
28  import de.tivsource.page.entity.vacancy.Vacancy;
29  
30  /**
31   * 
32   * @author Marc Michele
33   *
34   */
35  @TilesDefinitions({
36    @TilesDefinition(name="vacancyAddForm",  extend = "adminTemplate", putAttributes = {
37      @TilesPutAttribute(name = "meta",       value = "/WEB-INF/tiles/active/meta/chosen.jsp"),
38      @TilesPutAttribute(name = "navigation", value = "/WEB-INF/tiles/active/navigation/others.jsp"),
39      @TilesPutAttribute(name = "content",    value = "/WEB-INF/tiles/active/view/vacancy/add_form.jsp")
40    })
41  })
42  public class AddAction extends EmptyAction {
43  
44  	/**
45  	 * Serial Version UID.
46  	 */
47      private static final long serialVersionUID = 9114559679951589800L;
48  
49      /**
50       * Statischer Logger der Klasse.
51       */
52      private static final Logger LOGGER = LogManager.getLogger(AddAction.class);
53  
54      @InjectEJB(name = "CSSGroupDao")
55      private CSSGroupDaoLocal cssGroupDaoLocal;
56  
57      @InjectEJB(name="VacancyDao")
58      private VacancyDaoLocal vacancyDaoLocal;
59  
60      @InjectEJB(name="LocationDao")
61      private LocationDaoLocal locationDaoLocal;
62  
63      @InjectEJB(name="PictureDao")
64      private PictureDaoLocal pictureDaoLocal;
65  
66      @InjectEJB(name="PropertyDao")
67      private PropertyDaoLocal propertyDaoLocal;
68  
69      private Vacancy vacancy;
70  
71      private String lang;
72  
73      private List<Location> locationList;
74  
75      private List<Picture> pictureList;
76  
77      private List<CSSGroup> cssGroupList;
78  
79  	public Vacancy getVacancy() {
80          return vacancy;
81      }
82  
83      public void setVacancy(Vacancy vacancy) {
84          this.vacancy = vacancy;
85      }
86  
87      public String getLang() {
88          return lang;
89      }
90  
91      public void setLang(String lang) {
92          this.lang = lang;
93      }
94  
95      @Override
96      public void prepare() {
97          super.prepare();
98          locationList = locationDaoLocal.findAll(0, locationDaoLocal.countAll());
99          pictureList = pictureDaoLocal.findAll(propertyDaoLocal.findByKey("gallery.uuid.for.vacancy.picture").getValue());
100         cssGroupList = cssGroupDaoLocal.findAll(0, cssGroupDaoLocal.countAll());
101     }
102 
103     @Override
104     @Actions({
105         @Action(
106         		value = "add", 
107         		results = { 
108         				@Result(name = "success", type = "redirectAction", location = "index.html"),
109         				@Result(name = "input", type="tiles", location = "vacancyAddForm"),
110         				@Result(name = "error", type="tiles", location = "vacancyAddError")
111         				}
112         )
113     })
114     public String execute() throws Exception {
115     	LOGGER.info("execute() aufgerufen.");
116 
117         String remoteUser    = ServletActionContext.getRequest().getRemoteUser();
118         String remoteAddress = ServletActionContext.getRequest().getRemoteAddr();
119 
120     	if(vacancy != null) {
121     	    vacancy.setUuid(UUID.randomUUID().toString());
122     	    vacancy.setModified(new Date());
123     	    vacancy.setCreated(new Date());
124     	    vacancy.setModifiedBy(remoteUser);
125     	    vacancy.setModifiedAddress(remoteAddress);
126 
127 
128     	    vacancy.getDescriptionMap().get(Language.DE).setUuid(UUID.randomUUID().toString());
129     	    vacancy.getDescriptionMap().get(Language.DE).setNamingItem(vacancy);
130     	    vacancy.getDescriptionMap().get(Language.DE).setLanguage(Language.DE);
131     	    String noLineBreaks = vacancy.getDescription(Language.DE).replaceAll("(\\r|\\n)", "");
132     	    vacancy.getDescriptionMap().get(Language.DE).setDescription(noLineBreaks);
133 
134     	    vacancy.getContentMap().get(Language.DE).setUuid(UUID.randomUUID().toString());
135     	    vacancy.getContentMap().get(Language.DE).setContentItem(vacancy);
136     	    vacancy.getContentMap().get(Language.DE).setLanguage(Language.DE);
137     	    vacancy.getContentMap().get(Language.DE).setCreated(new Date());
138     	    vacancy.getContentMap().get(Language.DE).setModified(new Date());
139 
140 
141     	    vacancy.getDescriptionMap().get(Language.EN).setUuid(UUID.randomUUID().toString());
142     	    vacancy.getDescriptionMap().get(Language.EN).setNamingItem(vacancy);
143     	    vacancy.getDescriptionMap().get(Language.EN).setLanguage(Language.EN);
144     	    vacancy.getDescriptionMap().get(Language.EN).setDescription(vacancy.getDescriptionMap().get(Language.DE).getDescription());
145     	    vacancy.getDescriptionMap().get(Language.EN).setName(vacancy.getDescriptionMap().get(Language.DE).getName());
146     	    vacancy.getDescriptionMap().get(Language.EN).setKeywords(vacancy.getDescriptionMap().get(Language.DE).getKeywords());
147 
148     	    vacancy.getContentMap().get(Language.EN).setUuid(UUID.randomUUID().toString());
149     	    vacancy.getContentMap().get(Language.EN).setContentItem(vacancy);
150     	    vacancy.getContentMap().get(Language.EN).setLanguage(Language.EN);
151     	    vacancy.getContentMap().get(Language.EN).setCreated(new Date());
152     	    vacancy.getContentMap().get(Language.EN).setModified(new Date());
153     	    vacancy.getContentMap().get(Language.EN).setContent(vacancy.getContentMap().get(Language.DE).getContent());
154     	    
155     	    
156     	    vacancyDaoLocal.merge(vacancy);
157 
158             return SUCCESS;
159     	}
160     	else {
161     		return ERROR;
162     	}
163     	
164     	
165     }// Ende execute()
166 
167     public List<Location> getLocationList() {
168         return locationList;
169     }// Ende getLocationList()
170 
171     public List<Picture> getPictureList() {
172         return pictureList;
173     }// Ende getPictureList()
174 
175     public List<CSSGroup> getCssGroupList() {
176         LOGGER.info("getCssGroupList() aufgerufen.");
177         LOGGER.info("Anzahl der CSS-Gruppen in der Liste: " + cssGroupList.size());
178         return cssGroupList;
179     }// Ende getCssGroupList()
180 
181 }// Ende class