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