View Javadoc

1   package de.tivsource.page.reservation.actions;
2   
3   import java.util.List;
4   import java.util.regex.Pattern;
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.dao.event.EventDaoLocal;
15  import de.tivsource.page.dao.location.LocationDaoLocal;
16  import de.tivsource.page.dao.reservation.ReservationDaoLocal;
17  import de.tivsource.page.entity.event.Event;
18  import de.tivsource.page.entity.location.Location;
19  
20  public class EventListAction extends EmptyAction {
21  
22      /**
23       * Serial Version UID.
24       */
25      private static final long serialVersionUID = 6236431708460575442L;
26  
27      /**
28       * Statischer Logger der Klasse.
29       */
30      private static final Logger LOGGER = LogManager.getLogger(EventListAction.class);
31  
32      @InjectEJB(name="LocationDao")
33      private LocationDaoLocal locationDaoLocal;
34  
35      @InjectEJB(name="EventDao")
36      private EventDaoLocal eventDaoLocal;
37  
38      @InjectEJB(name="ReservationDao")
39      private ReservationDaoLocal reservationDaoLocal;
40  
41      /**
42       * Location Uuid im Pfad (Achtung kann duch den Benutzer manipuliert werden).
43       */
44      private String locationUuid;
45  
46      private List<Event> events;
47  
48      private Location location;
49  
50      public Location getLocation() {
51          return location;
52      }
53  
54      @Override
55      @Actions({
56          @Action(value = "*/list_create", results = {
57              @Result(name = "success", type = "tiles", location = "list_create"),
58              @Result(name = "input", type = "redirectAction", location = "index.html", params={"namespace", "/"}),
59              @Result(name = "error", type = "redirectAction", location = "index.html", params={"namespace", "/"})
60          }),
61          @Action(value = "*/list_edit", results = {
62                  @Result(name = "success", type = "tiles", location = "list_edit"),
63                  @Result(name = "input", type = "redirectAction", location = "index.html", params={"namespace", "/"}),
64                  @Result(name = "error", type = "redirectAction", location = "index.html", params={"namespace", "/"})
65          }),
66          @Action(value = "*/list_view", results = {
67                  @Result(name = "success", type = "tiles", location = "list_view"),
68                  @Result(name = "input", type = "redirectAction", location = "index.html", params={"namespace", "/"}),
69                  @Result(name = "error", type = "redirectAction", location = "index.html", params={"namespace", "/"})
70          })
71      })
72      public String execute() throws Exception {
73          LOGGER.info("execute() aufgerufen.");
74  
75          // Hole Action Locale
76          this.getLanguageFromActionContext();
77  
78          locationUuid = ServletActionContext.getRequest().getServletPath();
79          LOGGER.info("LocationUuid: " + locationUuid);
80  
81          // /gallery/painting/index.html?page=1&request_locale=de
82          
83          
84          locationUuid = locationUuid.replaceAll("/list_create.html", "");
85          locationUuid = locationUuid.replaceAll("/list_edit.html", "");
86          locationUuid = locationUuid.replaceAll("/list_view.html", "");
87          locationUuid = locationUuid.replaceAll("/", "");
88              
89          LOGGER.info("LocationUuid: " + locationUuid);
90  
91          /*
92           * Wenn die Location Uuid keine nicht erlaubten Zeichen enthält und es
93           * die Location mit der Uuid gibt dann wird der Block ausgeführt.
94           */
95          if (isValid(locationUuid) && locationDaoLocal.isEventLocation(locationUuid)) {
96              LOGGER.info("gültige Location Uuid.");
97              location = locationDaoLocal.findByUuid(locationUuid);
98              events = eventDaoLocal.findAll(locationUuid, 0, eventDaoLocal.countAll(locationUuid));
99              return SUCCESS;
100         }
101 
102         /*
103          * Wenn es die Seite nicht gibt oder es einen Manipulationsversuch
104          * gab.
105          */
106          return ERROR;
107     }// Ende execute()
108 
109     public List<Event> getList() {
110         return events;
111     }
112 
113 	public Integer countQuantity(String uuid) {
114 		LOGGER.info("countQuantity aufgerufen.");
115 		LOGGER.info("Event UUID: " + uuid);
116 		return reservationDaoLocal.countQuantity(uuid);
117 	}
118 
119 	public Integer countReservation(String uuid) {
120 		LOGGER.info("countReservation aufgerufen.");
121 		LOGGER.info("Event UUID: " + uuid);
122 		return reservationDaoLocal.countAll(eventDaoLocal.findByUuid(uuid));
123 	}
124 
125     private Boolean isValid(String input) {
126         if (Pattern.matches("[abcdef0-9-]*", input)) {
127             return true;
128         } else {
129             return false;
130         }
131     }
132 
133 }// Ende class