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