Subversion Repositories WebE

Rev

Rev 26 | Rev 34 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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