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