1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.student.lum.lo.service.impl; |
17 | |
|
18 | |
import java.util.ArrayList; |
19 | |
import java.util.List; |
20 | |
|
21 | |
import javax.jws.WebService; |
22 | |
|
23 | |
import org.kuali.student.common.dictionary.dto.ObjectStructureDefinition; |
24 | |
import org.kuali.student.common.dictionary.service.DictionaryService; |
25 | |
import org.kuali.student.common.dto.DtoConstants; |
26 | |
import org.kuali.student.common.dto.StatusInfo; |
27 | |
import org.kuali.student.common.exceptions.AlreadyExistsException; |
28 | |
import org.kuali.student.common.exceptions.DataValidationErrorException; |
29 | |
import org.kuali.student.common.exceptions.DependentObjectsExistException; |
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.UnsupportedActionException; |
36 | |
import org.kuali.student.common.exceptions.VersionMismatchException; |
37 | |
import org.kuali.student.common.search.dto.SearchCriteriaTypeInfo; |
38 | |
import org.kuali.student.common.search.dto.SearchParam; |
39 | |
import org.kuali.student.common.search.dto.SearchRequest; |
40 | |
import org.kuali.student.common.search.dto.SearchResult; |
41 | |
import org.kuali.student.common.search.dto.SearchResultCell; |
42 | |
import org.kuali.student.common.search.dto.SearchResultRow; |
43 | |
import org.kuali.student.common.search.dto.SearchResultTypeInfo; |
44 | |
import org.kuali.student.common.search.dto.SearchTypeInfo; |
45 | |
import org.kuali.student.common.search.service.SearchManager; |
46 | |
import org.kuali.student.common.validation.dto.ValidationResultInfo; |
47 | |
import org.kuali.student.common.validator.Validator; |
48 | |
import org.kuali.student.common.validator.ValidatorFactory; |
49 | |
import org.kuali.student.lum.lo.dao.LoDao; |
50 | |
import org.kuali.student.lum.lo.dto.LoCategoryInfo; |
51 | |
import org.kuali.student.lum.lo.dto.LoCategoryTypeInfo; |
52 | |
import org.kuali.student.lum.lo.dto.LoInfo; |
53 | |
import org.kuali.student.lum.lo.dto.LoLoRelationInfo; |
54 | |
import org.kuali.student.lum.lo.dto.LoLoRelationTypeInfo; |
55 | |
import org.kuali.student.lum.lo.dto.LoRepositoryInfo; |
56 | |
import org.kuali.student.lum.lo.dto.LoTypeInfo; |
57 | |
import org.kuali.student.lum.lo.entity.Lo; |
58 | |
import org.kuali.student.lum.lo.entity.LoCategory; |
59 | |
import org.kuali.student.lum.lo.entity.LoCategoryType; |
60 | |
import org.kuali.student.lum.lo.entity.LoLoRelation; |
61 | |
import org.kuali.student.lum.lo.entity.LoLoRelationType; |
62 | |
import org.kuali.student.lum.lo.entity.LoRepository; |
63 | |
import org.kuali.student.lum.lo.entity.LoType; |
64 | |
import org.kuali.student.lum.lo.service.LearningObjectiveService; |
65 | |
import org.springframework.transaction.annotation.Transactional; |
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
@WebService(endpointInterface = "org.kuali.student.lum.lo.service.LearningObjectiveService", serviceName = "LearningObjectiveService", portName = "LearningObjectiveService", targetNamespace = "http://student.kuali.org/wsdl/lo") |
72 | |
@Transactional(readOnly=true,noRollbackFor={DoesNotExistException.class},rollbackFor={Throwable.class}) |
73 | 6 | public class LearningObjectiveServiceImpl implements LearningObjectiveService { |
74 | |
private LoDao loDao; |
75 | |
private SearchManager searchManager; |
76 | |
private DictionaryService dictionaryServiceDelegate; |
77 | |
private ValidatorFactory validatorFactory; |
78 | |
|
79 | |
public LoDao getLoDao() { |
80 | 0 | return loDao; |
81 | |
} |
82 | |
|
83 | |
public void setLoDao(LoDao dao) { |
84 | 3 | this.loDao = dao; |
85 | 3 | } |
86 | |
|
87 | |
public void setSearchManager(SearchManager searchManager) { |
88 | 3 | this.searchManager = searchManager; |
89 | 3 | } |
90 | |
|
91 | |
public void setDictionaryServiceDelegate(DictionaryService dictionaryServiceDelegate) { |
92 | 3 | this.dictionaryServiceDelegate = dictionaryServiceDelegate; |
93 | 3 | } |
94 | |
|
95 | |
public ValidatorFactory getValidatorFactory() { |
96 | 0 | return validatorFactory; |
97 | |
} |
98 | |
|
99 | |
public void setValidatorFactory(ValidatorFactory validatorFactory) { |
100 | 3 | this.validatorFactory = validatorFactory; |
101 | 3 | } |
102 | |
|
103 | |
|
104 | |
|
105 | |
|
106 | |
|
107 | |
@Override |
108 | |
public List<LoRepositoryInfo> getLoRepositories() |
109 | |
throws OperationFailedException { |
110 | 1 | List<LoRepository> repositories = loDao.find(LoRepository.class); |
111 | 1 | return LearningObjectiveServiceAssembler.toLoRepositoryInfos(repositories); |
112 | |
} |
113 | |
|
114 | |
|
115 | |
|
116 | |
|
117 | |
|
118 | |
@Override |
119 | |
public LoRepositoryInfo getLoRepository(String loRepositoryKey) |
120 | |
throws DoesNotExistException, InvalidParameterException, |
121 | |
MissingParameterException, OperationFailedException { |
122 | 2 | checkForMissingParameter(loRepositoryKey, "loRepositoryKey"); |
123 | 1 | return LearningObjectiveServiceAssembler.toLoRepositoryInfo(loDao.fetch(LoRepository.class, loRepositoryKey)); |
124 | |
} |
125 | |
|
126 | |
|
127 | |
|
128 | |
|
129 | |
|
130 | |
@Override |
131 | |
public List<LoTypeInfo> getLoTypes() throws OperationFailedException { |
132 | 1 | List<LoType> find = loDao.find(LoType.class); |
133 | 1 | return LearningObjectiveServiceAssembler.toLoTypeInfos(find); |
134 | |
} |
135 | |
|
136 | |
|
137 | |
|
138 | |
|
139 | |
|
140 | |
@Override |
141 | |
public LoTypeInfo getLoType(String loTypeKey) throws DoesNotExistException, |
142 | |
InvalidParameterException, MissingParameterException, |
143 | |
OperationFailedException { |
144 | 3 | checkForMissingParameter(loTypeKey, "loTypeKey"); |
145 | 2 | LoType fetch = loDao.fetch(LoType.class, loTypeKey); |
146 | 2 | return LearningObjectiveServiceAssembler.toLoTypeInfo(fetch); |
147 | |
} |
148 | |
|
149 | |
|
150 | |
|
151 | |
|
152 | |
|
153 | |
@Override |
154 | |
public List<LoLoRelationTypeInfo> getLoLoRelationTypes() |
155 | |
throws OperationFailedException { |
156 | 1 | List<LoLoRelationType> fetch = loDao.find(LoLoRelationType.class); |
157 | 1 | return LearningObjectiveServiceAssembler.toLoLoRelationTypeInfos(fetch); |
158 | |
} |
159 | |
|
160 | |
|
161 | |
|
162 | |
|
163 | |
|
164 | |
@Override |
165 | |
public LoLoRelationTypeInfo getLoLoRelationType(String loLoRelationTypeKey) |
166 | |
throws OperationFailedException, MissingParameterException, DoesNotExistException { |
167 | 2 | checkForMissingParameter(loLoRelationTypeKey, "loLoRelationTypeKey"); |
168 | 1 | return LearningObjectiveServiceAssembler.toLoLoRelationTypeInfo(loDao.fetch(LoLoRelationType.class, loLoRelationTypeKey)); |
169 | |
} |
170 | |
|
171 | |
@Override |
172 | |
public List<String> getAllowedLoLoRelationTypesForLoType(String loTypeKey, String relatedLoTypeKey) |
173 | |
throws DoesNotExistException, InvalidParameterException, |
174 | |
MissingParameterException, OperationFailedException { |
175 | 2 | checkForMissingParameter(loTypeKey, "loTypeKey"); |
176 | 2 | checkForMissingParameter(relatedLoTypeKey, "relatedLoTypeKey"); |
177 | |
|
178 | 2 | return loDao.getAllowedLoLoRelationTypesForLoType(loTypeKey, relatedLoTypeKey); |
179 | |
} |
180 | |
|
181 | |
|
182 | |
|
183 | |
|
184 | |
|
185 | |
@Override |
186 | |
@Transactional(readOnly=false) |
187 | |
public StatusInfo addLoCategoryToLo(String loCategoryId, String loId) |
188 | |
throws AlreadyExistsException, DoesNotExistException, |
189 | |
InvalidParameterException, MissingParameterException, |
190 | |
OperationFailedException, PermissionDeniedException, |
191 | |
UnsupportedActionException { |
192 | 1291 | checkForMissingParameter(loCategoryId, "loCategoryId"); |
193 | 1291 | checkForMissingParameter(loId, "loId"); |
194 | 1291 | StatusInfo statusInfo = new StatusInfo(); |
195 | 1291 | statusInfo.setSuccess(loDao.addLoCategoryToLo(loCategoryId, loId)); |
196 | 1291 | return statusInfo; |
197 | |
} |
198 | |
|
199 | |
|
200 | |
|
201 | |
|
202 | |
@Override |
203 | |
@Transactional(readOnly=false) |
204 | |
public LoInfo createLo(String repositoryId, String loType, LoInfo loInfo) |
205 | |
throws DataValidationErrorException, DoesNotExistException, |
206 | |
InvalidParameterException, MissingParameterException, |
207 | |
OperationFailedException, PermissionDeniedException { |
208 | 656 | checkForMissingParameter(repositoryId, "repositoryId"); |
209 | 655 | checkForMissingParameter(loType, "loType"); |
210 | 654 | checkForMissingParameter(loInfo, "loInfo"); |
211 | |
|
212 | |
|
213 | |
|
214 | 653 | List<ValidationResultInfo> val = validateLo("SYSTEM", loInfo); |
215 | 653 | if(null != val && val.size() > 0) { |
216 | 1 | for (ValidationResultInfo result : val) { |
217 | 1 | System.err.println("Validation error. Element: " + result.getElement() + ", Value: " + result.getMessage()); |
218 | |
} |
219 | 1 | throw new DataValidationErrorException("Validation error!", val); |
220 | |
} |
221 | |
|
222 | |
|
223 | |
|
224 | 652 | LoType type = null; |
225 | 652 | LoRepository repository = null; |
226 | |
try { |
227 | 652 | type = loDao.fetch(LoType.class, loType); |
228 | 652 | repository = loDao.fetch(LoRepository.class, repositoryId); |
229 | 0 | } catch (DoesNotExistException dnee) { |
230 | 0 | throw new DoesNotExistException("Specified " + (null == type ? "LoType" : "LoRepository") + " does not exist", dnee); |
231 | 652 | } |
232 | |
|
233 | 652 | loInfo.setLoRepositoryKey(repositoryId); |
234 | 652 | loInfo.setType(loType); |
235 | |
|
236 | 652 | Lo lo = null; |
237 | |
try { |
238 | 652 | lo = LearningObjectiveServiceAssembler.toLo(false, loInfo, loDao); |
239 | 0 | } catch (VersionMismatchException vme) { |
240 | |
|
241 | 0 | throw new OperationFailedException("VersionMismatchException caught during Learning Objective creation"); |
242 | 652 | } |
243 | 652 | lo.setLoType(type); |
244 | 652 | lo.setLoRepository(repository); |
245 | 652 | loDao.create(lo); |
246 | |
|
247 | 652 | return LearningObjectiveServiceAssembler.toLoInfo(lo); |
248 | |
} |
249 | |
|
250 | |
|
251 | |
|
252 | |
|
253 | |
@Override |
254 | |
@Transactional(readOnly=false) |
255 | |
public StatusInfo deleteLo(String loId) |
256 | |
throws DependentObjectsExistException, DoesNotExistException, |
257 | |
InvalidParameterException, MissingParameterException, |
258 | |
OperationFailedException, PermissionDeniedException { |
259 | 25 | checkForMissingParameter(loId, "loId"); |
260 | |
|
261 | 25 | StatusInfo returnStatus = new StatusInfo(); |
262 | 25 | returnStatus.setSuccess(loDao.deleteLo(loId)); |
263 | 24 | return returnStatus; |
264 | |
} |
265 | |
|
266 | |
|
267 | |
|
268 | |
|
269 | |
@Override |
270 | |
@Transactional(readOnly=false) |
271 | |
public StatusInfo deleteLoCategory(String loCategoryId) |
272 | |
throws DependentObjectsExistException, DoesNotExistException, |
273 | |
InvalidParameterException, MissingParameterException, |
274 | |
OperationFailedException, PermissionDeniedException { |
275 | 6 | checkForMissingParameter(loCategoryId, "loCategoryId"); |
276 | |
|
277 | 6 | loDao.deleteLoCategory(loCategoryId); |
278 | |
|
279 | 5 | return new StatusInfo(); |
280 | |
} |
281 | |
|
282 | |
|
283 | |
|
284 | |
|
285 | |
@Override |
286 | |
public LoInfo getLo(String loId) throws DoesNotExistException, |
287 | |
InvalidParameterException, MissingParameterException, |
288 | |
OperationFailedException { |
289 | 86 | checkForMissingParameter(loId, "loId"); |
290 | |
|
291 | 85 | return LearningObjectiveServiceAssembler.toLoInfo(loDao.fetch(Lo.class, loId)); |
292 | |
} |
293 | |
|
294 | |
|
295 | |
|
296 | |
|
297 | |
@Override |
298 | |
public List<LoInfo> getLoByIdList(List<String> loIds) |
299 | |
throws InvalidParameterException, MissingParameterException, |
300 | |
OperationFailedException { |
301 | 1 | checkForMissingParameter(loIds, "loId"); |
302 | 1 | checkForEmptyList(loIds, "loId"); |
303 | 1 | List<Lo> los = loDao.getLoByIdList(loIds); |
304 | 1 | return LearningObjectiveServiceAssembler.toLoInfos(los); |
305 | |
} |
306 | |
|
307 | |
|
308 | |
|
309 | |
|
310 | |
@Override |
311 | |
public List<LoCategoryInfo> getLoCategories(String loRepositoryKey) |
312 | |
throws DoesNotExistException, InvalidParameterException, |
313 | |
MissingParameterException, OperationFailedException { |
314 | 3 | checkForMissingParameter(loRepositoryKey, "loRepositoryKey"); |
315 | 3 | List<LoCategory> categories = loDao.getLoCategories(loRepositoryKey); |
316 | 3 | return LearningObjectiveServiceAssembler.toLoCategoryInfos(categories); |
317 | |
} |
318 | |
|
319 | |
|
320 | |
|
321 | |
|
322 | |
@Override |
323 | |
public List<LoCategoryInfo> getLoCategoriesForLo(String loId) |
324 | |
throws DoesNotExistException, InvalidParameterException, |
325 | |
MissingParameterException, OperationFailedException { |
326 | 446 | checkForMissingParameter(loId, "loId"); |
327 | 446 | List<LoCategory> categories = loDao.getLoCategoriesForLo(loId); |
328 | 446 | return LearningObjectiveServiceAssembler.toLoCategoryInfos(categories); |
329 | |
} |
330 | |
|
331 | |
|
332 | |
|
333 | |
|
334 | |
@Override |
335 | |
public LoCategoryInfo getLoCategory(String loCategoryId) |
336 | |
throws DoesNotExistException, InvalidParameterException, |
337 | |
MissingParameterException, OperationFailedException { |
338 | 3 | checkForMissingParameter(loCategoryId, "loCategoryId"); |
339 | |
|
340 | 3 | return LearningObjectiveServiceAssembler.toLoCategoryInfo(loDao.fetch(LoCategory.class, loCategoryId)); |
341 | |
} |
342 | |
|
343 | |
|
344 | |
|
345 | |
|
346 | |
|
347 | |
|
348 | |
|
349 | |
|
350 | |
|
351 | |
|
352 | |
|
353 | |
|
354 | |
|
355 | |
|
356 | |
|
357 | |
@Override |
358 | |
public List<LoInfo> getLosByLoCategory(String loCategoryId) |
359 | |
throws DoesNotExistException, InvalidParameterException, |
360 | |
MissingParameterException, OperationFailedException { |
361 | 5 | checkForMissingParameter(loCategoryId, "loCategoryId"); |
362 | 5 | List<Lo> los = loDao.getLosByLoCategory(loCategoryId); |
363 | 5 | return LearningObjectiveServiceAssembler.toLoInfos(los); |
364 | |
} |
365 | |
|
366 | |
|
367 | |
|
368 | |
|
369 | |
|
370 | |
|
371 | |
|
372 | |
|
373 | |
|
374 | |
|
375 | |
|
376 | |
|
377 | |
|
378 | |
|
379 | |
|
380 | |
|
381 | |
|
382 | |
|
383 | |
|
384 | |
|
385 | |
|
386 | |
|
387 | |
|
388 | |
|
389 | |
|
390 | |
|
391 | |
|
392 | |
|
393 | |
|
394 | |
|
395 | |
|
396 | |
|
397 | |
|
398 | |
|
399 | |
|
400 | |
|
401 | |
|
402 | |
|
403 | |
|
404 | |
|
405 | |
|
406 | |
|
407 | |
|
408 | |
|
409 | |
|
410 | |
|
411 | |
|
412 | |
|
413 | |
|
414 | |
|
415 | |
|
416 | |
|
417 | |
|
418 | |
|
419 | |
|
420 | |
|
421 | |
|
422 | |
|
423 | |
|
424 | |
|
425 | |
|
426 | |
|
427 | |
@Override |
428 | |
@Transactional(readOnly=false) |
429 | |
public StatusInfo removeLoCategoryFromLo(String loCategoryId, String loId) |
430 | |
throws DoesNotExistException, InvalidParameterException, |
431 | |
MissingParameterException, OperationFailedException, |
432 | |
PermissionDeniedException, UnsupportedActionException { |
433 | 44 | checkForMissingParameter(loCategoryId, "loCategoryId"); |
434 | 44 | checkForMissingParameter(loId, "loId"); |
435 | |
|
436 | 44 | StatusInfo statusInfo = new StatusInfo(); |
437 | 44 | statusInfo.setSuccess(loDao.removeLoCategoryFromLo(loCategoryId, loId)); |
438 | 44 | return statusInfo; |
439 | |
} |
440 | |
|
441 | |
|
442 | |
|
443 | |
|
444 | |
@Override |
445 | |
@Transactional(readOnly=false) |
446 | |
public LoInfo updateLo(String loId, LoInfo loInfo) |
447 | |
throws DataValidationErrorException, DoesNotExistException, |
448 | |
InvalidParameterException, MissingParameterException, |
449 | |
OperationFailedException, PermissionDeniedException, |
450 | |
VersionMismatchException { |
451 | 25 | checkForMissingParameter(loId, "loId"); |
452 | 24 | checkForMissingParameter(loInfo, "loInfo"); |
453 | |
|
454 | |
|
455 | 23 | List<ValidationResultInfo> val = validateLo("SYSTEM", loInfo); |
456 | 23 | if(null != val && val.size() > 0) { |
457 | 0 | for (ValidationResultInfo result : val) { |
458 | 0 | System.err.println("Validation error. Element: " + result.getElement() + ", Value: " + result.getMessage()); |
459 | |
} |
460 | 0 | throw new DataValidationErrorException("Validation error!", val); |
461 | |
} |
462 | |
|
463 | 23 | Lo lo = loDao.fetch(Lo.class, loId); |
464 | |
|
465 | 23 | if (!String.valueOf(lo.getVersionNumber()).equals(loInfo.getMetaInfo().getVersionInd())){ |
466 | 1 | throw new VersionMismatchException("LO to be updated is not the current version"); |
467 | |
} |
468 | |
|
469 | 22 | lo = LearningObjectiveServiceAssembler.toLo(true, lo, loInfo, loDao); |
470 | 22 | loDao.update(lo); |
471 | 22 | return LearningObjectiveServiceAssembler.toLoInfo(lo); |
472 | |
} |
473 | |
|
474 | |
|
475 | |
|
476 | |
|
477 | |
@Override |
478 | |
@Transactional(readOnly=false) |
479 | |
public LoCategoryInfo updateLoCategory(String loCategoryId, |
480 | |
LoCategoryInfo loCategoryInfo) throws DataValidationErrorException, |
481 | |
DoesNotExistException, InvalidParameterException, |
482 | |
MissingParameterException, OperationFailedException, |
483 | |
PermissionDeniedException, VersionMismatchException { |
484 | 3 | checkForMissingParameter(loCategoryId, "loCategoryId"); |
485 | 3 | checkForMissingParameter(loCategoryInfo, "loCategoryInfo"); |
486 | |
|
487 | |
|
488 | 3 | List<ValidationResultInfo> val = validateLoCategory("SYSTEM", loCategoryInfo); |
489 | |
|
490 | |
|
491 | 3 | if (doesLoCategoryExist(loCategoryInfo.getLoRepository(), loCategoryInfo, loCategoryId)) { |
492 | 2 | ValidationResultInfo vr = new ValidationResultInfo(); |
493 | 2 | vr.setElement("LO Category Name"); |
494 | 2 | vr.setError("LO Category already exists"); |
495 | 2 | val.add(vr); |
496 | |
} |
497 | 3 | if(null != val && val.size() > 0) { |
498 | 2 | for (ValidationResultInfo result : val) { |
499 | 2 | System.err.println("Validation error. Element: " + result.getElement() + ", Value: " + result.getMessage()); |
500 | |
} |
501 | 2 | throw new DataValidationErrorException("Validation error!", val); |
502 | |
} |
503 | 1 | LoCategory loCategory = loDao.fetch(LoCategory.class, loCategoryId); |
504 | |
|
505 | 1 | if (!String.valueOf(loCategory.getVersionNumber()).equals(loCategoryInfo.getMetaInfo().getVersionInd())){ |
506 | 0 | throw new VersionMismatchException("LoCategory to be updated is not the current version"); |
507 | |
} |
508 | |
|
509 | |
|
510 | 1 | if (loCategory.getState().equals("active") && ( ! loCategoryInfo.getState().equals("active") )) { |
511 | |
|
512 | |
|
513 | 0 | List<LoInfo> loInfos = getLosByLoCategory(loCategoryId); |
514 | 0 | if (null != loInfos) { |
515 | |
|
516 | 0 | for (LoInfo info : loInfos) { |
517 | 0 | if (info.getState().equals("active")) { |
518 | |
try { |
519 | 0 | removeLoCategoryFromLo(loCategoryId, info.getId()); |
520 | 0 | } catch (UnsupportedActionException uaee) { |
521 | 0 | throw new OperationFailedException("Unable to update LoCategory: could not remove association with active LearningObjective", uaee); |
522 | 0 | } |
523 | |
} |
524 | |
} |
525 | |
} |
526 | |
} |
527 | |
|
528 | |
|
529 | 1 | if ( ! loCategory.getLoCategoryType().getId().equals(loCategoryInfo.getType()) ) { |
530 | 1 | loCategory = cloneLoCategory(loCategory, loCategoryInfo); |
531 | |
} else { |
532 | 0 | loCategory = LearningObjectiveServiceAssembler.toLoCategory(loCategory, loCategoryInfo, loDao); |
533 | 0 | loDao.update(loCategory); |
534 | |
} |
535 | 1 | return LearningObjectiveServiceAssembler.toLoCategoryInfo(loCategory); |
536 | |
} |
537 | |
|
538 | |
|
539 | |
|
540 | |
|
541 | |
private LoCategory cloneLoCategory(LoCategory loCategory, LoCategoryInfo loCategoryInfo) throws DoesNotExistException, InvalidParameterException, OperationFailedException { |
542 | 1 | LoCategoryType catType = null; |
543 | |
|
544 | |
try { |
545 | 1 | catType = loDao.fetch(LoCategoryType.class, loCategoryInfo.getType()); |
546 | 0 | } catch (DoesNotExistException dnee) { |
547 | 0 | throw new DoesNotExistException("Attempt to set LoCategory's type to nonexistent LoCategoryType", dnee); |
548 | 1 | } |
549 | |
|
550 | |
|
551 | 1 | LoCategoryInfo newLoCategoryInfo = LearningObjectiveServiceAssembler.toLoCategoryInfo(loCategory); |
552 | 1 | newLoCategoryInfo.setType(catType.getId()); |
553 | 1 | newLoCategoryInfo.setName(loCategoryInfo.getName()); |
554 | 1 | LoCategory newLoCategory = loDao.create(LearningObjectiveServiceAssembler.toLoCategory(newLoCategoryInfo, loDao)); |
555 | |
|
556 | |
|
557 | 1 | List<Lo> catsLos = loDao.getLosByLoCategory(loCategory.getId()); |
558 | 1 | for (Lo lo : catsLos) { |
559 | |
try { |
560 | |
|
561 | 2 | loDao.addLoCategoryToLo(newLoCategory.getId(), lo.getId()); |
562 | |
|
563 | 2 | loDao.removeLoCategoryFromLo(loCategory.getId(), lo.getId()); |
564 | 0 | } catch (UnsupportedActionException uae) { |
565 | 0 | throw new OperationFailedException(uae.getMessage(), uae); |
566 | 2 | } |
567 | |
} |
568 | |
|
569 | |
|
570 | 1 | loCategory.setState("inactive"); |
571 | 1 | loDao.update(loCategory); |
572 | |
|
573 | 1 | return newLoCategory; |
574 | |
} |
575 | |
|
576 | |
|
577 | |
|
578 | |
|
579 | |
@Override |
580 | |
public List<ValidationResultInfo> validateLo(String validationType, |
581 | |
LoInfo loInfo) throws DoesNotExistException, |
582 | |
InvalidParameterException, MissingParameterException, |
583 | |
OperationFailedException { |
584 | 676 | checkForMissingParameter(validationType, "validationType"); |
585 | 676 | checkForMissingParameter(loInfo, "loInfo"); |
586 | |
|
587 | |
|
588 | |
|
589 | |
|
590 | |
|
591 | |
|
592 | |
|
593 | |
|
594 | |
|
595 | 676 | ObjectStructureDefinition objStructure = this.getObjectStructure(LoInfo.class.getName()); |
596 | 676 | Validator validator = validatorFactory.getValidator(); |
597 | 676 | return validator.validateObject(loInfo, objStructure); |
598 | |
} |
599 | |
|
600 | |
|
601 | |
|
602 | |
|
603 | |
@Override |
604 | |
public List<ValidationResultInfo> validateLoCategory(String validationType, |
605 | |
LoCategoryInfo loCategoryInfo) throws DoesNotExistException, |
606 | |
InvalidParameterException, MissingParameterException, |
607 | |
OperationFailedException { |
608 | 10 | checkForMissingParameter(validationType, "validationType"); |
609 | 10 | checkForMissingParameter(loCategoryInfo, "loCategoryInfo"); |
610 | |
|
611 | |
|
612 | |
|
613 | |
|
614 | |
|
615 | |
|
616 | |
|
617 | |
|
618 | |
|
619 | 10 | ObjectStructureDefinition objStructure = this.getObjectStructure(LoCategoryInfo.class.getName()); |
620 | 10 | Validator validator = validatorFactory.getValidator(); |
621 | 10 | return validator.validateObject(loCategoryInfo, objStructure); |
622 | |
|
623 | |
} |
624 | |
|
625 | |
@Override |
626 | |
public List<ValidationResultInfo> validateLoLoRelation( |
627 | |
String validationType, LoLoRelationInfo loLoRelationInfo) |
628 | |
throws DoesNotExistException, InvalidParameterException, |
629 | |
MissingParameterException, OperationFailedException { |
630 | |
|
631 | 554 | ObjectStructureDefinition objStructure = this.getObjectStructure(LoLoRelationInfo.class.getName()); |
632 | 554 | Validator validator = validatorFactory.getValidator(); |
633 | 554 | return validator.validateObject(loLoRelationInfo, objStructure); |
634 | |
} |
635 | |
|
636 | |
|
637 | |
|
638 | |
|
639 | |
|
640 | |
|
641 | |
|
642 | |
|
643 | |
private void checkForMissingParameter(Object param, String paramName) |
644 | |
throws MissingParameterException { |
645 | 9706 | if (param == null) { |
646 | 16 | throw new MissingParameterException(paramName + " can not be null"); |
647 | |
} |
648 | 9690 | } |
649 | |
|
650 | |
|
651 | |
|
652 | |
|
653 | |
|
654 | |
|
655 | |
private void checkForEmptyList(Object param, String paramName) |
656 | |
throws MissingParameterException { |
657 | 1 | if (param != null && param instanceof List && ((List<?>)param).size() == 0) { |
658 | 0 | throw new MissingParameterException(paramName + " can not be an empty list"); |
659 | |
} |
660 | 1 | } |
661 | |
|
662 | |
|
663 | |
|
664 | |
|
665 | |
|
666 | |
|
667 | |
|
668 | |
|
669 | |
|
670 | |
|
671 | |
|
672 | |
|
673 | |
|
674 | |
|
675 | |
|
676 | |
|
677 | |
|
678 | |
|
679 | |
|
680 | |
|
681 | |
|
682 | |
private boolean doesLoCategoryExist(String loRepositoryKey, LoCategoryInfo loCategoryInfo, String loCategoryId) |
683 | |
throws MissingParameterException, DataValidationErrorException { |
684 | 10 | if (loCategoryInfo.getName() == null) |
685 | |
{ |
686 | 1 | return false; |
687 | |
} |
688 | 9 | boolean exists = false; |
689 | 9 | SearchRequest request = new SearchRequest(); |
690 | 9 | request.setSearchKey("lo.search.loCategoriesByNameRepoTypeState"); |
691 | |
|
692 | 9 | List<SearchParam> searchParams = new ArrayList<SearchParam>(); |
693 | 9 | SearchParam qpv1 = new SearchParam(); |
694 | 9 | qpv1.setKey("lo.queryParam.loCategoryName"); |
695 | 9 | qpv1.setValue(loCategoryInfo.getName().toLowerCase()); |
696 | 9 | searchParams.add(qpv1); |
697 | 9 | SearchParam qpv2 = new SearchParam(); |
698 | 9 | qpv2.setKey("lo.queryParam.loCategoryRepo"); |
699 | 9 | qpv2.setValue(loRepositoryKey); |
700 | 9 | searchParams.add(qpv2); |
701 | 9 | SearchParam qpv3 = new SearchParam(); |
702 | 9 | qpv3.setKey("lo.queryParam.loCategoryType"); |
703 | 9 | qpv3.setValue(loCategoryInfo.getType()); |
704 | 9 | searchParams.add(qpv3); |
705 | 9 | SearchParam qpv4 = new SearchParam(); |
706 | 9 | qpv4.setKey("lo.queryParam.loCategoryState"); |
707 | 9 | qpv4.setValue(loCategoryInfo.getState()); |
708 | 9 | searchParams.add(qpv4); |
709 | |
|
710 | 9 | request.setParams(searchParams); |
711 | |
|
712 | 9 | SearchResult result = search(request); |
713 | |
|
714 | 9 | if(loCategoryId != null && !loCategoryId.trim().equals("")){ |
715 | 3 | if (result.getRows().size() > 0) { |
716 | 2 | for(SearchResultRow srrow : result.getRows()){ |
717 | 2 | List<SearchResultCell> srCells = srrow.getCells(); |
718 | 2 | if(srCells != null && srCells.size() > 0){ |
719 | 2 | for(SearchResultCell srcell : srCells){ |
720 | 2 | if(!srcell.getValue().equals(loCategoryId)) { |
721 | 2 | exists = true; |
722 | |
} |
723 | |
} |
724 | |
} |
725 | 2 | } |
726 | |
} |
727 | |
} |
728 | |
else{ |
729 | 6 | if (result.getRows().size() > 0) { |
730 | 2 | exists = true; |
731 | |
} |
732 | |
} |
733 | 9 | return exists; |
734 | |
} |
735 | |
|
736 | |
@Override |
737 | |
public ObjectStructureDefinition getObjectStructure(String objectTypeKey) { |
738 | 1240 | return dictionaryServiceDelegate.getObjectStructure(objectTypeKey); |
739 | |
} |
740 | |
|
741 | |
@Override |
742 | |
public List<String> getObjectTypes() { |
743 | 0 | return dictionaryServiceDelegate.getObjectTypes(); |
744 | |
} |
745 | |
|
746 | |
|
747 | |
|
748 | |
|
749 | |
@Override |
750 | |
public SearchCriteriaTypeInfo getSearchCriteriaType( |
751 | |
String searchCriteriaTypeKey) throws DoesNotExistException, |
752 | |
InvalidParameterException, MissingParameterException, |
753 | |
OperationFailedException { |
754 | |
|
755 | 0 | return searchManager.getSearchCriteriaType(searchCriteriaTypeKey); |
756 | |
} |
757 | |
|
758 | |
|
759 | |
|
760 | |
|
761 | |
@Override |
762 | |
public List<SearchCriteriaTypeInfo> getSearchCriteriaTypes() |
763 | |
throws OperationFailedException { |
764 | 0 | return searchManager.getSearchCriteriaTypes(); |
765 | |
} |
766 | |
|
767 | |
|
768 | |
|
769 | |
|
770 | |
@Override |
771 | |
public SearchResultTypeInfo getSearchResultType(String searchResultTypeKey) |
772 | |
throws DoesNotExistException, InvalidParameterException, |
773 | |
MissingParameterException, OperationFailedException { |
774 | 0 | checkForMissingParameter(searchResultTypeKey, "searchResultTypeKey"); |
775 | 0 | return searchManager.getSearchResultType(searchResultTypeKey); |
776 | |
} |
777 | |
|
778 | |
|
779 | |
|
780 | |
|
781 | |
@Override |
782 | |
public List<SearchResultTypeInfo> getSearchResultTypes() |
783 | |
throws OperationFailedException { |
784 | 0 | return searchManager.getSearchResultTypes(); |
785 | |
} |
786 | |
|
787 | |
|
788 | |
|
789 | |
|
790 | |
@Override |
791 | |
public SearchTypeInfo getSearchType(String searchTypeKey) |
792 | |
throws DoesNotExistException, InvalidParameterException, |
793 | |
MissingParameterException, OperationFailedException { |
794 | 0 | checkForMissingParameter(searchTypeKey, "searchTypeKey"); |
795 | 0 | return searchManager.getSearchType(searchTypeKey); |
796 | |
} |
797 | |
|
798 | |
|
799 | |
|
800 | |
|
801 | |
@Override |
802 | |
public List<SearchTypeInfo> getSearchTypes() |
803 | |
throws OperationFailedException { |
804 | 0 | return searchManager.getSearchTypes(); |
805 | |
} |
806 | |
|
807 | |
|
808 | |
|
809 | |
|
810 | |
@Override |
811 | |
public List<SearchTypeInfo> getSearchTypesByCriteria( |
812 | |
String searchCriteriaTypeKey) throws DoesNotExistException, |
813 | |
InvalidParameterException, MissingParameterException, |
814 | |
OperationFailedException { |
815 | 0 | checkForMissingParameter(searchCriteriaTypeKey, "searchCriteriaTypeKey"); |
816 | 0 | return searchManager.getSearchTypesByCriteria(searchCriteriaTypeKey); |
817 | |
} |
818 | |
|
819 | |
|
820 | |
|
821 | |
|
822 | |
@Override |
823 | |
public List<SearchTypeInfo> getSearchTypesByResult( |
824 | |
String searchResultTypeKey) throws DoesNotExistException, |
825 | |
InvalidParameterException, MissingParameterException, |
826 | |
OperationFailedException { |
827 | 0 | checkForMissingParameter(searchResultTypeKey, "searchResultTypeKey"); |
828 | 0 | return searchManager.getSearchTypesByResult(searchResultTypeKey); |
829 | |
} |
830 | |
|
831 | |
@Override |
832 | |
@Transactional(readOnly=false) |
833 | |
public LoLoRelationInfo createLoLoRelation(String loId, String relatedLoId, |
834 | |
String loLoRelationType, LoLoRelationInfo loLoRelationInfo) |
835 | |
throws AlreadyExistsException, |
836 | |
DataValidationErrorException, DoesNotExistException, |
837 | |
InvalidParameterException, MissingParameterException, |
838 | |
OperationFailedException, PermissionDeniedException { |
839 | 558 | checkForMissingParameter(loId, "loId"); |
840 | 557 | checkForMissingParameter(relatedLoId, "relatedLoId"); |
841 | 556 | checkForMissingParameter(loLoRelationType, "loLoRelationType"); |
842 | 555 | checkForMissingParameter(loLoRelationInfo, "loLoRelationInfo"); |
843 | |
|
844 | |
|
845 | 554 | List<ValidationResultInfo> val = validateLoLoRelation("SYSTEM", loLoRelationInfo); |
846 | 554 | if(null != val && val.size() > 0) { |
847 | 0 | for (ValidationResultInfo result : val) { |
848 | 0 | System.err.println("Validation error. Element: " + result.getElement() + ", Value: " + result.getMessage()); |
849 | |
} |
850 | 0 | throw new DataValidationErrorException("Validation error!", val); |
851 | |
} |
852 | |
|
853 | 554 | if (null == loLoRelationInfo.getState()) { |
854 | 2 | loLoRelationInfo.setState(DtoConstants.STATE_DRAFT); |
855 | |
} |
856 | 554 | Lo lo = loDao.fetch(Lo.class, loId); |
857 | 554 | Lo relatedLo = loDao.fetch(Lo.class, relatedLoId); |
858 | 554 | LoLoRelationType type = loDao.fetch(LoLoRelationType.class, loLoRelationType); |
859 | 554 | loLoRelationInfo.setLoId(loId); |
860 | 554 | loLoRelationInfo.setRelatedLoId(relatedLoId); |
861 | 554 | loLoRelationInfo.setType(loLoRelationType); |
862 | |
|
863 | 554 | LoLoRelation relation = null; |
864 | |
try { |
865 | 554 | relation = LearningObjectiveServiceAssembler.toLoLoRelation(false, loLoRelationInfo, loDao); |
866 | 0 | } catch (VersionMismatchException vme) { |
867 | |
|
868 | 0 | throw new OperationFailedException("VersionMismatchException caught during LoLoRelation creation"); |
869 | 554 | } |
870 | 554 | relation.setLo(lo); |
871 | 554 | relation.setRelatedLo(relatedLo); |
872 | 554 | relation.setLoLoRelationType(type); |
873 | |
|
874 | 554 | relation = loDao.create(relation); |
875 | |
|
876 | 554 | return LearningObjectiveServiceAssembler.toLoLoRelationInfo(relation); |
877 | |
} |
878 | |
|
879 | |
@Override |
880 | |
@Transactional(readOnly=false) |
881 | |
public StatusInfo deleteLoLoRelation(String loLoRelationId) |
882 | |
throws DoesNotExistException, InvalidParameterException, |
883 | |
MissingParameterException, OperationFailedException, |
884 | |
PermissionDeniedException { |
885 | 18 | checkForMissingParameter(loLoRelationId, "loLoRelationId"); |
886 | |
|
887 | 18 | loDao.deleteLoLoRelation(loLoRelationId); |
888 | |
|
889 | 18 | return new StatusInfo(); |
890 | |
} |
891 | |
|
892 | |
@Override |
893 | |
public LoLoRelationInfo getLoLoRelation(String loLoRelationId) |
894 | |
throws DoesNotExistException, InvalidParameterException, |
895 | |
MissingParameterException, OperationFailedException { |
896 | 4 | checkForMissingParameter(loLoRelationId, "loLoRelationId"); |
897 | 3 | return LearningObjectiveServiceAssembler.toLoLoRelationInfo(loDao.fetch(LoLoRelation.class, loLoRelationId)); |
898 | |
} |
899 | |
|
900 | |
@Override |
901 | |
public List<LoLoRelationInfo> getLoLoRelationsByLoId(String loId) |
902 | |
throws DoesNotExistException, InvalidParameterException, |
903 | |
MissingParameterException, OperationFailedException { |
904 | 52 | List<LoLoRelation> llRelations = loDao.getLoLoRelationsByLoId(loId); |
905 | 52 | return LearningObjectiveServiceAssembler.toLoLoRelationInfos(llRelations); |
906 | |
} |
907 | |
|
908 | |
@Override |
909 | |
public List<LoInfo> getLosByRelatedLoId(String relatedLoId, |
910 | |
String loLoRelationType) throws DoesNotExistException, |
911 | |
InvalidParameterException, MissingParameterException, |
912 | |
OperationFailedException { |
913 | 0 | List<Lo> relatedLos = loDao.getLosByRelatedLoId(relatedLoId, loLoRelationType); |
914 | 0 | return LearningObjectiveServiceAssembler.toLoInfos(relatedLos); |
915 | |
} |
916 | |
|
917 | |
@Override |
918 | |
public List<LoInfo> getRelatedLosByLoId(String loId, String loLoRelationTypeKey) |
919 | |
throws DoesNotExistException, InvalidParameterException, |
920 | |
MissingParameterException, OperationFailedException { |
921 | 390 | checkForMissingParameter(loId, "loId"); |
922 | 389 | checkForMissingParameter(loLoRelationTypeKey, "loLoRelationTypeKey"); |
923 | 388 | List<Lo> relatedLos = loDao.getRelatedLosByLoId(loId, loLoRelationTypeKey); |
924 | 388 | return LearningObjectiveServiceAssembler.toLoInfos(relatedLos); |
925 | |
} |
926 | |
|
927 | |
@Override |
928 | |
@Transactional(readOnly=false) |
929 | |
public LoLoRelationInfo updateLoLoRelation(String loLoRelationId, |
930 | |
LoLoRelationInfo loLoRelationInfo) |
931 | |
throws DataValidationErrorException, DoesNotExistException, |
932 | |
InvalidParameterException, MissingParameterException, |
933 | |
OperationFailedException, PermissionDeniedException, |
934 | |
VersionMismatchException { |
935 | |
|
936 | |
|
937 | |
|
938 | 0 | List<ValidationResultInfo> val = validateLoLoRelation("SYSTEM", loLoRelationInfo); |
939 | 0 | if(null != val && val.size() > 0) { |
940 | 0 | throw new DataValidationErrorException("Validation error!", val); |
941 | |
} |
942 | |
|
943 | |
|
944 | 0 | return null; |
945 | |
} |
946 | |
|
947 | |
@Override |
948 | |
@Transactional(readOnly=false) |
949 | |
public LoCategoryInfo createLoCategory(String loRepositoryKey, |
950 | |
String loCategoryTypeKey, LoCategoryInfo loCategoryInfo) |
951 | |
throws DataValidationErrorException, DoesNotExistException, |
952 | |
InvalidParameterException, MissingParameterException, |
953 | |
OperationFailedException, PermissionDeniedException { |
954 | 7 | checkForMissingParameter(loRepositoryKey, "loRepositoryKey"); |
955 | 7 | checkForMissingParameter(loCategoryTypeKey, "loCategoryTypeKey"); |
956 | 7 | checkForMissingParameter(loCategoryInfo, "loCategoryInfo"); |
957 | |
|
958 | |
|
959 | 7 | List<ValidationResultInfo> val = validateLoCategory("SYSTEM", loCategoryInfo); |
960 | |
|
961 | |
|
962 | 7 | if (doesLoCategoryExist(loRepositoryKey, loCategoryInfo, null)) { |
963 | 2 | ValidationResultInfo vr = new ValidationResultInfo(); |
964 | 2 | vr.setElement("LO Category Name"); |
965 | 2 | vr.setError("LO Category already exists"); |
966 | 2 | val.add(vr); |
967 | |
} |
968 | 7 | if(null != val && val.size() > 0) { |
969 | 3 | for (ValidationResultInfo result : val) { |
970 | 3 | System.err.println("Validation error. Element: " + result.getElement() + ", Value: " + result.getMessage()); |
971 | |
} |
972 | 3 | throw new DataValidationErrorException("Validation error!", val); |
973 | |
} |
974 | |
|
975 | 4 | LoCategory category = LearningObjectiveServiceAssembler.toLoCategory(loCategoryInfo, loDao); |
976 | 4 | LoCategoryType loCatType = loDao.fetch(LoCategoryType.class, loCategoryTypeKey); |
977 | 4 | category.setLoCategoryType(loCatType); |
978 | 4 | LoRepository loRepository = loDao.fetch(LoRepository.class, loRepositoryKey); |
979 | 4 | category.setLoRepository(loRepository); |
980 | 4 | loDao.create(category); |
981 | 4 | return LearningObjectiveServiceAssembler.toLoCategoryInfo(category); |
982 | |
} |
983 | |
|
984 | |
@Override |
985 | |
public LoCategoryTypeInfo getLoCategoryType(String loCategoryTypeKey) |
986 | |
throws DoesNotExistException, InvalidParameterException, |
987 | |
MissingParameterException, OperationFailedException { |
988 | 0 | checkForMissingParameter(loCategoryTypeKey, "loCategoryTypeKey"); |
989 | 0 | LoCategoryType loCatType = loDao.fetch(LoCategoryType.class, loCategoryTypeKey); |
990 | 0 | return LearningObjectiveServiceAssembler.toLoCategoryTypeInfo(loCatType); |
991 | |
} |
992 | |
|
993 | |
@Override |
994 | |
public List<LoCategoryTypeInfo> getLoCategoryTypes() |
995 | |
throws OperationFailedException { |
996 | 1 | List<LoCategoryType> categoryTypes = loDao.find(LoCategoryType.class); |
997 | 1 | return LearningObjectiveServiceAssembler.toLoCategoryTypeInfos(categoryTypes); |
998 | |
} |
999 | |
|
1000 | |
@Override |
1001 | |
public List<LoInfo> getLosByRepository(String loRepositoryKey, |
1002 | |
String loTypeKey, String loStateKey) |
1003 | |
throws InvalidParameterException, MissingParameterException, |
1004 | |
OperationFailedException { |
1005 | 0 | checkForMissingParameter(loRepositoryKey, "loRepositoryKey"); |
1006 | 0 | List<Lo> los = loDao.getLosByRepository(loRepositoryKey); |
1007 | 0 | return LearningObjectiveServiceAssembler.toLoInfos(los); |
1008 | |
} |
1009 | |
|
1010 | |
@Override |
1011 | |
public SearchResult search(SearchRequest searchRequest) throws MissingParameterException { |
1012 | 10 | checkForMissingParameter(searchRequest, "searchRequest"); |
1013 | 10 | return searchManager.search(searchRequest, loDao); |
1014 | |
} |
1015 | |
|
1016 | |
} |