View Javadoc

1   package de.tivsource.page.admin.actions.others.companion;
2   
3   import java.util.Date;
4   import java.util.List;
5   import java.util.UUID;
6   
7   import org.apache.logging.log4j.LogManager;
8   import org.apache.logging.log4j.Logger;
9   import org.apache.struts2.ServletActionContext;
10  import org.apache.struts2.convention.annotation.Action;
11  import org.apache.struts2.convention.annotation.Actions;
12  import org.apache.struts2.convention.annotation.Result;
13  import org.apache.struts2.tiles.annotation.TilesDefinition;
14  import org.apache.struts2.tiles.annotation.TilesDefinitions;
15  import org.apache.struts2.tiles.annotation.TilesPutAttribute;
16  
17  import de.tivsource.ejb3plugin.InjectEJB;
18  import de.tivsource.page.admin.actions.EmptyAction;
19  import de.tivsource.page.dao.companion.CompanionDaoLocal;
20  import de.tivsource.page.dao.companion.CompanionGroupDaoLocal;
21  import de.tivsource.page.entity.companion.Companion;
22  import de.tivsource.page.entity.companion.CompanionGroup;
23  
24  /**
25   * 
26   * @author Marc Michele
27   *
28   */
29  @TilesDefinitions({
30    @TilesDefinition(name="companionAddForm",  extend = "adminTemplate", putAttributes = {
31      @TilesPutAttribute(name = "meta",       value = "/WEB-INF/tiles/active/meta/chosen.jsp"),
32      @TilesPutAttribute(name = "navigation", value = "/WEB-INF/tiles/active/navigation/others.jsp"),
33      @TilesPutAttribute(name = "content",    value = "/WEB-INF/tiles/active/view/companion/add_form.jsp")
34    })
35  })
36  public class AddAction extends EmptyAction {
37  
38  	/**
39  	 * Serial Version UID.
40  	 */
41      private static final long serialVersionUID = -6268903742931993162L;
42  
43      /**
44       * Statischer Logger der Klasse.
45       */
46      private static final Logger LOGGER = LogManager.getLogger(AddAction.class);
47  
48      @InjectEJB(name="CompanionDao")
49      private CompanionDaoLocal companionDaoLocal;
50  
51      @InjectEJB(name="CompanionGroupDao")
52      private CompanionGroupDaoLocal companionGroupDaoLocal;
53  
54      private Companion companion;
55  
56      public Companion getCompanion() {
57          return companion;
58      }
59  
60      public void setCompanion(Companion companion) {
61          this.companion = companion;
62      }
63  
64  	@Override
65      @Actions({
66          @Action(
67          		value = "add", 
68          		results = { 
69          				@Result(name = "success", type = "redirectAction", location = "index.html"),
70          				@Result(name = "input", type="tiles", location = "companionAddForm"),
71          				@Result(name = "error", type="tiles", location = "companionAddError")
72          				}
73          )
74      })
75      public String execute() throws Exception {
76      	LOGGER.info("execute() aufgerufen.");
77  
78          String remoteUser    = ServletActionContext.getRequest().getRemoteUser();
79          String remoteAddress = ServletActionContext.getRequest().getRemoteAddr();
80  
81      	if(companion != null) {
82      	    companion.setUuid(UUID.randomUUID().toString());
83      	    companion.setModified(new Date());
84      	    companion.setCreated(new Date());
85      	    companion.setModifiedBy(remoteUser);
86      	    companion.setModifiedAddress(remoteAddress);
87      	    
88      		companionDaoLocal.merge(companion);
89  
90              return SUCCESS;
91      	}
92      	else {
93      		return ERROR;
94      	}
95      	
96      	
97      }// Ende execute()
98  
99      public List<CompanionGroup> getCompanionGroupList() {
100         return companionGroupDaoLocal.findAll(0, companionGroupDaoLocal.countAll());
101     }
102 
103 }// Ende class