View Javadoc

1   package de.tivsource.page.admin.actions.locations.location;
2   
3   
4   import java.util.Date;
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  
14  import de.tivsource.ejb3plugin.InjectEJB;
15  import de.tivsource.page.admin.actions.EmptyAction;
16  import de.tivsource.page.dao.location.LocationDaoLocal;
17  import de.tivsource.page.entity.location.Location;
18  import de.tivsource.page.entity.location.OpeningHour;
19  
20  /**
21   * 
22   * @author Marc Michele
23   *
24   */
25  public class OpeningHourAddAction extends EmptyAction {
26  
27  	/**
28  	 * Serial Version UID.
29  	 */
30      private static final long serialVersionUID = -3637008080563139796L;
31  
32      /**
33  	 * Statischer Logger der Klasse.
34  	 */
35      private static final Logger LOGGER = LogManager.getLogger(OpeningHourAddAction.class);
36  
37      @InjectEJB(name="LocationDao")
38      private LocationDaoLocal locationDaoLocal;
39  
40      private Location location;
41  
42  	private OpeningHour openingHour;
43  
44      public Location getLocation() {
45          return location;
46      }
47  
48      public OpeningHour getOpeningHour() {
49          return openingHour;
50      }
51  
52      public void setOpeningHour(OpeningHour openingHour) {
53          this.openingHour = openingHour;
54      }
55  
56      @Override
57      @Actions({
58          @Action(
59          		value = "openingHourAdd", 
60          		results = {
61                          @Result(name = "success", type = "redirect", params={"locationUuid", "%{openingHour.location.uuid}", "location", "overview.html", "namespace", "/location"}),
62                          @Result(name = "input", type="tiles", location = "openingHourAddForm"),
63                          @Result(name = "error", type="tiles", location = "openingHourAddError")
64                          }
65          )
66      })
67      public String execute() throws Exception {
68      	LOGGER.info("execute() aufgerufen.");
69  
70          String remoteUser    = ServletActionContext.getRequest().getRemoteUser();
71          String remoteAddress = ServletActionContext.getRequest().getRemoteAddr();
72  
73          if(openingHour != null) {
74  
75              Location dbLocation = locationDaoLocal.findByUuid(openingHour.getLocation().getUuid());
76              location = dbLocation;
77              dbLocation.setModified(new Date());
78              dbLocation.setModifiedBy(remoteUser);
79              dbLocation.setModifiedAddress(remoteAddress);
80  
81              openingHour.setUuid(UUID.randomUUID().toString());
82              openingHour.setLocation(dbLocation);
83              dbLocation.getOpeningHours().add(openingHour);
84              
85              locationDaoLocal.merge(dbLocation);
86  
87              return SUCCESS;
88          }
89          else {
90              return ERROR;
91          }
92  
93      }// Ende execute()
94  
95  }// Ende class