1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.student.core.comment.service.impl; |
17 | |
|
18 | |
import java.util.List; |
19 | |
|
20 | |
import javax.jws.WebService; |
21 | |
import javax.persistence.NoResultException; |
22 | |
|
23 | |
import org.apache.log4j.Logger; |
24 | |
import org.kuali.student.common.validator.Validator; |
25 | |
import org.kuali.student.common.validator.ValidatorFactory; |
26 | |
import org.kuali.student.core.comment.dao.CommentDao; |
27 | |
import org.kuali.student.core.comment.dto.CommentInfo; |
28 | |
import org.kuali.student.core.comment.dto.CommentTypeInfo; |
29 | |
import org.kuali.student.core.comment.dto.TagInfo; |
30 | |
import org.kuali.student.core.comment.dto.TagTypeInfo; |
31 | |
import org.kuali.student.core.comment.entity.Comment; |
32 | |
import org.kuali.student.core.comment.entity.CommentType; |
33 | |
import org.kuali.student.core.comment.entity.Reference; |
34 | |
import org.kuali.student.core.comment.entity.ReferenceType; |
35 | |
import org.kuali.student.core.comment.entity.Tag; |
36 | |
import org.kuali.student.core.comment.entity.TagType; |
37 | |
import org.kuali.student.core.comment.service.CommentService; |
38 | |
import org.kuali.student.core.dictionary.dto.ObjectStructureDefinition; |
39 | |
import org.kuali.student.core.dictionary.service.DictionaryService; |
40 | |
import org.kuali.student.core.dto.ReferenceTypeInfo; |
41 | |
import org.kuali.student.core.dto.StatusInfo; |
42 | |
import org.kuali.student.core.exceptions.AlreadyExistsException; |
43 | |
import org.kuali.student.core.exceptions.DataValidationErrorException; |
44 | |
import org.kuali.student.core.exceptions.DoesNotExistException; |
45 | |
import org.kuali.student.core.exceptions.InvalidParameterException; |
46 | |
import org.kuali.student.core.exceptions.MissingParameterException; |
47 | |
import org.kuali.student.core.exceptions.OperationFailedException; |
48 | |
import org.kuali.student.core.exceptions.PermissionDeniedException; |
49 | |
import org.kuali.student.core.exceptions.VersionMismatchException; |
50 | |
import org.kuali.student.core.search.service.SearchManager; |
51 | |
import org.kuali.student.core.validation.dto.ValidationResultInfo; |
52 | |
import org.springframework.transaction.annotation.Transactional; |
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
@WebService(endpointInterface = "org.kuali.student.core.comment.service.CommentService", serviceName = "CommentService", portName = "CommentService", targetNamespace = "http://student.kuali.org/wsdl/commentService") |
61 | |
@Transactional(noRollbackFor={DoesNotExistException.class},rollbackFor={Throwable.class}) |
62 | 2 | public class CommentServiceImpl implements CommentService { |
63 | |
|
64 | 2 | final Logger logger = Logger.getLogger(CommentServiceImpl.class); |
65 | |
|
66 | |
private CommentDao commentDao; |
67 | |
private DictionaryService dictionaryServiceDelegate; |
68 | |
private SearchManager searchManager; |
69 | |
private ValidatorFactory validatorFactory; |
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | |
@Override |
77 | |
public CommentInfo addComment(String referenceId, String referenceTypeKey, CommentInfo commentInfo) throws DataValidationErrorException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
78 | 4 | commentInfo.setReferenceTypeKey(referenceTypeKey); |
79 | 4 | commentInfo.setReferenceId(referenceId); |
80 | |
|
81 | |
|
82 | 4 | List<ValidationResultInfo> validationResults = null; |
83 | |
try { |
84 | 4 | validationResults = validateComment("OBJECT", commentInfo); |
85 | 0 | } catch (DoesNotExistException e1) { |
86 | 0 | throw new OperationFailedException("Validation call failed." + e1.getMessage()); |
87 | 4 | } |
88 | 4 | if (null != validationResults && validationResults.size() > 0) { |
89 | 0 | throw new DataValidationErrorException("Validation error!", validationResults); |
90 | |
} |
91 | |
|
92 | 4 | Reference reference=null; |
93 | 4 | reference = commentDao.getReference(referenceId, referenceTypeKey); |
94 | 4 | if(reference==null){ |
95 | 3 | reference = new Reference(); |
96 | 3 | reference.setReferenceId(referenceId); |
97 | |
try { |
98 | 3 | ReferenceType referenceType = commentDao.fetch(ReferenceType.class, referenceTypeKey); |
99 | 3 | reference.setReferenceType(referenceType); |
100 | 3 | commentDao.create(reference); |
101 | 0 | } catch (DoesNotExistException e) { |
102 | 0 | throw new InvalidParameterException(e.getMessage()); |
103 | 3 | } |
104 | |
} |
105 | |
|
106 | 4 | Comment comment = null; |
107 | |
|
108 | |
try { |
109 | 4 | comment = CommentServiceAssembler.toComment(false, commentInfo, commentDao); |
110 | 0 | } catch (DoesNotExistException e) { |
111 | 0 | throw new InvalidParameterException(e.getMessage()); |
112 | 4 | } |
113 | |
|
114 | 4 | Comment createdComment = commentDao.create(comment); |
115 | |
|
116 | 4 | CommentInfo createdCommentInfo = CommentServiceAssembler.toCommentInfo(createdComment); |
117 | |
|
118 | 4 | return createdCommentInfo; |
119 | |
} |
120 | |
|
121 | |
|
122 | |
|
123 | |
|
124 | |
|
125 | |
@Override |
126 | |
public TagInfo addTag(String referenceId, String referenceTypeKey, TagInfo tagInfo) throws DataValidationErrorException, AlreadyExistsException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
127 | |
|
128 | |
|
129 | 4 | List<ValidationResultInfo> validationResults = null; |
130 | |
try { |
131 | 4 | validationResults = validateTag("OBJECT", tagInfo); |
132 | 0 | } catch (DoesNotExistException e1) { |
133 | 0 | throw new OperationFailedException("Validation call failed." + e1.getMessage()); |
134 | 4 | } |
135 | 4 | if (null != validationResults && validationResults.size() > 0) { |
136 | 0 | throw new DataValidationErrorException("Validation error!", validationResults); |
137 | |
} |
138 | |
|
139 | 4 | tagInfo.setReferenceTypeKey(referenceTypeKey); |
140 | 4 | tagInfo.setReferenceId(referenceId); |
141 | 4 | Reference reference=null; |
142 | 4 | reference = commentDao.getReference(referenceId, referenceTypeKey); |
143 | 4 | if(reference==null){ |
144 | 1 | reference = new Reference(); |
145 | 1 | reference.setReferenceId(referenceId); |
146 | |
try { |
147 | 1 | ReferenceType referenceType = commentDao.fetch(ReferenceType.class, referenceTypeKey); |
148 | 1 | reference.setReferenceType(referenceType); |
149 | 1 | commentDao.create(reference); |
150 | 0 | } catch (DoesNotExistException e) { |
151 | 0 | throw new InvalidParameterException(e.getMessage()); |
152 | 1 | } |
153 | |
} |
154 | |
|
155 | 4 | Tag tag = null; |
156 | |
|
157 | |
try { |
158 | 4 | tag = CommentServiceAssembler.toTag(false, tagInfo, commentDao); |
159 | 0 | } catch (DoesNotExistException e) { |
160 | 0 | logger.error("Exception occured: ", e); |
161 | 4 | } |
162 | |
|
163 | 4 | Tag createdTag = commentDao.create(tag); |
164 | |
|
165 | 4 | TagInfo createdTagInfo = CommentServiceAssembler.toTagInfo(createdTag); |
166 | |
|
167 | 4 | return createdTagInfo; |
168 | |
} |
169 | |
|
170 | |
|
171 | |
|
172 | |
|
173 | |
|
174 | |
|
175 | |
@Override |
176 | |
public CommentInfo getComment(String commentId) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
177 | 8 | checkForMissingParameter(commentId, "commentId"); |
178 | 7 | Comment comment = commentDao.fetch(Comment.class, commentId); |
179 | 3 | return CommentServiceAssembler.toCommentInfo(comment); |
180 | |
} |
181 | |
|
182 | |
|
183 | |
|
184 | |
|
185 | |
|
186 | |
|
187 | |
@Override |
188 | |
public List<CommentTypeInfo> getCommentTypes() throws OperationFailedException { |
189 | 0 | List<CommentType> commentTypes = commentDao.find(CommentType.class); |
190 | 0 | return CommentServiceAssembler.toCommentTypeInfos(commentTypes); |
191 | |
} |
192 | |
|
193 | |
|
194 | |
|
195 | |
|
196 | |
|
197 | |
|
198 | |
@Override |
199 | |
public List<CommentTypeInfo> getCommentTypesForReferenceType(String referenceTypeKey) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException { |
200 | 1 | List<CommentType> commentTypes = commentDao.getCommentTypesByReferenceTypeId(referenceTypeKey); |
201 | 1 | return CommentServiceAssembler.toCommentTypeInfos(commentTypes); |
202 | |
} |
203 | |
|
204 | |
|
205 | |
|
206 | |
|
207 | |
|
208 | |
|
209 | |
@Override |
210 | |
public List<CommentInfo> getComments(String referenceId, String referenceTypeKey) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
211 | 2 | List<Comment> comments = commentDao.getComments(referenceId, referenceTypeKey); |
212 | 2 | return CommentServiceAssembler.toCommentInfos(comments); |
213 | |
} |
214 | |
|
215 | |
|
216 | |
|
217 | |
|
218 | |
|
219 | |
|
220 | |
@Override |
221 | |
public List<CommentInfo> getCommentsByType(String referenceId, String referenceTypeKey, String commentTypeKey) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
222 | 0 | List<Comment> comments = commentDao.getCommentsByType(referenceId, referenceTypeKey, commentTypeKey); |
223 | 0 | return CommentServiceAssembler.toCommentInfos(comments); |
224 | |
} |
225 | |
|
226 | |
|
227 | |
|
228 | |
|
229 | |
|
230 | |
|
231 | |
@Override |
232 | |
public List<ReferenceTypeInfo> getReferenceTypes() throws OperationFailedException { |
233 | 1 | List<ReferenceType> referenceTypes = commentDao.find(ReferenceType.class); |
234 | 1 | return CommentServiceAssembler.toReferenceTypeInfos(referenceTypes); |
235 | |
} |
236 | |
|
237 | |
|
238 | |
|
239 | |
|
240 | |
|
241 | |
|
242 | |
@Override |
243 | |
public TagInfo getTag(String tagId) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
244 | 4 | checkForMissingParameter(tagId, "tagId"); |
245 | 3 | Tag tag = commentDao.fetch(Tag.class, tagId); |
246 | 2 | return CommentServiceAssembler.toTagInfo(tag); |
247 | |
} |
248 | |
|
249 | |
|
250 | |
|
251 | |
|
252 | |
|
253 | |
|
254 | |
@Override |
255 | |
public List<TagTypeInfo> getTagTypes() throws OperationFailedException { |
256 | 1 | List<TagType> tagTypes = commentDao.find(TagType.class); |
257 | |
|
258 | 1 | return CommentServiceAssembler.toTagTypeInfos(tagTypes); |
259 | |
} |
260 | |
|
261 | |
|
262 | |
|
263 | |
|
264 | |
|
265 | |
|
266 | |
@Override |
267 | |
public List<TagInfo> getTags(String referenceId, String referenceTypeKey) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
268 | |
|
269 | 2 | List<Tag> tags = commentDao.getTags(referenceId, referenceTypeKey); |
270 | |
|
271 | 2 | return CommentServiceAssembler.toTagInfos(tags); |
272 | |
} |
273 | |
|
274 | |
|
275 | |
|
276 | |
|
277 | |
|
278 | |
|
279 | |
@Override |
280 | |
public List<TagInfo> getTagsByType(String referenceId, String referenceTypeKey, String tagTypeKey) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
281 | |
|
282 | 1 | List<Tag> tags = commentDao.getTagsByType(referenceId, referenceTypeKey, tagTypeKey); |
283 | 1 | return CommentServiceAssembler.toTagInfos(tags); |
284 | |
} |
285 | |
|
286 | |
|
287 | |
|
288 | |
|
289 | |
|
290 | |
|
291 | |
@Override |
292 | |
public StatusInfo removeComment(String commentId, String referenceId, String referenceTypeKey) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
293 | |
try{ |
294 | 2 | checkForMissingParameter(commentId, "commentId"); |
295 | 2 | commentDao.delete(Comment.class, commentId); |
296 | 1 | return new StatusInfo(); |
297 | |
} |
298 | 0 | catch(MissingParameterException mpe){ |
299 | 0 | Comment comment = null; |
300 | |
try{ |
301 | 0 | comment = commentDao.getComment(referenceId, referenceTypeKey); |
302 | 0 | if(comment==null){ |
303 | 0 | throw new DoesNotExistException(); |
304 | |
} |
305 | |
} |
306 | 0 | catch(NoResultException nre){ |
307 | 0 | throw new DoesNotExistException(); |
308 | 0 | } |
309 | 0 | commentDao.delete(comment); |
310 | 0 | return new StatusInfo(); |
311 | |
} |
312 | |
|
313 | |
} |
314 | |
|
315 | |
|
316 | |
|
317 | |
|
318 | |
|
319 | |
|
320 | |
@Override |
321 | |
public StatusInfo removeComments(String referenceId) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
322 | 1 | List<Comment> comments = commentDao.getCommentsByRefId(referenceId); |
323 | 1 | for(Comment comment:comments){ |
324 | 2 | commentDao.delete(comment); |
325 | |
} |
326 | 1 | return new StatusInfo(); |
327 | |
} |
328 | |
|
329 | |
|
330 | |
|
331 | |
|
332 | |
|
333 | |
|
334 | |
|
335 | |
@Override |
336 | |
public StatusInfo removeTag(String tagId, String referenceId, String referenceTypeKey) throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, DoesNotExistException { |
337 | |
try{ |
338 | 3 | checkForMissingParameter(tagId, "tagId"); |
339 | 0 | commentDao.delete(Tag.class, tagId); |
340 | 0 | return new StatusInfo(); |
341 | |
} |
342 | 3 | catch(MissingParameterException mpe){ |
343 | 3 | Tag tag = null; |
344 | |
try{ |
345 | 3 | tag = commentDao.getTag(referenceId, referenceTypeKey); |
346 | 1 | if(tag==null){ |
347 | 0 | throw new DoesNotExistException(); |
348 | |
} |
349 | |
} |
350 | 2 | catch(NoResultException nre){ |
351 | 2 | throw new DoesNotExistException(); |
352 | 1 | } |
353 | 1 | commentDao.delete(tag); |
354 | 1 | return new StatusInfo(); |
355 | |
} |
356 | |
} |
357 | |
|
358 | |
|
359 | |
|
360 | |
|
361 | |
|
362 | |
|
363 | |
@Override |
364 | |
public StatusInfo removeTags(String tagId) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
365 | |
|
366 | 1 | List<Tag> tags = commentDao.getTagsByRefId(tagId); |
367 | 1 | for(Tag tag:tags){ |
368 | 3 | commentDao.delete(tag); |
369 | |
} |
370 | 1 | return new StatusInfo(); |
371 | |
} |
372 | |
|
373 | |
|
374 | |
|
375 | |
|
376 | |
|
377 | |
|
378 | |
|
379 | |
@Override |
380 | |
public CommentInfo updateComment(String referenceId, String referenceTypeKey, CommentInfo commentInfo) throws DataValidationErrorException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, DoesNotExistException, VersionMismatchException { |
381 | |
|
382 | |
|
383 | 1 | List<ValidationResultInfo> validationResults = validateComment("OBJECT", commentInfo); |
384 | 1 | if (null != validationResults && validationResults.size() > 0) { |
385 | 0 | throw new DataValidationErrorException("Validation error!", validationResults); |
386 | |
} |
387 | |
|
388 | 1 | Comment entity = commentDao.fetch(Comment.class, commentInfo.getId()); |
389 | 1 | if (!String.valueOf(entity.getVersionNumber()).equals(commentInfo.getMetaInfo().getVersionInd())){ |
390 | 0 | throw new VersionMismatchException("ResultComponent to be updated is not the current version"); |
391 | |
} |
392 | |
|
393 | 1 | CommentServiceAssembler.toComment(entity, referenceId, referenceTypeKey, commentInfo, commentDao); |
394 | 1 | commentDao.update(entity); |
395 | |
|
396 | 1 | return CommentServiceAssembler.toCommentInfo(entity); |
397 | |
} |
398 | |
|
399 | |
|
400 | |
|
401 | |
|
402 | |
|
403 | |
|
404 | |
@Override |
405 | |
public List<ValidationResultInfo> validateComment(String validationType, CommentInfo commentInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException { |
406 | 5 | checkForMissingParameter(validationType, "validationType"); |
407 | 5 | checkForMissingParameter(commentInfo, "commentInfo"); |
408 | |
|
409 | 5 | ObjectStructureDefinition objStructure = this.getObjectStructure(CommentInfo.class.getName()); |
410 | 5 | Validator defaultValidator = validatorFactory.getValidator(); |
411 | 5 | List<ValidationResultInfo> validationResults = defaultValidator.validateObject(commentInfo, objStructure); |
412 | 5 | return validationResults; |
413 | |
} |
414 | |
|
415 | |
private List<ValidationResultInfo> validateTag(String validationType, TagInfo tagInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException { |
416 | 4 | checkForMissingParameter(validationType, "validationType"); |
417 | 4 | checkForMissingParameter(tagInfo, "tagInfo"); |
418 | |
|
419 | 4 | ObjectStructureDefinition objStructure = this.getObjectStructure(TagInfo.class.getName()); |
420 | 4 | Validator defaultValidator = validatorFactory.getValidator(); |
421 | 4 | List<ValidationResultInfo> validationResults = defaultValidator.validateObject(tagInfo, objStructure); |
422 | 4 | return validationResults; |
423 | |
} |
424 | |
|
425 | |
|
426 | |
|
427 | |
|
428 | |
public CommentDao getCommentDao() { |
429 | 0 | return commentDao; |
430 | |
} |
431 | |
|
432 | |
|
433 | |
|
434 | |
|
435 | |
public void setCommentDao(CommentDao commentDao) { |
436 | 1 | this.commentDao = commentDao; |
437 | 1 | } |
438 | |
|
439 | |
|
440 | |
|
441 | |
|
442 | |
|
443 | |
|
444 | |
|
445 | |
|
446 | |
private void checkForMissingParameter(Object param, String paramName) |
447 | |
throws MissingParameterException { |
448 | 35 | if (param == null) { |
449 | 5 | throw new MissingParameterException(paramName + " can not be null"); |
450 | |
} |
451 | 30 | } |
452 | |
|
453 | |
|
454 | |
|
455 | |
|
456 | |
public DictionaryService getDictionaryServiceDelegate() { |
457 | 0 | return dictionaryServiceDelegate; |
458 | |
} |
459 | |
|
460 | |
|
461 | |
|
462 | |
|
463 | |
public void setDictionaryServiceDelegate( |
464 | |
DictionaryService dictionaryServiceDelegate) { |
465 | 1 | this.dictionaryServiceDelegate = dictionaryServiceDelegate; |
466 | 1 | } |
467 | |
|
468 | |
|
469 | |
|
470 | |
public SearchManager getSearchManager() { |
471 | 0 | return searchManager; |
472 | |
} |
473 | |
|
474 | |
|
475 | |
|
476 | |
|
477 | |
public void setSearchManager(SearchManager searchManager) { |
478 | 1 | this.searchManager = searchManager; |
479 | 1 | } |
480 | |
|
481 | |
@Override |
482 | |
public ObjectStructureDefinition getObjectStructure(String objectTypeKey) { |
483 | 9 | return dictionaryServiceDelegate.getObjectStructure(objectTypeKey); |
484 | |
} |
485 | |
@Override |
486 | |
public List<String> getObjectTypes() { |
487 | 0 | return dictionaryServiceDelegate.getObjectTypes(); |
488 | |
} |
489 | |
|
490 | |
|
491 | |
|
492 | |
|
493 | |
public ValidatorFactory getValidatorFactory() { |
494 | 0 | return validatorFactory; |
495 | |
} |
496 | |
|
497 | |
|
498 | |
|
499 | |
|
500 | |
public void setValidatorFactory(ValidatorFactory validatorFactory) { |
501 | 1 | this.validatorFactory = validatorFactory; |
502 | 1 | } |
503 | |
} |