View Javadoc

1   package de.tivsource.page.admin.actions.others.appointment;
2   
3   import java.util.Date;
4   
5   import org.apache.logging.log4j.LogManager;
6   import org.apache.logging.log4j.Logger;
7   import org.apache.struts2.ServletActionContext;
8   import org.apache.struts2.convention.annotation.Action;
9   import org.apache.struts2.convention.annotation.Actions;
10  import org.apache.struts2.convention.annotation.Result;
11  import org.apache.struts2.tiles.annotation.TilesDefinition;
12  import org.apache.struts2.tiles.annotation.TilesDefinitions;
13  import org.apache.struts2.tiles.annotation.TilesPutAttribute;
14  
15  import de.tivsource.ejb3plugin.InjectEJB;
16  import de.tivsource.page.admin.actions.EmptyAction;
17  import de.tivsource.page.dao.appointment.AppointmentDaoLocal;
18  import de.tivsource.page.entity.appointment.Appointment;
19  
20  /**
21   * 
22   * @author Marc Michele
23   *
24   */
25  @TilesDefinitions({
26    @TilesDefinition(name="appointmentDeleteForm", extend = "adminTemplate", putAttributes = {
27      @TilesPutAttribute(name = "navigation", value = "/WEB-INF/tiles/active/navigation/others.jsp"),
28      @TilesPutAttribute(name = "content",    value = "/WEB-INF/tiles/active/view/appointment/delete_form.jsp")
29    }),
30    @TilesDefinition(name="appointmentDeleteError", extend = "adminTemplate", putAttributes = {
31      @TilesPutAttribute(name = "navigation", value = "/WEB-INF/tiles/active/navigation/others.jsp"),
32      @TilesPutAttribute(name = "content",    value = "/WEB-INF/tiles/active/view/appointment/delete_error.jsp")
33    })
34  })
35  public class DeleteAction extends EmptyAction {
36  
37      /**
38       * Serial Version UID.
39       */
40      private static final long serialVersionUID = 4018486413901664427L;
41  
42      /**
43       * Statischer Logger der Klasse.
44       */
45      private static final Logger LOGGER = LogManager.getLogger(DeleteAction.class);
46  
47      @InjectEJB(name="AppointmentDao")
48      private AppointmentDaoLocal appointmentDaoLocal;
49  
50      private Appointment appointment;
51  
52      public Appointment getAppointment() {
53          return appointment;
54      }
55  
56      public void setAppointment(Appointment appointment) {
57          this.appointment = appointment;
58      }
59  
60  	@Override
61      @Actions({
62          @Action(
63          		value = "delete", 
64          		results = { 
65          				@Result(name = "success", type = "redirectAction", location = "index.html"),
66          				@Result(name = "input", type="tiles", location = "appointmentDeleteForm"),
67          				@Result(name = "error", type="tiles", location = "appointmentDeleteError")
68          				}
69          )
70      })
71      public String execute() throws Exception {
72      	LOGGER.info("execute() aufgerufen.");
73  
74          String remoteUser    = ServletActionContext.getRequest().getRemoteUser();
75          String remoteAddress = ServletActionContext.getRequest().getRemoteAddr();
76  
77      	if(appointment != null) {
78      	    Appointment dbAppointment = appointmentDaoLocal.findByUuid(appointment.getUuid());
79      		dbAppointment.setModified(new Date());
80      		dbAppointment.setModifiedBy(remoteUser);
81      		dbAppointment.setModifiedAddress(remoteAddress);
82      		appointmentDaoLocal.merge(dbAppointment);
83      		appointmentDaoLocal.delete(dbAppointment);
84              return SUCCESS;
85      	}
86      	else {
87      		return ERROR;
88      	}
89      	
90      	
91      }// Ende execute()
92  	
93  }// Ende class