Subversion Repositories WebE

Rev

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