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 47... | Line 47... | ||
47 | /**
|
47 | /**
|
48 | * Session object
|
48 | * Session object
|
49 | */
|
49 | */
|
50 | Map<String, Object> session = ActionContext.getContext().getSession(); |
50 | Map<String, Object> session = ActionContext.getContext().getSession(); |
51 | 51 | ||
- | 52 | /**
|
|
- | 53 | * @var <code>true</code> if the relationship is to be edited/renamed,
|
|
- | 54 | * <code>false</code> otherwise
|
|
- | 55 | */
|
|
- | 56 | public boolean edit = false; |
|
- | 57 | ||
- | 58 | /**
|
|
- | 59 | * @var <code>true</code> if a relationship was added, <code>false</code>
|
|
- | 60 | * otherwise
|
|
- | 61 | */
|
|
- | 62 | public boolean added = false; |
|
- | 63 | ||
52 | private final HttpServletRequest request = (HttpServletRequest) ActionContext |
64 | private final HttpServletRequest request = (HttpServletRequest) ActionContext |
53 | .getContext().get(StrutsStatics.HTTP_REQUEST); |
65 | .getContext().get(StrutsStatics.HTTP_REQUEST); |
54 | 66 | ||
- | 67 | /**
|
|
- | 68 | * The term that was just saved (added, renamed)
|
|
- | 69 | */
|
|
- | 70 | private Relationship modifiedRelationship; |
|
- | 71 | ||
55 | /*
|
72 | /*
|
56 | * (non-Javadoc)
|
73 | * (non-Javadoc)
|
57 | *
|
74 | *
|
58 | * @see com.opensymphony.xwork2.ModelDriven#getModel()
|
75 | * @see com.opensymphony.xwork2.ModelDriven#getModel()
|
59 | */
|
76 | */
|
Line 61... | Line 78... | ||
61 | {
|
78 | {
|
62 | return this.relationship; |
79 | return this.relationship; |
63 | }
|
80 | }
|
64 | 81 | ||
65 | /**
|
82 | /**
|
66 | * Prepares to add a relationship
|
83 | * DB query for relationship list
|
67 | *
|
84 | *
|
68 | * @return
|
85 | * @return SUCCESS
|
69 | */
|
86 | */
|
70 | public String add() |
87 | public String list() |
71 | {
|
88 | {
|
72 | this.setTerms(this.termDAO.getTerms()); |
89 | this.setTerms(this.termDAO.getTerms()); |
73 | this.setRelationshipTypes(this.relationshipTypeDAO.getRelTypes()); |
90 | this.setRelationshipTypes(this.relationshipTypeDAO.getRelTypes()); |
- | 91 | this.setRelationshipList(this.relationshipDAO.getRelationshipList()); |
|
74 | return Action.SUCCESS; |
92 | return Action.SUCCESS; |
75 | }
|
93 | }
|
76 | 94 | ||
77 | /**
|
95 | /**
|
78 | * Executes the DB query to save the user
|
96 | * Executes the DB query to save the relationship
|
79 | *
|
97 | *
|
80 | * @return {@link Action#SUCCESS}
|
98 | * @return {@link Action#SUCCESS}
|
81 | */
|
99 | */
|
82 | public String save() |
100 | public String save() |
83 | {
|
101 | {
|
Line 86... | Line 104... | ||
86 | this.relationship.setTermTo(this.termDAO.getTermById(Integer |
104 | this.relationship.setTermTo(this.termDAO.getTermById(Integer |
87 | .parseInt(this.request.getParameter("term2")))); |
105 | .parseInt(this.request.getParameter("term2")))); |
88 | this.relationship.setRelationshipType(this.relationshipTypeDAO |
106 | this.relationship.setRelationshipType(this.relationshipTypeDAO |
89 | .getRelTypeById(Integer.parseInt(this.request.getParameter("type")))); |
107 | .getRelTypeById(Integer.parseInt(this.request.getParameter("type")))); |
90 | 108 | ||
- | 109 | User user = this.userDAO.searchUsername((String) this.session |
|
- | 110 | .get("username")); |
|
- | 111 | ||
91 | if (!"1".equals(this.request.getParameter("edit"))) |
112 | if ("false".equals(this.request.getParameter("edit"))) |
92 | {
|
113 | {
|
93 | User user = this.userDAO.searchUsername((String) this.session |
- | |
94 | .get("username")); |
114 | /* Add a new relationship */
|
95 | ObjectEntity obj = new ObjectEntity(user, new ObjectType( |
115 | ObjectEntity obj = new ObjectEntity(user, new ObjectType( |
96 | ObjectType.RELATIONSHIP), user, null, new Date(), false, null, null, |
116 | ObjectType.RELATIONSHIP), user, null, new Date(), false, null, null, |
97 | this.relationship); |
117 | this.relationship); |
98 | this.relationship.setObject(obj); |
118 | this.relationship.setObject(obj); |
- | 119 | this.added = true; |
|
99 | }
|
120 | }
|
100 | 121 | ||
- | 122 | this.edit = false; |
|
- | 123 | ||
- | 124 | String result = Action.SUCCESS; |
|
101 | if (this.relationshipDAO.saveOrUpdate(this.relationship)) |
125 | if (!this.relationshipDAO.saveOrUpdate(this.relationship)) |
102 | {
|
126 | {
|
103 | return Action.SUCCESS; |
127 | result = Action.ERROR; |
104 | }
|
128 | }
|
105 | 129 | ||
- | 130 | this.setModifiedRelationship(this.relationship); |
|
106 | return Action.ERROR; |
131 | this.setRelationship(null); |
107 | }
|
- | |
108 | 132 | ||
109 | /**
|
- | |
110 | * DB query for relationship list
|
- | |
111 | *
|
- | |
112 | * @return SUCCESS
|
- | |
113 | */
|
- | |
114 | public String list() |
133 | this.list(); |
115 | {
|
134 | |
116 | this.relationshipList = this.relationshipDAO.listRelationships(); |
- | |
117 | return Action.SUCCESS; |
135 | return result; |
118 | }
|
136 | }
|
119 | 137 | ||
120 | /**
|
138 | /**
|
121 | * @return {@link Action#SUCCESS} if <var>id</var> > 0, {@link Action#ERROR}
|
139 | * @return {@link Action#SUCCESS} if <var>id</var> > 0, {@link Action#ERROR}
|
122 | * otherwise
|
140 | * otherwise
|
123 | */
|
141 | */
|
124 | public String edit() |
142 | public String edit() |
125 | {
|
143 | {
|
126 | int id = this.getIdParameter(); |
144 | int id = this.getIdParameter(); |
127 | 145 | ||
- | 146 | String result = Action.ERROR; |
|
128 | if (id > 0) |
147 | if (id > 0) |
129 | {
|
148 | {
|
130 | this.relationship = this.relationshipDAO.getRelationshipById(id); |
149 | this.setRelationship(this.relationshipDAO.getRelationshipById(id)); |
131 | if (this.relationship != null) |
150 | if (this.getRelationship() != null) |
132 | {
|
151 | {
|
- | 152 | this.edit = true; |
|
133 | return Action.SUCCESS; |
153 | result = Action.SUCCESS; |
134 | }
|
154 | }
|
135 | }
|
155 | }
|
136 | 156 | ||
137 | return Action.ERROR; |
- | |
138 | }
|
- | |
139 | - | ||
140 | /**
|
- | |
141 | * Gets the ID Parameter for update / delete requests
|
- | |
142 | *
|
- | |
143 | * @return int from the ID request. If not set or wrong, it gives back -1
|
- | |
144 | */
|
- | |
145 | private int getIdParameter() |
- | |
146 | {
|
- | |
147 | int id = -1; |
157 | this.list(); |
148 | try
|
- | |
149 | {
|
- | |
150 | id = Integer.parseInt(this.request.getParameter("id")); //$NON-NLS-1$ |
- | |
151 | }
|
- | |
152 | catch (Exception e) |
- | |
153 | {
|
- | |
154 | /* TODO: Logging - wrong parameter set */
|
- | |
155 | }
|
- | |
156 | 158 | ||
157 | return id; |
159 | return result; |
158 | }
|
160 | }
|
159 | 161 | ||
160 | /**
|
162 | /**
|
161 | * deletes a user, gets the ID from the "id" parameter that was submitted with
|
163 | * deletes a user, gets the ID from the "id" parameter that was submitted with
|
162 | * the HTTP request
|
164 | * the HTTP request
|
163 | *
|
165 | *
|
164 | * @return String - either SUCCESS or ERROR constant
|
166 | * @return String - either SUCCESS or ERROR constant
|
165 | */
|
167 | */
|
166 | public String delete() |
168 | public String delete() |
167 | {
|
169 | {
|
168 | - | ||
169 | int id = this.getIdParameter(); |
170 | int id = this.getIdParameter(); |
170 | 171 | ||
171 | /* Check for malicious ID values */
|
172 | /* Check for malicious ID values */
|
- | 173 | String result = Action.SUCCESS; |
|
172 | if (id > 0) |
174 | if (id > 0) |
173 | {
|
175 | {
|
174 | this.relationshipDAO.deleteRelationship(id); |
176 | this.relationshipDAO.deleteRelationship(id); |
175 | return Action.SUCCESS; |
- | |
176 | }
|
177 | }
|
177 | else
|
178 | else
|
178 | {
|
179 | {
|
179 | return Action.ERROR; |
180 | result = Action.ERROR; |
180 | }
|
181 | }
|
- | 182 | ||
- | 183 | this.list(); |
|
- | 184 | ||
- | 185 | return result; |
|
181 | }
|
186 | }
|
182 | 187 | ||
183 | /*
|
188 | /**
|
184 | * Standard getters and setters
|
189 | * Gets the ID Parameter for update / delete requests
|
- | 190 | *
|
|
- | 191 | * @return int from the ID request. If not set or wrong, it gives back -1
|
|
185 | */
|
192 | */
|
- | 193 | private int getIdParameter() |
|
- | 194 | {
|
|
- | 195 | int id = -1; |
|
- | 196 | try
|
|
- | 197 | {
|
|
- | 198 | id = Integer.parseInt(this.request.getParameter("id")); //$NON-NLS-1$ |
|
- | 199 | }
|
|
- | 200 | catch (Exception e) |
|
- | 201 | {
|
|
- | 202 | /* TODO: Logging - wrong parameter set */
|
|
- | 203 | }
|
|
- | 204 | ||
- | 205 | return id; |
|
- | 206 | }
|
|
- | 207 | ||
- | 208 | /* Standard getters and setters */
|
|
186 | 209 | ||
187 | /**
|
210 | /**
|
188 | * @return The relationship edited with this instance
|
211 | * @return The relationship edited with this instance
|
189 | */
|
212 | */
|
190 | public Relationship getRelationship() |
213 | public Relationship getRelationship() |
Line 249... | Line 272... | ||
249 | */
|
272 | */
|
250 | public void setTerms(List<Term> terms) |
273 | public void setTerms(List<Term> terms) |
251 | {
|
274 | {
|
252 | this.terms = terms; |
275 | this.terms = terms; |
253 | }
|
276 | }
|
- | 277 | ||
- | 278 | /**
|
|
- | 279 | * @return the modifiedRelationship
|
|
- | 280 | */
|
|
- | 281 | public Relationship getModifiedRelationship() |
|
- | 282 | {
|
|
- | 283 | return this.modifiedRelationship; |
|
- | 284 | }
|
|
- | 285 | ||
- | 286 | /**
|
|
- | 287 | * @param modifiedRelationship
|
|
- | 288 | * the modifiedRelationship to set
|
|
- | 289 | */
|
|
- | 290 | public void setModifiedRelationship(Relationship modifiedRelationship) |
|
- | 291 | {
|
|
- | 292 | this.modifiedRelationship = modifiedRelationship; |
|
- | 293 | }
|
|
254 | }
|
294 | }
|