1 |
|
package org.kuali.student.lum.lu.ui.course.server.gwt; |
2 |
|
|
3 |
|
import java.util.List; |
4 |
|
|
5 |
|
import org.apache.commons.beanutils.PropertyUtils; |
6 |
|
import org.apache.log4j.Logger; |
7 |
|
import org.kuali.student.common.assembly.data.Data; |
8 |
|
import org.kuali.student.common.dto.CurrencyAmountInfo; |
9 |
|
import org.kuali.student.common.dto.DtoConstants; |
10 |
|
import org.kuali.student.common.exceptions.AlreadyExistsException; |
11 |
|
import org.kuali.student.common.exceptions.CircularRelationshipException; |
12 |
|
import org.kuali.student.common.exceptions.DataValidationErrorException; |
13 |
|
import org.kuali.student.common.exceptions.DependentObjectsExistException; |
14 |
|
import org.kuali.student.common.exceptions.DoesNotExistException; |
15 |
|
import org.kuali.student.common.exceptions.InvalidParameterException; |
16 |
|
import org.kuali.student.common.exceptions.MissingParameterException; |
17 |
|
import org.kuali.student.common.exceptions.OperationFailedException; |
18 |
|
import org.kuali.student.common.exceptions.PermissionDeniedException; |
19 |
|
import org.kuali.student.common.exceptions.UnsupportedActionException; |
20 |
|
import org.kuali.student.common.exceptions.VersionMismatchException; |
21 |
|
import org.kuali.student.common.ui.client.service.DataSaveResult; |
22 |
|
import org.kuali.student.common.ui.server.gwt.DataService; |
23 |
|
import org.kuali.student.core.proposal.dto.ProposalInfo; |
24 |
|
import org.kuali.student.core.proposal.service.ProposalService; |
25 |
|
import org.kuali.student.core.statement.dto.ReqCompFieldInfo; |
26 |
|
import org.kuali.student.core.statement.dto.ReqComponentInfo; |
27 |
|
import org.kuali.student.core.statement.dto.StatementTreeViewInfo; |
28 |
|
import org.kuali.student.core.statement.service.StatementService; |
29 |
|
import org.kuali.student.lum.course.dto.ActivityInfo; |
30 |
|
import org.kuali.student.lum.course.dto.CourseCrossListingInfo; |
31 |
|
import org.kuali.student.lum.course.dto.CourseFeeInfo; |
32 |
|
import org.kuali.student.lum.course.dto.CourseInfo; |
33 |
|
import org.kuali.student.lum.course.dto.CourseJointInfo; |
34 |
|
import org.kuali.student.lum.course.dto.CourseRevenueInfo; |
35 |
|
import org.kuali.student.lum.course.dto.CourseVariationInfo; |
36 |
|
import org.kuali.student.lum.course.dto.FormatInfo; |
37 |
|
import org.kuali.student.lum.course.dto.LoDisplayInfo; |
38 |
|
import org.kuali.student.lum.course.service.CourseService; |
39 |
|
import org.kuali.student.lum.lrc.dto.ResultComponentInfo; |
40 |
|
import org.kuali.student.lum.lu.LUConstants; |
41 |
|
import org.kuali.student.lum.lu.dto.AffiliatedOrgInfo; |
42 |
|
import org.kuali.student.lum.lu.dto.CluSetInfo; |
43 |
|
import org.kuali.student.lum.lu.service.LuService; |
44 |
|
import org.kuali.student.lum.statement.typekey.ReqComponentFieldTypes; |
45 |
|
import org.springframework.transaction.annotation.Transactional; |
46 |
|
@Transactional(noRollbackFor={DoesNotExistException.class},rollbackFor={Throwable.class}) |
|
|
| 0% |
Uncovered Elements: 130 (130) |
Complexity: 29 |
Complexity Density: 0.29 |
|
47 |
|
public class CopyCourseServiceImpl { |
48 |
|
final static Logger LOG = Logger.getLogger(CopyCourseServiceImpl.class); |
49 |
|
|
50 |
|
private DataService courseDataService; |
51 |
|
private DataService courseProposalDataService; |
52 |
|
private CourseService courseService; |
53 |
|
private LuService luService; |
54 |
|
private StatementService statementService; |
55 |
|
private ProposalService proposalService; |
56 |
|
|
57 |
|
private String defaultDocumentType=LUConstants.PROPOSAL_TYPE_COURSE_CREATE; |
58 |
|
private String defaultState=DtoConstants.STATE_DRAFT; |
59 |
|
|
60 |
|
private List<String> ignoreProperties; |
61 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
62 |
0
|
public DataSaveResult createCopyCourse(String originalCluId) throws Exception {... |
63 |
|
|
64 |
0
|
CourseInfo copiedCourse = copyCourse(originalCluId); |
65 |
|
|
66 |
0
|
DataSaveResult result = new DataSaveResult(); |
67 |
0
|
result.setValue(courseDataService.getData(copiedCourse.getId())); |
68 |
0
|
return result; |
69 |
|
} |
70 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
71 |
0
|
public DataSaveResult createCopyCourseProposal(String originalProposalId) throws Exception {... |
72 |
|
|
73 |
0
|
ProposalInfo copiedProposal = copyProposal(originalProposalId); |
74 |
|
|
75 |
|
|
76 |
0
|
Data data = courseProposalDataService.getData(copiedProposal.getId()); |
77 |
|
|
78 |
|
|
79 |
0
|
return courseProposalDataService.saveData(data); |
80 |
|
} |
81 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
82 |
0
|
private CourseInfo copyCourse(String originalCluId) throws Exception{... |
83 |
|
|
84 |
0
|
return copyCourse(originalCluId, null, defaultState, ignoreProperties, statementService, luService, courseService); |
85 |
|
} |
|
|
| 0% |
Uncovered Elements: 15 (15) |
Complexity: 2 |
Complexity Density: 0.13 |
|
86 |
0
|
private ProposalInfo copyProposal(String originalProposalId) throws Exception{... |
87 |
0
|
try { |
88 |
|
|
89 |
0
|
ProposalInfo originalProposal = proposalService.getProposal(originalProposalId); |
90 |
|
|
91 |
|
|
92 |
0
|
String originalCluId = originalProposal.getProposalReference().get(0); |
93 |
0
|
CourseInfo copiedCourse = copyCourse(originalCluId); |
94 |
|
|
95 |
|
|
96 |
0
|
originalProposal.setId(null); |
97 |
0
|
originalProposal.setWorkflowId(null); |
98 |
0
|
originalProposal.setState(defaultState); |
99 |
0
|
originalProposal.setType(defaultDocumentType); |
100 |
0
|
originalProposal.getProposalReference().set(0, copiedCourse.getId()); |
101 |
0
|
originalProposal.getProposerOrg().clear(); |
102 |
0
|
originalProposal.getProposerPerson().clear(); |
103 |
|
|
104 |
|
|
105 |
0
|
ProposalInfo copiedProposal = proposalService.createProposal(defaultDocumentType, originalProposal); |
106 |
|
|
107 |
0
|
return copiedProposal; |
108 |
|
|
109 |
|
} catch (Exception e) { |
110 |
0
|
LOG.error("Error copying proposal id:" + originalProposalId, e); |
111 |
0
|
throw e; |
112 |
|
} |
113 |
|
} |
114 |
|
|
|
|
| 0% |
Uncovered Elements: 24 (24) |
Complexity: 1 |
Complexity Density: 0.04 |
|
115 |
0
|
private void resetIds(CourseInfo course) {... |
116 |
|
|
117 |
0
|
for(CourseJointInfo joint:course.getJoints()){ |
118 |
0
|
joint.setRelationId(null); |
119 |
|
} |
120 |
|
|
121 |
0
|
for(LoDisplayInfo lo:course.getCourseSpecificLOs()){ |
122 |
0
|
resetLoRecursively(lo); |
123 |
|
} |
124 |
|
|
125 |
0
|
for(FormatInfo format:course.getFormats()){ |
126 |
0
|
format.setId(null); |
127 |
0
|
for(ActivityInfo activity:format.getActivities()){ |
128 |
0
|
activity.setId(null); |
129 |
|
} |
130 |
|
} |
131 |
|
|
132 |
0
|
for(ResultComponentInfo result:course.getCreditOptions()){ |
133 |
0
|
result.setId(null); |
134 |
|
} |
135 |
|
|
136 |
0
|
for(CourseCrossListingInfo crossListing:course.getCrossListings()){ |
137 |
0
|
crossListing.setId(null); |
138 |
|
} |
139 |
|
|
140 |
0
|
for(AffiliatedOrgInfo orgInfo:course.getExpenditure().getAffiliatedOrgs()){ |
141 |
0
|
orgInfo.setId(null); |
142 |
|
} |
143 |
|
|
144 |
0
|
for(CourseFeeInfo fee:course.getFees()){ |
145 |
0
|
fee.setId(null); |
146 |
0
|
for(CurrencyAmountInfo feeAmount:fee.getFeeAmounts()){ |
147 |
0
|
feeAmount.setId(null); |
148 |
|
} |
149 |
|
} |
150 |
|
|
151 |
0
|
for(CourseRevenueInfo revenue:course.getRevenues()){ |
152 |
0
|
revenue.setId(null); |
153 |
0
|
for(AffiliatedOrgInfo orgInfo:revenue.getAffiliatedOrgs()){ |
154 |
0
|
orgInfo.setId(null); |
155 |
|
} |
156 |
|
} |
157 |
|
|
158 |
0
|
for(CourseVariationInfo variation:course.getVariations()){ |
159 |
0
|
variation.setId(null); |
160 |
|
} |
161 |
|
} |
162 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
163 |
0
|
private void resetLoRecursively(LoDisplayInfo lo){... |
164 |
|
|
165 |
0
|
lo.getLoInfo().setId(null); |
166 |
0
|
for(LoDisplayInfo nestedLo:lo.getLoDisplayInfoList()){ |
167 |
0
|
resetLoRecursively(nestedLo); |
168 |
|
} |
169 |
|
} |
170 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
171 |
0
|
private void clearStatementTreeViewIds(... |
172 |
|
List<StatementTreeViewInfo> statementTreeViews, String newState, LuService luService) throws OperationFailedException { |
173 |
|
|
174 |
0
|
for(StatementTreeViewInfo statementTreeView:statementTreeViews){ |
175 |
0
|
clearStatementTreeViewIdsRecursively(statementTreeView, newState, luService); |
176 |
|
} |
177 |
|
} |
178 |
|
|
179 |
|
|
180 |
|
|
181 |
|
@param |
182 |
|
@param |
183 |
|
@throws |
184 |
|
|
|
|
| 0% |
Uncovered Elements: 24 (24) |
Complexity: 6 |
Complexity Density: 0.3 |
|
185 |
0
|
private void clearStatementTreeViewIdsRecursively(StatementTreeViewInfo statementTreeView, String newState,LuService luService) throws OperationFailedException{... |
186 |
0
|
statementTreeView.setId(null); |
187 |
0
|
statementTreeView.setState(newState); |
188 |
|
|
189 |
|
|
190 |
0
|
for(ReqComponentInfo reqComp:statementTreeView.getReqComponents()){ |
191 |
0
|
reqComp.setId(null); |
192 |
0
|
reqComp.setState(newState); |
193 |
0
|
for(ReqCompFieldInfo field:reqComp.getReqCompFields()){ |
194 |
0
|
field.setId(null); |
195 |
|
|
196 |
0
|
if(ReqComponentFieldTypes.COURSE_CLUSET_KEY.getId().equals(field.getType())|| |
197 |
|
ReqComponentFieldTypes.PROGRAM_CLUSET_KEY.getId().equals(field.getType())|| |
198 |
|
ReqComponentFieldTypes.CLUSET_KEY.getId().equals(field.getType())){ |
199 |
0
|
try { |
200 |
0
|
CluSetInfo cluSet = luService.getCluSetInfo(field.getValue()); |
201 |
0
|
cluSet.setId(null); |
202 |
0
|
cluSet.setState(newState); |
203 |
|
|
204 |
0
|
if (cluSet.getMembershipQuery() != null){ |
205 |
0
|
cluSet.getCluIds().clear(); |
206 |
0
|
cluSet.getCluSetIds().clear(); |
207 |
|
} |
208 |
0
|
cluSet = luService.createCluSet(cluSet.getType(), cluSet); |
209 |
0
|
field.setValue(cluSet.getId()); |
210 |
|
} catch (Exception e) { |
211 |
0
|
throw new OperationFailedException("Error copying clusets.", e); |
212 |
|
} |
213 |
|
} |
214 |
|
|
215 |
|
} |
216 |
|
} |
217 |
|
|
218 |
0
|
for(StatementTreeViewInfo child: statementTreeView.getStatements()){ |
219 |
0
|
clearStatementTreeViewIdsRecursively(child,newState,luService); |
220 |
|
} |
221 |
|
} |
222 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
223 |
0
|
private void copyStatements(String originalCluId, String newCluId, String newState,... |
224 |
|
StatementService statementService, LuService luService, CourseService courseService) throws OperationFailedException, DoesNotExistException, InvalidParameterException, MissingParameterException, PermissionDeniedException, DataValidationErrorException { |
225 |
|
|
226 |
0
|
List<StatementTreeViewInfo> statementTreeViews = courseService.getCourseStatements(originalCluId,null,null); |
227 |
|
|
228 |
|
|
229 |
0
|
if(statementTreeViews!=null){ |
230 |
0
|
clearStatementTreeViewIds(statementTreeViews,newState,luService); |
231 |
|
|
232 |
0
|
for(StatementTreeViewInfo statementTreeView:statementTreeViews){ |
233 |
0
|
courseService.createCourseStatement(newCluId, statementTreeView); |
234 |
|
} |
235 |
|
} |
236 |
|
} |
237 |
|
|
|
|
| 0% |
Uncovered Elements: 19 (19) |
Complexity: 4 |
Complexity Density: 0.27 |
|
238 |
0
|
private CourseInfo copyCourse(String originalCluId, String newCluId, String newState, List<String> ignoreProperties, StatementService statementService, LuService luService, CourseService courseService) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, AlreadyExistsException, DataValidationErrorException, VersionMismatchException, CircularRelationshipException, DependentObjectsExistException, UnsupportedActionException{... |
239 |
0
|
CourseInfo originalCourse = courseService.getCourse(originalCluId); |
240 |
0
|
resetIds(originalCourse); |
241 |
0
|
originalCourse.setCourseTitle("Copy of "+originalCourse.getCourseTitle()); |
242 |
|
|
243 |
|
|
244 |
0
|
if(newState==null){ |
245 |
0
|
newState = originalCourse.getState(); |
246 |
|
} |
247 |
|
|
248 |
0
|
originalCourse.setId(newCluId); |
249 |
0
|
originalCourse.setState(newState); |
250 |
|
|
251 |
|
|
252 |
0
|
if(ignoreProperties!=null){ |
253 |
0
|
for(String property:ignoreProperties){ |
254 |
0
|
try { |
255 |
0
|
PropertyUtils.setProperty(originalCourse, property, null); |
256 |
|
} catch (Exception e) { |
257 |
0
|
throw new InvalidParameterException("Ignore property is invalid and is causing an exception.",e); |
258 |
|
} |
259 |
|
} |
260 |
|
} |
261 |
|
|
262 |
0
|
CourseInfo newCourse = courseService.createCourse(originalCourse); |
263 |
0
|
copyStatements(originalCluId, newCourse.getId(), newState, statementService, luService, courseService); |
264 |
0
|
return newCourse; |
265 |
|
} |
266 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
267 |
0
|
public void setCourseService(CourseService courseService) {... |
268 |
0
|
this.courseService = courseService; |
269 |
|
} |
270 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
271 |
0
|
public void setLuService(LuService luService) {... |
272 |
0
|
this.luService = luService; |
273 |
|
} |
274 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
275 |
0
|
public void setStatementService(StatementService statementService) {... |
276 |
0
|
this.statementService = statementService; |
277 |
|
} |
278 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
279 |
0
|
public void setProposalService(ProposalService proposalService) {... |
280 |
0
|
this.proposalService = proposalService; |
281 |
|
} |
282 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
283 |
0
|
public void setCourseDataService(DataService courseDataService) {... |
284 |
0
|
this.courseDataService = courseDataService; |
285 |
|
} |
286 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
287 |
0
|
public void setCourseProposalDataService(DataService courseProposalDataService) {... |
288 |
0
|
this.courseProposalDataService = courseProposalDataService; |
289 |
|
} |
290 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
291 |
0
|
public void setDefaultDocumentType(String defaultDocumentType) {... |
292 |
0
|
this.defaultDocumentType = defaultDocumentType; |
293 |
|
} |
294 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
295 |
0
|
public void setDefaultState(String defaultState) {... |
296 |
0
|
this.defaultState = defaultState; |
297 |
|
} |
298 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
299 |
0
|
public void setIgnoreProperties(List<String> ignoreProperties) {... |
300 |
0
|
this.ignoreProperties = ignoreProperties; |
301 |
|
} |
302 |
|
|
303 |
|
} |