1 |
|
package org.kuali.student.lum.workflow; |
2 |
|
|
3 |
|
import java.util.Iterator; |
4 |
|
import java.util.List; |
5 |
|
|
6 |
|
import org.kuali.student.common.dto.DtoConstants; |
7 |
|
import org.kuali.student.common.dto.StatusInfo; |
8 |
|
import org.kuali.student.common.exceptions.CircularReferenceException; |
9 |
|
import org.kuali.student.common.exceptions.DataValidationErrorException; |
10 |
|
import org.kuali.student.common.exceptions.DoesNotExistException; |
11 |
|
import org.kuali.student.common.exceptions.InvalidParameterException; |
12 |
|
import org.kuali.student.common.exceptions.MissingParameterException; |
13 |
|
import org.kuali.student.common.exceptions.OperationFailedException; |
14 |
|
import org.kuali.student.common.exceptions.PermissionDeniedException; |
15 |
|
import org.kuali.student.common.exceptions.VersionMismatchException; |
16 |
|
import org.kuali.student.common.versionmanagement.dto.VersionDisplayInfo; |
17 |
|
import org.kuali.student.core.statement.dto.StatementTreeViewInfo; |
18 |
|
import org.kuali.student.lum.course.dto.CourseInfo; |
19 |
|
import org.kuali.student.lum.course.service.CourseService; |
20 |
|
import org.kuali.student.lum.course.service.CourseServiceConstants; |
21 |
|
import org.springframework.transaction.annotation.Transactional; |
22 |
|
|
23 |
|
@Transactional(noRollbackFor = { DoesNotExistException.class }, rollbackFor = { Throwable.class }) |
|
|
| 0% |
Uncovered Elements: 106 (106) |
Complexity: 33 |
Complexity Density: 0.51 |
|
24 |
|
public class CourseStateChangeServiceImpl { |
25 |
|
private CourseService courseService; |
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
@param |
31 |
|
@param |
32 |
|
@param |
33 |
|
@return |
34 |
|
@throws |
35 |
|
|
|
|
| 0% |
Uncovered Elements: 15 (15) |
Complexity: 4 |
Complexity Density: 0.36 |
|
36 |
0
|
public StatusInfo changeState(String courseId, String newState, String prevEndTermAtpId) throws Exception {... |
37 |
|
|
38 |
0
|
CourseInfo courseInfo = courseService.getCourse(courseId); |
39 |
|
|
40 |
0
|
StatusInfo ret = new StatusInfo(); |
41 |
0
|
try { |
42 |
0
|
if (newState.equals(DtoConstants.STATE_ACTIVE)) { |
43 |
0
|
activateCourse(courseInfo, prevEndTermAtpId); |
44 |
0
|
} else if (newState.equals(DtoConstants.STATE_RETIRED)) { |
45 |
0
|
retireCourse(courseInfo); |
46 |
|
} |
47 |
|
|
48 |
0
|
ret.setSuccess(new Boolean(true)); |
49 |
|
} catch (Exception e) { |
50 |
0
|
ret.setSuccess(new Boolean(false)); |
51 |
0
|
ret.setMessage(e.getMessage()); |
52 |
|
} |
53 |
|
|
54 |
0
|
return ret; |
55 |
|
} |
56 |
|
|
57 |
|
|
58 |
|
|
59 |
|
|
60 |
|
@param |
61 |
|
@param |
62 |
|
|
|
|
| 0% |
Uncovered Elements: 15 (15) |
Complexity: 5 |
Complexity Density: 0.56 |
|
63 |
0
|
protected void activateCourse(CourseInfo courseToActivate, String prevEndTermAtpId) throws Exception{... |
64 |
0
|
CourseInfo currVerCourse = getCurrentVersionOfCourse(courseToActivate); |
65 |
0
|
String existingState = courseToActivate.getState(); |
66 |
0
|
String currVerState = currVerCourse.getState(); |
67 |
0
|
boolean isCurrVer = (courseToActivate.getId().equals(currVerCourse.getId())); |
68 |
|
|
69 |
0
|
if (existingState.equals(DtoConstants.STATE_DRAFT)) { |
70 |
|
|
71 |
0
|
if (isCurrVer) { |
72 |
|
|
73 |
0
|
updateCourseVersionStates(courseToActivate, DtoConstants.STATE_ACTIVE, currVerCourse, null, true, prevEndTermAtpId); |
74 |
0
|
} else if (currVerState.equals(DtoConstants.STATE_ACTIVE) || |
75 |
|
currVerState.equals(DtoConstants.STATE_SUSPENDED)) { |
76 |
0
|
updateCourseVersionStates(courseToActivate, DtoConstants.STATE_ACTIVE, currVerCourse, DtoConstants.STATE_SUPERSEDED, true, prevEndTermAtpId); |
77 |
|
} |
78 |
|
} |
79 |
|
} |
80 |
|
|
81 |
|
|
82 |
|
|
83 |
|
|
84 |
|
@param |
85 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 3 |
Complexity Density: 0.6 |
|
86 |
0
|
protected void retireCourse(CourseInfo courseToRetire) throws Exception{... |
87 |
0
|
String existingState = courseToRetire.getState(); |
88 |
|
|
89 |
0
|
if (existingState.equals(DtoConstants.STATE_ACTIVE) || existingState.equals(DtoConstants.STATE_SUSPENDED)){ |
90 |
0
|
courseToRetire.setState(DtoConstants.STATE_RETIRED); |
91 |
|
|
92 |
0
|
courseService.updateCourse(courseToRetire); |
93 |
0
|
updateStatementTreeViewInfoState(courseToRetire); |
94 |
|
} |
95 |
|
} |
96 |
|
|
97 |
|
|
98 |
|
|
99 |
|
|
100 |
|
@param |
101 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
102 |
0
|
protected CourseInfo getCurrentVersionOfCourse(CourseInfo course)... |
103 |
|
throws Exception { |
104 |
|
|
105 |
0
|
String verIndId = course.getVersionInfo().getVersionIndId(); |
106 |
|
|
107 |
|
|
108 |
0
|
VersionDisplayInfo curVerDisplayInfo = courseService.getCurrentVersion( |
109 |
|
CourseServiceConstants.COURSE_NAMESPACE_URI, verIndId); |
110 |
0
|
String curVerId = curVerDisplayInfo.getId(); |
111 |
|
|
112 |
|
|
113 |
0
|
CourseInfo currVerCourse = courseService.getCourse(curVerId); |
114 |
|
|
115 |
0
|
return currVerCourse; |
116 |
|
} |
117 |
|
|
118 |
|
|
119 |
|
|
120 |
|
|
121 |
|
|
122 |
|
|
123 |
|
@param |
124 |
|
|
125 |
|
@param |
126 |
|
|
127 |
|
|
128 |
|
@param |
129 |
|
|
130 |
|
|
131 |
|
@param |
132 |
|
|
133 |
|
|
134 |
|
@param |
135 |
|
|
136 |
|
@param |
137 |
|
|
138 |
|
@throws |
139 |
|
|
|
|
| 0% |
Uncovered Elements: 47 (47) |
Complexity: 16 |
Complexity Density: 0.55 |
|
140 |
0
|
@Transactional(readOnly = false)... |
141 |
|
private void updateCourseVersionStates(CourseInfo thisVerCourse, |
142 |
|
String thisVerNewState, CourseInfo currVerCourse, |
143 |
|
String currVerNewState, boolean makeCurrent, |
144 |
|
String prevEndTermAtpId) throws Exception { |
145 |
0
|
String thisVerPrevState = thisVerCourse.getState(); |
146 |
|
|
147 |
|
|
148 |
|
|
149 |
0
|
boolean isCurrent = thisVerCourse.getId().equals(currVerCourse.getId()); |
150 |
0
|
if(!makeCurrent || !isCurrent || !thisVerCourse.getVersionInfo().getSequenceNumber().equals(1)){ |
151 |
0
|
makeCurrent &= !isCurrent; |
152 |
|
} |
153 |
|
|
154 |
0
|
if (thisVerNewState == null) { |
155 |
0
|
throw new InvalidParameterException("new state cannot be null"); |
156 |
|
} else { |
157 |
0
|
thisVerCourse.setState(thisVerNewState); |
158 |
0
|
courseService.updateCourse(thisVerCourse); |
159 |
0
|
updateStatementTreeViewInfoState(thisVerCourse); |
160 |
|
} |
161 |
|
|
162 |
|
|
163 |
0
|
if (currVerNewState != null) { |
164 |
0
|
currVerCourse.setState(currVerNewState); |
165 |
0
|
if(currVerCourse.getEndTerm()==null){ |
166 |
0
|
currVerCourse.setEndTerm(prevEndTermAtpId); |
167 |
|
} |
168 |
0
|
courseService.updateCourse(currVerCourse); |
169 |
0
|
updateStatementTreeViewInfoState(currVerCourse); |
170 |
|
} |
171 |
|
|
172 |
0
|
if (makeCurrent == true) { |
173 |
0
|
courseService.setCurrentCourseVersion(thisVerCourse.getId(), |
174 |
|
null); |
175 |
|
} |
176 |
|
|
177 |
|
|
178 |
|
|
179 |
|
|
180 |
|
|
181 |
0
|
if (thisVerPrevState.equals(DtoConstants.STATE_APPROVED) |
182 |
|
&& thisVerNewState.equals(DtoConstants.STATE_ACTIVE)) { |
183 |
|
|
184 |
0
|
List<VersionDisplayInfo> versions = courseService.getVersions( |
185 |
|
CourseServiceConstants.COURSE_NAMESPACE_URI, thisVerCourse |
186 |
|
.getVersionInfo().getVersionIndId()); |
187 |
0
|
Long startSeq = new Long(1); |
188 |
|
|
189 |
0
|
if (!isCurrent && (currVerCourse.getId() != thisVerCourse.getId())) { |
190 |
0
|
startSeq = currVerCourse.getVersionInfo().getSequenceNumber() + 1; |
191 |
|
} |
192 |
|
|
193 |
0
|
for (VersionDisplayInfo versionInfo : versions) { |
194 |
0
|
if (versionInfo.getSequenceNumber() >= startSeq) { |
195 |
0
|
CourseInfo otherCourse = courseService |
196 |
|
.getCourse(versionInfo.getId()); |
197 |
0
|
if (otherCourse.getState().equals( |
198 |
|
DtoConstants.STATE_APPROVED) |
199 |
|
|| otherCourse.getState().equals( |
200 |
|
DtoConstants.STATE_SUBMITTED) |
201 |
|
|| otherCourse.getState().equals( |
202 |
|
DtoConstants.STATE_DRAFT)) { |
203 |
0
|
otherCourse.setState(DtoConstants.STATE_SUPERSEDED); |
204 |
0
|
courseService.updateCourse(otherCourse); |
205 |
0
|
updateStatementTreeViewInfoState(otherCourse); |
206 |
|
} |
207 |
|
} |
208 |
|
} |
209 |
|
} |
210 |
|
|
211 |
|
} |
212 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
213 |
0
|
public void setCourseService(CourseService courseService) {... |
214 |
0
|
this.courseService = courseService; |
215 |
|
} |
216 |
|
|
217 |
|
|
218 |
|
|
219 |
|
|
220 |
|
|
221 |
|
|
222 |
|
|
223 |
|
@param |
224 |
|
|
225 |
|
|
226 |
|
@throws |
227 |
|
@throws |
228 |
|
@throws |
229 |
|
@throws |
230 |
|
@throws |
231 |
|
@throws |
232 |
|
@throws |
233 |
|
@throws |
234 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 3 |
Complexity Density: 0.6 |
|
235 |
0
|
public void updateStatementTreeViewInfoState(CourseInfo courseInfo)... |
236 |
|
throws DoesNotExistException, InvalidParameterException, |
237 |
|
MissingParameterException, OperationFailedException, |
238 |
|
PermissionDeniedException, DataValidationErrorException, |
239 |
|
CircularReferenceException, VersionMismatchException { |
240 |
|
|
241 |
|
|
242 |
|
|
243 |
0
|
List<StatementTreeViewInfo> statementTreeViewInfos = courseService |
244 |
|
.getCourseStatements(courseInfo.getId(), null, null); |
245 |
|
|
246 |
|
|
247 |
0
|
for (Iterator<StatementTreeViewInfo> it = statementTreeViewInfos |
248 |
0
|
.iterator(); it.hasNext();) |
249 |
0
|
StatementUtil.updateStatementTreeViewInfoState(courseInfo |
250 |
|
.getState(), it.next()); |
251 |
|
|
252 |
|
|
253 |
|
|
254 |
0
|
for (Iterator<StatementTreeViewInfo> it = statementTreeViewInfos |
255 |
0
|
.iterator(); it.hasNext();) |
256 |
0
|
courseService.updateCourseStatement(courseInfo.getId(), it.next()); |
257 |
|
} |
258 |
|
|
259 |
|
} |