View Javadoc

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