Subversion Repositories WebE

Rev

Rev 27 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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