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