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