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