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