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