1 | |
package org.kuali.student.lum.course.service.impl; |
2 | |
|
3 | |
import static org.apache.commons.collections.CollectionUtils.isEmpty; |
4 | |
|
5 | |
import java.util.ArrayList; |
6 | |
import java.util.Date; |
7 | |
import java.util.List; |
8 | |
|
9 | |
import org.apache.log4j.Logger; |
10 | |
import org.kuali.student.common.validator.Validator; |
11 | |
import org.kuali.student.common.validator.ValidatorFactory; |
12 | |
import org.kuali.student.core.assembly.BaseDTOAssemblyNode; |
13 | |
import org.kuali.student.core.assembly.BaseDTOAssemblyNode.NodeOperation; |
14 | |
import org.kuali.student.core.assembly.BusinessServiceMethodInvoker; |
15 | |
import org.kuali.student.core.assembly.data.AssemblyException; |
16 | |
import org.kuali.student.core.dictionary.dto.ObjectStructureDefinition; |
17 | |
import org.kuali.student.core.dictionary.service.DictionaryService; |
18 | |
import org.kuali.student.core.dto.StatusInfo; |
19 | |
import org.kuali.student.core.exceptions.AlreadyExistsException; |
20 | |
import org.kuali.student.core.exceptions.CircularReferenceException; |
21 | |
import org.kuali.student.core.exceptions.CircularRelationshipException; |
22 | |
import org.kuali.student.core.exceptions.DataValidationErrorException; |
23 | |
import org.kuali.student.core.exceptions.DependentObjectsExistException; |
24 | |
import org.kuali.student.core.exceptions.DoesNotExistException; |
25 | |
import org.kuali.student.core.exceptions.IllegalVersionSequencingException; |
26 | |
import org.kuali.student.core.exceptions.InvalidParameterException; |
27 | |
import org.kuali.student.core.exceptions.MissingParameterException; |
28 | |
import org.kuali.student.core.exceptions.OperationFailedException; |
29 | |
import org.kuali.student.core.exceptions.PermissionDeniedException; |
30 | |
import org.kuali.student.core.exceptions.UnsupportedActionException; |
31 | |
import org.kuali.student.core.exceptions.VersionMismatchException; |
32 | |
import org.kuali.student.core.statement.dto.RefStatementRelationInfo; |
33 | |
import org.kuali.student.core.statement.dto.ReqCompFieldInfo; |
34 | |
import org.kuali.student.core.statement.dto.ReqComponentInfo; |
35 | |
import org.kuali.student.core.statement.dto.StatementTreeViewInfo; |
36 | |
import org.kuali.student.core.statement.service.StatementService; |
37 | |
import org.kuali.student.core.validation.dto.ValidationResultInfo; |
38 | |
import org.kuali.student.core.versionmanagement.dto.VersionDisplayInfo; |
39 | |
import org.kuali.student.lum.course.dto.ActivityInfo; |
40 | |
import org.kuali.student.lum.course.dto.CourseInfo; |
41 | |
import org.kuali.student.lum.course.dto.CourseJointInfo; |
42 | |
import org.kuali.student.lum.course.dto.FormatInfo; |
43 | |
import org.kuali.student.lum.course.dto.LoDisplayInfo; |
44 | |
import org.kuali.student.lum.course.service.CourseService; |
45 | |
import org.kuali.student.lum.course.service.CourseServiceConstants; |
46 | |
import org.kuali.student.lum.course.service.assembler.CourseAssembler; |
47 | |
import org.kuali.student.lum.course.service.assembler.CourseAssemblerConstants; |
48 | |
import org.kuali.student.lum.lu.dto.CluInfo; |
49 | |
import org.kuali.student.lum.lu.dto.CluSetInfo; |
50 | |
import org.kuali.student.lum.lu.service.LuService; |
51 | |
import org.kuali.student.lum.lu.service.LuServiceConstants; |
52 | |
import org.kuali.student.lum.statement.typekey.ReqComponentFieldTypes; |
53 | |
import org.springframework.transaction.annotation.Transactional; |
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | |
@Transactional(readOnly=true,noRollbackFor={DoesNotExistException.class},rollbackFor={Throwable.class}) |
76 | 2 | public class CourseServiceImpl implements CourseService { |
77 | 1 | final static Logger LOG = Logger.getLogger(CourseServiceImpl.class); |
78 | |
|
79 | |
private LuService luService; |
80 | |
private CourseAssembler courseAssembler; |
81 | |
private BusinessServiceMethodInvoker courseServiceMethodInvoker; |
82 | |
private DictionaryService dictionaryServiceDelegate; |
83 | |
private ValidatorFactory validatorFactory; |
84 | |
private StatementService statementService; |
85 | |
|
86 | |
@Override |
87 | |
@Transactional(readOnly=false) |
88 | |
public CourseInfo createCourse(CourseInfo courseInfo) throws AlreadyExistsException, DataValidationErrorException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, VersionMismatchException, DoesNotExistException, CircularRelationshipException, DependentObjectsExistException, UnsupportedActionException { |
89 | |
|
90 | 14 | checkForMissingParameter(courseInfo, "CourseInfo"); |
91 | |
|
92 | |
|
93 | 14 | List<ValidationResultInfo> validationResults = validateCourse("OBJECT", courseInfo); |
94 | 14 | if (null != validationResults && validationResults.size() > 0) { |
95 | 0 | throw new DataValidationErrorException("Validation error!", validationResults); |
96 | |
} |
97 | |
|
98 | |
try { |
99 | 14 | return processCourseInfo(courseInfo, NodeOperation.CREATE); |
100 | 0 | } catch (AssemblyException e) { |
101 | 0 | LOG.error("Error disassembling course", e); |
102 | 0 | throw new OperationFailedException("Error disassembling course"); |
103 | 0 | } catch (Exception e){ |
104 | 0 | LOG.error("Error disassembling course", e); |
105 | 0 | throw new OperationFailedException("Error disassembling course"); |
106 | |
} |
107 | |
} |
108 | |
|
109 | |
@Override |
110 | |
@Transactional(readOnly=false) |
111 | |
public CourseInfo updateCourse(CourseInfo courseInfo) throws DataValidationErrorException, DoesNotExistException, InvalidParameterException, MissingParameterException, VersionMismatchException, OperationFailedException, PermissionDeniedException, AlreadyExistsException, CircularRelationshipException, DependentObjectsExistException, UnsupportedActionException, UnsupportedOperationException, CircularReferenceException { |
112 | |
|
113 | 2 | checkForMissingParameter(courseInfo, "CourseInfo"); |
114 | |
|
115 | |
|
116 | 2 | List<ValidationResultInfo> validationResults = validateCourse("OBJECT", courseInfo); |
117 | 2 | if (null != validationResults && validationResults.size() > 0) { |
118 | 0 | throw new DataValidationErrorException("Validation error!", validationResults); |
119 | |
} |
120 | |
|
121 | |
try { |
122 | |
|
123 | 2 | return processCourseInfo(courseInfo, NodeOperation.UPDATE); |
124 | |
|
125 | 0 | } catch (AssemblyException e) { |
126 | 0 | LOG.error("Error disassembling course", e); |
127 | 0 | throw new OperationFailedException("Error disassembling course"); |
128 | |
} |
129 | |
} |
130 | |
|
131 | |
@Override |
132 | |
@Transactional(readOnly=false) |
133 | |
public StatusInfo deleteCourse(String courseId) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, VersionMismatchException, DataValidationErrorException, AlreadyExistsException, CircularRelationshipException, DependentObjectsExistException, UnsupportedActionException, UnsupportedOperationException, CircularReferenceException { |
134 | |
|
135 | |
try { |
136 | 1 | CourseInfo course = getCourse(courseId); |
137 | |
|
138 | 1 | processCourseInfo(course, NodeOperation.DELETE); |
139 | |
|
140 | 1 | StatusInfo status = new StatusInfo(); |
141 | 1 | status.setSuccess(true); |
142 | 1 | return status; |
143 | |
|
144 | 0 | } catch (AssemblyException e) { |
145 | 0 | LOG.error("Error disassembling course", e); |
146 | 0 | throw new OperationFailedException("Error disassembling course"); |
147 | |
} |
148 | |
} |
149 | |
|
150 | |
@Override |
151 | |
public CourseInfo getCourse(String courseId) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
152 | |
|
153 | 15 | CluInfo clu = luService.getClu(courseId); |
154 | |
|
155 | |
CourseInfo course; |
156 | |
try { |
157 | 14 | course = courseAssembler.assemble(clu, null, false); |
158 | 0 | } catch (AssemblyException e) { |
159 | 0 | LOG.error("Error assembling course", e); |
160 | 0 | throw new OperationFailedException("Error assembling course"); |
161 | 14 | } |
162 | |
|
163 | 14 | return course; |
164 | |
|
165 | |
} |
166 | |
|
167 | |
@Override |
168 | |
public List<ActivityInfo> getCourseActivities(String formatId) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
169 | 1 | throw new UnsupportedOperationException("GetCourseActivities"); |
170 | |
} |
171 | |
|
172 | |
@Override |
173 | |
public List<FormatInfo> getCourseFormats(String courseId) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
174 | 1 | throw new UnsupportedOperationException("GetCourseFormats"); |
175 | |
} |
176 | |
|
177 | |
@Override |
178 | |
public List<LoDisplayInfo> getCourseLos(String courseId) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
179 | 1 | throw new UnsupportedOperationException("GetCourseLos"); |
180 | |
} |
181 | |
|
182 | |
@Override |
183 | |
public List<StatementTreeViewInfo> getCourseStatements(String courseId, String nlUsageTypeKey, String language) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
184 | 12 | checkForMissingParameter(courseId, "courseId"); |
185 | |
|
186 | 12 | CluInfo clu = luService.getClu(courseId); |
187 | 12 | if (!CourseAssemblerConstants.COURSE_TYPE.equals(clu.getType())) { |
188 | 1 | throw new DoesNotExistException("Specified CLU is not a Course"); |
189 | |
} |
190 | 11 | List<RefStatementRelationInfo> relations = statementService.getRefStatementRelationsByRef(CourseAssemblerConstants.COURSE_TYPE, clu.getId()); |
191 | 11 | if (relations == null) { |
192 | 7 | return new ArrayList<StatementTreeViewInfo>(0); |
193 | |
} |
194 | |
|
195 | 4 | List<StatementTreeViewInfo> tree = new ArrayList<StatementTreeViewInfo>(relations.size()); |
196 | 4 | for (RefStatementRelationInfo relation : relations) { |
197 | 9 | tree.add(statementService.getStatementTreeView(relation.getStatementId())); |
198 | |
} |
199 | 4 | return tree; |
200 | |
} |
201 | |
|
202 | |
@Override |
203 | |
public List<ValidationResultInfo> validateCourse(String validationType, CourseInfo courseInfo) throws InvalidParameterException, MissingParameterException, OperationFailedException { |
204 | |
|
205 | 16 | ObjectStructureDefinition objStructure = this.getObjectStructure(CourseInfo.class.getName()); |
206 | 16 | Validator defaultValidator = validatorFactory.getValidator(); |
207 | 16 | List<ValidationResultInfo> validationResults = defaultValidator.validateObject(courseInfo, objStructure); |
208 | 16 | return validationResults; |
209 | |
} |
210 | |
|
211 | |
@Override |
212 | |
@Transactional(readOnly=false) |
213 | |
public StatementTreeViewInfo createCourseStatement(String courseId, StatementTreeViewInfo statementTreeViewInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, DataValidationErrorException { |
214 | 8 | checkForMissingParameter(courseId, "courseId"); |
215 | 7 | checkForMissingParameter(statementTreeViewInfo, "statementTreeViewInfo"); |
216 | |
|
217 | |
|
218 | 6 | List<ValidationResultInfo> validationResults = validateCourseStatement(courseId, statementTreeViewInfo); |
219 | 6 | if (!isEmpty(validationResults)) { |
220 | 0 | throw new DataValidationErrorException("Validation error!", validationResults); |
221 | |
} |
222 | |
|
223 | 6 | if (findStatementReference(courseId, statementTreeViewInfo) != null) { |
224 | 1 | throw new InvalidParameterException("Statement is already referenced by this course"); |
225 | |
} |
226 | |
|
227 | |
try { |
228 | 5 | StatementTreeViewInfo tree = statementService.createStatementTreeView(statementTreeViewInfo); |
229 | 5 | RefStatementRelationInfo relation = new RefStatementRelationInfo(); |
230 | 5 | relation.setRefObjectId(courseId); |
231 | 5 | relation.setRefObjectTypeKey(CourseAssemblerConstants.COURSE_TYPE); |
232 | 5 | relation.setStatementId(tree.getId()); |
233 | 5 | relation.setType(CourseAssemblerConstants.COURSE_REFERENCE_TYPE); |
234 | 5 | relation.setState(CourseAssemblerConstants.ACTIVE); |
235 | 5 | statementService.createRefStatementRelation(relation); |
236 | 0 | } catch (Exception e) { |
237 | 0 | throw new OperationFailedException("Unable to create clu/tree relation", e); |
238 | 5 | } |
239 | 5 | return statementTreeViewInfo; |
240 | |
} |
241 | |
|
242 | |
@Override |
243 | |
@Transactional(readOnly=false) |
244 | |
public StatusInfo deleteCourseStatement(String courseId, StatementTreeViewInfo statementTreeViewInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
245 | 5 | checkForMissingParameter(courseId, "courseId"); |
246 | 4 | checkForMissingParameter(statementTreeViewInfo, "statementTreeViewInfo"); |
247 | |
|
248 | 3 | RefStatementRelationInfo relation = findStatementReference(courseId, statementTreeViewInfo); |
249 | 3 | if (relation != null) { |
250 | 1 | statementService.deleteRefStatementRelation(relation.getId()); |
251 | 1 | statementService.deleteStatementTreeView(statementTreeViewInfo.getId()); |
252 | 1 | StatusInfo result = new StatusInfo(); |
253 | 1 | return result; |
254 | |
} |
255 | |
|
256 | 2 | throw new DoesNotExistException("Course does not have this StatemenTree"); |
257 | |
} |
258 | |
|
259 | |
@Override |
260 | |
@Transactional(readOnly=false) |
261 | |
public StatementTreeViewInfo updateCourseStatement(String courseId, StatementTreeViewInfo statementTreeViewInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, DataValidationErrorException, CircularReferenceException, VersionMismatchException { |
262 | 1 | checkForMissingParameter(courseId, "courseId"); |
263 | 1 | checkForMissingParameter(statementTreeViewInfo, "statementTreeViewInfo"); |
264 | |
|
265 | |
|
266 | 1 | List<ValidationResultInfo> validationResults = validateCourseStatement(courseId, statementTreeViewInfo); |
267 | 1 | if (!isEmpty(validationResults)) { |
268 | 0 | throw new DataValidationErrorException("Validation error!", validationResults); |
269 | |
} |
270 | |
|
271 | 1 | if (findStatementReference(courseId, statementTreeViewInfo) == null) { |
272 | 0 | throw new InvalidParameterException("Statement is not part of this course"); |
273 | |
} |
274 | |
|
275 | 1 | return statementService.updateStatementTreeView(statementTreeViewInfo.getId(), statementTreeViewInfo); |
276 | |
} |
277 | |
|
278 | |
@Override |
279 | |
public List<ValidationResultInfo> validateCourseStatement(String courseId, StatementTreeViewInfo statementTreeViewInfo) throws InvalidParameterException, MissingParameterException, OperationFailedException { |
280 | 7 | checkForMissingParameter(courseId, "courseId"); |
281 | 7 | checkForMissingParameter(statementTreeViewInfo, "statementTreeViewInfo"); |
282 | |
|
283 | |
try { |
284 | 7 | CluInfo clu = luService.getClu(courseId); |
285 | 0 | } catch (DoesNotExistException e) { |
286 | 0 | throw new InvalidParameterException("course does not exist"); |
287 | 7 | } |
288 | |
|
289 | 7 | ObjectStructureDefinition objStructure = this.getObjectStructure(StatementTreeViewInfo.class.getName()); |
290 | 7 | Validator defaultValidator = validatorFactory.getValidator(); |
291 | 7 | List<ValidationResultInfo> validationResults = defaultValidator.validateObject(statementTreeViewInfo, objStructure); |
292 | 7 | return validationResults; |
293 | |
} |
294 | |
|
295 | |
@Override |
296 | |
public ObjectStructureDefinition getObjectStructure(String objectTypeKey) { |
297 | 24 | return dictionaryServiceDelegate.getObjectStructure(objectTypeKey); |
298 | |
} |
299 | |
|
300 | |
@Override |
301 | |
public List<String> getObjectTypes() { |
302 | 1 | return dictionaryServiceDelegate.getObjectTypes(); |
303 | |
} |
304 | |
|
305 | |
public CourseAssembler getCourseAssembler() { |
306 | 0 | return courseAssembler; |
307 | |
} |
308 | |
|
309 | |
public void setCourseAssembler(CourseAssembler courseAssembler) { |
310 | 1 | this.courseAssembler = courseAssembler; |
311 | 1 | } |
312 | |
|
313 | |
public BusinessServiceMethodInvoker getCourseServiceMethodInvoker() { |
314 | 0 | return courseServiceMethodInvoker; |
315 | |
} |
316 | |
|
317 | |
public void setCourseServiceMethodInvoker(BusinessServiceMethodInvoker courseServiceMethodInvoker) { |
318 | 1 | this.courseServiceMethodInvoker = courseServiceMethodInvoker; |
319 | 1 | } |
320 | |
|
321 | |
public DictionaryService getDictionaryServiceDelegate() { |
322 | 0 | return dictionaryServiceDelegate; |
323 | |
} |
324 | |
|
325 | |
public void setDictionaryServiceDelegate(DictionaryService dictionaryServiceDelegate) { |
326 | 1 | this.dictionaryServiceDelegate = dictionaryServiceDelegate; |
327 | 1 | } |
328 | |
|
329 | |
private CourseInfo processCourseInfo(CourseInfo courseInfo, NodeOperation operation) throws AssemblyException, OperationFailedException, VersionMismatchException, PermissionDeniedException, MissingParameterException, InvalidParameterException, DoesNotExistException, DataValidationErrorException, AlreadyExistsException, CircularRelationshipException, DependentObjectsExistException, UnsupportedActionException, UnsupportedOperationException, CircularReferenceException { |
330 | |
|
331 | 17 | BaseDTOAssemblyNode<CourseInfo, CluInfo> results = courseAssembler.disassemble(courseInfo, operation); |
332 | |
|
333 | |
|
334 | 17 | courseServiceMethodInvoker.invokeServiceCalls(results); |
335 | |
|
336 | 16 | return results.getBusinessDTORef(); |
337 | |
} |
338 | |
|
339 | |
public ValidatorFactory getValidatorFactory() { |
340 | 0 | return validatorFactory; |
341 | |
} |
342 | |
|
343 | |
public void setValidatorFactory(ValidatorFactory validatorFactory) { |
344 | 1 | this.validatorFactory = validatorFactory; |
345 | 1 | } |
346 | |
|
347 | |
public LuService getLuService() { |
348 | 0 | return luService; |
349 | |
} |
350 | |
|
351 | |
public void setLuService(LuService luService) { |
352 | 1 | this.luService = luService; |
353 | 1 | } |
354 | |
|
355 | |
public StatementService getStatementService() { |
356 | 0 | return statementService; |
357 | |
} |
358 | |
|
359 | |
public void setStatementService(StatementService statementService) { |
360 | 1 | this.statementService = statementService; |
361 | 1 | } |
362 | |
|
363 | |
@Override |
364 | |
@Transactional(readOnly=false) |
365 | |
public CourseInfo createNewCourseVersion(String versionIndCourseId, |
366 | |
String versionComment) throws DataValidationErrorException, |
367 | |
DoesNotExistException, InvalidParameterException, |
368 | |
MissingParameterException, OperationFailedException, |
369 | |
PermissionDeniedException, VersionMismatchException { |
370 | |
|
371 | |
|
372 | 8 | VersionDisplayInfo currentVersion = luService.getCurrentVersion(LuServiceConstants.CLU_NAMESPACE_URI, versionIndCourseId); |
373 | 8 | CourseInfo originalCourse = getCourse(currentVersion.getId()); |
374 | |
|
375 | |
|
376 | 8 | CluInfo newVersionClu = luService.createNewCluVersion(versionIndCourseId, versionComment); |
377 | |
|
378 | |
try { |
379 | |
BaseDTOAssemblyNode<CourseInfo, CluInfo> results; |
380 | |
|
381 | |
|
382 | 8 | courseAssembler.assemble(newVersionClu, originalCourse, true); |
383 | |
|
384 | |
|
385 | 8 | resetIds(originalCourse); |
386 | |
|
387 | |
|
388 | 8 | results = courseAssembler.disassemble(originalCourse, NodeOperation.UPDATE); |
389 | |
|
390 | |
|
391 | 8 | courseServiceMethodInvoker.invokeServiceCalls(results); |
392 | |
|
393 | |
|
394 | 8 | List<StatementTreeViewInfo> statementTreeViews = getCourseStatements(currentVersion.getId(),null,null); |
395 | |
|
396 | 8 | clearStatementTreeViewIds(statementTreeViews); |
397 | |
|
398 | 8 | for(StatementTreeViewInfo statementTreeView:statementTreeViews){ |
399 | 1 | createCourseStatement(results.getBusinessDTORef().getId(), statementTreeView); |
400 | |
} |
401 | |
|
402 | 8 | return results.getBusinessDTORef(); |
403 | 0 | } catch (AlreadyExistsException e) { |
404 | 0 | throw new OperationFailedException("Error creating new course version",e); |
405 | 0 | } catch (DependentObjectsExistException e) { |
406 | 0 | throw new OperationFailedException("Error creating new course version",e); |
407 | 0 | } catch (CircularRelationshipException e) { |
408 | 0 | throw new OperationFailedException("Error creating new course version",e); |
409 | 0 | } catch (UnsupportedActionException e) { |
410 | 0 | throw new OperationFailedException("Error creating new course version",e); |
411 | 0 | } catch (AssemblyException e) { |
412 | 0 | throw new OperationFailedException("Error creating new course version",e); |
413 | 0 | } catch (UnsupportedOperationException e) { |
414 | 0 | throw new OperationFailedException("Error creating new course version",e); |
415 | 0 | } catch (CircularReferenceException e) { |
416 | 0 | throw new OperationFailedException("Error creating new course version",e); |
417 | |
} |
418 | |
|
419 | |
} |
420 | |
|
421 | |
private void clearStatementTreeViewIds( |
422 | |
List<StatementTreeViewInfo> statementTreeViews) throws OperationFailedException { |
423 | 8 | for(StatementTreeViewInfo statementTreeView:statementTreeViews){ |
424 | 1 | clearStatementTreeViewIdsRecursively(statementTreeView); |
425 | |
} |
426 | 8 | } |
427 | |
|
428 | |
private void clearStatementTreeViewIdsRecursively(StatementTreeViewInfo statementTreeView) throws OperationFailedException{ |
429 | 3 | statementTreeView.setId(null); |
430 | 3 | for(ReqComponentInfo reqComp:statementTreeView.getReqComponents()){ |
431 | 4 | reqComp.setId(null); |
432 | 4 | for(ReqCompFieldInfo field:reqComp.getReqCompFields()){ |
433 | 0 | field.setId(null); |
434 | |
|
435 | 0 | if(ReqComponentFieldTypes.COURSE_CLUSET_KEY.getId().equals(field.getType())|| |
436 | |
ReqComponentFieldTypes.PROGRAM_CLUSET_KEY.getId().equals(field.getType())|| |
437 | |
ReqComponentFieldTypes.CLUSET_KEY.getId().equals(field.getType())){ |
438 | |
try { |
439 | 0 | CluSetInfo cluSet = luService.getCluSetInfo(field.getValue()); |
440 | 0 | cluSet.setId(null); |
441 | |
|
442 | 0 | if (cluSet.getMembershipQuery() != null){ |
443 | 0 | cluSet.getCluIds().clear(); |
444 | 0 | cluSet.getCluSetIds().clear(); |
445 | |
} |
446 | 0 | cluSet = luService.createCluSet(cluSet.getType(), cluSet); |
447 | 0 | field.setValue(cluSet.getId()); |
448 | 0 | } catch (Exception e) { |
449 | 0 | throw new OperationFailedException("Error copying clusets.", e); |
450 | 0 | } |
451 | |
} |
452 | |
|
453 | |
} |
454 | |
} |
455 | 3 | for(StatementTreeViewInfo child: statementTreeView.getStatements()){ |
456 | 2 | clearStatementTreeViewIdsRecursively(child); |
457 | |
} |
458 | 3 | } |
459 | |
|
460 | |
private void resetIds(CourseInfo course) { |
461 | |
|
462 | 8 | for(CourseJointInfo joint:course.getJoints()){ |
463 | 0 | joint.setRelationId(null); |
464 | |
} |
465 | |
|
466 | 8 | for(LoDisplayInfo lo:course.getCourseSpecificLOs()){ |
467 | 16 | resetLoRecursively(lo); |
468 | |
} |
469 | |
|
470 | 8 | for(FormatInfo format:course.getFormats()){ |
471 | 16 | format.setId(null); |
472 | 16 | for(ActivityInfo activity:format.getActivities()){ |
473 | 32 | activity.setId(null); |
474 | |
} |
475 | |
} |
476 | 8 | } |
477 | |
|
478 | |
private void resetLoRecursively(LoDisplayInfo lo){ |
479 | 112 | lo.getLoInfo().setId(null); |
480 | 112 | for(LoDisplayInfo nestedLo:lo.getLoDisplayInfoList()){ |
481 | 96 | resetLoRecursively(nestedLo); |
482 | |
} |
483 | 112 | } |
484 | |
|
485 | |
@Override |
486 | |
@Transactional(readOnly=false) |
487 | |
public StatusInfo setCurrentCourseVersion(String courseVersionId, |
488 | |
Date currentVersionStart) throws DoesNotExistException, |
489 | |
InvalidParameterException, MissingParameterException, |
490 | |
IllegalVersionSequencingException, OperationFailedException, |
491 | |
PermissionDeniedException { |
492 | 2 | return luService.setCurrentCluVersion(courseVersionId, currentVersionStart); |
493 | |
} |
494 | |
|
495 | |
@Override |
496 | |
public VersionDisplayInfo getCurrentVersion(String refObjectTypeURI, |
497 | |
String refObjectId) throws DoesNotExistException, |
498 | |
InvalidParameterException, MissingParameterException, |
499 | |
OperationFailedException, PermissionDeniedException { |
500 | 2 | if(CourseServiceConstants.COURSE_NAMESPACE_URI.equals(refObjectTypeURI)){ |
501 | 1 | return luService.getCurrentVersion(LuServiceConstants.CLU_NAMESPACE_URI, refObjectId); |
502 | |
} |
503 | 1 | throw new InvalidParameterException("Object type: " + refObjectTypeURI + " is not known to this implementation"); |
504 | |
} |
505 | |
|
506 | |
@Override |
507 | |
public VersionDisplayInfo getCurrentVersionOnDate(String refObjectTypeURI, |
508 | |
String refObjectId, Date date) throws DoesNotExistException, |
509 | |
InvalidParameterException, MissingParameterException, |
510 | |
OperationFailedException, PermissionDeniedException { |
511 | 4 | if(CourseServiceConstants.COURSE_NAMESPACE_URI.equals(refObjectTypeURI)){ |
512 | 3 | return luService.getCurrentVersionOnDate(LuServiceConstants.CLU_NAMESPACE_URI, refObjectId, date); |
513 | |
} |
514 | 1 | throw new InvalidParameterException("Object type: " + refObjectTypeURI + " is not known to this implementation"); |
515 | |
} |
516 | |
|
517 | |
@Override |
518 | |
public VersionDisplayInfo getFirstVersion(String refObjectTypeURI, |
519 | |
String refObjectId) throws DoesNotExistException, |
520 | |
InvalidParameterException, MissingParameterException, |
521 | |
OperationFailedException, PermissionDeniedException { |
522 | 2 | if(CourseServiceConstants.COURSE_NAMESPACE_URI.equals(refObjectTypeURI)){ |
523 | 1 | return luService.getFirstVersion(LuServiceConstants.CLU_NAMESPACE_URI, refObjectId); |
524 | |
} |
525 | 1 | throw new InvalidParameterException("Object type: " + refObjectTypeURI + " is not known to this implementation"); |
526 | |
|
527 | |
} |
528 | |
|
529 | |
@Override |
530 | |
public VersionDisplayInfo getLatestVersion(String refObjectTypeURI, |
531 | |
String refObjectId) throws DoesNotExistException, |
532 | |
InvalidParameterException, MissingParameterException, |
533 | |
OperationFailedException, PermissionDeniedException { |
534 | 0 | if(CourseServiceConstants.COURSE_NAMESPACE_URI.equals(refObjectTypeURI)){ |
535 | 0 | return luService.getLatestVersion(LuServiceConstants.CLU_NAMESPACE_URI, refObjectId); |
536 | |
} |
537 | 0 | throw new InvalidParameterException("Object type: " + refObjectTypeURI + " is not known to this implementation"); |
538 | |
|
539 | |
} |
540 | |
|
541 | |
@Override |
542 | |
public VersionDisplayInfo getVersionBySequenceNumber( |
543 | |
String refObjectTypeURI, String refObjectId, Long sequence) |
544 | |
throws DoesNotExistException, InvalidParameterException, |
545 | |
MissingParameterException, OperationFailedException, |
546 | |
PermissionDeniedException { |
547 | 2 | if(CourseServiceConstants.COURSE_NAMESPACE_URI.equals(refObjectTypeURI)){ |
548 | 1 | return luService.getVersionBySequenceNumber(LuServiceConstants.CLU_NAMESPACE_URI, refObjectId, sequence); |
549 | |
} |
550 | 1 | throw new InvalidParameterException("Object type: " + refObjectTypeURI + " is not known to this implementation"); |
551 | |
} |
552 | |
|
553 | |
@Override |
554 | |
public List<VersionDisplayInfo> getVersions(String refObjectTypeURI, |
555 | |
String refObjectId) throws DoesNotExistException, |
556 | |
InvalidParameterException, MissingParameterException, |
557 | |
OperationFailedException, PermissionDeniedException { |
558 | 3 | if(CourseServiceConstants.COURSE_NAMESPACE_URI.equals(refObjectTypeURI)){ |
559 | 2 | return luService.getVersions(LuServiceConstants.CLU_NAMESPACE_URI, refObjectId); |
560 | |
} |
561 | 1 | throw new InvalidParameterException("Object type: " + refObjectTypeURI + " is not known to this implementation"); |
562 | |
} |
563 | |
|
564 | |
@Override |
565 | |
public List<VersionDisplayInfo> getVersionsInDateRange( |
566 | |
String refObjectTypeURI, String refObjectId, Date from, Date to) |
567 | |
throws DoesNotExistException, InvalidParameterException, |
568 | |
MissingParameterException, OperationFailedException, |
569 | |
PermissionDeniedException { |
570 | 2 | if(CourseServiceConstants.COURSE_NAMESPACE_URI.equals(refObjectTypeURI)){ |
571 | 1 | return luService.getVersionsInDateRange(LuServiceConstants.CLU_NAMESPACE_URI, refObjectId, from, to); |
572 | |
} |
573 | 1 | throw new InvalidParameterException("Object type: " + refObjectTypeURI + " is not known to this implementation"); |
574 | |
} |
575 | |
|
576 | |
|
577 | |
|
578 | |
|
579 | |
|
580 | |
|
581 | |
|
582 | |
|
583 | |
private void checkForMissingParameter(Object param, String paramName) |
584 | |
throws MissingParameterException { |
585 | 68 | if (param == null) { |
586 | 4 | throw new MissingParameterException(paramName + " can not be null"); |
587 | |
} |
588 | 64 | } |
589 | |
|
590 | |
|
591 | |
|
592 | |
|
593 | |
|
594 | |
|
595 | |
|
596 | |
|
597 | |
|
598 | |
|
599 | |
|
600 | |
private RefStatementRelationInfo findStatementReference(String courseId, |
601 | |
StatementTreeViewInfo statementTreeViewInfo) |
602 | |
throws InvalidParameterException, MissingParameterException, |
603 | |
OperationFailedException, DoesNotExistException { |
604 | 10 | List<RefStatementRelationInfo> course = statementService.getRefStatementRelationsByRef(CourseAssemblerConstants.COURSE_TYPE, courseId); |
605 | 10 | if (course != null) { |
606 | 7 | for (RefStatementRelationInfo refRelation : course) { |
607 | 20 | if (refRelation.getStatementId().equals(statementTreeViewInfo.getId())) { |
608 | 3 | return refRelation; |
609 | |
} |
610 | |
} |
611 | |
} |
612 | 7 | return null; |
613 | |
} |
614 | |
} |