Clover Coverage Report - Kuali Student 1.2-M4-SNAPSHOT (Aggregated)
Coverage timestamp: Wed Jul 20 2011 11:14:35 EDT
../../../../../../../img/srcFileCovDistChart6.png 34% of files have more coverage
67   186   14   11.17
8   146   0.21   6
6     2.33  
1    
 
  CourseServiceUtils       Line # 38 67 0% 14 37 54.3% 0.54320985
 
  (7)
 
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   
 
38    public class CourseServiceUtils {
 
39  8 toggle public static void resetIds(CourseInfo course) {
40    //Clear/Reset Joint info ids
41  8 for(CourseJointInfo joint:course.getJoints()){
42  0 joint.setRelationId(null);
43    }
44    //Clear Los
45  8 for(LoDisplayInfo lo:course.getCourseSpecificLOs()){
46  16 resetLoRecursively(lo);
47    }
48    //Clear format/activity ids
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    //Clear result component ids
56  8 for(ResultComponentInfo result:course.getCreditOptions()){
57  16 result.setId(null);
58    }
59    //Clear cross listing ids
60  8 for(CourseCrossListingInfo crossListing:course.getCrossListings()){
61  0 crossListing.setId(null);
62    }
63    //Clear Expenditures
64  8 for(AffiliatedOrgInfo orgInfo:course.getExpenditure().getAffiliatedOrgs()){
65  16 orgInfo.setId(null);
66    }
67    //Clear Fees
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    //Clear revenue
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    //Clear variation ids
82  8 for(CourseVariationInfo variation:course.getVariations()){
83  16 variation.setId(null);
84    }
85    }
86   
 
87  112 toggle private static void resetLoRecursively(LoDisplayInfo lo){
88    //Clear out all the Lo ids recursively
89  112 lo.getLoInfo().setId(null);
90  112 for(LoDisplayInfo nestedLo:lo.getLoDisplayInfoList()){
91  96 resetLoRecursively(nestedLo);
92    }
93    }
94   
 
95  8 toggle private static void clearStatementTreeViewIds(
96    List<StatementTreeViewInfo> statementTreeViews, String newState, LuService luService) throws OperationFailedException {
97    //Clear out all statement ids recursively
98  8 for(StatementTreeViewInfo statementTreeView:statementTreeViews){
99  1 clearStatementTreeViewIdsRecursively(statementTreeView, newState, luService);
100    }
101    }
102   
103    /**
104    * Clears out ids recursively and also copies adhock clusets
105    * @param statementTreeView
106    * @param luService
107    * @throws OperationFailedException
108    */
 
109  3 toggle private static void clearStatementTreeViewIdsRecursively(StatementTreeViewInfo statementTreeView, String newState,LuService luService) throws OperationFailedException{
110  3 statementTreeView.setId(null);
111  3 statementTreeView.setState(newState);
112   
113    //clear out all the nested requirement components
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    //copy any clusets that are adhoc'd and set the field value to the new cluset
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    //Clear clu ids if membership info exists, they will be re-added based on membership info
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    //recurse through nested statements
142  3 for(StatementTreeViewInfo child: statementTreeView.getStatements()){
143  2 clearStatementTreeViewIdsRecursively(child,newState,luService);
144    }
145    }
146   
 
147  8 toggle 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   
 
158  0 toggle 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    //Default the newState to the existing course state if no state was set.
163    //State should never be null
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    }