| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
package org.kuali.student.enrollment.class2.courseofferingset.service.decorators; |
| 6 | |
|
| 7 | |
import java.util.ArrayList; |
| 8 | |
import java.util.List; |
| 9 | |
import org.kuali.student.enrollment.acal.dto.TermInfo; |
| 10 | |
import org.kuali.student.enrollment.acal.service.AcademicCalendarService; |
| 11 | |
import org.kuali.student.enrollment.courseoffering.dto.ActivityOfferingInfo; |
| 12 | |
import org.kuali.student.enrollment.courseoffering.dto.CourseOfferingInfo; |
| 13 | |
import org.kuali.student.enrollment.courseoffering.service.CourseOfferingService; |
| 14 | |
import org.kuali.student.enrollment.courseofferingset.dto.SocInfo; |
| 15 | |
import org.kuali.student.enrollment.courseofferingset.dto.SocRolloverResultInfo; |
| 16 | |
import org.kuali.student.enrollment.courseofferingset.dto.SocRolloverResultItemInfo; |
| 17 | |
import org.kuali.student.lum.course.service.CourseService; |
| 18 | |
import org.kuali.student.r2.common.dto.ContextInfo; |
| 19 | |
import org.kuali.student.r2.common.dto.StatusInfo; |
| 20 | |
import org.kuali.student.r2.common.exceptions.*; |
| 21 | |
import org.kuali.student.r2.common.util.constants.CourseOfferingSetServiceConstants; |
| 22 | |
import org.springframework.transaction.annotation.Transactional; |
| 23 | |
|
| 24 | |
@Transactional(readOnly = true, noRollbackFor = {DoesNotExistException.class}, rollbackFor = {Throwable.class}) |
| 25 | 0 | public class CourseOfferingSetServiceCalculationDecorator extends CourseOfferingSetServiceDecorator { |
| 26 | |
|
| 27 | |
private CourseOfferingService coService; |
| 28 | |
private CourseService courseService; |
| 29 | |
private AcademicCalendarService acalService; |
| 30 | |
|
| 31 | |
public CourseOfferingService getCoService() { |
| 32 | 0 | return coService; |
| 33 | |
} |
| 34 | |
|
| 35 | |
public void setCoService(CourseOfferingService coService) { |
| 36 | 0 | this.coService = coService; |
| 37 | 0 | } |
| 38 | |
|
| 39 | |
public CourseService getCourseService() { |
| 40 | 0 | return courseService; |
| 41 | |
} |
| 42 | |
|
| 43 | |
public void setCourseService(CourseService courseService) { |
| 44 | 0 | this.courseService = courseService; |
| 45 | 0 | } |
| 46 | |
|
| 47 | |
public AcademicCalendarService getAcalService() { |
| 48 | 0 | return acalService; |
| 49 | |
} |
| 50 | |
|
| 51 | |
public void setAcalService(AcademicCalendarService acalService) { |
| 52 | 0 | this.acalService = acalService; |
| 53 | 0 | } |
| 54 | |
|
| 55 | |
@Override |
| 56 | |
@Transactional(readOnly = false) |
| 57 | |
public StatusInfo scheduleSoc(String socId, ContextInfo context) |
| 58 | |
throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, |
| 59 | |
PermissionDeniedException { |
| 60 | 0 | throw new OperationFailedException("scheduleSoc has not been implemented"); |
| 61 | |
} |
| 62 | |
|
| 63 | |
@Override |
| 64 | |
@Transactional(readOnly = false) |
| 65 | |
public SocInfo rolloverSoc(String sourceSocId, String targetTermId, List<String> optionKeys, ContextInfo context) |
| 66 | |
throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, |
| 67 | |
PermissionDeniedException { |
| 68 | |
|
| 69 | 0 | TermInfo targetTerm = this.acalService.getTerm(targetTermId, context); |
| 70 | |
|
| 71 | 0 | SocInfo sourceSoc = this.getSoc(sourceSocId, context); |
| 72 | 0 | if (sourceSoc.getTermId().equals(targetTermId)) { |
| 73 | 0 | throw new InvalidParameterException("The term of the source soc and the target term must be different"); |
| 74 | |
} |
| 75 | |
|
| 76 | 0 | SocInfo targetSoc = new SocInfo(sourceSoc); |
| 77 | 0 | targetSoc.setId(null); |
| 78 | 0 | targetSoc.setTermId(targetTermId); |
| 79 | |
try { |
| 80 | 0 | targetSoc = this.createSoc(targetSoc.getTermId(), targetSoc.getTypeKey(), targetSoc, context); |
| 81 | 0 | } catch (DataValidationErrorException ex) { |
| 82 | 0 | throw new OperationFailedException("Unexpected", ex); |
| 83 | 0 | } catch (ReadOnlyException ex) { |
| 84 | 0 | throw new OperationFailedException("Unexpected", ex); |
| 85 | 0 | } |
| 86 | |
|
| 87 | 0 | SocRolloverResultInfo result = new SocRolloverResultInfo(); |
| 88 | 0 | result.setTypeKey(CourseOfferingSetServiceConstants.ROLLOVER_RESULT_TYPE_KEY); |
| 89 | 0 | result.setStateKey(CourseOfferingSetServiceConstants.SUBMITTED_RESULT_STATE_KEY); |
| 90 | 0 | result.setSourceSocId(sourceSocId); |
| 91 | 0 | result.setTargetTermId(targetTermId); |
| 92 | 0 | result.setOptionKeys(optionKeys); |
| 93 | 0 | result.setTargetSocId(targetSoc.getId()); |
| 94 | |
try { |
| 95 | 0 | result = this.createSocRolloverResult(result.getTypeKey(), result, context); |
| 96 | 0 | } catch (DataValidationErrorException ex) { |
| 97 | 0 | throw new OperationFailedException("Unexpected", ex); |
| 98 | 0 | } catch (ReadOnlyException ex) { |
| 99 | 0 | throw new OperationFailedException("Unexpected", ex); |
| 100 | 0 | } |
| 101 | |
|
| 102 | 0 | CourseOfferingRolloverRunner runner = new CourseOfferingRolloverRunner(); |
| 103 | 0 | runner.setContext(context); |
| 104 | 0 | runner.setCoService(coService); |
| 105 | 0 | runner.setCourseService(courseService); |
| 106 | 0 | runner.setAcalService(acalService); |
| 107 | 0 | runner.setSocService(this); |
| 108 | 0 | runner.setResult(result); |
| 109 | 0 | if (optionKeys.contains(CourseOfferingSetServiceConstants.RUN_SYNCHRONOUSLY_OPTION_KEY)) { |
| 110 | 0 | runner.run(); |
| 111 | |
} else { |
| 112 | 0 | Thread thread = new Thread(runner); |
| 113 | 0 | thread.start(); |
| 114 | |
} |
| 115 | 0 | return targetSoc; |
| 116 | |
} |
| 117 | |
|
| 118 | |
|
| 119 | |
|
| 120 | |
|
| 121 | |
|
| 122 | |
|
| 123 | |
|
| 124 | |
|
| 125 | |
@Override |
| 126 | |
@Transactional(readOnly = false) |
| 127 | |
public SocRolloverResultInfo reverseRollover(String rolloverResultId, List<String> optionKeys, ContextInfo context) |
| 128 | |
throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, |
| 129 | |
PermissionDeniedException { |
| 130 | 0 | SocRolloverResultInfo rolloverResult = this.getSocRolloverResult(rolloverResultId, context); |
| 131 | 0 | if (optionKeys.contains(CourseOfferingSetServiceConstants.REVERSE_JUST_CREATES_OPTION_KEY)) { |
| 132 | 0 | if (!rolloverResult.getOptionKeys().contains(CourseOfferingSetServiceConstants.LOG_SUCCESSES_OPTION_KEY)) { |
| 133 | 0 | throw new InvalidParameterException( |
| 134 | |
"You cannot reverse just the creates if the original rollover did not log the course offerings that it successfully created"); |
| 135 | |
} |
| 136 | |
} |
| 137 | 0 | SocRolloverResultInfo reverseResult = new SocRolloverResultInfo(rolloverResult); |
| 138 | 0 | reverseResult.setTypeKey(CourseOfferingSetServiceConstants.ROLLOVER_RESULT_TYPE_KEY); |
| 139 | 0 | reverseResult.setStateKey(CourseOfferingSetServiceConstants.SUBMITTED_RESULT_STATE_KEY); |
| 140 | 0 | reverseResult.setOptionKeys(optionKeys); |
| 141 | |
|
| 142 | |
try { |
| 143 | 0 | reverseResult = this.createSocRolloverResult(reverseResult.getTypeKey(), reverseResult, context); |
| 144 | 0 | } catch (DataValidationErrorException ex) { |
| 145 | 0 | throw new OperationFailedException("Unexpected", ex); |
| 146 | 0 | } catch (ReadOnlyException ex) { |
| 147 | 0 | throw new OperationFailedException("Unexpected", ex); |
| 148 | 0 | } |
| 149 | |
|
| 150 | 0 | CourseOfferingReverseRolloverRunner runner = new CourseOfferingReverseRolloverRunner(); |
| 151 | 0 | runner.setContext(context); |
| 152 | 0 | runner.setCoService(coService); |
| 153 | 0 | runner.setSocService(this); |
| 154 | 0 | runner.setCourseService(courseService); |
| 155 | 0 | runner.setAcalService(acalService); |
| 156 | 0 | runner.setRolloverResult(rolloverResult); |
| 157 | 0 | runner.setReverseResult(reverseResult); |
| 158 | 0 | if (optionKeys.contains(CourseOfferingSetServiceConstants.RUN_SYNCHRONOUSLY_OPTION_KEY)) { |
| 159 | 0 | runner.run(); |
| 160 | |
} else { |
| 161 | 0 | Thread thread = new Thread(runner); |
| 162 | 0 | thread.start(); |
| 163 | |
} |
| 164 | 0 | return reverseResult; |
| 165 | |
} |
| 166 | |
|
| 167 | |
@Override |
| 168 | |
public List<String> getCourseOfferingIdsBySoc(String socId, ContextInfo context) |
| 169 | |
throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, |
| 170 | |
PermissionDeniedException { |
| 171 | |
|
| 172 | 0 | SocInfo soc = this.getSoc(socId, context); |
| 173 | |
|
| 174 | 0 | if (soc.getTypeKey().equals(CourseOfferingSetServiceConstants.MAIN_SOC_TYPE_KEY)) { |
| 175 | 0 | return coService.getCourseOfferingIdsByTerm(soc.getTermId(), Boolean.TRUE, context); |
| 176 | |
} |
| 177 | |
|
| 178 | 0 | if (soc.getTypeKey().equals(CourseOfferingSetServiceConstants.SUBJECT_AREA_SOC_TYPE_KEY)) { |
| 179 | 0 | return coService.getCourseOfferingIdsByTermAndSubjectArea(soc.getTermId(), soc.getSubjectArea(), context); |
| 180 | |
} |
| 181 | |
|
| 182 | 0 | if (soc.getTypeKey().equals(CourseOfferingSetServiceConstants.UNITS_CONTENT_OWNER_SOC_TYPE_KEY)) { |
| 183 | 0 | return coService.getCourseOfferingIdsByTermAndUnitsContentOwner(soc.getTermId(), soc.getUnitsContentOwnerId(), context); |
| 184 | |
} |
| 185 | 0 | throw new OperationFailedException(soc.getTypeKey() + " is an unsupported type for this implementation"); |
| 186 | |
|
| 187 | |
|
| 188 | |
|
| 189 | |
|
| 190 | |
|
| 191 | |
|
| 192 | |
|
| 193 | |
} |
| 194 | |
|
| 195 | |
@Override |
| 196 | |
@Transactional(readOnly = false) |
| 197 | |
public Integer deleteCourseOfferingsBySoc(String socId, ContextInfo context) |
| 198 | |
throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, |
| 199 | |
PermissionDeniedException { |
| 200 | |
|
| 201 | |
|
| 202 | 0 | List<String> ids = this.getCourseOfferingIdsBySoc(socId, context); |
| 203 | 0 | for (String id : ids) { |
| 204 | |
try { |
| 205 | 0 | this.coService.deleteCourseOffering(socId, context); |
| 206 | 0 | } catch (DependentObjectsExistException e) { |
| 207 | 0 | throw new OperationFailedException( e.getMessage()); |
| 208 | 0 | } |
| 209 | |
} |
| 210 | 0 | return ids.size(); |
| 211 | |
} |
| 212 | |
|
| 213 | |
@Override |
| 214 | |
public Boolean isCourseOfferingInSoc(String socId, String courseOfferingId, ContextInfo context) |
| 215 | |
throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, |
| 216 | |
PermissionDeniedException { |
| 217 | |
|
| 218 | 0 | SocInfo soc = this.getSoc(socId, context); |
| 219 | 0 | CourseOfferingInfo co = this.coService.getCourseOffering(courseOfferingId, context); |
| 220 | |
|
| 221 | 0 | if (soc.getTypeKey().equals(CourseOfferingSetServiceConstants.MAIN_SOC_TYPE_KEY)) { |
| 222 | 0 | if (co.getTermId().equals(soc.getTermId())) { |
| 223 | 0 | return true; |
| 224 | |
} |
| 225 | |
|
| 226 | 0 | return false; |
| 227 | |
} |
| 228 | |
|
| 229 | 0 | if (soc.getTypeKey().equals(CourseOfferingSetServiceConstants.SUBJECT_AREA_SOC_TYPE_KEY)) { |
| 230 | 0 | if (co.getTermId().equals(soc.getTermId())) { |
| 231 | 0 | if (co.getSubjectArea().equals(soc.getSubjectArea())) { |
| 232 | 0 | return true; |
| 233 | |
} |
| 234 | |
} |
| 235 | |
|
| 236 | 0 | return false; |
| 237 | |
} |
| 238 | |
|
| 239 | 0 | if (soc.getTypeKey().equals(CourseOfferingSetServiceConstants.UNITS_CONTENT_OWNER_SOC_TYPE_KEY)) { |
| 240 | 0 | if (co.getTermId().equals(soc.getTermId())) { |
| 241 | 0 | if (co.getUnitsContentOwnerOrgIds().equals(soc.getUnitsContentOwnerId())) { |
| 242 | 0 | return true; |
| 243 | |
} |
| 244 | |
} |
| 245 | |
|
| 246 | 0 | return false; |
| 247 | |
} |
| 248 | |
|
| 249 | 0 | List<String> ids = this.getCourseOfferingIdsBySoc(socId, context); |
| 250 | 0 | return ids.contains(courseOfferingId); |
| 251 | |
} |
| 252 | |
|
| 253 | |
@Override |
| 254 | |
public List<String> getPublishedCourseOfferingIdsBySoc(String socId, ContextInfo context) |
| 255 | |
throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, |
| 256 | |
PermissionDeniedException { |
| 257 | 0 | List<String> list = new ArrayList<String>(); |
| 258 | 0 | List<String> list2 = this.getCourseOfferingIdsBySoc(socId, context); |
| 259 | 0 | for (CourseOfferingInfo info : this.coService.getCourseOfferingsByIds(list2, context)) { |
| 260 | |
|
| 261 | |
|
| 262 | 0 | list.add(info.getId()); |
| 263 | |
|
| 264 | |
} |
| 265 | 0 | return list; |
| 266 | |
} |
| 267 | |
|
| 268 | |
@Override |
| 269 | |
public List<String> getUnpublishedCourseOfferingIdsBySoc(String socId, ContextInfo context) |
| 270 | |
throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, |
| 271 | |
PermissionDeniedException { |
| 272 | 0 | List<String> list = new ArrayList<String>(); |
| 273 | 0 | List<String> list2 = this.getCourseOfferingIdsBySoc(socId, context); |
| 274 | 0 | for (CourseOfferingInfo info : this.coService.getCourseOfferingsByIds(list2, context)) { |
| 275 | |
|
| 276 | |
|
| 277 | 0 | list.add(info.getId()); |
| 278 | |
|
| 279 | |
} |
| 280 | 0 | return list; |
| 281 | |
} |
| 282 | |
|
| 283 | |
@Override |
| 284 | |
public List<String> getUnpublishedActivityOfferingIdsBySoc(String socId, ContextInfo context) |
| 285 | |
throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, |
| 286 | |
PermissionDeniedException { |
| 287 | 0 | List<String> list = new ArrayList<String>(); |
| 288 | 0 | List<String> list2 = this.getCourseOfferingIdsBySoc(socId, context); |
| 289 | 0 | for (String coId : list2) { |
| 290 | 0 | for (ActivityOfferingInfo ao : this.coService.getActivityOfferingsByCourseOffering(coId, context)) { |
| 291 | |
|
| 292 | |
|
| 293 | 0 | list.add(ao.getId()); |
| 294 | |
|
| 295 | |
} |
| 296 | |
} |
| 297 | 0 | return list; |
| 298 | |
} |
| 299 | |
|
| 300 | |
@Override |
| 301 | |
public List<String> getUnscheduledActivityOfferingIdsBySoc(String socId, ContextInfo context) |
| 302 | |
throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, |
| 303 | |
PermissionDeniedException { |
| 304 | 0 | List<String> list = new ArrayList<String>(); |
| 305 | 0 | List<String> list2 = this.getCourseOfferingIdsBySoc(socId, context); |
| 306 | 0 | for (String coId : list2) { |
| 307 | 0 | for (ActivityOfferingInfo ao : this.coService.getActivityOfferingsByCourseOffering(coId, context)) { |
| 308 | |
|
| 309 | |
|
| 310 | 0 | list.add(ao.getId()); |
| 311 | |
|
| 312 | |
} |
| 313 | |
} |
| 314 | 0 | return list; |
| 315 | |
} |
| 316 | |
|
| 317 | |
@Override |
| 318 | |
public SocRolloverResultInfo getSocRolloverResult(String rolloverResultId, ContextInfo context) throws DoesNotExistException, |
| 319 | |
InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
| 320 | 0 | SocRolloverResultInfo result = this.getNextDecorator().getSocRolloverResult(rolloverResultId, context); |
| 321 | 0 | this.updateCalculatedFields(result, context); |
| 322 | 0 | return result; |
| 323 | |
} |
| 324 | |
|
| 325 | |
|
| 326 | |
|
| 327 | |
private void updateCalculatedFields(SocRolloverResultInfo info, ContextInfo context) throws OperationFailedException { |
| 328 | |
try { |
| 329 | 0 | if (info.getSourceSocId() != null) { |
| 330 | 0 | SocInfo sourceSoc = this.getSoc(info.getSourceSocId(), context); |
| 331 | 0 | info.setSourceTermId(sourceSoc.getTermId()); |
| 332 | |
} |
| 333 | |
|
| 334 | 0 | if (info.getStateKey().equals(CourseOfferingSetServiceConstants.FINISHED_RESULT_STATE_KEY)) { |
| 335 | 0 | List<SocRolloverResultItemInfo> items = this.getSocRolloverResultItemsByResultId(info.getId(), context); |
| 336 | 0 | int success = 0; |
| 337 | 0 | int failure = 0; |
| 338 | 0 | for (SocRolloverResultItemInfo item : items) { |
| 339 | 0 | if (item.getStateKey().equals(CourseOfferingSetServiceConstants.SUCCESS_RESULT_ITEM_STATE_KEY)) { |
| 340 | 0 | success++; |
| 341 | |
} else { |
| 342 | 0 | failure++; |
| 343 | |
} |
| 344 | |
} |
| 345 | 0 | info.setCourseOfferingsCreated(success); |
| 346 | 0 | info.setCourseOfferingsSkipped(failure); |
| 347 | |
} |
| 348 | 0 | } catch (Exception ex) { |
| 349 | 0 | throw new OperationFailedException("unexpected", ex); |
| 350 | 0 | } |
| 351 | 0 | } |
| 352 | |
} |