| 1 | |
package org.kuali.student.lum.workflow; |
| 2 | |
|
| 3 | |
import java.util.Date; |
| 4 | |
import java.util.List; |
| 5 | |
|
| 6 | |
import org.kuali.student.common.dto.DtoConstants; |
| 7 | |
import org.kuali.student.common.exceptions.DoesNotExistException; |
| 8 | |
import org.kuali.student.common.exceptions.InvalidParameterException; |
| 9 | |
import org.kuali.student.common.exceptions.MissingParameterException; |
| 10 | |
import org.kuali.student.common.exceptions.OperationFailedException; |
| 11 | |
import org.kuali.student.common.versionmanagement.dto.VersionDisplayInfo; |
| 12 | |
import org.kuali.student.core.atp.dto.AtpInfo; |
| 13 | |
import org.kuali.student.core.atp.service.AtpService; |
| 14 | |
import org.kuali.student.core.statement.dto.StatementTreeViewInfo; |
| 15 | |
import org.kuali.student.lum.program.dto.MajorDisciplineInfo; |
| 16 | |
import org.kuali.student.lum.program.dto.ProgramRequirementInfo; |
| 17 | |
import org.kuali.student.lum.program.dto.ProgramVariationInfo; |
| 18 | |
import org.kuali.student.lum.program.service.ProgramService; |
| 19 | |
import org.kuali.student.lum.program.service.ProgramServiceConstants; |
| 20 | |
import org.springframework.transaction.annotation.Transactional; |
| 21 | |
|
| 22 | |
|
| 23 | |
|
| 24 | |
|
| 25 | |
|
| 26 | |
|
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | |
@Transactional(noRollbackFor = {DoesNotExistException.class}, rollbackFor = {Throwable.class}) |
| 34 | 0 | public class MajorDisciplineStateChangeServiceImpl implements StateChangeService{ |
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | |
|
| 39 | |
private ProgramService programService; |
| 40 | |
private AtpService atpService; |
| 41 | |
|
| 42 | |
|
| 43 | |
|
| 44 | |
|
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 48 | |
|
| 49 | |
|
| 50 | |
public void changeState(String majorDisciplineId, String newState) throws Exception { |
| 51 | |
|
| 52 | |
|
| 53 | 0 | changeState(null, null, null, majorDisciplineId, newState); |
| 54 | 0 | } |
| 55 | |
|
| 56 | |
|
| 57 | |
|
| 58 | |
|
| 59 | |
|
| 60 | |
|
| 61 | |
|
| 62 | |
|
| 63 | |
|
| 64 | |
|
| 65 | |
|
| 66 | |
|
| 67 | |
public void changeState(String endEntryTerm, String endEnrollTerm, String endInstAdmitTerm, String majorDisciplineId, String newState) throws Exception { |
| 68 | |
|
| 69 | |
|
| 70 | |
|
| 71 | |
|
| 72 | |
|
| 73 | |
|
| 74 | |
|
| 75 | |
|
| 76 | |
|
| 77 | |
|
| 78 | |
|
| 79 | |
|
| 80 | 0 | if (newState == null){ |
| 81 | 0 | return; |
| 82 | |
} |
| 83 | |
|
| 84 | |
|
| 85 | 0 | MajorDisciplineInfo selectedVersion = programService.getMajorDiscipline(majorDisciplineId); |
| 86 | |
|
| 87 | |
|
| 88 | |
|
| 89 | 0 | if (newState.equals(DtoConstants.STATE_ACTIVE)) { |
| 90 | |
|
| 91 | |
|
| 92 | 0 | updatePreviousVersions(selectedVersion, endEntryTerm, endEnrollTerm, endInstAdmitTerm); |
| 93 | |
|
| 94 | |
|
| 95 | |
|
| 96 | 0 | updateMajorDisciplineInfoState(selectedVersion, newState); |
| 97 | |
|
| 98 | |
|
| 99 | 0 | makeCurrent(selectedVersion); |
| 100 | |
} else { |
| 101 | |
|
| 102 | |
|
| 103 | 0 | updateMajorDisciplineInfoState(selectedVersion, newState); |
| 104 | |
} |
| 105 | |
|
| 106 | |
|
| 107 | |
|
| 108 | 0 | } |
| 109 | |
|
| 110 | |
|
| 111 | |
|
| 112 | |
|
| 113 | |
|
| 114 | |
|
| 115 | |
|
| 116 | |
|
| 117 | |
|
| 118 | |
private void updateMajorDisciplineInfoState(MajorDisciplineInfo majorDisciplineInfo, String newState) throws Exception { |
| 119 | |
|
| 120 | 0 | List<String> programRequirementIds = majorDisciplineInfo.getProgramRequirements(); |
| 121 | 0 | updateRequirementsState(programRequirementIds, newState); |
| 122 | |
|
| 123 | |
|
| 124 | |
|
| 125 | 0 | List<ProgramVariationInfo> variationList = majorDisciplineInfo.getVariations(); |
| 126 | 0 | updateVariationsRequirementsState(variationList, newState); |
| 127 | |
|
| 128 | |
|
| 129 | |
|
| 130 | 0 | majorDisciplineInfo.setState(newState); |
| 131 | 0 | programService.updateMajorDiscipline(majorDisciplineInfo); |
| 132 | 0 | } |
| 133 | |
|
| 134 | |
|
| 135 | |
|
| 136 | |
|
| 137 | |
|
| 138 | |
|
| 139 | |
private void makeCurrent(MajorDisciplineInfo majorDisciplineInfo) throws Exception { |
| 140 | |
|
| 141 | |
|
| 142 | |
|
| 143 | 0 | VersionDisplayInfo currentVersion = programService.getCurrentVersion(ProgramServiceConstants.PROGRAM_NAMESPACE_MAJOR_DISCIPLINE_URI, majorDisciplineInfo.getVersionInfo().getVersionIndId()); |
| 144 | |
|
| 145 | |
|
| 146 | 0 | if (!currentVersion.getSequenceNumber().equals(majorDisciplineInfo.getVersionInfo().getSequenceNumber())) { |
| 147 | 0 | programService.setCurrentMajorDisciplineVersion(majorDisciplineInfo.getId(), null); |
| 148 | |
} |
| 149 | 0 | } |
| 150 | |
|
| 151 | |
|
| 152 | |
|
| 153 | |
|
| 154 | |
|
| 155 | |
|
| 156 | |
|
| 157 | |
|
| 158 | |
|
| 159 | |
|
| 160 | |
|
| 161 | |
private void updatePreviousVersions (MajorDisciplineInfo selectedVersion, String endEntryTerm, String endEnrollTerm, String endInstAdmitTerm) throws Exception { |
| 162 | |
|
| 163 | 0 | MajorDisciplineInfo currentVersion = getCurrentVersion(selectedVersion); |
| 164 | |
|
| 165 | 0 | boolean isSelectedVersionCurrent = selectedVersion.getId().equals(currentVersion.getId()); |
| 166 | |
|
| 167 | |
|
| 168 | 0 | setEndTerms(currentVersion, endEntryTerm, endEnrollTerm, endInstAdmitTerm); |
| 169 | 0 | updateMajorDisciplineInfoState(currentVersion, DtoConstants.STATE_SUPERSEDED); |
| 170 | |
|
| 171 | |
|
| 172 | |
|
| 173 | |
|
| 174 | |
|
| 175 | 0 | List<VersionDisplayInfo> versions = programService.getVersions(ProgramServiceConstants.PROGRAM_NAMESPACE_MAJOR_DISCIPLINE_URI, |
| 176 | |
selectedVersion.getVersionInfo().getVersionIndId()); |
| 177 | 0 | Long startSeq = new Long(1); |
| 178 | |
|
| 179 | 0 | if (!isSelectedVersionCurrent) { |
| 180 | 0 | startSeq = currentVersion.getVersionInfo().getSequenceNumber() + 1; |
| 181 | |
} |
| 182 | |
|
| 183 | 0 | for (VersionDisplayInfo versionInfo : versions) { |
| 184 | 0 | if (versionInfo.getSequenceNumber() >= startSeq && versionInfo.getSequenceNumber() != selectedVersion.getVersionInfo().getSequenceNumber()) { |
| 185 | 0 | MajorDisciplineInfo otherProgram = programService.getMajorDiscipline(versionInfo.getId()); |
| 186 | 0 | if (otherProgram.getState().equals(DtoConstants.STATE_APPROVED) || |
| 187 | |
otherProgram.getState().equals(DtoConstants.STATE_ACTIVE)){ |
| 188 | 0 | updateMajorDisciplineInfoState(otherProgram, DtoConstants.STATE_SUPERSEDED); |
| 189 | |
} |
| 190 | 0 | } |
| 191 | |
} |
| 192 | |
|
| 193 | 0 | } |
| 194 | |
|
| 195 | |
|
| 196 | |
|
| 197 | |
|
| 198 | |
|
| 199 | |
|
| 200 | |
protected MajorDisciplineInfo getCurrentVersion(MajorDisciplineInfo majorDisciplineInfo) |
| 201 | |
throws Exception { |
| 202 | |
|
| 203 | 0 | String verIndId = majorDisciplineInfo.getVersionInfo().getVersionIndId(); |
| 204 | |
|
| 205 | |
|
| 206 | 0 | VersionDisplayInfo curVerDisplayInfo = programService.getCurrentVersion( |
| 207 | |
ProgramServiceConstants.PROGRAM_NAMESPACE_MAJOR_DISCIPLINE_URI, verIndId); |
| 208 | 0 | String curVerId = curVerDisplayInfo.getId(); |
| 209 | |
|
| 210 | |
|
| 211 | 0 | MajorDisciplineInfo currentVersion = programService.getMajorDiscipline(curVerId); |
| 212 | |
|
| 213 | 0 | return currentVersion; |
| 214 | |
} |
| 215 | |
|
| 216 | |
|
| 217 | |
|
| 218 | |
|
| 219 | |
|
| 220 | |
|
| 221 | |
|
| 222 | |
|
| 223 | |
|
| 224 | |
|
| 225 | |
|
| 226 | |
|
| 227 | |
|
| 228 | |
|
| 229 | |
|
| 230 | |
private void setEndTerms(MajorDisciplineInfo majorDisciplineInfo, String endEntryTerm, String endEnrollTerm, String endInstAdmitTerm) throws InvalidParameterException, MissingParameterException, OperationFailedException, DoesNotExistException { |
| 231 | |
|
| 232 | |
|
| 233 | 0 | majorDisciplineInfo.setEndProgramEntryTerm(endEntryTerm); |
| 234 | 0 | majorDisciplineInfo.setEndTerm(endEnrollTerm); |
| 235 | 0 | majorDisciplineInfo.getAttributes().put("endInstAdmitTerm", endInstAdmitTerm); |
| 236 | |
|
| 237 | |
|
| 238 | 0 | if(!majorDisciplineInfo.getVariations().isEmpty()){ |
| 239 | |
|
| 240 | |
|
| 241 | 0 | AtpInfo majorEndEntryTermAtp = atpService.getAtp(endEntryTerm); |
| 242 | 0 | Date majorEndEntryTermEndDate = majorEndEntryTermAtp.getEndDate(); |
| 243 | 0 | AtpInfo majorEndEnrollTermAtp = atpService.getAtp(endEnrollTerm); |
| 244 | 0 | Date majorEndEnrollTermEndDate = majorEndEnrollTermAtp.getEndDate(); |
| 245 | 0 | AtpInfo majorEndInstAdmitTermAtp = atpService.getAtp(endInstAdmitTerm); |
| 246 | 0 | Date majorEndInstAdmitTermEndDate = majorEndInstAdmitTermAtp.getEndDate(); |
| 247 | |
|
| 248 | |
|
| 249 | 0 | for(ProgramVariationInfo variation:majorDisciplineInfo.getVariations()){ |
| 250 | |
|
| 251 | 0 | if(variation.getEndProgramEntryTerm() != null){ |
| 252 | 0 | AtpInfo variationEndEntryTermAtp = atpService.getAtp(variation.getEndProgramEntryTerm()); |
| 253 | 0 | Date variationEndEntryTermEndDate = variationEndEntryTermAtp.getEndDate(); |
| 254 | 0 | if(majorEndEnrollTermEndDate.compareTo(variationEndEntryTermEndDate)<=0){ |
| 255 | 0 | variation.setEndProgramEntryTerm(endEntryTerm); |
| 256 | |
} |
| 257 | 0 | }else{ |
| 258 | 0 | variation.setEndProgramEntryTerm(endEntryTerm); |
| 259 | |
} |
| 260 | |
|
| 261 | 0 | if(variation.getEndTerm() != null){ |
| 262 | 0 | AtpInfo variationEndTermAtp = atpService.getAtp(variation.getEndTerm()); |
| 263 | 0 | Date variationEndTermEndDate = variationEndTermAtp.getEndDate(); |
| 264 | 0 | if(majorEndEntryTermEndDate.compareTo(variationEndTermEndDate)<=0){ |
| 265 | 0 | variation.setEndTerm(endEnrollTerm); |
| 266 | |
} |
| 267 | 0 | }else{ |
| 268 | 0 | variation.setEndTerm(endEnrollTerm); |
| 269 | |
} |
| 270 | |
|
| 271 | 0 | if(variation.getAttributes().get("endInstAdmitTerm") != null){ |
| 272 | 0 | AtpInfo variationEndInstAdmitAtp = atpService.getAtp(variation.getAttributes().get("endInstAdmitTerm")); |
| 273 | 0 | Date variationEndInstAdmitEndDate = variationEndInstAdmitAtp.getEndDate(); |
| 274 | 0 | if(majorEndInstAdmitTermEndDate.compareTo(variationEndInstAdmitEndDate)<=0){ |
| 275 | 0 | variation.getAttributes().put("endInstAdmitTerm", endInstAdmitTerm); |
| 276 | |
} |
| 277 | 0 | }else{ |
| 278 | 0 | variation.getAttributes().put("endInstAdmitTerm", endInstAdmitTerm); |
| 279 | |
} |
| 280 | |
|
| 281 | |
} |
| 282 | |
} |
| 283 | 0 | } |
| 284 | |
|
| 285 | |
|
| 286 | |
|
| 287 | |
|
| 288 | |
|
| 289 | |
|
| 290 | |
|
| 291 | |
|
| 292 | |
|
| 293 | |
|
| 294 | |
public void updateRequirementsState(List<String> programRequirementIds, String newState) throws Exception { |
| 295 | |
|
| 296 | 0 | for (String programRequirementId : programRequirementIds) { |
| 297 | |
|
| 298 | |
|
| 299 | 0 | ProgramRequirementInfo programRequirementInfo = programService.getProgramRequirement(programRequirementId, null, null); |
| 300 | |
|
| 301 | |
|
| 302 | 0 | StatementTreeViewInfo statementTree = programRequirementInfo.getStatement(); |
| 303 | |
|
| 304 | |
|
| 305 | 0 | StatementUtil.updateStatementTreeViewInfoState(newState, statementTree); |
| 306 | |
|
| 307 | |
|
| 308 | 0 | programRequirementInfo.setState(newState); |
| 309 | |
|
| 310 | |
|
| 311 | 0 | programService.updateProgramRequirement(programRequirementInfo); |
| 312 | |
|
| 313 | 0 | } |
| 314 | 0 | } |
| 315 | |
|
| 316 | |
|
| 317 | |
|
| 318 | |
|
| 319 | |
|
| 320 | |
|
| 321 | |
|
| 322 | |
|
| 323 | |
|
| 324 | |
|
| 325 | |
|
| 326 | |
|
| 327 | |
|
| 328 | |
|
| 329 | |
|
| 330 | |
|
| 331 | |
public void updateVariationsRequirementsState(List<ProgramVariationInfo> variationList, String newState) throws Exception { |
| 332 | |
|
| 333 | |
|
| 334 | 0 | for (ProgramVariationInfo variation : variationList) { |
| 335 | |
|
| 336 | |
|
| 337 | 0 | List<String> programRequirementIds = variation.getProgramRequirements(); |
| 338 | |
|
| 339 | |
|
| 340 | |
|
| 341 | 0 | updateRequirementsState(programRequirementIds, newState); |
| 342 | 0 | } |
| 343 | 0 | } |
| 344 | |
|
| 345 | |
|
| 346 | |
|
| 347 | |
|
| 348 | |
|
| 349 | |
|
| 350 | |
|
| 351 | |
public void setProgramService(ProgramService programService) { |
| 352 | 0 | this.programService = programService; |
| 353 | 0 | } |
| 354 | |
|
| 355 | |
public void setAtpService(AtpService atpService) { |
| 356 | 0 | this.atpService = atpService; |
| 357 | 0 | } |
| 358 | |
} |