1 |
|
package org.kuali.student.lum.course.service.impl; |
2 |
|
|
3 |
|
import java.util.List; |
4 |
|
|
5 |
|
import org.apache.commons.beanutils.PropertyUtils; |
6 |
|
import org.kuali.student.common.dto.CurrencyAmountInfo; |
7 |
|
import org.kuali.student.common.exceptions.AlreadyExistsException; |
8 |
|
import org.kuali.student.common.exceptions.CircularRelationshipException; |
9 |
|
import org.kuali.student.common.exceptions.DataValidationErrorException; |
10 |
|
import org.kuali.student.common.exceptions.DependentObjectsExistException; |
11 |
|
import org.kuali.student.common.exceptions.DoesNotExistException; |
12 |
|
import org.kuali.student.common.exceptions.InvalidParameterException; |
13 |
|
import org.kuali.student.common.exceptions.MissingParameterException; |
14 |
|
import org.kuali.student.common.exceptions.OperationFailedException; |
15 |
|
import org.kuali.student.common.exceptions.PermissionDeniedException; |
16 |
|
import org.kuali.student.common.exceptions.UnsupportedActionException; |
17 |
|
import org.kuali.student.common.exceptions.VersionMismatchException; |
18 |
|
import org.kuali.student.core.statement.dto.ReqCompFieldInfo; |
19 |
|
import org.kuali.student.core.statement.dto.ReqComponentInfo; |
20 |
|
import org.kuali.student.core.statement.dto.StatementTreeViewInfo; |
21 |
|
import org.kuali.student.core.statement.service.StatementService; |
22 |
|
import org.kuali.student.lum.course.dto.ActivityInfo; |
23 |
|
import org.kuali.student.lum.course.dto.CourseCrossListingInfo; |
24 |
|
import org.kuali.student.lum.course.dto.CourseFeeInfo; |
25 |
|
import org.kuali.student.lum.course.dto.CourseInfo; |
26 |
|
import org.kuali.student.lum.course.dto.CourseJointInfo; |
27 |
|
import org.kuali.student.lum.course.dto.CourseRevenueInfo; |
28 |
|
import org.kuali.student.lum.course.dto.CourseVariationInfo; |
29 |
|
import org.kuali.student.lum.course.dto.FormatInfo; |
30 |
|
import org.kuali.student.lum.course.dto.LoDisplayInfo; |
31 |
|
import org.kuali.student.lum.course.service.CourseService; |
32 |
|
import org.kuali.student.lum.lrc.dto.ResultComponentInfo; |
33 |
|
import org.kuali.student.lum.lu.dto.AffiliatedOrgInfo; |
34 |
|
import org.kuali.student.lum.lu.dto.CluSetInfo; |
35 |
|
import org.kuali.student.lum.lu.service.LuService; |
36 |
|
import org.kuali.student.lum.statement.typekey.ReqComponentFieldTypes; |
37 |
|
|
|
|
| 54.3% |
Uncovered Elements: 37 (81) |
Complexity: 14 |
Complexity Density: 0.21 |
|
38 |
|
public class CourseServiceUtils { |
|
|
| 91.7% |
Uncovered Elements: 2 (24) |
Complexity: 1 |
Complexity Density: 0.04 |
|
39 |
8
|
public static void resetIds(CourseInfo course) {... |
40 |
|
|
41 |
8
|
for(CourseJointInfo joint:course.getJoints()){ |
42 |
0
|
joint.setRelationId(null); |
43 |
|
} |
44 |
|
|
45 |
8
|
for(LoDisplayInfo lo:course.getCourseSpecificLOs()){ |
46 |
16
|
resetLoRecursively(lo); |
47 |
|
} |
48 |
|
|
49 |
8
|
for(FormatInfo format:course.getFormats()){ |
50 |
16
|
format.setId(null); |
51 |
16
|
for(ActivityInfo activity:format.getActivities()){ |
52 |
32
|
activity.setId(null); |
53 |
|
} |
54 |
|
} |
55 |
|
|
56 |
8
|
for(ResultComponentInfo result:course.getCreditOptions()){ |
57 |
16
|
result.setId(null); |
58 |
|
} |
59 |
|
|
60 |
8
|
for(CourseCrossListingInfo crossListing:course.getCrossListings()){ |
61 |
0
|
crossListing.setId(null); |
62 |
|
} |
63 |
|
|
64 |
8
|
for(AffiliatedOrgInfo orgInfo:course.getExpenditure().getAffiliatedOrgs()){ |
65 |
16
|
orgInfo.setId(null); |
66 |
|
} |
67 |
|
|
68 |
8
|
for(CourseFeeInfo fee:course.getFees()){ |
69 |
16
|
fee.setId(null); |
70 |
16
|
for(CurrencyAmountInfo feeAmount:fee.getFeeAmounts()){ |
71 |
32
|
feeAmount.setId(null); |
72 |
|
} |
73 |
|
} |
74 |
|
|
75 |
8
|
for(CourseRevenueInfo revenue:course.getRevenues()){ |
76 |
16
|
revenue.setId(null); |
77 |
16
|
for(AffiliatedOrgInfo orgInfo:revenue.getAffiliatedOrgs()){ |
78 |
32
|
orgInfo.setId(null); |
79 |
|
} |
80 |
|
} |
81 |
|
|
82 |
8
|
for(CourseVariationInfo variation:course.getVariations()){ |
83 |
16
|
variation.setId(null); |
84 |
|
} |
85 |
|
} |
86 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
87 |
112
|
private static void resetLoRecursively(LoDisplayInfo lo){... |
88 |
|
|
89 |
112
|
lo.getLoInfo().setId(null); |
90 |
112
|
for(LoDisplayInfo nestedLo:lo.getLoDisplayInfoList()){ |
91 |
96
|
resetLoRecursively(nestedLo); |
92 |
|
} |
93 |
|
} |
94 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
95 |
8
|
private static void clearStatementTreeViewIds(... |
96 |
|
List<StatementTreeViewInfo> statementTreeViews, String newState, LuService luService) throws OperationFailedException { |
97 |
|
|
98 |
8
|
for(StatementTreeViewInfo statementTreeView:statementTreeViews){ |
99 |
1
|
clearStatementTreeViewIdsRecursively(statementTreeView, newState, luService); |
100 |
|
} |
101 |
|
} |
102 |
|
|
103 |
|
|
104 |
|
|
105 |
|
@param |
106 |
|
@param |
107 |
|
@throws |
108 |
|
|
|
|
| 33.3% |
Uncovered Elements: 16 (24) |
Complexity: 6 |
Complexity Density: 0.3 |
|
109 |
3
|
private static void clearStatementTreeViewIdsRecursively(StatementTreeViewInfo statementTreeView, String newState,LuService luService) throws OperationFailedException{... |
110 |
3
|
statementTreeView.setId(null); |
111 |
3
|
statementTreeView.setState(newState); |
112 |
|
|
113 |
|
|
114 |
3
|
for(ReqComponentInfo reqComp:statementTreeView.getReqComponents()){ |
115 |
4
|
reqComp.setId(null); |
116 |
4
|
reqComp.setState(newState); |
117 |
4
|
for(ReqCompFieldInfo field:reqComp.getReqCompFields()){ |
118 |
0
|
field.setId(null); |
119 |
|
|
120 |
0
|
if(ReqComponentFieldTypes.COURSE_CLUSET_KEY.getId().equals(field.getType())|| |
121 |
|
ReqComponentFieldTypes.PROGRAM_CLUSET_KEY.getId().equals(field.getType())|| |
122 |
|
ReqComponentFieldTypes.CLUSET_KEY.getId().equals(field.getType())){ |
123 |
0
|
try { |
124 |
0
|
CluSetInfo cluSet = luService.getCluSetInfo(field.getValue()); |
125 |
0
|
cluSet.setId(null); |
126 |
0
|
cluSet.setState(newState); |
127 |
|
|
128 |
0
|
if (cluSet.getMembershipQuery() != null){ |
129 |
0
|
cluSet.getCluIds().clear(); |
130 |
0
|
cluSet.getCluSetIds().clear(); |
131 |
|
} |
132 |
0
|
cluSet = luService.createCluSet(cluSet.getType(), cluSet); |
133 |
0
|
field.setValue(cluSet.getId()); |
134 |
|
} catch (Exception e) { |
135 |
0
|
throw new OperationFailedException("Error copying clusets.", e); |
136 |
|
} |
137 |
|
} |
138 |
|
|
139 |
|
} |
140 |
|
} |
141 |
|
|
142 |
3
|
for(StatementTreeViewInfo child: statementTreeView.getStatements()){ |
143 |
2
|
clearStatementTreeViewIdsRecursively(child,newState,luService); |
144 |
|
} |
145 |
|
} |
146 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
147 |
8
|
public static void copyStatements(String originalCluId, String newCluId, String newState,... |
148 |
|
StatementService statementService, LuService luService, CourseService courseService) throws OperationFailedException, DoesNotExistException, InvalidParameterException, MissingParameterException, PermissionDeniedException, DataValidationErrorException { |
149 |
8
|
List<StatementTreeViewInfo> statementTreeViews = courseService.getCourseStatements(originalCluId,null,null); |
150 |
|
|
151 |
8
|
clearStatementTreeViewIds(statementTreeViews,newState,luService); |
152 |
|
|
153 |
8
|
for(StatementTreeViewInfo statementTreeView:statementTreeViews){ |
154 |
1
|
courseService.createCourseStatement(newCluId, statementTreeView); |
155 |
|
} |
156 |
|
} |
157 |
|
|
|
|
| 0% |
Uncovered Elements: 18 (18) |
Complexity: 4 |
Complexity Density: 0.29 |
|
158 |
0
|
public static CourseInfo copyCourse(String originalCluId, String newCluId, String newState, String[] ignoreProperties, StatementService statementService, LuService luService, CourseService courseService) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, AlreadyExistsException, DataValidationErrorException, VersionMismatchException, CircularRelationshipException, DependentObjectsExistException, UnsupportedActionException{... |
159 |
0
|
CourseInfo originalCourse = courseService.getCourse(originalCluId); |
160 |
0
|
resetIds(originalCourse); |
161 |
|
|
162 |
|
|
163 |
|
|
164 |
0
|
if(newState==null){ |
165 |
0
|
newState = originalCourse.getState(); |
166 |
|
} |
167 |
|
|
168 |
0
|
originalCourse.setId(newCluId); |
169 |
0
|
originalCourse.setState(newState); |
170 |
|
|
171 |
0
|
if(ignoreProperties!=null){ |
172 |
0
|
for(String property:ignoreProperties){ |
173 |
0
|
try { |
174 |
0
|
PropertyUtils.setProperty(originalCourse, property, null); |
175 |
|
} catch (Exception e) { |
176 |
0
|
throw new InvalidParameterException("Ignore property is invalid and is causing an exception.",e); |
177 |
|
} |
178 |
|
} |
179 |
|
} |
180 |
|
|
181 |
0
|
CourseInfo newCourse = courseService.createCourse(originalCourse); |
182 |
0
|
copyStatements(originalCluId, newCourse.getId(), newState, statementService, luService, courseService); |
183 |
0
|
return newCourse; |
184 |
|
} |
185 |
|
|
186 |
|
} |