Subversion Repositories WebE

Rev

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

Rev 34 Rev 35
Line 38... Line 38...
38
  /**
38
  /**
39
   * Session object
39
   * Session object
40
   */
40
   */
41
  Map<String, Object> session = ActionContext.getContext().getSession();
41
  Map<String, Object> session = ActionContext.getContext().getSession();
42
42
-
 
43
  /**
-
 
44
   * @var <code>true</code> if the term is edited/renamed, <code>false</code>
-
 
45
   *      otherwise
-
 
46
   */
-
 
47
  public boolean edit = false;
-
 
48
-
 
49
  /**
-
 
50
   * @var <code>true</code> if a term was added, <code>false</code> otherwise
-
 
51
   */
-
 
52
  public boolean added = false;
-
 
53
43
  private final HttpServletRequest request = (HttpServletRequest) ActionContext
54
  private final HttpServletRequest request = (HttpServletRequest) ActionContext
44
      .getContext().get(StrutsStatics.HTTP_REQUEST);
55
      .getContext().get(StrutsStatics.HTTP_REQUEST);
45
56
-
 
57
  /**
-
 
58
   * The term that was just saved (added, renamed)
-
 
59
   */
-
 
60
  public Term savedTerm;
-
 
61
46
  /*
62
  /*
47
   * (non-Javadoc)
63
   * (non-Javadoc)
48
   *
64
   *
49
   * @see com.opensymphony.xwork2.ModelDriven#getModel()
65
   * @see com.opensymphony.xwork2.ModelDriven#getModel()
50
   */
66
   */
Line 52... Line 68...
52
  {
68
  {
53
    return this.term;
69
    return this.term;
54
  }
70
  }
55
71
56
  /**
72
  /**
-
 
73
   * DB query for term list
-
 
74
   *
-
 
75
   * @return SUCCESS
-
 
76
   */
-
 
77
  public String list()
-
 
78
  {
-
 
79
    this.termList = this.termDAO.getTerms();
-
 
80
    return Action.SUCCESS;
-
 
81
  }
-
 
82
-
 
83
  /**
57
   * Executes the DB query to save the user
84
   * Executes the DB query to save the user
58
   *
85
   *
59
   * @return {@link Action#SUCCESS}
86
   * @return {@link Action#SUCCESS}
60
   */
87
   */
61
  public String save()
88
  public String save()
62
  {
89
  {
-
 
90
    User user = this.userDAO.searchUsername((String) this.session
-
 
91
        .get("username"));
-
 
92
63
    if (!"1".equals(this.request.getParameter("edit")))
93
    if ("false".equals(this.request.getParameter("edit")))
64
    {
94
    {
65
      User user = this.userDAO.searchUsername((String) this.session
-
 
66
          .get("username"));
95
      /* Add a new term */
67
      ObjectEntity obj = new ObjectEntity(user,
96
      ObjectEntity obj = new ObjectEntity(user,
68
          new ObjectType(ObjectType.TERM), user, null, new Date(), false,
97
          new ObjectType(ObjectType.TERM), user, null, new Date(), false,
69
          this.term, null, null);
98
          this.term, null, null);
70
      this.term.setObject(obj);
99
      this.term.setObject(obj);
-
 
100
      this.added = true;
71
    }
101
    }
72
102
-
 
103
    this.edit = false;
-
 
104
-
 
105
    String result = Action.SUCCESS;
73
    if (this.termDAO.saveOrUpdate(this.term))
106
    if (!this.termDAO.saveOrUpdate(this.term))
74
    {
107
    {
75
      return Action.SUCCESS;
108
      result = Action.ERROR;
76
    }
109
    }
77
110
78
    return Action.ERROR;
111
    this.savedTerm = this.term;
79
  }
112
    this.term = null;
80
113
81
  /**
-
 
82
   * DB query for term list
-
 
83
   *
-
 
84
   * @return SUCCESS
-
 
85
   */
-
 
86
  public String list()
114
    this.list();
87
  {
115
88
    this.termList = this.termDAO.getTerms();
-
 
89
    return Action.SUCCESS;
116
    return result;
90
  }
117
  }
