Coverage Report - org.kuali.student.enrollment.class2.courseoffering.service.impl.CourseOfferingServiceImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
CourseOfferingServiceImpl
0%
0/410
0%
0/132
2.579
 
 1  
 package org.kuali.student.enrollment.class2.courseoffering.service.impl;
 2  
 
 3  
 import org.apache.commons.lang.StringUtils;
 4  
 import org.kuali.rice.core.api.criteria.GenericQueryResults;
 5  
 import org.kuali.rice.core.api.criteria.QueryByCriteria;
 6  
 import org.kuali.student.common.util.UUIDHelper;
 7  
 import org.kuali.student.enrollment.acal.service.AcademicCalendarService;
 8  
 import org.kuali.student.enrollment.class1.lui.model.LuiEntity;
 9  
 import org.kuali.student.enrollment.class2.courseoffering.service.transformer.FormatOfferingTransformer;
 10  
 import org.kuali.student.enrollment.class2.courseoffering.service.assembler.RegistrationGroupAssembler;
 11  
 import org.kuali.student.enrollment.courseoffering.dto.*;
 12  
 import org.kuali.student.enrollment.courseoffering.service.CourseOfferingService;
 13  
 import org.kuali.student.enrollment.lpr.dto.LprInfo;
 14  
 import org.kuali.student.enrollment.lpr.service.LprService;
 15  
 import org.kuali.student.enrollment.lui.dto.LuiInfo;
 16  
 import org.kuali.student.enrollment.lui.dto.LuiLuiRelationInfo;
 17  
 import org.kuali.student.enrollment.lui.service.LuiService;
 18  
 import org.kuali.student.lum.course.dto.CourseInfo;
 19  
 import org.kuali.student.lum.course.service.CourseService;
 20  
 import org.kuali.student.r2.common.criteria.CriteriaLookupService;
 21  
 import org.kuali.student.r2.common.dto.ContextInfo;
 22  
 import org.kuali.student.r2.common.dto.StatusInfo;
 23  
 import org.kuali.student.r2.common.dto.ValidationResultInfo;
 24  
 import org.kuali.student.r2.common.exceptions.AlreadyExistsException;
 25  
 import org.kuali.student.r2.common.exceptions.CircularRelationshipException;
 26  
 import org.kuali.student.r2.common.exceptions.DataValidationErrorException;
 27  
 import org.kuali.student.r2.common.exceptions.DependentObjectsExistException;
 28  
 import org.kuali.student.r2.common.exceptions.DisabledIdentifierException;
 29  
 import org.kuali.student.r2.common.exceptions.DoesNotExistException;
 30  
 import org.kuali.student.r2.common.exceptions.InvalidParameterException;
 31  
 import org.kuali.student.r2.common.exceptions.MissingParameterException;
 32  
 import org.kuali.student.r2.common.exceptions.OperationFailedException;
 33  
 import org.kuali.student.r2.common.exceptions.PermissionDeniedException;
 34  
 import org.kuali.student.r2.common.exceptions.ReadOnlyException;
 35  
 import org.kuali.student.r2.common.exceptions.VersionMismatchException;
 36  
 import org.kuali.student.r2.common.util.constants.LprServiceConstants;
 37  
 import org.kuali.student.r2.common.util.constants.LuiServiceConstants;
 38  
 import org.kuali.student.r2.core.state.service.StateService;
 39  
 import org.kuali.student.r2.core.type.dto.TypeInfo;
 40  
 import org.kuali.student.r2.core.type.service.TypeService;
 41  
 import org.springframework.transaction.annotation.Transactional;
 42  
 
 43  
 import java.util.*;
 44  
 
 45  
 import org.kuali.student.enrollment.acal.dto.TermInfo;
 46  
 import org.kuali.student.enrollment.class2.courseoffering.service.decorators.R1CourseServiceHelper;
 47  
 import org.kuali.student.enrollment.class2.courseoffering.service.transformer.ActivityOfferingTransformer;
 48  
 import org.kuali.student.enrollment.class2.courseoffering.service.transformer.CourseOfferingTransformer;
 49  
 import org.kuali.student.lum.course.dto.FormatInfo;
 50  
 
 51  
 import javax.jws.WebParam;
 52  
 
 53  
 
 54  
 @Transactional(readOnly = true, noRollbackFor = {DoesNotExistException.class}, rollbackFor = {Throwable.class})
 55  0
 public class CourseOfferingServiceImpl implements CourseOfferingService {
 56  
 
 57  
 
 58  
     private LuiService luiService;
 59  
     private TypeService typeService;
 60  
     private CourseService courseService;
 61  
     private AcademicCalendarService acalService;
 62  
     private RegistrationGroupAssembler registrationGroupAssembler;
 63  
     private StateService stateService;
 64  
     private LprService lprService;
 65  
     // TODO - remove when KSENROLL-247 is resolved
 66  0
     private static final Integer TEMP_MAX_ENROLLMENT_DEFAULT = 50;
 67  
 
 68  
 
 69  
     @Override
 70  
     public StatusInfo deleteCourseOfferingCascaded( String courseOfferingId, ContextInfo context) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
 71  0
             throw new UnsupportedOperationException();
 72  
     }
 73  
 
 74  
     @Override
 75  
     public StatusInfo deleteFormatOfferingCascaded( String formatOfferingId,ContextInfo context) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
 76  0
         throw new UnsupportedOperationException();
 77  
     }
 78  
 
 79  
     @Override
 80  
     public RegistrationGroupInfo createRegistrationGroup( String formatOfferingId,  String registrationGroupType,  RegistrationGroupInfo registrationGroupInfo, @WebParam(name = "context") ContextInfo context) throws DoesNotExistException, DataValidationErrorException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, ReadOnlyException {
 81  0
         throw new UnsupportedOperationException();
 82  
     }
 83  
 
 84  
     public CriteriaLookupService getCriteriaLookupService() {
 85  0
         return criteriaLookupService;
 86  
     }
 87  
 
 88  
     public void setCriteriaLookupService(CriteriaLookupService criteriaLookupService) {
 89  0
         this.criteriaLookupService = criteriaLookupService;
 90  0
     }
 91  
 
 92  
     private CriteriaLookupService criteriaLookupService;
 93  
 
 94  
     public LuiService getLuiService() {
 95  0
         return luiService;
 96  
     }
 97  
 
 98  
     public void setLuiService(LuiService luiService) {
 99  0
         this.luiService = luiService;
 100  0
     }
 101  
 
 102  
     public TypeService getTypeService() {
 103  0
         return typeService;
 104  
     }
 105  
 
 106  
     public void setTypeService(TypeService typeService) {
 107  0
         this.typeService = typeService;
 108  0
     }
 109  
 
 110  
     public CourseService getCourseService() {
 111  0
         return courseService;
 112  
     }
 113  
 
 114  
     public void setCourseService(CourseService courseService) {
 115  0
         this.courseService = courseService;
 116  0
     }
 117  
 
 118  
     public AcademicCalendarService getAcalService() {
 119  0
         return acalService;
 120  
     }
 121  
 
 122  
     public void setAcalService(AcademicCalendarService acalService) {
 123  0
         this.acalService = acalService;
 124  0
     }
 125  
 
 126  
     public RegistrationGroupAssembler getRgAssembler() {
 127  0
         return registrationGroupAssembler;
 128  
     }
 129  
 
 130  
     public void setRgAssembler(RegistrationGroupAssembler rgAssembler) {
 131  0
         this.registrationGroupAssembler = rgAssembler;
 132  0
     }
 133  
 
 134  
     public StateService getStateService() {
 135  0
         return stateService;
 136  
     }
 137  
 
 138  
     public void setStateService(StateService stateService) {
 139  0
         this.stateService = stateService;
 140  0
     }
 141  
 
 142  
     public LprService getLprService() {
 143  0
         return lprService;
 144  
     }
 145  
 
 146  
     public void setLprService(LprService lprService) {
 147  0
         this.lprService = lprService;
 148  0
     }
 149  
 
 150  
 
 151  
     @Override
 152  
     public TypeInfo getCourseOfferingType(String courseOfferingTypeKey, ContextInfo context) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
 153  0
         throw new UnsupportedOperationException("Not supported yet");
 154  
     }        
 155  
 
 156  
     @Override
 157  
     public List<TypeInfo> getCourseOfferingTypes(ContextInfo context) throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
 158  0
         throw new UnsupportedOperationException("Not supported yet");
 159  
     }
 160  
 
 161  
     @Override
 162  
     public List<TypeInfo> getInstructorTypesForCourseOfferingType(String courseOfferingTypeKey, ContextInfo context) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
 163  0
         throw new UnsupportedOperationException("Not supported yet");
 164  
     }
 165  
 
 166  
     @Override
 167  
     public CourseOfferingInfo getCourseOffering(String courseOfferingId, ContextInfo context)
 168  
             throws DoesNotExistException, InvalidParameterException, MissingParameterException,
 169  
             OperationFailedException, PermissionDeniedException {
 170  0
         LuiInfo lui = luiService.getLui(courseOfferingId, context);
 171  0
         CourseOfferingInfo co = new CourseOfferingInfo();
 172  0
         new CourseOfferingTransformer().lui2CourseOffering(lui, co, context);
 173  0
         return co;
 174  
     }
 175  
 
 176  
     @Override
 177  
     public CourseOfferingAdminDisplayInfo getCourseOfferingAdminDisplay(String courseOfferingId, ContextInfo context) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
 178  0
         throw new UnsupportedOperationException("Not supported yet");
 179  
     }
 180  
 
 181  
     @Override
 182  
     public List<CourseOfferingAdminDisplayInfo> getCourseOfferingAdminDisplaysByIds(List<String> courseOfferingIds, ContextInfo context) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
 183  0
         throw new UnsupportedOperationException("Not supported yet");
 184  
     }
 185  
    
 186  
     @Override
 187  
     public ActivityOfferingAdminDisplayInfo getActivityOfferingAdminDisplay(String activityOfferingId, ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
 188  0
         throw new UnsupportedOperationException("Not supported yet");
 189  
     }
 190  
 
 191  
     @Override
 192  
     public List<ActivityOfferingAdminDisplayInfo> getActivityOfferingAdminDisplaysByIds(List<String> activityOfferingIds, ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
 193  0
         throw new UnsupportedOperationException("Not supported yet");
 194  
     }
 195  
 
 196  
     @Override                                                                                        
 197  
     public List<ActivityOfferingAdminDisplayInfo> getActivityOfferingAdminDisplaysForCourseOffering(String courseOfferingId, ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
 198  0
         throw new UnsupportedOperationException("Not supported yet");
 199  
     }
 200  
 
 201  
     @Override
 202  
     public List<CourseOfferingInfo> getCourseOfferingsByIds(List<String> courseOfferingIds, ContextInfo context)
 203  
             throws DoesNotExistException, InvalidParameterException,
 204  
             MissingParameterException, OperationFailedException, PermissionDeniedException {
 205  
         // TODO: speed this up by calling the bulk lui methods?
 206  0
         List<CourseOfferingInfo> results = new ArrayList<CourseOfferingInfo>();
 207  0
         for (String id : courseOfferingIds) {
 208  0
             CourseOfferingInfo co = getCourseOffering(id, context);
 209  0
             results.add(co);
 210  0
         }
 211  0
         return results;
 212  
     }
 213  
 
 214  
     @Override
 215  
     public List<CourseOfferingInfo> getCourseOfferingsByCourse(String courseId, ContextInfo context)
 216  
             throws DoesNotExistException, InvalidParameterException, MissingParameterException,
 217  
             OperationFailedException, PermissionDeniedException {
 218  0
         List<String> luiIds = luiService.getLuiIdsByClu(courseId, context);
 219  0
         List<CourseOfferingInfo> results = new ArrayList<CourseOfferingInfo>();
 220  0
         for (String luiId : luiIds) {
 221  0
             CourseOfferingInfo co = getCourseOffering(luiId, context);
 222  0
             results.add(co);
 223  0
         }
 224  0
         return results;
 225  
     }
 226  
 
 227  
     @Override
 228  
     public List<CourseOfferingInfo> getCourseOfferingsByCourseAndTerm(String courseId, String termId, ContextInfo context)
 229  
             throws DoesNotExistException, InvalidParameterException, MissingParameterException,
 230  
             OperationFailedException, PermissionDeniedException {
 231  
         // check the term is valid
 232  0
         acalService.getTerm(termId, context);
 233  0
         List<String> luiIds = luiService.getLuiIdsByAtpAndType(termId, LuiServiceConstants.COURSE_OFFERING_TYPE_KEY, context);
 234  0
         List<CourseOfferingInfo> results = new ArrayList<CourseOfferingInfo>();
 235  
 
 236  0
         for (String luiId : luiIds) {
 237  0
             CourseOfferingInfo co = getCourseOffering(luiId, context);
 238  
 
 239  0
             if (StringUtils.equals(co.getCourseId(), courseId)) {
 240  0
                 results.add(co);
 241  
             }
 242  0
         }
 243  0
         return results;
 244  
     }
 245  
 
 246  
     @Override
 247  
     public List<String> getCourseOfferingIdsByTerm(String termId, Boolean useIncludedTerm, ContextInfo context)
 248  
             throws DoesNotExistException, InvalidParameterException, MissingParameterException,
 249  
             OperationFailedException, PermissionDeniedException {
 250  0
         this.acalService.getTerm(termId, context); // check term exists
 251  0
         List<String> luiIds = luiService.getLuiIdsByAtpAndType(termId, LuiServiceConstants.COURSE_OFFERING_TYPE_KEY, context);
 252  0
         return luiIds;
 253  
     }
 254  
 
 255  
     @Override
 256  
     public List<String> getCourseOfferingIdsByTermAndSubjectArea(String termId, String subjectArea, ContextInfo context)
 257  
             throws DoesNotExistException, InvalidParameterException, MissingParameterException,
 258  
             OperationFailedException, PermissionDeniedException {
 259  0
         List<String> luiIds = luiService.getLuiIdsByAtpAndType(termId, LuiServiceConstants.COURSE_OFFERING_TYPE_KEY, context);
 260  0
         List<String> results = new ArrayList<String>();
 261  
 
 262  0
         for (String luiId : luiIds) {
 263  0
             CourseOfferingInfo co = getCourseOffering(luiId, context);
 264  
 
 265  0
             if (StringUtils.equals(co.getSubjectArea(), subjectArea)) {
 266  0
                 results.add(luiId);
 267  
             }
 268  0
         }
 269  
 
 270  0
         return results;
 271  
     }
 272  
 
 273  
     @Override
 274  
     public List<CourseOfferingInfo> getCourseOfferingsByTermAndInstructor(String termId, String instructorId, ContextInfo context) throws DoesNotExistException, InvalidParameterException,
 275  
             MissingParameterException, OperationFailedException, PermissionDeniedException {
 276  0
         List<LprInfo> lprInfos = lprService.getLprsByPersonAndTypeForAtp(instructorId, termId, LprServiceConstants.INSTRUCTOR_MAIN_TYPE_KEY, context);
 277  0
         List<CourseOfferingInfo> cos = new ArrayList<CourseOfferingInfo>();
 278  0
         for (LprInfo lprInfo : lprInfos) {
 279  0
             cos.add(getCourseOffering(lprInfo.getLuiId(), context));
 280  
         }
 281  0
         return cos;
 282  
     }
 283  
 
 284  
     @Override
 285  
     public List<String> getCourseOfferingIdsByTermAndUnitsContentOwner(String termId, String unitsContentOwnerId,
 286  
                                                                        ContextInfo context) throws DoesNotExistException, InvalidParameterException,
 287  
             MissingParameterException, OperationFailedException, PermissionDeniedException {
 288  
         //TODO: use custom search
 289  0
         List<String> luiIds = luiService.getLuiIdsByAtpAndType(termId, LuiServiceConstants.COURSE_OFFERING_TYPE_KEY, context);
 290  0
         List<String> results = new ArrayList<String>();
 291  
 
 292  0
         for (String luiId : luiIds) {
 293  0
             CourseOfferingInfo co = getCourseOffering(luiId, context);
 294  
 
 295  0
             if (co.getUnitsContentOwnerOrgIds().contains(unitsContentOwnerId)) {
 296  0
                 results.add(luiId);
 297  
             }
 298  0
         }
 299  
 
 300  0
         return results;
 301  
 
 302  
     }
 303  
 
 304  
     @Override
 305  
     public List<String> getCourseOfferingIdsByType(String typeKey, ContextInfo context) throws DoesNotExistException,
 306  
             InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
 307  0
         throw new OperationFailedException("not implemented");
 308  
     }
 309  
 
 310  
 
 311  
     public List<String> getCourseOfferingIdsByTermAndUnitContentOwner(String termKey, String unitOwnerId,
 312  
                                                                       ContextInfo context) throws DoesNotExistException, InvalidParameterException,
 313  
             MissingParameterException, OperationFailedException, PermissionDeniedException {
 314  0
         throw new OperationFailedException("not implemented");
 315  
     }
 316  
 
 317  
     public List<CourseOfferingInfo> getCourseOfferingsBySoc(String s, ContextInfo contextInfo) throws DoesNotExistException,
 318  
             InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
 319  0
         throw new OperationFailedException("not implemented");
 320  
     }
 321  
 
 322  
     public List<CourseOfferingInfo> getPublishedCourseOfferingsBySoc(String s, ContextInfo contextInfo) throws DoesNotExistException,
 323  
             InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
 324  0
         throw new OperationFailedException("not implemented");
 325  
     }
 326  
 
 327  
     @Override
 328  
     public List<String> getValidCanonicalCourseToCourseOfferingOptionKeys(ContextInfo context) throws InvalidParameterException,
 329  
             MissingParameterException, OperationFailedException, PermissionDeniedException, ReadOnlyException {
 330  0
         throw new UnsupportedOperationException("Not supported yet.");
 331  
     }
 332  
 
 333  
     @Override
 334  
     public List<String> getValidRolloverOptionKeys(ContextInfo context) throws InvalidParameterException,
 335  
             MissingParameterException, OperationFailedException, PermissionDeniedException, ReadOnlyException {
 336  0
         throw new UnsupportedOperationException("Not supported yet.");
 337  
     }
 338  
 
 339  
     @Override
 340  
     @Transactional(readOnly = false)
 341  
     public CourseOfferingInfo rolloverCourseOffering(String sourceCourseOfferingId, String targetTermId, List<String> optionKeys, ContextInfo context) throws AlreadyExistsException,
 342  
             DataValidationErrorException, DoesNotExistException, DataValidationErrorException, InvalidParameterException,
 343  
             MissingParameterException, OperationFailedException, PermissionDeniedException, ReadOnlyException {
 344  0
         throw new UnsupportedOperationException("Configuration Error this method should have been implemented in the calculation layer and not reached here");
 345  
     }
 346  
     
 347  
     
 348  
 
 349  
     @Override
 350  
     @Transactional(readOnly = false)
 351  
     public CourseOfferingInfo createCourseOffering(String courseId, String termId, String courseOfferingTypeKey,
 352  
             CourseOfferingInfo coInfo, 
 353  
             List<String> optionKeys, ContextInfo context)
 354  
             throws DoesNotExistException, DataValidationErrorException,
 355  
             InvalidParameterException, MissingParameterException,
 356  
             OperationFailedException, PermissionDeniedException, ReadOnlyException {
 357  
 
 358  
         // validate params
 359  0
         if (!courseId.equals(coInfo.getCourseId())) {
 360  0
             throw new InvalidParameterException(courseId + " does not match the corresponding value in the object " + coInfo.getCourseId());
 361  
         }
 362  0
         if (!termId.equals(coInfo.getTermId())) {
 363  0
             throw new InvalidParameterException(termId + " does not match the corresponding value in the object " + coInfo.getTermId());
 364  
         }
 365  0
         if (!courseOfferingTypeKey.equals(coInfo.getTypeKey())) {
 366  0
             throw new InvalidParameterException(courseOfferingTypeKey + " does not match the corresponding value in the object " + coInfo.getTypeKey());
 367  
         }
 368  
         // check the term and course
 369  0
         TermInfo term = acalService.getTerm(termId, context);
 370  0
         CourseInfo courseInfo = getCourse(courseId);
 371  
         // copy from cannonical
 372  0
         CourseOfferingTransformer coTransformer = new CourseOfferingTransformer();
 373  0
         coTransformer.copyFromCanonical(courseInfo, coInfo, optionKeys);
 374  
         // copy to lui
 375  0
         LuiInfo lui = new LuiInfo();
 376  0
         coTransformer.courseOffering2Lui(coInfo, lui, context);
 377  
         // create it
 378  0
         lui = luiService.createLui(courseId, termId, lui.getTypeKey(), lui, context);
 379  
         // transform it back to a course offering
 380  0
         CourseOfferingInfo createdCo = new CourseOfferingInfo();
 381  0
         new CourseOfferingTransformer().lui2CourseOffering(lui, createdCo, context);
 382  0
         return createdCo;
 383  
     }
 384  
 
 385  
     private CourseInfo getCourse(String courseId) throws DoesNotExistException, OperationFailedException {
 386  0
         return new R1CourseServiceHelper (courseService, acalService).getCourse(courseId);
 387  
     }
 388  
 
 389  
     @Override
 390  
     @Transactional(readOnly = false)
 391  
     public CourseOfferingInfo updateCourseOffering(String courseOfferingId, CourseOfferingInfo coInfo, ContextInfo context)
 392  
             throws DataValidationErrorException, DoesNotExistException, InvalidParameterException,
 393  
             MissingParameterException, OperationFailedException, PermissionDeniedException,
 394  
             ReadOnlyException, VersionMismatchException {
 395  0
         if (!courseOfferingId.equals(coInfo.getId())) {
 396  0
             throw new InvalidParameterException(courseOfferingId + " does not match the corresponding value in the object " + coInfo.getId());
 397  
         }
 398  
 
 399  
         // get the backing lui
 400  0
         LuiInfo lui = luiService.getLui(courseOfferingId, context);
 401  0
         CourseOfferingTransformer transformer = new CourseOfferingTransformer();
 402  
         // copy fields and update            
 403  0
         transformer.courseOffering2Lui(coInfo, lui, context);
 404  0
         lui = luiService.updateLui(courseOfferingId, lui, context);
 405  
         // convert back to co and return
 406  0
         CourseOfferingInfo co = new CourseOfferingInfo();
 407  0
         transformer.lui2CourseOffering(lui, co, context);
 408  0
         return co;
 409  
     }
 410  
 
 411  
     @Override
 412  
     @Transactional(readOnly = false)
 413  
     public CourseOfferingInfo updateCourseOfferingFromCanonical(String courseOfferingId,
 414  
                                                                 List<String> optionKeys,
 415  
                                                                 ContextInfo context)
 416  
             throws DataValidationErrorException, DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException,
 417  
             VersionMismatchException {
 418  
 
 419  0
         CourseOfferingInfo co = this.getCourseOffering(courseOfferingId, context);
 420  0
         CourseInfo course = this.getCourse(co.getCourseId());
 421  
         // TODO: move this logic to the calculation decorator do the persistence layer doesn't have this logic mixed in with it
 422  0
         new CourseOfferingTransformer().copyFromCanonical(course, co, optionKeys);
 423  
         try {
 424  0
             co = this.updateCourseOffering(courseOfferingId, co, context);
 425  0
         } catch (ReadOnlyException roe) {
 426  0
             throw new OperationFailedException("updating read only fields", roe);
 427  0
         }
 428  0
         return co;
 429  
     }
 430  
 
 431  
     private void processInstructors(String courseOfferingId, List<OfferingInstructorInfo> instructors, String atpId, ContextInfo context) throws DoesNotExistException, InvalidParameterException,
 432  
             MissingParameterException, OperationFailedException, PermissionDeniedException, DataValidationErrorException, VersionMismatchException {
 433  
 
 434  0
         List<String> currrentInstructors = lprService.getPersonIdsByLuiAndTypeAndState(courseOfferingId, LprServiceConstants.INSTRUCTOR_MAIN_TYPE_KEY,
 435  
                 LprServiceConstants.ASSIGNED_STATE_KEY, context);
 436  
 
 437  0
         if (instructors != null && !instructors.isEmpty()) {
 438  0
             for (OfferingInstructorInfo instructor : instructors) {
 439  
                 try {
 440  0
                     if (currrentInstructors.contains(instructor.getPersonId())) {
 441  0
                         LprInfo existingLpr = getLpr(instructor.getPersonId(), courseOfferingId, context);
 442  0
                         if (existingLpr != null) {
 443  0
                             if (instructor.getPercentageEffort() != null) {
 444  0
                                 existingLpr.setCommitmentPercent("" + instructor.getPercentageEffort());
 445  
                             } else {
 446  0
                                 existingLpr.setCommitmentPercent(null);
 447  
                             }
 448  0
                             lprService.updateLpr(existingLpr.getId(), existingLpr, context);
 449  0
                             currrentInstructors.remove(instructor.getPersonId());
 450  
                         }
 451  0
                     } else {
 452  0
                         lprService.createLpr(instructor.getPersonId(), courseOfferingId, instructor.getTypeKey(), getNewLpr(instructor, courseOfferingId), context);
 453  
                     }
 454  0
                 } catch (ReadOnlyException e) {
 455  0
                     throw new OperationFailedException();
 456  0
                 }
 457  
             }
 458  
         }
 459  
 
 460  0
         if (currrentInstructors != null && currrentInstructors.size() > 0) {
 461  0
             if (atpId != null) {
 462  0
                 for (String instructorId : currrentInstructors) {
 463  0
                     LprInfo lpr = getLpr(instructorId, courseOfferingId, context);
 464  0
                     if (lpr != null) {
 465  0
                         lprService.deleteLpr(lpr.getId(), context);
 466  
                     }
 467  0
                 }
 468  
             }
 469  
         }
 470  0
     }
 471  
 
 472  
     private LprInfo getNewLpr(OfferingInstructorInfo instructor, String courseOfferingId) {
 473  0
         LprInfo lpr = new LprInfo();
 474  0
         lpr.setPersonId(instructor.getPersonId());
 475  0
         if (instructor.getPercentageEffort() != null) {
 476  0
             lpr.setCommitmentPercent("" + instructor.getPercentageEffort());
 477  
         } else {
 478  0
             lpr.setCommitmentPercent(null);
 479  
         }
 480  0
         lpr.setId(UUIDHelper.genStringUUID());
 481  0
         lpr.setLuiId(courseOfferingId);
 482  0
         lpr.setTypeKey(instructor.getTypeKey());
 483  0
         lpr.setStateKey(instructor.getStateKey());
 484  0
         return lpr;
 485  
     }
 486  
 
 487  
     private LprInfo getLpr(String instructor, String courseOfferingId, ContextInfo context) throws DoesNotExistException, InvalidParameterException, MissingParameterException,
 488  
             OperationFailedException, PermissionDeniedException {
 489  0
         LprInfo lpr = null;
 490  0
             List<LprInfo> lprs = lprService.getLprsByPersonAndLui(instructor, courseOfferingId, context);
 491  
 
 492  0
             if (lprs != null && !lprs.isEmpty()) {
 493  0
                 for (LprInfo lpri : lprs) {
 494  0
                     if (lpri.getTypeKey().equals(LprServiceConstants.INSTRUCTOR_MAIN_TYPE_KEY)) {
 495  0
                         lpr = lpri;
 496  
                     }
 497  
                 }
 498  
             }
 499  0
         return lpr;
 500  
     }
 501  
 
 502  
     @Override
 503  
     @Transactional(readOnly = false)
 504  
     public StatusInfo deleteCourseOffering(String courseOfferingId, ContextInfo context)
 505  
             throws DoesNotExistException, InvalidParameterException, MissingParameterException,
 506  
             OperationFailedException, PermissionDeniedException {
 507  
         try {
 508  0
             return luiService.deleteLui(courseOfferingId, context);
 509  0
         } catch (DependentObjectsExistException e) {
 510  0
             throw new OperationFailedException("Error deleting course offering", e);
 511  
         }
 512  
     }
 513  
 
 514  
     @Override
 515  
     public List<ValidationResultInfo> validateCourseOffering(String validationType, CourseOfferingInfo courseOfferingInfo,
 516  
                                                              ContextInfo context) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException {
 517  0
         return new ArrayList<ValidationResultInfo>();
 518  
     }
 519  
 
 520  
     @Override
 521  
     public List<ValidationResultInfo> validateCourseOfferingFromCanonical(CourseOfferingInfo courseOfferingInfo,
 522  
        List<String> optionKeys,
 523  
        ContextInfo context)
 524  
             throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException {
 525  0
         return new ArrayList<ValidationResultInfo>();
 526  
     }
 527  
 
 528  
     @Override
 529  
     public FormatOfferingInfo getFormatOffering(String formatOfferingId, ContextInfo context)
 530  
             throws DoesNotExistException, InvalidParameterException,
 531  
             MissingParameterException, OperationFailedException, PermissionDeniedException {
 532  0
         LuiInfo lui = luiService.getLui(formatOfferingId, context);
 533  0
         FormatOfferingInfo fo = new FormatOfferingInfo();
 534  0
         new FormatOfferingTransformer().lui2Format(lui, fo);
 535  0
         LuiInfo coLui = this.findCourseOfferingLui(lui.getId(), context);
 536  0
         fo.setCourseOfferingId(coLui.getId());
 537  0
         return fo;
 538  
     }
 539  
 
 540  
     private LuiInfo findCourseOfferingLui(String formatOfferingId, ContextInfo context)
 541  
             throws OperationFailedException {
 542  
         List<LuiInfo> rels;
 543  
         try {
 544  0
             rels = luiService.getLuisByRelatedLuiAndRelationType(formatOfferingId,
 545  
                     LuiServiceConstants.LUI_LUI_RELATION_ASSOCIATED_TYPE_KEY, context);
 546  0
         } catch (Exception ex) {
 547  0
             throw new OperationFailedException("unexpected", ex);
 548  0
         }
 549  0
         for (LuiInfo lui : rels) {
 550  0
             if (lui.getTypeKey().equals(LuiServiceConstants.COURSE_OFFERING_TYPE_KEY)) {
 551  0
                 return lui;
 552  
             }
 553  
         }
 554  0
         throw new OperationFailedException("format offering is not associated with a course offering " + formatOfferingId + " among " + rels.size());
 555  
     }
 556  
 
 557  
     private LuiInfo findFormatOfferingLui(String activityOfferingId, ContextInfo context)
 558  
             throws OperationFailedException {
 559  
         List<LuiInfo> rels;
 560  
         try {
 561  0
             rels = luiService.getLuisByRelatedLuiAndRelationType(activityOfferingId, LuiServiceConstants.LUI_LUI_RELATION_ASSOCIATED_TYPE_KEY, context);
 562  0
         } catch (Exception ex) {
 563  0
             throw new OperationFailedException("unexpected", ex);
 564  0
         }
 565  0
         for (LuiInfo lui : rels) {
 566  0
             if (lui.getTypeKey().equals(LuiServiceConstants.FORMAT_OFFERING_TYPE_KEY)) {
 567  0
                 return lui;
 568  
             }
 569  
         }
 570  0
         throw new OperationFailedException("format offering is not associated with a course offering " + activityOfferingId + " among " + rels.size());
 571  
     }
 572  
 
 573  
     @Override
 574  
     public List<FormatOfferingInfo> getFormatOfferingsByCourseOffering(String courseOfferingId, ContextInfo context)
 575  
             throws DoesNotExistException, InvalidParameterException, MissingParameterException,
 576  
             OperationFailedException, PermissionDeniedException {
 577  0
         throw new OperationFailedException("not implemented");
 578  
     }
 579  
 
 580  
     @Override
 581  
     @Transactional(readOnly = false)
 582  
     public StatusInfo deleteFormatOffering(String formatOfferingId, ContextInfo context) throws DoesNotExistException,
 583  
             InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, DependentObjectsExistException {
 584  
 
 585  0
         List<LuiLuiRelationInfo> formatOfferingRelations = luiService.getLuiLuiRelationsByLui(formatOfferingId, context);
 586  0
         for (LuiLuiRelationInfo luiLuiRelation : formatOfferingRelations) {
 587  0
             luiService.deleteLuiLuiRelation(luiLuiRelation.getId(), context);
 588  
         }
 589  0
         return luiService.deleteLui(formatOfferingId, context);
 590  
 
 591  
     }
 592  
 
 593  
     @Override
 594  
     @Transactional(readOnly = false)
 595  
     public FormatOfferingInfo updateFormatOffering(String formatOfferingId, FormatOfferingInfo formatOfferingInfo, ContextInfo context)
 596  
             throws DataValidationErrorException, DoesNotExistException,
 597  
             InvalidParameterException, MissingParameterException, OperationFailedException,
 598  
             PermissionDeniedException, ReadOnlyException, VersionMismatchException {
 599  
         // get the existing
 600  0
         LuiInfo lui = this.luiService.getLui(formatOfferingId, context);
 601  
         // transform and update
 602  0
         new FormatOfferingTransformer().format2Lui(formatOfferingInfo, lui);
 603  0
         lui = luiService.updateLui(formatOfferingId, lui, context);
 604  
         // rebuild the fo to return it
 605  0
         FormatOfferingInfo fo = new FormatOfferingInfo();
 606  0
         new FormatOfferingTransformer().lui2Format(lui, fo);
 607  0
         LuiInfo coLui = this.findCourseOfferingLui(formatOfferingId, context);
 608  0
         fo.setCourseOfferingId(coLui.getId());
 609  0
         return fo;
 610  
     }
 611  
 
 612  
     @Override
 613  
     public List<ValidationResultInfo> validateFormatOffering(String validationType, FormatOfferingInfo formatOfferingInfo,
 614  
                                                              ContextInfo context) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException {
 615  0
         return new ArrayList<ValidationResultInfo>();
 616  
     }
 617  
 
 618  
     @Override
 619  
     @Transactional(readOnly = false)
 620  
     public FormatOfferingInfo createFormatOffering(String courseOfferingId, String formatId, String formatOfferingType, FormatOfferingInfo foInfo, ContextInfo context)
 621  
             throws DoesNotExistException, DataValidationErrorException,
 622  
             InvalidParameterException, MissingParameterException, OperationFailedException,
 623  
             PermissionDeniedException, ReadOnlyException {
 624  
 
 625  
         // validate params
 626  0
         if (!courseOfferingId.equals(foInfo.getCourseOfferingId())) {
 627  0
             throw new InvalidParameterException(courseOfferingId + " does not match the corresponding value in the object " + foInfo.getCourseOfferingId());
 628  
         }
 629  0
         if (!formatId.equals(foInfo.getFormatId())) {
 630  0
             throw new InvalidParameterException(formatId + " does not match the corresponding value in the object " + foInfo.getFormatId());
 631  
         }
 632  0
         if (!formatOfferingType.equals(foInfo.getTypeKey())) {
 633  0
             throw new InvalidParameterException(formatOfferingType + " does not match the corresponding value in the object " + foInfo.getTypeKey());
 634  
         }
 635  
         // get the course offering
 636  0
         CourseOfferingInfo co = this.getCourseOffering(courseOfferingId, context);
 637  0
         if (foInfo.getTermId() != null) {
 638  0
             if (co.getTermId().equals(foInfo.getTermId())) {
 639  0
                 throw new InvalidParameterException(foInfo.getTermId() + " term in the format offering does not match the one in the course offering " + co.getTermId());
 640  
             }
 641  
         }
 642  0
         foInfo.setTermId(co.getTermId());
 643  
 
 644  
         // get formatId out of the course
 645  0
         CourseInfo course = this.getCourse(co.getCourseId()); // make sure it exists
 646  0
         FormatInfo format = null;
 647  0
         for (FormatInfo info : course.getFormats()) {
 648  0
             if (info.getId().equals(formatId)) {
 649  0
                 format = info;
 650  0
                 break;
 651  
             }
 652  
         }
 653  0
         if (format == null) {
 654  0
             throw new DoesNotExistException(formatId);
 655  
         }
 656  
         // copy to lui
 657  0
         LuiInfo lui = new LuiInfo();
 658  0
         new FormatOfferingTransformer().format2Lui(foInfo, lui);
 659  
 
 660  
 
 661  
         try {
 662  0
             lui = luiService.createLui(lui.getCluId(), lui.getAtpId(), lui.getTypeKey(), lui, context);
 663  0
         } catch (Exception aee) {
 664  0
             throw new OperationFailedException("Unexpected", aee);
 665  0
         }
 666  
         // now connect it to the course offering lui
 667  0
         LuiLuiRelationInfo rel = new LuiLuiRelationInfo();
 668  0
         rel.setLuiId(courseOfferingId);
 669  0
         rel.setRelatedLuiId(lui.getId());
 670  0
         rel.setStateKey(LuiServiceConstants.LUI_LUI_RELATION_ACTIVE_STATE_KEY);
 671  0
         rel.setTypeKey(LuiServiceConstants.LUI_LUI_RELATION_ASSOCIATED_TYPE_KEY);
 672  0
         rel.setEffectiveDate(new Date());
 673  
         try {
 674  0
             rel = luiService.createLuiLuiRelation(rel.getLuiId(), rel.getRelatedLuiId(), rel.getTypeKey(), rel, context);
 675  0
         } catch (Exception aee) {
 676  0
             throw new OperationFailedException("Unexpected", aee);
 677  0
         }
 678  
         // reubild to return it
 679  0
         FormatOfferingInfo formatOffering = new FormatOfferingInfo();
 680  0
         new FormatOfferingTransformer().lui2Format(lui, formatOffering);
 681  0
         formatOffering.setCourseOfferingId(rel.getLuiId());
 682  0
         return formatOffering;
 683  
     }
 684  
 
 685  
     @Override
 686  
     public TypeInfo getActivityOfferingType(String activityOfferingTypeKey, ContextInfo context) throws DoesNotExistException,
 687  
             InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
 688  0
         throw new OperationFailedException("not implemented");
 689  
     }
 690  
 
 691  
     @Override
 692  
     public List<TypeInfo> getActivityOfferingTypes(ContextInfo context) throws InvalidParameterException, MissingParameterException, OperationFailedException,
 693  
             PermissionDeniedException {
 694  0
         throw new OperationFailedException("not implemented");
 695  
     }
 696  
 
 697  
     @Override
 698  
     public List<TypeInfo> getInstructorTypesForActivityOfferingType(String activityOfferingTypeKey, ContextInfo context) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
 699  0
         throw new OperationFailedException("not implemented");
 700  
     }
 701  
 
 702  
     @Override
 703  
     public List<TypeInfo> getActivityOfferingTypesForActivityType(String activityTypeKey, ContextInfo context) throws DoesNotExistException, InvalidParameterException, MissingParameterException,
 704  
             OperationFailedException, PermissionDeniedException {
 705  0
         return typeService.getAllowedTypesForType(activityTypeKey, context);
 706  
     }
 707  
 
 708  
     @Override
 709  
     public ActivityOfferingInfo getActivityOffering(String activityOfferingId, ContextInfo context) throws DoesNotExistException, InvalidParameterException, MissingParameterException,
 710  
             OperationFailedException, PermissionDeniedException {
 711  0
         LuiInfo lui = luiService.getLui(activityOfferingId, context);
 712  0
         ActivityOfferingInfo ao = new ActivityOfferingInfo();
 713  0
         new ActivityOfferingTransformer().lui2Activity(ao, lui);
 714  0
         LuiInfo foLui = this.findFormatOfferingLui(activityOfferingId, context);
 715  0
         ao.setFormatOfferingId(foLui.getId());
 716  0
         return ao;
 717  
     }
 718  
 
 719  
     @Override
 720  
     public List<ActivityOfferingInfo> getActivityOfferingsByIds(List<String> strings, ContextInfo contextInfo)
 721  
             throws DoesNotExistException, InvalidParameterException, MissingParameterException,
 722  
             OperationFailedException, PermissionDeniedException {
 723  0
         throw new OperationFailedException("not implemented");
 724  
     }
 725  
 
 726  
     @Override
 727  
     public List<ActivityOfferingInfo> getActivityOfferingsByCourseOffering(String courseOfferingId, ContextInfo context)
 728  
             throws DoesNotExistException, InvalidParameterException,
 729  
             MissingParameterException, OperationFailedException,
 730  
             PermissionDeniedException {
 731  
 
 732  0
         List<ActivityOfferingInfo> list = new ArrayList<ActivityOfferingInfo>();
 733  0
         List<FormatOfferingInfo> formats = this.getFormatOfferingsByCourseOffering(courseOfferingId, context);
 734  0
         for (FormatOfferingInfo fo : formats) {
 735  0
             List<ActivityOfferingInfo> activities = this.getActivityOfferingsByFormatOffering(courseOfferingId, context);
 736  0
             list.addAll(activities);
 737  0
         }
 738  0
         return list;
 739  
     }
 740  
 
 741  
     @Override
 742  
     public List<ActivityOfferingInfo> getActivityOfferingsByFormatOffering(String formatOfferingId, ContextInfo context)
 743  
             throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
 744  0
         throw new UnsupportedOperationException();
 745  
     }
 746  
 
 747  
     @Override
 748  
     public List<ActivityOfferingInfo> getActivityOfferingsByCourseOfferingWithoutRegGroup(String courseOfferingId, ContextInfo context)
 749  
             throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
 750  0
         throw new UnsupportedOperationException();
 751  
     }
 752  
 
 753  
 
 754  
     @Override
 755  
     @Transactional(readOnly = false)
 756  
     public ActivityOfferingInfo createActivityOffering(String formatOfferingId,
 757  
                                                        String activityId,
 758  
                                                        String activityOfferingTypeKey,
 759  
                                                        ActivityOfferingInfo aoInfo, ContextInfo context)
 760  
             throws DoesNotExistException, DataValidationErrorException,
 761  
             InvalidParameterException, MissingParameterException,
 762  
             OperationFailedException, PermissionDeniedException,
 763  
             ReadOnlyException {
 764  
 
 765  
         // validate params
 766  0
         if (!formatOfferingId.equals(aoInfo.getFormatOfferingId())) {
 767  0
             throw new InvalidParameterException(formatOfferingId + " does not match the corresponding value in the object " + aoInfo.getFormatOfferingId());
 768  
         }
 769  0
         if (!activityId.equals(aoInfo.getActivityId())) {
 770  0
             throw new InvalidParameterException(activityId + " does not match the corresponding value in the object " + aoInfo.getActivityId());
 771  
         }
 772  0
         if (!activityOfferingTypeKey.equals(aoInfo.getTypeKey())) {
 773  0
             throw new InvalidParameterException(activityOfferingTypeKey + " does not match the corresponding value in the object " + aoInfo.getTypeKey());
 774  
         }
 775  
         // get the required objects checking they exist
 776  0
         FormatOfferingInfo fo = this.getFormatOffering(formatOfferingId, context);
 777  0
         CourseOfferingInfo co = this.getCourseOffering(fo.getCourseOfferingId(), context);
 778  0
         if (aoInfo.getTermId() != null) {
 779  0
             if (!aoInfo.getTermId().equals(fo.getTermId())) {
 780  0
                 throw new InvalidParameterException(aoInfo.getTermId() + " term in the activity offering does not match the one in the format offering " + fo.getTermId());
 781  
             }
 782  
         }
 783  0
         aoInfo.setTermId(fo.getTermId());
 784  
         // copy to the lui
 785  0
         LuiInfo lui = new LuiInfo();
 786  0
         new ActivityOfferingTransformer().activity2Lui(aoInfo, lui);
 787  
         try {
 788  0
             lui = luiService.createLui(lui.getCluId(), lui.getAtpId(), lui.getTypeKey(), lui, context);
 789  0
         } catch (Exception ex) {
 790  0
             throw new OperationFailedException("unexpected", ex);
 791  0
         }
 792  
 
 793  
         // now build the lui lui relation
 794  0
         LuiLuiRelationInfo luiRel = new LuiLuiRelationInfo();
 795  0
         luiRel.setLuiId(formatOfferingId);
 796  0
         luiRel.setRelatedLuiId(lui.getId());
 797  0
         luiRel.setTypeKey(LuiServiceConstants.LUI_LUI_RELATION_ASSOCIATED_TYPE_KEY);
 798  0
         luiRel.setStateKey(LuiServiceConstants.LUI_LUI_RELATION_ACTIVE_STATE_KEY);
 799  0
         luiRel.setEffectiveDate(new Date());
 800  
         try {
 801  0
             luiRel = luiService.createLuiLuiRelation(luiRel.getLuiId(), luiRel.getRelatedLuiId(), luiRel.getTypeKey(), luiRel, context);
 802  0
         } catch (Exception ex) {
 803  0
             throw new OperationFailedException("unexpected", ex);
 804  0
         }
 805  0
         ActivityOfferingInfo ao = new ActivityOfferingInfo();
 806  0
         new ActivityOfferingTransformer().lui2Activity(ao, lui);
 807  0
         ao.setFormatOfferingId(luiRel.getLuiId());
 808  0
         return ao;
 809  
 
 810  
     }
 811  
 
 812  
     @Override
 813  
     @Transactional(readOnly = false)
 814  
     public ActivityOfferingInfo copyActivityOffering(String activityOfferingId, ContextInfo context) throws DoesNotExistException, DataValidationErrorException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, ReadOnlyException {
 815  0
         throw new OperationFailedException("not implemented");
 816  
     }
 817  
 
 818  
     @Override
 819  
     @Transactional(readOnly = false)
 820  
     public List<ActivityOfferingInfo> generateActivityOfferings(String formatOfferingId, String activityOfferingType, Integer quantity, ContextInfo context) throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
 821  0
         throw new OperationFailedException("not implemented");
 822  
     }
 823  
 
 824  
 
 825  
     @Override
 826  
     @Transactional(readOnly = false)
 827  
     public ActivityOfferingInfo updateActivityOffering(String activityOfferingId,
 828  
                                                        ActivityOfferingInfo activityOfferingInfo,
 829  
                                                        ContextInfo context)
 830  
             throws DataValidationErrorException,
 831  
             DoesNotExistException, InvalidParameterException, MissingParameterException,
 832  
             OperationFailedException, PermissionDeniedException,
 833  
             ReadOnlyException, VersionMismatchException {
 834  
         // validate params
 835  0
         if (!activityOfferingId.equals(activityOfferingInfo.getId())) {
 836  0
             throw new InvalidParameterException(activityOfferingId + " does not match the corresponding value in the object " + activityOfferingInfo.getId());
 837  
         }
 838  
         // get it
 839  0
         LuiInfo lui = luiService.getLui(activityOfferingId, context);
 840  
         // TODO: check that the lui being updated is an activity not another kind of lui
 841  
         // copy to lui
 842  0
         new ActivityOfferingTransformer().activity2Lui(activityOfferingInfo, lui);
 843  
         // update lui
 844  0
         lui = luiService.updateLui(activityOfferingId, lui, context);
 845  
         // rebuild activity to return it
 846  0
         ActivityOfferingInfo ao = new ActivityOfferingInfo();
 847  0
         new ActivityOfferingTransformer().lui2Activity(ao, lui);
 848  0
         LuiInfo foLui = this.findFormatOfferingLui(lui.getId(), context);
 849  0
         ao.setFormatOfferingId(foLui.getId());
 850  0
         return ao;
 851  
     }
 852  
 
 853  
     @Override
 854  
     @Transactional(readOnly = false)
 855  
     public StatusInfo deleteActivityOffering(String activityOfferingId, ContextInfo context)
 856  
             throws DoesNotExistException, InvalidParameterException, MissingParameterException,
 857  
             OperationFailedException, PermissionDeniedException {
 858  
         // TODO: check that the lui being deleted is an activity not another kind of lui
 859  
         try {
 860  0
             return luiService.deleteLui(activityOfferingId, context);
 861  0
         } catch (DependentObjectsExistException e) {
 862  0
             throw new OperationFailedException("Error deleting dependent objects", e);
 863  
         }
 864  
     }
 865  
 
 866  
     @Override
 867  
     public List<ValidationResultInfo> validateActivityOffering(String validationType,
 868  
                                                                ActivityOfferingInfo activityOfferingInfo, ContextInfo context)
 869  
             throws DoesNotExistException,
 870  
             InvalidParameterException, MissingParameterException, OperationFailedException {
 871  0
         throw new UnsupportedOperationException();
 872  
     }
 873  
 
 874  
     @Override
 875  
     public Float calculateInClassContactHoursForTerm(String activityOfferingId, ContextInfo context) throws DoesNotExistException,
 876  
             InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
 877  0
         throw new UnsupportedOperationException();
 878  
     }
 879  
 
 880  
     @Override
 881  
     public Float calculateOutofClassContactHoursForTerm(String activityOfferingId, ContextInfo context)
 882  
             throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
 883  0
         throw new UnsupportedOperationException();
 884  
     }
 885  
 
 886  
     @Override
 887  
     public Float calculateTotalContactHoursForTerm(String activityOfferingId, ContextInfo context) throws DoesNotExistException,
 888  
             InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
 889  0
         throw new UnsupportedOperationException();
 890  
     }
 891  
 
 892  
     @Override
 893  
     public RegistrationGroupInfo getRegistrationGroup(String registrationGroupId, ContextInfo context) throws DoesNotExistException, InvalidParameterException, MissingParameterException,
 894  
             OperationFailedException, PermissionDeniedException {
 895  0
         LuiInfo lui = luiService.getLui(registrationGroupId, context);
 896  
 
 897  0
         return registrationGroupAssembler.assemble(lui, context);
 898  
 
 899  
     }
 900  
 
 901  
     @Override
 902  
     public List<RegistrationGroupInfo> getRegistrationGroupsByIds(List<String> registrationGroupsIds, ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException,
 903  
             MissingParameterException, OperationFailedException, PermissionDeniedException {
 904  
 
 905  0
         List<RegistrationGroupInfo> regGroups = new ArrayList<RegistrationGroupInfo>();
 906  
 
 907  0
         for (String registrationGroupId : registrationGroupsIds) {
 908  
 
 909  0
             regGroups.add(registrationGroupAssembler.assemble(luiService.getLui(registrationGroupId, contextInfo), contextInfo));
 910  
         }
 911  
 
 912  0
         return regGroups;
 913  
     }
 914  
 
 915  
     @Override
 916  
     public List<RegistrationGroupInfo> getRegistrationGroupsForCourseOffering(String courseOfferingId, ContextInfo context) throws DoesNotExistException, InvalidParameterException,
 917  
             MissingParameterException, OperationFailedException, PermissionDeniedException {
 918  
         // TODO: implement LuiService.getLuiIdsByRelation and call it instead
 919  0
         List<RegistrationGroupInfo> rgs = new ArrayList<RegistrationGroupInfo>();
 920  0
         List<String> rgIds = new ArrayList<String>();
 921  0
         List<LuiLuiRelationInfo> rels = luiService.getLuiLuiRelationsByLui(courseOfferingId, context);
 922  0
         if (rels != null && !rels.isEmpty()) {
 923  0
             for (LuiLuiRelationInfo rel : rels) {
 924  0
                 if (rel.getRelatedLuiId().equals(courseOfferingId)) {
 925  0
                     if (rel.getTypeKey().equals(LuiServiceConstants.LUI_LUI_RELATION_REGISTEREDFORVIA_TYPE_KEY)) {
 926  0
                         String luiId = rel.getLuiId();
 927  0
                         LuiInfo lui = luiService.getLui(luiId, context);
 928  0
                         if (lui != null && lui.getTypeKey().equals(LuiServiceConstants.REGISTRATION_GROUP_TYPE_KEY) && !rgIds.contains(luiId)) {
 929  0
                             rgIds.add(luiId);
 930  0
                             rgs.add(getRegistrationGroup(luiId, context));
 931  
                         }
 932  0
                     }
 933  
                 }
 934  
             }
 935  
         }
 936  
 
 937  0
         return rgs;
 938  
     }
 939  
 
 940  
     @Override
 941  
     public List<RegistrationGroupInfo> getRegistrationGroupsWithActivityOfferings(List<String> activityOfferingIds,
 942  
                                                                                   ContextInfo context) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
 943  0
         throw new UnsupportedOperationException();
 944  
     }
 945  
 
 946  
     @Override
 947  
     public List<RegistrationGroupInfo> getRegistrationGroupsByFormatOffering(String formatOfferingId, ContextInfo context)
 948  
             throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
 949  0
         throw new UnsupportedOperationException();
 950  
     }
 951  
 
 952  
 
 953  
 
 954  
     @Override
 955  
     @Transactional(readOnly = false)
 956  
     public List<RegistrationGroupInfo> generateRegistrationGroupsForFormatOffering(String formatOfferingId, ContextInfo context)
 957  
             throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
 958  0
         throw new UnsupportedOperationException();
 959  
     }
 960  
 
 961  
     private String getTermkeyByCourseOffering(String courseOfferingId, ContextInfo context) throws DoesNotExistException, InvalidParameterException, MissingParameterException,
 962  
             OperationFailedException, PermissionDeniedException {
 963  0
         String termId = null;
 964  
 
 965  0
         LuiInfo co = luiService.getLui(courseOfferingId, context);
 966  0
         if (co != null) {
 967  0
             termId = co.getAtpId();
 968  
         }
 969  
 
 970  0
         return termId;
 971  
     }
 972  
 
 973  
     @Override
 974  
     @Transactional(readOnly = false)
 975  
     public RegistrationGroupInfo updateRegistrationGroup(String registrationGroupId, RegistrationGroupInfo registrationGroupInfo, ContextInfo context)
 976  
             throws DataValidationErrorException,
 977  
             DoesNotExistException, InvalidParameterException,
 978  
             MissingParameterException, OperationFailedException,
 979  
             PermissionDeniedException,
 980  
             ReadOnlyException, VersionMismatchException {
 981  
 
 982  0
         Set<String> existingRelatedLuiIds = new HashSet<String>();
 983  0
         Set<String> newRelatedLuiIds = new HashSet<String>(registrationGroupInfo.getActivityOfferingIds());
 984  0
         newRelatedLuiIds.add(registrationGroupInfo.getCourseOfferingId());
 985  
 
 986  
         // Delete relations for removed Activity Offerings or Course Offering
 987  0
         List<LuiLuiRelationInfo> llrs = luiService.getLuiLuiRelationsByLui(registrationGroupId, context);
 988  0
         for (LuiLuiRelationInfo llr : llrs) {
 989  0
             if (registrationGroupId.equals(llr.getLuiId()) && LuiServiceConstants.LUI_LUI_RELATION_REGISTEREDFORVIA_TYPE_KEY.equals(llr.getTypeKey())) {
 990  0
                 String relatedLuiId = llr.getRelatedLuiId();
 991  0
                 existingRelatedLuiIds.add(relatedLuiId);
 992  0
                 if (!newRelatedLuiIds.contains(relatedLuiId)) {
 993  0
                     luiService.deleteLuiLuiRelation(llr.getId(), context);
 994  
                 }
 995  0
             }
 996  
         }
 997  
 
 998  
         // Create relations for added Activity Offerings or Course Offering
 999  0
         for (String luiId : newRelatedLuiIds) {
 1000  0
             if (!existingRelatedLuiIds.contains(luiId)) {
 1001  0
                 createLuiLuiRelationForRegGroups(registrationGroupId, luiId, LuiServiceConstants.LUI_LUI_RELATION_REGISTEREDFORVIA_TYPE_KEY, context);
 1002  
             }
 1003  
         }
 1004  
 
 1005  0
         LuiInfo regGroupLui = registrationGroupAssembler.disassemble(registrationGroupInfo, context);
 1006  0
         LuiInfo updatedRegGroupLui = luiService.updateLui(regGroupLui.getId(), regGroupLui, context);
 1007  0
         return registrationGroupAssembler.assemble(updatedRegGroupLui, context);
 1008  
 
 1009  
     }
 1010  
 
 1011  
     @Override
 1012  
     @Transactional(readOnly = false)
 1013  
     public StatusInfo deleteRegistrationGroup(String registrationGroupId, ContextInfo context) throws DoesNotExistException, InvalidParameterException, MissingParameterException,
 1014  
             OperationFailedException, PermissionDeniedException {
 1015  
         try {
 1016  0
             return luiService.deleteLui(registrationGroupId, context);
 1017  0
         } catch (DependentObjectsExistException e) {
 1018  0
             throw new OperationFailedException("Could not delete LUI '" + registrationGroupId + "'", e);
 1019  
         }
 1020  
     }
 1021  
 
 1022  
     @Override
 1023  
     public List<ValidationResultInfo> validateRegistrationGroup(String validationType,
 1024  
                                                                 RegistrationGroupInfo registrationGroupInfo, ContextInfo context) throws DoesNotExistException,
 1025  
             InvalidParameterException, MissingParameterException, OperationFailedException {
 1026  0
         throw new UnsupportedOperationException();
 1027  
     }
 1028  
 
 1029  
     @Override
 1030  
     public RegistrationGroupTemplateInfo getRegistrationGroupTemplate(String registrationGroupTemplateId,
 1031  
                                                                       ContextInfo context)
 1032  
             throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
 1033  0
         throw new UnsupportedOperationException();
 1034  
     }
 1035  
 
 1036  
     @Override
 1037  
     @Transactional(readOnly = false)
 1038  
     public RegistrationGroupTemplateInfo updateRegistrationGroupTemplate(String registrationGroupTemplateId,
 1039  
                                                                          RegistrationGroupTemplateInfo registrationGroupTemplateInfo,
 1040  
                                                                          ContextInfo context)
 1041  
             throws DataValidationErrorException, DoesNotExistException,
 1042  
             InvalidParameterException, MissingParameterException,
 1043  
             OperationFailedException, PermissionDeniedException,
 1044  
             ReadOnlyException, VersionMismatchException {
 1045  0
         throw new UnsupportedOperationException();
 1046  
     }
 1047  
 
 1048  
     @Override
 1049  
     @Transactional(readOnly = false)
 1050  
     public StatusInfo deleteRegistrationGroupTemplate(String registrationGroupTemplateId, ContextInfo context)
 1051  
             throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
 1052  0
         throw new UnsupportedOperationException();
 1053  
     }
 1054  
 
 1055  
     @Override
 1056  
     public SeatPoolDefinitionInfo getSeatPoolDefinition(String seatPoolDefinitionId, ContextInfo context)
 1057  
             throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
 1058  0
         throw new UnsupportedOperationException();
 1059  
     }
 1060  
 
 1061  
     @Override
 1062  
     public List<SeatPoolDefinitionInfo> getSeatPoolDefinitionsForCourseOffering(String courseOfferingId, ContextInfo context)
 1063  
             throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
 1064  0
         throw new UnsupportedOperationException();
 1065  
     }
 1066  
 
 1067  
     @Override
 1068  
     public List<SeatPoolDefinitionInfo> getSeatPoolDefinitionsForRegGroup(String registrationGroupId, ContextInfo context)
 1069  
             throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
 1070  0
         throw new UnsupportedOperationException();
 1071  
     }
 1072  
 
 1073  
     @Override
 1074  
     @Transactional(readOnly = false)
 1075  
     public SeatPoolDefinitionInfo createSeatPoolDefinition(SeatPoolDefinitionInfo seatPoolDefinitionInfo, ContextInfo context)
 1076  
             throws DataValidationErrorException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, ReadOnlyException {
 1077  0
         throw new UnsupportedOperationException();
 1078  
     }
 1079  
 
 1080  
     @Override
 1081  
     @Transactional(readOnly = false)
 1082  
     public SeatPoolDefinitionInfo updateSeatPoolDefinition(String seatPoolDefinitionId,
 1083  
                                                            SeatPoolDefinitionInfo seatPoolDefinitionInfo,
 1084  
                                                            ContextInfo context)
 1085  
             throws DataValidationErrorException,
 1086  
             DoesNotExistException, InvalidParameterException, MissingParameterException,
 1087  
             OperationFailedException, PermissionDeniedException,
 1088  
             ReadOnlyException, ReadOnlyException, VersionMismatchException {
 1089  0
         throw new UnsupportedOperationException();
 1090  
     }
 1091  
 
 1092  
     @Override
 1093  
     public List<ValidationResultInfo> validateSeatPoolDefinition(String validationTypeKey,
 1094  
                                                                  SeatPoolDefinitionInfo seatPoolDefinitionInfo, ContextInfo context) throws DataValidationErrorException,
 1095  
             DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, VersionMismatchException {
 1096  0
         throw new UnsupportedOperationException();
 1097  
     }
 1098  
 
 1099  
     @Override
 1100  
     @Transactional(readOnly = false)
 1101  
     public StatusInfo deleteSeatPoolDefinition(String seatPoolDefinitionId, ContextInfo context) throws DoesNotExistException,
 1102  
             InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
 1103  0
         throw new UnsupportedOperationException();
 1104  
     }
 1105  
 
 1106  
     @Override
 1107  
     public List<CourseOfferingInfo> searchForCourseOfferings(QueryByCriteria criteria, ContextInfo context)
 1108  
             throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
 1109  0
         GenericQueryResults<LuiEntity> results = criteriaLookupService.lookup(LuiEntity.class, criteria);
 1110  0
         List<CourseOfferingInfo> courseOfferings = new ArrayList<CourseOfferingInfo>(results.getResults().size());
 1111  0
         for (LuiEntity lui : results.getResults()) {
 1112  
             try {
 1113  0
                 CourseOfferingInfo co = this.getCourseOffering(lui.getId(), context);
 1114  0
             } catch (DoesNotExistException ex) {
 1115  0
                 throw new OperationFailedException(lui.getId(), ex);
 1116  0
             }
 1117  
         }
 1118  0
         return courseOfferings;
 1119  
     }
 1120  
 
 1121  
     private void createLuiLuiRelationForRegGroups(String luiId, String relatedLuiId, String luLuRelationTypeKey, ContextInfo context) throws DataValidationErrorException,
 1122  
             InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
 1123  
         try {
 1124  0
             LuiLuiRelationInfo luiRel = new LuiLuiRelationInfo();
 1125  0
             luiRel.setLuiId(luiId);
 1126  0
             luiRel.setRelatedLuiId(relatedLuiId);
 1127  0
             luiRel.setTypeKey(LuiServiceConstants.LUI_LUI_RELATION_ASSOCIATED_TYPE_KEY);
 1128  0
             luiRel.setStateKey(LuiServiceConstants.LUI_LUI_RELATION_ACTIVE_STATE_KEY);
 1129  0
             luiRel.setEffectiveDate(new Date());
 1130  
             try {
 1131  0
                 luiService.createLuiLuiRelation(luiId, relatedLuiId, luLuRelationTypeKey, luiRel, context);
 1132  0
             } catch (ReadOnlyException roe) {
 1133  0
                 throw new OperationFailedException("setting read only fields", roe);
 1134  0
             }
 1135  0
         } catch (CircularRelationshipException e) {
 1136  0
             throw new OperationFailedException();
 1137  0
         } catch (DoesNotExistException e) {
 1138  0
             throw new OperationFailedException();
 1139  0
         }
 1140  0
     }
 1141  
 
 1142  
     @Override
 1143  
     public List<String> searchForCourseOfferingIds(QueryByCriteria criteria, ContextInfo context) throws InvalidParameterException,
 1144  
             MissingParameterException, OperationFailedException, PermissionDeniedException {
 1145  0
         throw new UnsupportedOperationException();
 1146  
     }
 1147  
 
 1148  
     @Override
 1149  
     public List<ActivityOfferingInfo> searchForActivityOfferings(QueryByCriteria criteria, ContextInfo context)
 1150  
             throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
 1151  0
         throw new UnsupportedOperationException();
 1152  
     }
 1153  
 
 1154  
     @Override
 1155  
     public List<String> searchForActivityOfferingIds(QueryByCriteria criteria, ContextInfo context) throws InvalidParameterException,
 1156  
             MissingParameterException, OperationFailedException, PermissionDeniedException {
 1157  0
         throw new UnsupportedOperationException();
 1158  
     }
 1159  
 
 1160  
     @Override
 1161  
     public List<RegistrationGroupInfo> searchForRegistrationGroups(QueryByCriteria criteria, ContextInfo context)
 1162  
             throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
 1163  0
         throw new UnsupportedOperationException();
 1164  
     }
 1165  
 
 1166  
     @Override
 1167  
     public List<String> searchForRegistrationGroupIds(QueryByCriteria criteria, ContextInfo context) throws InvalidParameterException,
 1168  
             MissingParameterException, OperationFailedException, PermissionDeniedException {
 1169  0
         throw new UnsupportedOperationException();
 1170  
     }
 1171  
 
 1172  
     @Override
 1173  
     public List<SeatPoolDefinitionInfo> searchForSeatpoolDefintions(QueryByCriteria criteria, ContextInfo context)
 1174  
             throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
 1175  0
         throw new UnsupportedOperationException();
 1176  
     }
 1177  
 
 1178  
     @Override
 1179  
     public List<String> searchForSeatpoolDefintionIds(QueryByCriteria criteria, ContextInfo context) throws InvalidParameterException,
 1180  
             MissingParameterException, OperationFailedException, PermissionDeniedException {
 1181  0
         throw new UnsupportedOperationException();
 1182  
     }
 1183  
 }