Rev 26 | Rev 34 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
26 | moos | 1 | package ch.ffhs.webE.action; |
2 | |||
3 | import java.util.ArrayList; |
||
4 | import java.util.List; |
||
5 | |||
6 | import javax.servlet.http.HttpServletRequest; |
||
7 | |||
8 | import org.apache.struts2.ServletActionContext; |
||
9 | |||
10 | import ch.ffhs.webE.dao.RelationshipTypeDAO; |
||
11 | import ch.ffhs.webE.dao.RelationshipTypeDAOImpl; |
||
12 | import ch.ffhs.webE.domain.RelationshipType; |
||
13 | |||
14 | import com.opensymphony.xwork2.ActionContext; |
||
15 | import com.opensymphony.xwork2.ActionSupport; |
||
16 | import com.opensymphony.xwork2.ModelDriven; |
||
17 | |||
18 | public class RelationshipTypeAction extends ActionSupport implements |
||
19 | ModelDriven<RelationshipType> |
||
20 | { |
||
21 | |||
22 | private static final long serialVersionUID = -3644691864156792139L; |
||
23 | |||
24 | private RelationshipType relType = new RelationshipType(); |
||
25 | private List<RelationshipType> relTypeList = new ArrayList<RelationshipType>(); |
||
26 | private RelationshipTypeDAO relTypeDAO = new RelationshipTypeDAOImpl(); |
||
27 | |||
28 | @Override |
||
29 | public RelationshipType getModel() |
||
30 | { |
||
31 | return relType; |
||
32 | } |
||
33 | |||
27 | moos | 34 | public String addOrUpdate() |
26 | moos | 35 | { |
27 | moos | 36 | relTypeDAO.saveOrUpdateRelType(relType); |
26 | moos | 37 | return SUCCESS; |
38 | } |
||
39 | |||
40 | public String list() |
||
41 | { |
||
42 | relTypeList = relTypeDAO.listRelationshipTypes(); |
||
43 | return SUCCESS; |
||
44 | } |
||
27 | moos | 45 | |
46 | public String edit() |
||
47 | { |
||
48 | int id = getIdParameter(); |
||
26 | moos | 49 | |
27 | moos | 50 | if (id > 0) |
51 | { |
||
52 | relType = relTypeDAO.listRelTypeById(id); |
||
53 | return SUCCESS; |
||
54 | } |
||
55 | else |
||
56 | { |
||
57 | return ERROR; |
||
58 | } |
||
59 | } |
||
60 | |||
26 | moos | 61 | /** |
27 | moos | 62 | * Gets the ID Parameter for update / delete requests |
26 | moos | 63 | * |
27 | moos | 64 | * @return int from the ID request. If not set or wrong, it gives back -1 |
26 | moos | 65 | */ |
27 | moos | 66 | private int getIdParameter() |
26 | moos | 67 | { |
68 | HttpServletRequest request = (HttpServletRequest) ActionContext |
||
69 | .getContext().get(ServletActionContext.HTTP_REQUEST); |
||
70 | |||
27 | moos | 71 | int id = -1; |
26 | moos | 72 | try |
73 | { |
||
74 | id = Integer.parseInt(request.getParameter("id")); |
||
75 | } |
||
76 | catch (Exception e) |
||
77 | { |
||
27 | moos | 78 | // TODO: Logging - wrong parameter set |
26 | moos | 79 | } |
80 | |||
27 | moos | 81 | return id; |
82 | } |
||
83 | |||
84 | /** |
||
85 | * deletes a relationshipType, gets the ID from the id parameter that was |
||
86 | * submitted |
||
87 | * |
||
88 | * @return String - either success or error |
||
89 | */ |
||
90 | public String delete() |
||
91 | { |
||
92 | int id = getIdParameter(); |
||
93 | |||
26 | moos | 94 | // Check for malicious ID values |
95 | if (id > 0) |
||
96 | { |
||
97 | relTypeDAO.deleteRelationshipType(id); |
||
98 | return SUCCESS; |
||
99 | } |
||
100 | else |
||
101 | { |
||
102 | return ERROR; |
||
103 | } |
||
104 | } |
||
105 | |||
106 | /* |
||
107 | * Getters and setters |
||
108 | */ |
||
109 | |||
110 | public RelationshipType getRelType() |
||
111 | { |
||
112 | return relType; |
||
113 | } |
||
114 | |||
115 | public void setRelType(RelationshipType relType) |
||
116 | { |
||
117 | this.relType = relType; |
||
118 | } |
||
119 | |||
120 | public List<RelationshipType> getRelTypeList() |
||
121 | { |
||
122 | return relTypeList; |
||
123 | } |
||
124 | |||
125 | public void setRelTypeList(List<RelationshipType> relTypeList) |
||
126 | { |
||
127 | this.relTypeList = relTypeList; |
||
128 | } |
||
129 | } |