91
118
92
  /**
119
  /**
93
   * @return {@link Action#SUCCESS} if <var>id</var> > 0, {@link Action#ERROR}
120
   * @return {@link Action#SUCCESS} if <var>id</var> > 0, {@link Action#ERROR}
94
   *         otherwise
121
   *         otherwise
95
   */
122
   */
96
  public String edit()
123
  public String edit()
97
  {
124
  {
98
    int id = this.getIdParameter();
125
    int id = this.getIdParameter();
99
126
-
 
127
    String result = Action.ERROR;
100
    if (id > 0)
128
    if (id > 0)
101
    {
129
    {
102
      this.term = this.termDAO.getTermById(id);
130
      this.term = this.termDAO.getTermById(id);
103
      if (this.term != null)
131
      if (this.term != null)
104
      {
132
      {
105
        this.term.edit = true;
133
        this.edit = true;
106
        return Action.SUCCESS;
134
        result = Action.SUCCESS;
107
      }
135
      }
108
    }
136
    }
109
137
110
    return Action.ERROR;
-
 
111
  }
-
 
112
-
 
113
  /**
-
 
114
   * Gets the ID Parameter for update / delete requests
-
 
115
   *
-
 
116
   * @return int from the ID request. If not set or wrong, it gives back -1
-
 
117
   */
-
 
118
  private int getIdParameter()
-
 
119
  {
-
 
120
    int id = -1;
138
    this.list();
121
    try
-
 
122
    {
-
 
123
      id = Integer.parseInt(this.request.getParameter("id")); //$NON-NLS-1$
-
 
124
    }
-
 
125
    catch (Exception e)
-
 
126
    {
-
 
127
      /* TODO: Logging - wrong parameter set */
-
 
128
    }
-
 
129
139
130
    return id;
140
    return result;
131
  }
141
  }
132
142
133
  /**
143
  /**
134
   * deletes a user, gets the ID from the "id" parameter that was submitted with
144
   * deletes a term, gets the ID from the "id" parameter that was submitted with
135
   * the HTTP request
145
   * the HTTP request
136
   *
146
   *
137
   * @return String - either SUCCESS or ERROR constant
147
   * @return String - either SUCCESS or ERROR constant
138
   */
148
   */
139
  public String delete()
149
  public String delete()
140
  {
150
  {
141
151
142
    int id = this.getIdParameter();
152
    int id = this.getIdParameter();
143
153
144
    /* Check for malicious ID values */
154
    /* Check for malicious ID values */
-
 
155
    String result = Action.SUCCESS;
145
    if (id > 0)
156
    if (id > 0)
146
    {
157
    {
147
      this.termDAO.deleteTerm(id);
158
      this.termDAO.deleteTerm(id);
148
      return Action.SUCCESS;
-
 
149
    }
159
    }
150
    else
160
    else
151
    {
161
    {
152
      return Action.ERROR;
162
      result = Action.ERROR;
153
    }
163
    }
-
 
164
-
 
165
    this.list();
-
 
166
-
 
167
    return result;
154
  }
168
  }
155
169
156
  /*
170
  /**
157
   * Standard getters and setters
171
   * Gets the ID Parameter for update / delete requests
-
 
172
   *
-
 
173
   * @return int from the ID request. If not set or wrong, it gives back -1
158
   */
174
   */
-
 
175
  private int getIdParameter()
-
 
176
  {
-
 
177
    int id = -1;
-
 
178
    try
-
 
179
    {
-
 
180
      id = Integer.parseInt(this.request.getParameter("id")); //$NON-NLS-1$
-
 
181
    }
-
 
182
    catch (Exception e)
-
 
183
    {
-
 
184
      /* TODO: Logging - wrong parameter set */
-
 
185
    }
-
 
186
-
 
187
    return id;
-
 
188
  }
-
 
189
-
 
190
  /* Standard getters and setters */
159
191
160
  /**
192
  /**
161
   * @return The term edited with this instance
193
   * @return The term edited with this instance
162
   */
194
   */
163
  public Term getTerm()
195
  public Term getTerm()