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