Subversion Repositories WebE

Rev

Rev 34 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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