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.RelationshipDAOImpl; |
14 | import ch.ffhs.webE.dao.RelationshipDAO; |
13 | import ch.ffhs.webE.dao.RelationshipTypeDAOImpl; |
15 | import ch.ffhs.webE.dao.RelationshipTypeDAO; |
14 | import ch.ffhs.webE.dao.TermDAOImpl; |
16 | import ch.ffhs.webE.dao.TermDAO; |
15 | import ch.ffhs.webE.dao.UserDAOImpl; |
17 | import ch.ffhs.webE.dao.UserDAO; |
- | 18 | import ch.ffhs.webE.domain.ActionType; |
|
- | 19 | import ch.ffhs.webE.domain.History; |
|
16 | import ch.ffhs.webE.domain.ObjectEntity; |
20 | import ch.ffhs.webE.domain.ObjectEntity; |
17 | import ch.ffhs.webE.domain.ObjectType; |
21 | import ch.ffhs.webE.domain.ObjectType; |
18 | import ch.ffhs.webE.domain.Relationship; |
22 | import ch.ffhs.webE.domain.Relationship; |
19 | import ch.ffhs.webE.domain.RelationshipType; |
23 | import ch.ffhs.webE.domain.RelationshipType; |
20 | import ch.ffhs.webE.domain.Term; |
24 | import ch.ffhs.webE.domain.Term; |
Line 34... | Line 38... | ||
34 | ModelDriven<Relationship> |
38 | ModelDriven<Relationship> |
35 | {
|
39 | {
|
36 | private static final long serialVersionUID = 1L; |
40 | private static final long serialVersionUID = 1L; |
37 | 41 | ||
38 | private List<RelationshipType> relationshipTypes = new ArrayList<RelationshipType>(); |
42 | private List<RelationshipType> relationshipTypes = new ArrayList<RelationshipType>(); |
39 | private final RelationshipTypeDAOImpl relationshipTypeDAO = new RelationshipTypeDAOImpl(); |
43 | private final RelationshipTypeDAO relationshipTypeDAO = new RelationshipTypeDAO(); |
- | 44 | ||
40 | private List<Term> terms = new ArrayList<Term>(); |
45 | private List<Term> terms = new ArrayList<Term>(); |
41 | private final TermDAOImpl termDAO = new TermDAOImpl(); |
46 | private final TermDAO termDAO = new TermDAO(); |
- | 47 | ||
42 | private List<Relationship> relationshipList = new ArrayList<Relationship>(); |
48 | private List<Relationship> relationshipList = new ArrayList<Relationship>(); |
43 | private final RelationshipDAOImpl relationshipDAO = new RelationshipDAOImpl(); |
- | |
44 | private final UserDAOImpl userDAO = new UserDAOImpl(); |
- | |
45 | private Relationship relationship = new Relationship(); |
49 | private Relationship relationship = new Relationship(); |
46 | 50 | ||
47 | /**
|
51 | /**
|
- | 52 | * The term that was just saved (added, renamed)
|
|
- | 53 | */
|
|
- | 54 | private Relationship modifiedRelationship; |
|
- | 55 | ||
- | 56 | private final RelationshipDAO relationshipDAO = new RelationshipDAO(); |
|
- | 57 | ||
- | 58 | private final UserDAO userDAO = new UserDAO(); |
|
- | 59 | ||
- | 60 | private Set<History> history; |
|
- | 61 | private final HistoryDAO historyDAO = new HistoryDAO(); |
|
- | 62 | ||
- | 63 | /**
|
|
48 | * Session object
|
64 | * Session object
|
49 | */
|
65 | */
|
50 | Map<String, Object> session = ActionContext.getContext().getSession(); |
66 | Map<String, Object> session = ActionContext.getContext().getSession(); |
51 | 67 | ||
52 | /**
|
68 | /**
|
Line 62... | Line 78... | ||
62 | public boolean added = false; |
78 | public boolean added = false; |
63 | 79 | ||
64 | private final HttpServletRequest request = (HttpServletRequest) ActionContext |
80 | private final HttpServletRequest request = (HttpServletRequest) ActionContext |
65 | .getContext().get(StrutsStatics.HTTP_REQUEST); |
81 | .getContext().get(StrutsStatics.HTTP_REQUEST); |
66 | 82 | ||
67 | /**
|
- | |
68 | * The term that was just saved (added, renamed)
|
- | |
69 | */
|
- | |
70 | private Relationship modifiedRelationship; |
- | |
71 | - | ||
72 | /*
|
83 | /*
|
73 | * (non-Javadoc)
|
84 | * (non-Javadoc)
|
74 | *
|
85 | *
|
75 | * @see com.opensymphony.xwork2.ModelDriven#getModel()
|
86 | * @see com.opensymphony.xwork2.ModelDriven#getModel()
|
76 | */
|
87 | */
|
Line 84... | Line 95... | ||
84 | *
|
95 | *
|
85 | * @return SUCCESS
|
96 | * @return SUCCESS
|
86 | */
|
97 | */
|
87 | public String list() |
98 | public String list() |
88 | {
|
99 | {
|
89 | this.setTerms(this.termDAO.getTerms()); |
100 | this.setTerms(this.termDAO.getList()); |
90 | this.setRelationshipTypes(this.relationshipTypeDAO.getRelTypes()); |
101 | this.setRelationshipTypes(this.relationshipTypeDAO.getList()); |
91 | this.setRelationshipList(this.relationshipDAO.getRelationshipList()); |
102 | this.setRelationshipList(this.relationshipDAO.getList()); |
92 | return Action.SUCCESS; |
103 | return Action.SUCCESS; |
93 | }
|
104 | }
|
94 | 105 | ||
95 | /**
|
106 | /**
|
96 | * Executes the DB query to save the relationship
|
107 | * Executes the DB query to save the relationship
|
97 | *
|
108 | *
|
98 | * @return {@link Action#SUCCESS}
|
109 | * @return {@link Action#SUCCESS}
|
99 | */
|
110 | */
|
100 | public String save() |
111 | public String save() |
101 | {
|
112 | {
|
102 | this.relationship.setTermFrom(this.termDAO.getTermById(Integer |
113 | this.relationship.setTermFrom(this.termDAO.getById(Integer |
103 | .parseInt(this.request.getParameter("term1")))); |
114 | .parseInt(this.request.getParameter("term1")))); |
104 | this.relationship.setTermTo(this.termDAO.getTermById(Integer |
115 | this.relationship.setTermTo(this.termDAO.getById(Integer |
105 | .parseInt(this.request.getParameter("term2")))); |
116 | .parseInt(this.request.getParameter("term2")))); |
106 | this.relationship.setRelationshipType(this.relationshipTypeDAO |
117 | this.relationship.setRelationshipType(this.relationshipTypeDAO |
107 | .getRelTypeById(Integer.parseInt(this.request.getParameter("type")))); |
118 | .getById(Integer.parseInt(this.request.getParameter("type")))); |
108 | 119 | ||
109 | User user = this.userDAO.searchUsername((String) this.session |
120 | User user = this.userDAO.getByUsername((String) this.session |
110 | .get("username")); |
121 | .get("username")); |
- | 122 | Date now = new Date(); |
|
- | 123 | ObjectEntity obj;
|
|
- | 124 | int action = 0; |
|
111 | 125 | ||
112 | if ("false".equals(this.request.getParameter("edit"))) |
126 | if ("false".equals(this.request.getParameter("edit"))) |
113 | {
|
127 | {
|
114 | /* Add a new relationship */
|
128 | /* Add a new relationship */
|
115 | ObjectEntity obj = new ObjectEntity(user, new ObjectType( |
129 | obj = new ObjectEntity(user, new ObjectType(ObjectType.RELATIONSHIP), |
116 | ObjectType.RELATIONSHIP), user, null, new Date(), false, null, null, |
130 | user, null, new Date(), false, null, null, this.relationship); |
117 | this.relationship); |
- | |
118 | this.relationship.setObject(obj); |
131 | this.relationship.setObject(obj); |
119 | this.added = true; |
132 | this.added = true; |
- | 133 | action = ActionType.ADD; |
|
- | 134 | }
|
|
- | 135 | else
|
|
- | 136 | {
|
|
- | 137 | obj = new ObjectEntity(); |
|
- | 138 | obj.setId(this.relationship.getObjectId()); |
|
- | 139 | action = ActionType.MODIFY; |
|
120 | }
|
140 | }
|
121 | 141 | ||
122 | this.edit = false; |
142 | this.edit = false; |
123 | 143 | ||
124 | String result = Action.SUCCESS; |
144 | String result = Action.SUCCESS; |
125 | if (!this.relationshipDAO.saveOrUpdate(this.relationship)) |
145 | if (this.relationshipDAO.saveOrUpdate(this.relationship)) |
- | 146 | {
|
|
- | 147 | String comment = this.request.getParameter("comment"); |
|
- | 148 | ||
- | 149 | History historyRecord = new History(user, new ActionType(action), obj, |
|
- | 150 | "(" + this.relationship.getTermFrom().getName() + ") (" |
|
- | 151 | + this.relationship.getRelationshipType().getNameFrom() + ") (" |
|
- | 152 | + this.relationship.getTermTo().getName() + ")", comment, now); |
|
- | 153 | ||
- | 154 | this.historyDAO.saveOrUpdate(historyRecord); |
|
- | 155 | }
|
|
- | 156 | else
|
|
126 | {
|
157 | {
|
127 | result = Action.ERROR; |
158 | result = Action.ERROR; |
128 | }
|
159 | }
|
129 | 160 | ||
130 | this.setModifiedRelationship(this.relationship); |
161 | this.setModifiedRelationship(this.relationship); |
Line 144... | Line 175... | ||
144 | int id = this.getIdParameter(); |
175 | int id = this.getIdParameter(); |
145 | 176 | ||
146 | String result = Action.ERROR; |
177 | String result = Action.ERROR; |
147 | if (id > 0) |
178 | if (id > 0) |
148 | {
|
179 | {
|
149 | this.setRelationship(this.relationshipDAO.getRelationshipById(id)); |
180 | this.setRelationship(this.relationshipDAO.getById(id)); |
150 | if (this.getRelationship() != null) |
181 | if (this.getRelationship() != null) |
151 | {
|
182 | {
|
152 | this.edit = true; |
183 | this.edit = true; |
153 | result = Action.SUCCESS; |
184 | result = Action.SUCCESS; |
154 | }
|
185 | }
|
Line 171... | Line 202... | ||
171 | 202 | ||
172 | /* Check for malicious ID values */
|
203 | /* Check for malicious ID values */
|
173 | String result = Action.SUCCESS; |
204 | String result = Action.SUCCESS; |
174 | if (id > 0) |
205 | if (id > 0) |
175 | {
|
206 | {
|
176 | this.relationshipDAO.deleteRelationship(id); |
207 | this.relationshipDAO.delete(id); |
177 | }
|
208 | }
|
178 | else
|
209 | else
|
179 | {
|
210 | {
|
180 | result = Action.ERROR; |
211 | result = Action.ERROR; |
181 | }
|
212 | }
|
Line 289... | Line 320... | ||
289 | */
|
320 | */
|
290 | public void setModifiedRelationship(Relationship modifiedRelationship) |
321 | public void setModifiedRelationship(Relationship modifiedRelationship) |
291 | {
|
322 | {
|
292 | this.modifiedRelationship = modifiedRelationship; |
323 | this.modifiedRelationship = modifiedRelationship; |
293 | }
|
324 | }
|
- | 325 | ||
- | 326 | /**
|
|
- | 327 | * @return the history
|
|
- | 328 | */
|
|
- | 329 | public Set<History> getHistory() |
|
- | 330 | {
|
|
- | 331 | return this.history; |
|
- | 332 | }
|
|
- | 333 | ||
- | 334 | /**
|
|
- | 335 | * @param history
|
|
- | 336 | * the history to set
|
|
- | 337 | */
|
|
- | 338 | public void setHistory(Set<History> history) |
|
- | 339 | {
|
|
- | 340 | this.history = history; |
|
- | 341 | }
|
|
294 | }
|
342 | }
|