Rev 35 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 35 | Rev 37 | ||
---|---|---|---|
Line 2... | Line 2... | ||
2 | 2 | ||
3 | import java.util.ArrayList; |
3 | import java.util.ArrayList; |
4 | import java.util.Date; |
4 | import java.util.Date; |
5 | import java.util.List; |
5 | import java.util.List; |
6 | import java.util.Map; |
6 | import java.util.Map; |
- | 7 | import java.util.Set; |
|
7 | 8 | ||
8 | import javax.servlet.http.HttpServletRequest; |
9 | import javax.servlet.http.HttpServletRequest; |
9 | 10 | ||
10 | import org.apache.struts2.StrutsStatics; |
11 | import org.apache.struts2.StrutsStatics; |
11 | 12 | ||
- | 13 | import ch.ffhs.webE.dao.HistoryDAO; |
|
12 | import ch.ffhs.webE.dao.TermDAOImpl; |
14 | import ch.ffhs.webE.dao.TermDAO; |
13 | import ch.ffhs.webE.dao.UserDAOImpl; |
15 | import ch.ffhs.webE.dao.UserDAO; |
- | 16 | import ch.ffhs.webE.domain.ActionType; |
|
- | 17 | import ch.ffhs.webE.domain.History; |
|
14 | import ch.ffhs.webE.domain.ObjectEntity; |
18 | import ch.ffhs.webE.domain.ObjectEntity; |
15 | import ch.ffhs.webE.domain.ObjectType; |
19 | import ch.ffhs.webE.domain.ObjectType; |
16 | import ch.ffhs.webE.domain.Term; |
20 | import ch.ffhs.webE.domain.Term; |
17 | import ch.ffhs.webE.domain.User; |
21 | import ch.ffhs.webE.domain.User; |
18 | 22 | ||
Line 30... | Line 34... | ||
30 | {
|
34 | {
|
31 | private static final long serialVersionUID = 1L; |
35 | private static final long serialVersionUID = 1L; |
32 | 36 | ||
33 | private Term term = new Term(); |
37 | private Term term = new Term(); |
34 | private List<Term> termList = new ArrayList<Term>(); |
38 | private List<Term> termList = new ArrayList<Term>(); |
35 | private final TermDAOImpl termDAO = new TermDAOImpl(); |
39 | private final TermDAO termDAO = new TermDAO(); |
36 | private final UserDAOImpl userDAO = new UserDAOImpl(); |
40 | private final UserDAO userDAO = new UserDAO(); |
37 | 41 | ||
38 | /**
|
42 | /**
|
39 | * Session object
|
43 | * Session object
|
40 | */
|
44 | */
|
41 | Map<String, Object> session = ActionContext.getContext().getSession(); |
45 | Map<String, Object> session = ActionContext.getContext().getSession(); |
Line 57... | Line 61... | ||
57 | /**
|
61 | /**
|
58 | * The term that was just saved (added, renamed)
|
62 | * The term that was just saved (added, renamed)
|
59 | */
|
63 | */
|
60 | public Term savedTerm; |
64 | public Term savedTerm; |
61 | 65 | ||
- | 66 | private final HistoryDAO historyDAO = new HistoryDAO(); |
|
- | 67 | ||
- | 68 | private Set<History> history; |
|
- | 69 | ||
62 | /*
|
70 | /*
|
63 | * (non-Javadoc)
|
71 | * (non-Javadoc)
|
64 | *
|
72 | *
|
65 | * @see com.opensymphony.xwork2.ModelDriven#getModel()
|
73 | * @see com.opensymphony.xwork2.ModelDriven#getModel()
|
66 | */
|
74 | */
|
Line 74... | Line 82... | ||
74 | *
|
82 | *
|
75 | * @return SUCCESS
|
83 | * @return SUCCESS
|
76 | */
|
84 | */
|
77 | public String list() |
85 | public String list() |
78 | {
|
86 | {
|
79 | this.termList = this.termDAO.getTerms(); |
87 | this.termList = this.termDAO.getList(); |
80 | return Action.SUCCESS; |
88 | return Action.SUCCESS; |
81 | }
|
89 | }
|
82 | 90 | ||
83 | /**
|
91 | /**
|
84 | * Executes the DB query to save the user
|
92 | * Executes the DB query to save the user
|
85 | *
|
93 | *
|
86 | * @return {@link Action#SUCCESS}
|
94 | * @return {@link Action#SUCCESS}
|
87 | */
|
95 | */
|
88 | public String save() |
96 | public String save() |
89 | {
|
97 | {
|
90 | User user = this.userDAO.searchUsername((String) this.session |
98 | User user = this.userDAO.getByUsername((String) this.session |
91 | .get("username")); |
99 | .get("username")); |
- | 100 | Date now = new Date(); |
|
- | 101 | ObjectEntity obj;
|
|
92 | 102 | ||
- | 103 | int action = 0; |
|
93 | if ("false".equals(this.request.getParameter("edit"))) |
104 | if ("false".equals(this.request.getParameter("edit"))) |
94 | {
|
105 | {
|
95 | /* Add a new term */
|
106 | /* Add a new term */
|
96 | ObjectEntity obj = new ObjectEntity(user, |
- | |
97 | new ObjectType(ObjectType.TERM), user, null, new Date(), false, |
107 | obj = new ObjectEntity(user, new ObjectType(ObjectType.TERM), user, null, |
98 | this.term, null, null); |
108 | now, false, this.term, null, null); |
- | 109 | ||
99 | this.term.setObject(obj); |
110 | this.term.setObject(obj); |
100 | this.added = true; |
111 | this.added = true; |
- | 112 | action = ActionType.ADD; |
|
- | 113 | }
|
|
- | 114 | else
|
|
- | 115 | {
|
|
- | 116 | obj = new ObjectEntity(); |
|
- | 117 | obj.setId(this.term.getObjectId()); |
|
- | 118 | action = ActionType.RENAME; |
|
101 | }
|
119 | }
|
102 | - | ||
103 | this.edit = false; |
- | |
104 | 120 | ||
105 | String result = Action.SUCCESS; |
121 | String result = Action.SUCCESS; |
106 | if (!this.termDAO.saveOrUpdate(this.term)) |
122 | if (this.termDAO.saveOrUpdate(this.term)) |
- | 123 | {
|
|
- | 124 | String comment = this.request.getParameter("comment"); |
|
- | 125 | ||
- | 126 | History historyRecord = new History(user, new ActionType(action), obj, |
|
- | 127 | this.term.getName(), comment, now); |
|
- | 128 | ||
- | 129 | this.historyDAO.saveOrUpdate(historyRecord); |
|
- | 130 | }
|
|
- | 131 | else
|
|
107 | {
|
132 | {
|
108 | result = Action.ERROR; |
133 | result = Action.ERROR; |
109 | }
|
134 | }
|
110 | 135 | ||
111 | this.savedTerm = this.term; |
136 | this.savedTerm = this.term; |
Line 125... | Line 150... | ||
125 | int id = this.getIdParameter(); |
150 | int id = this.getIdParameter(); |
126 | 151 | ||
127 | String result = Action.ERROR; |
152 | String result = Action.ERROR; |
128 | if (id > 0) |
153 | if (id > 0) |
129 | {
|
154 | {
|
130 | this.term = this.termDAO.getTermById(id); |
155 | this.term = this.termDAO.getById(id); |
131 | if (this.term != null) |
156 | if (this.term != null) |
132 | {
|
157 | {
|
133 | this.edit = true; |
158 | this.edit = true; |
134 | result = Action.SUCCESS; |
159 | result = Action.SUCCESS; |
135 | }
|
160 | }
|
Line 153... | Line 178... | ||
153 | 178 | ||
154 | /* Check for malicious ID values */
|
179 | /* Check for malicious ID values */
|
155 | String result = Action.SUCCESS; |
180 | String result = Action.SUCCESS; |
156 | if (id > 0) |
181 | if (id > 0) |
157 | {
|
182 | {
|
158 | this.termDAO.deleteTerm(id); |
183 | this.termDAO.delete(id); |
159 | }
|
184 | }
|
160 | else
|
185 | else
|
161 | {
|
186 | {
|
162 | result = Action.ERROR; |
187 | result = Action.ERROR; |
163 | }
|
188 | }
|
Line 220... | Line 245... | ||
220 | */
|
245 | */
|
221 | public void setTermList(List<Term> termList) |
246 | public void setTermList(List<Term> termList) |
222 | {
|
247 | {
|
223 | this.termList = termList; |
248 | this.termList = termList; |
224 | }
|
249 | }
|
- | 250 | ||
- | 251 | /**
|
|
- | 252 | * @return the histories
|
|
- | 253 | */
|
|
- | 254 | public Set<History> getHistories() |
|
- | 255 | {
|
|
- | 256 | return this.history; |
|
- | 257 | }
|
|
- | 258 | ||
- | 259 | /**
|
|
- | 260 | * @param histories
|
|
- | 261 | * the histories to set
|
|
- | 262 | */
|
|
- | 263 | public void setHistories(Set<History> histories) |
|
- | 264 | {
|
|
- | 265 | this.history = histories; |
|
- | 266 | }
|
|
225 | }
|
267 | }
|