View Javadoc

1   package de.tivsource.page.reservation.actions.event;
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.reservation.ReservationDaoLocal;
16  import de.tivsource.page.entity.event.Event;
17  import de.tivsource.page.entity.reservation.Reservation;
18  import de.tivsource.page.reservation.actions.EmptyAction;
19  
20  /**
21   * 
22   * @author Marc Michele
23   *
24   */
25  public class IndexAction extends EmptyAction {
26  
27      /**
28       * Serial Version UID.
29       */
30  	private static final long serialVersionUID = -2094121636327219921L;
31  
32  	/**
33  	 * Statischer Logger der Klasse.
34  	 */
35      private static final Logger LOGGER = LogManager.getLogger(IndexAction.class);
36  
37      @InjectEJB(name="ReservationDao")
38      private ReservationDaoLocal reservationDaoLocal;
39  
40      @InjectEJB(name="EventDao")
41      private EventDaoLocal eventDaoLocal;
42  
43      private Event event;
44  
45      private String eventUuid;
46  
47      private List<Reservation> reservations;
48  
49      @Override
50      @Actions({
51          @Action(
52          		value = "*/reservation_list_view", 
53          		results = {
54          		  @Result(name = "success", type="tiles", location = "reservation_list_view"),
55          		  @Result(name = "error", type = "redirectAction", location = "index.html", params={"namespace", "/"})
56          		}
57          ),
58          @Action(
59          		value = "*/reservation_list_edit", 
60          		results = {
61          		  @Result(name = "success", type="tiles", location = "reservation_list_edit"),
62          		  @Result(name = "error", type = "redirectAction", location = "index.html", params={"namespace", "/"})
63          		}
64          )
65      })
66      public String execute() throws Exception {
67      	LOGGER.info("execute() aufgerufen.");
68  
69      	// Hole Action Locale
70      	this.getLanguageFromActionContext();
71  
72      	eventUuid = ServletActionContext.getRequest().getServletPath();
73          LOGGER.info("EventUuid: " + eventUuid);
74  
75      	// http://ncc1701a/reservation/event/ac7006f9-625c-4996-a534-eb123c5f0320/view.html
76  
77          eventUuid = eventUuid.replaceAll("/reservation_list_view.html", "");
78          eventUuid = eventUuid.replaceAll("/reservation_list_edit.html", "");
79          eventUuid = eventUuid.replaceAll("/event/", "");
80  
81          LOGGER.info("EventUuid: " + eventUuid);
82  
83          /*
84           * Wenn die Location Uuid keine nicht erlaubten Zeichen enthält und es
85           * die Location mit der Uuid gibt dann wird der Block ausgeführt.
86           */
87          if (isValid(eventUuid) && eventDaoLocal.isEvent(eventUuid)) {
88              LOGGER.info("gültige Event Uuid.");
89              event = eventDaoLocal.findByUuid(eventUuid);
90              reservations = reservationDaoLocal.findAll(event, 0, reservationDaoLocal.countAll(event));
91              return SUCCESS;
92          }
93  
94          /*
95           * Wenn es die Seite nicht gibt oder es einen Manipulationsversuch
96           * gab.
97           */
98           return ERROR;
99      }// Ende execute()
100 
101     public Event getEvent() {
102 		return event;
103 	}
104 
105 	public List<Reservation> getList() {
106         return reservations;
107     }
108 	
109     private Boolean isValid(String input) {
110         if (Pattern.matches("[abcdef0-9-]*", input)) {
111             return true;
112         } else {
113             return false;
114         }
115     }
116 
117 }// Ende class