Clover Coverage Report - Kuali Student 1.2-M6-SNAPSHOT (Aggregated)
Coverage timestamp: Mon Sep 12 2011 05:03:53 EDT
../../../../../../../../../img/srcFileCovDistChart0.png 42% of files have more coverage
101   303   29   5.32
10   229   0.29   19
19     1.53  
1    
 
  CopyCourseServiceImpl       Line # 47 101 0% 29 130 0% 0.0
 
No Tests
 
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})
 
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   
 
62  0 toggle public DataSaveResult createCopyCourse(String originalCluId) throws Exception {
63    //Copy the course and use the data service to return
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   
 
71  0 toggle public DataSaveResult createCopyCourseProposal(String originalProposalId) throws Exception {
72    //Copy the proposal and use the data service to return
73  0 ProposalInfo copiedProposal = copyProposal(originalProposalId);
74   
75    //Grab the data object so it is transformed
76  0 Data data = courseProposalDataService.getData(copiedProposal.getId());
77   
78    //Save it so that it goes through the filters and creates workflow
79  0 return courseProposalDataService.saveData(data);
80    }
81   
 
82  0 toggle private CourseInfo copyCourse(String originalCluId) throws Exception{
83    //Copy the course
84  0 return copyCourse(originalCluId, null, defaultState, ignoreProperties, statementService, luService, courseService);
85    }
 
86  0 toggle private ProposalInfo copyProposal(String originalProposalId) throws Exception{
87  0 try {
88    //Get the original Proposal
89  0 ProposalInfo originalProposal = proposalService.getProposal(originalProposalId);
90   
91    //Copy the course from the original Proposal
92  0 String originalCluId = originalProposal.getProposalReference().get(0);
93  0 CourseInfo copiedCourse = copyCourse(originalCluId);
94   
95    //Clear ids and set the reference to the copied course
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    //Create the proposal
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   
 
115  0 toggle private void resetIds(CourseInfo course) {
116    //Clear/Reset Joint info ids
117  0 for(CourseJointInfo joint:course.getJoints()){
118  0 joint.setRelationId(null);
119    }
120    //Clear Los
121  0 for(LoDisplayInfo lo:course.getCourseSpecificLOs()){
122  0 resetLoRecursively(lo);
123    }
124    //Clear format/activity ids
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    //Clear result component ids
132  0 for(ResultComponentInfo result:course.getCreditOptions()){
133  0 result.setId(null);
134    }
135    //Clear cross listing ids
136  0 for(CourseCrossListingInfo crossListing:course.getCrossListings()){
137  0 crossListing.setId(null);
138    }
139    //Clear Expenditures
140  0 for(AffiliatedOrgInfo orgInfo:course.getExpenditure().getAffiliatedOrgs()){
141  0 orgInfo.setId(null);
142    }
143    //Clear Fees
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    //Clear revenue
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    //Clear variation ids
158  0 for(CourseVariationInfo variation:course.getVariations()){
159  0 variation.setId(null);
160    }
161    }
162   
 
163  0 toggle private void resetLoRecursively(LoDisplayInfo lo){
164    //Clear out all the Lo ids recursively
165  0 lo.getLoInfo().setId(null);
166  0 for(LoDisplayInfo nestedLo:lo.getLoDisplayInfoList()){
167  0 resetLoRecursively(nestedLo);
168    }
169    }
170   
 
171  0 toggle private void clearStatementTreeViewIds(
172    List<StatementTreeViewInfo> statementTreeViews, String newState, LuService luService) throws OperationFailedException {
173    //Clear out all statement ids recursively
174  0 for(StatementTreeViewInfo statementTreeView:statementTreeViews){
175  0 clearStatementTreeViewIdsRecursively(statementTreeView, newState, luService);
176    }
177    }
178   
179    /**
180    * Clears out ids recursively and also copies adhock clusets
181    * @param statementTreeView
182    * @param luService
183    * @throws OperationFailedException
184    */
 
185  0 toggle private void clearStatementTreeViewIdsRecursively(StatementTreeViewInfo statementTreeView, String newState,LuService luService) throws OperationFailedException{
186  0 statementTreeView.setId(null);
187  0 statementTreeView.setState(newState);
188   
189    //clear out all the nested requirement components
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    //copy any clusets that are adhoc'd and set the field value to the new cluset
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    //Clear clu ids if membership info exists, they will be re-added based on membership info
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    //recurse through nested statements
218  0 for(StatementTreeViewInfo child: statementTreeView.getStatements()){
219  0 clearStatementTreeViewIdsRecursively(child,newState,luService);
220    }
221    }
222   
 
223  0 toggle private void copyStatements(String originalCluId, String newCluId, String newState,
224    StatementService statementService, LuService luService, CourseService courseService) throws OperationFailedException, DoesNotExistException, InvalidParameterException, MissingParameterException, PermissionDeniedException, DataValidationErrorException {
225    //Get the course statements
226  0 List<StatementTreeViewInfo> statementTreeViews = courseService.getCourseStatements(originalCluId,null,null);
227   
228    //Clear out the ids and create causing a copy to be made
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   
 
238  0 toggle 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    //Default the newState to the existing course state if no state was set.
243    //State should never be null
244  0 if(newState==null){
245  0 newState = originalCourse.getState();
246    }
247   
248  0 originalCourse.setId(newCluId);
249  0 originalCourse.setState(newState);
250   
251    //Loop through the ignore properties and null out the values
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   
 
267  0 toggle public void setCourseService(CourseService courseService) {
268  0 this.courseService = courseService;
269    }
270   
 
271  0 toggle public void setLuService(LuService luService) {
272  0 this.luService = luService;
273    }
274   
 
275  0 toggle public void setStatementService(StatementService statementService) {
276  0 this.statementService = statementService;
277    }
278   
 
279  0 toggle public void setProposalService(ProposalService proposalService) {
280  0 this.proposalService = proposalService;
281    }
282   
 
283  0 toggle public void setCourseDataService(DataService courseDataService) {
284  0 this.courseDataService = courseDataService;
285    }
286   
 
287  0 toggle public void setCourseProposalDataService(DataService courseProposalDataService) {
288  0 this.courseProposalDataService = courseProposalDataService;
289    }
290   
 
291  0 toggle public void setDefaultDocumentType(String defaultDocumentType) {
292  0 this.defaultDocumentType = defaultDocumentType;
293    }
294   
 
295  0 toggle public void setDefaultState(String defaultState) {
296  0 this.defaultState = defaultState;
297    }
298   
 
299  0 toggle public void setIgnoreProperties(List<String> ignoreProperties) {
300  0 this.ignoreProperties = ignoreProperties;
301    }
302   
303    }