View Javadoc

1   package de.tivsource.page.user.actions.appointment;
2   
3   import java.util.Date;
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  import org.apache.struts2.tiles.annotation.TilesDefinition;
13  import org.apache.struts2.tiles.annotation.TilesDefinitions;
14  import org.apache.struts2.tiles.annotation.TilesPutAttribute;
15  
16  import de.tivsource.ejb3plugin.InjectEJB;
17  import de.tivsource.page.dao.appointment.AppointmentDaoLocal;
18  import de.tivsource.page.dao.page.PageDaoLocal;
19  import de.tivsource.page.dao.property.PropertyDaoLocal;
20  import de.tivsource.page.entity.appointment.Appointment;
21  import de.tivsource.page.entity.page.Page;
22  import de.tivsource.page.user.actions.EmptyAction;
23  
24  @TilesDefinitions({
25    @TilesDefinition(name="appointment", extend = "userTemplate", putAttributes = {
26      @TilesPutAttribute(name = "meta",       value = "/WEB-INF/tiles/active/meta/appointment.jsp"),
27      @TilesPutAttribute(name = "twitter",    value = "/WEB-INF/tiles/active/twitter/content.jsp"),
28      @TilesPutAttribute(name = "content",    value = "/WEB-INF/tiles/active/view/appointment/appointment.jsp")
29    })
30  })
31  public class AppointmentAction extends EmptyAction {
32  
33      /**
34       * Serial Version UID.
35       */
36  	private static final long serialVersionUID = 6773842640719364262L;
37  
38  	/**
39       * Statischer Logger der Klasse.
40       */
41      private static final Logger LOGGER = LogManager.getLogger(AppointmentAction.class);
42  
43      @InjectEJB(name = "PageDao")
44      private PageDaoLocal pageDaoLocal;
45  
46      @InjectEJB(name="PropertyDao")
47      private PropertyDaoLocal propertyDaoLocal;
48  
49      @InjectEJB(name="AppointmentDao")
50      private AppointmentDaoLocal appointmentDaoLocal;
51  
52      private Appointment appointment;
53  
54      private String appointmentUuid;
55      
56      private Page page;
57  
58      @Override
59      @Actions({
60          @Action(value = "*/index", results = {
61              @Result(name = "success", type = "tiles", location = "appointment"),
62              @Result(name = "input", type = "redirectAction", location = "index.html", params={"namespace", "/"}),
63              @Result(name = "error", type = "redirectAction", location = "index.html", params={"namespace", "/"})
64          })
65      })
66      public String execute() throws Exception {
67          LOGGER.info("execute() aufgerufen.");
68  
69          // Hole Action Locale
70          this.getLanguageFromActionContext();
71  
72          appointmentUuid = ServletActionContext.getRequest().getServletPath();
73          LOGGER.info("Appointment Uuid: " + appointmentUuid);
74  
75          // /gallery/painting/index.html?page=1&request_locale=de
76          
77          
78          appointmentUuid = appointmentUuid.replaceAll("/index.html", "");
79          appointmentUuid = appointmentUuid.replaceAll("/appointment/", "");
80              
81          LOGGER.info("Appointment Uuid: " + appointmentUuid);
82  
83          /*
84           * Wenn die Appointment Uuid keine nicht erlaubten Zeichen enthält und es
85           * das Appointment Objekt mit der Uuid gibt dann wird der Block ausgeführt.
86           */
87          if (isValid(appointmentUuid) && appointmentDaoLocal.isAppointmentUuid(appointmentUuid)) {
88              LOGGER.info("gültige Appointment Uuid.");
89              appointment = appointmentDaoLocal.findByUuid(appointmentUuid);
90              
91              /*
92               * Wenn das Appointment Objekt sichbar sein soll und auch schon das
93               * Anzeigedtaum erreicht hat wird dieser Block ausgefüht.
94               */
95              if(appointment.getVisible() && new Date().after(appointment.getVisibleFrom())) {
96                  // Setze Daten in ein Page Objekt
97                  setUpPage();
98  
99                  return SUCCESS;
100             }
101         }
102 
103         /*
104          * Wenn es die Seite nicht gibt oder es einen Manipulationsversuch
105          * gab.
106          */
107          return ERROR;
108     }// Ende execute()
109 
110     @Override
111     public Page getPage() {
112         return page;
113     }
114 
115     public Appointment getAppointment() {
116         return appointment;
117     }
118 
119     private Boolean isValid(String input) {
120         if (Pattern.matches("[abcdef0-9-]*", input)) {
121             return true;
122         } else {
123             return false;
124         }
125     }
126 
127     private void setUpPage() {
128         page = new Page();
129         page.setDescriptionMap(appointment.getDescriptionMap());
130         page.setPicture(appointment.getPicture());
131         page.setPictureOnPage(appointment.getPictureOnPage());
132         page.setCssGroup(appointment.getCssGroup());
133     }
134 
135 }// Ende class