Subversion Repositories WebE

Rev

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

Rev 31 Rev 33
Line 1... Line 1...
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.Date;
4
import java.util.List;
5
import java.util.List;
-
 
6
import java.util.Map;
5
7
6
import javax.servlet.http.HttpServletRequest;
8
import javax.servlet.http.HttpServletRequest;
7
9
8
import org.apache.struts2.StrutsStatics;
10
import org.apache.struts2.StrutsStatics;
9
11
10
import ch.ffhs.webE.dao.TermDAO;
-
 
11
import ch.ffhs.webE.dao.TermDAOImpl;
12
import ch.ffhs.webE.dao.TermDAOImpl;
-
 
13
import ch.ffhs.webE.dao.UserDAOImpl;
-
 
14
import ch.ffhs.webE.domain.ObjectEntity;
-
 
15
import ch.ffhs.webE.domain.ObjectType;
12
import ch.ffhs.webE.domain.Term;
16
import ch.ffhs.webE.domain.Term;
-
 
17
import ch.ffhs.webE.domain.User;
13
18
14
import com.opensymphony.xwork2.Action;
19
import com.opensymphony.xwork2.Action;
15
import com.opensymphony.xwork2.ActionContext;
20
import com.opensymphony.xwork2.ActionContext;
16
import com.opensymphony.xwork2.ActionSupport;
21
import com.opensymphony.xwork2.ActionSupport;
17
import com.opensymphony.xwork2.ModelDriven;
22
import com.opensymphony.xwork2.ModelDriven;
Line 21... Line 26...
21
 *
26
 *
22
 * @author Thomas Lahn
27
 * @author Thomas Lahn
23
 */
28
 */
24
public class TermAction extends ActionSupport implements ModelDriven<Term>
29
public class TermAction extends ActionSupport implements ModelDriven<Term>
25
{
30
{
26
  private static final long serialVersionUID = -6659925652584240539L;
31
  private static final long serialVersionUID = 1L;
27
32
28
  private Term term = new Term();
33
  private Term term = new Term();
29
  private List<Term> termList = new ArrayList<Term>();
34
  private List<Term> termList = new ArrayList<Term>();
30
  private final TermDAO termDAO = new TermDAOImpl();
35
  private final TermDAOImpl termDAO = new TermDAOImpl();
-
 
36
  private final UserDAOImpl userDAO = new UserDAOImpl();
-
 
37
-
 
38
  /**
-
 
39
   * Session object
-
 
40
   */
-
 
41
  Map<String, Object> session = ActionContext.getContext().getSession();
31
42
32
  /*
43
  /*
33
   * (non-Javadoc)
44
   * (non-Javadoc)
34
   *
45
   *
35
   * @see com.opensymphony.xwork2.ModelDriven#getModel()
46
   * @see com.opensymphony.xwork2.ModelDriven#getModel()
Line 42... Line 53...
42
  /**
53
  /**
43
   * Executes the DB query to save the user
54
   * Executes the DB query to save the user
44
   *
55
   *
45
   * @return {@link Action#SUCCESS}
56
   * @return {@link Action#SUCCESS}
46
   */
57
   */
47
  public String addOrUpdate()
58
  public String add()
48
  {
59
  {
-
 
60
    User user = this.userDAO.searchUsername((String) this.session
-
 
61
        .get("username"));
-
 
62
    ObjectEntity obj = new ObjectEntity(user, new ObjectType(ObjectType.TERM),
-
 
63
        user, null, new Date(), false, this.term, null, null);
-
 
64
    this.term.setObject(obj);
49
    this.termDAO.saveOrUpdate(this.term);
65
    if (this.termDAO.saveOrUpdate(this.term))
-
 
66
    {
50
    return Action.SUCCESS;
67
      return Action.SUCCESS;
-
 
68
    }
-
 
69
-
 
70
    return Action.ERROR;
51
  }
71
  }
52
72
53
  /**
73
  /**
54
   * DB query for userList
74
   * DB query for term list
55
   *
75
   *
56
   * @return SUCCESS
76
   * @return SUCCESS
57
   */
77
   */
58
  public String list()
78
  public String list()
59
  {
79
  {
Line 69... Line 89...
69
  {
89
  {
70
    int id = this.getIdParameter();
90
    int id = this.getIdParameter();
71
91
72
    if (id > 0)
92
    if (id > 0)
73
    {
93
    {
74
      this.term = this.termDAO.listTermById(id);
94
      this.term = this.termDAO.getTermById(id);
75
      return Action.SUCCESS;
95
      if (this.term != null)
76
    }
96
      {
77
    else
97
        return Action.SUCCESS;
78
    {
98
      }
79
      return Action.ERROR;
-
 
80
    }
99
    }
-
 
100
-
 
101
    return Action.ERROR;
81
  }
102
  }
82
103
83
  /**
104
  /**
84
   * Gets the ID Parameter for update / delete requests
105
   * Gets the ID Parameter for update / delete requests
85
   *
106
   *