1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.kuali.student.cm.course.service.impl;
18
19 import org.kuali.rice.krms.dto.AgendaEditor;
20 import org.kuali.rice.krms.dto.PropositionEditor;
21 import org.kuali.rice.krms.dto.PropositionParameterEditor;
22 import org.kuali.rice.krms.dto.RuleEditor;
23 import org.kuali.rice.krms.dto.RuleManagementWrapper;
24 import org.kuali.rice.krms.dto.TermEditor;
25 import org.kuali.rice.krms.dto.TermParameterEditor;
26 import org.kuali.student.cm.common.util.CurriculumManagementConstants;
27 import org.kuali.student.cm.course.form.wrapper.CourseInfoWrapper;
28 import org.kuali.student.cm.course.service.CourseCopyHelper;
29 import org.kuali.student.r2.common.dto.AttributeInfo;
30 import org.kuali.student.r2.common.dto.DtoConstants;
31 import org.kuali.student.r2.lum.clu.dto.AffiliatedOrgInfo;
32 import org.kuali.student.r2.lum.course.dto.ActivityInfo;
33 import org.kuali.student.r2.lum.course.dto.CourseCrossListingInfo;
34 import org.kuali.student.r2.lum.course.dto.CourseFeeInfo;
35 import org.kuali.student.r2.lum.course.dto.CourseInfo;
36 import org.kuali.student.r2.lum.course.dto.CourseJointInfo;
37 import org.kuali.student.r2.lum.course.dto.CourseRevenueInfo;
38 import org.kuali.student.r2.lum.course.dto.CourseVariationInfo;
39 import org.kuali.student.r2.lum.course.dto.FormatInfo;
40 import org.kuali.student.r2.lum.course.dto.LoDisplayInfo;
41 import org.springframework.beans.BeanUtils;
42
43 import java.util.Arrays;
44 import java.util.Iterator;
45 import java.util.List;
46
47
48
49
50
51
52
53
54
55
56 public class CourseCopyHelperImpl implements CourseCopyHelper {
57
58 private List<String> ignoreProperties;
59
60 public CourseCopyHelperImpl() {}
61
62
63
64
65
66
67
68
69
70 @Override
71 public void copyCourse(CourseInfo source, CourseInfo target){
72
73 Object[] propertiesToSkip = (Object[]) getIgnoreProperties().toArray();
74 String[] stringArray = Arrays.copyOf(propertiesToSkip, propertiesToSkip.length, String[].class);
75
76 BeanUtils.copyProperties(source, target, stringArray);
77
78 target.setCourseTitle("Copy of " + source.getCourseTitle());
79
80 resetCourse(target);
81 }
82
83 @Override
84 public void cleanUpCourseWrapperOnCopy(CourseInfoWrapper target){
85
86
87 target.setRefObjectId(null);
88
89
90
91
92
93 resetCourse(target.getCourseInfo());
94 resetRequisites(target);
95
96 }
97
98
99
100
101
102
103 protected void resetCourse(CourseInfo course) {
104
105 course.setId(null);
106 course.setVersion(null);
107 course.setMeta(null);
108 course.setEffectiveDate(null);
109 course.setExpirationDate(null);
110
111
112 course.setStateKey(DtoConstants.STATE_DRAFT);
113
114
115 List<AttributeInfo> attributes = course.getAttributes();
116 for (Iterator<AttributeInfo> it = attributes.iterator(); it.hasNext();) {
117 AttributeInfo attributeInfo = it.next();
118 if (attributeInfo.getKey().equals(CurriculumManagementConstants.COURSE_ATTRIBUTE_LAST_TERM_OFFERED)
119 || attributeInfo.getKey().equals(CurriculumManagementConstants.COURSE_ATTRIBUTE_LAST_PUBLICATION_YEAR)
120 || attributeInfo.getKey().equals(CurriculumManagementConstants.COURSE_ATTRIBUTE_RETIREMENT_COMMENT)
121 || attributeInfo.getKey().equals(CurriculumManagementConstants.COURSE_ATTRIBUTE_RETIREMENT_RATIONALE)
122 ) {
123 it.remove();
124 } else {
125 attributeInfo.setId(null);
126 }
127 }
128
129 for (CourseJointInfo joint : course.getJoints()) {
130 joint.setRelationId(null);
131 }
132
133 for (LoDisplayInfo lo : course.getCourseSpecificLOs()) {
134 recursivelyClobberLoIds(lo);
135 }
136
137 for (CourseCrossListingInfo crossListing : course.getCrossListings()) {
138 crossListing.setId(null);
139 }
140
141 for (FormatInfo format : course.getFormats()) {
142 format.setId(null);
143 format.setMeta(null);
144 for (ActivityInfo activity : format.getActivities()) {
145 activity.setId(null);
146 activity.setMeta(null);
147 }
148 }
149
150 for (AffiliatedOrgInfo orgInfo : course.getExpenditure().getAffiliatedOrgs()) {
151 orgInfo.setId(null);
152 }
153
154 for (CourseFeeInfo fee : course.getFees()) {
155 fee.setId(null);
156 }
157
158 for (CourseRevenueInfo revenue : course.getRevenues()) {
159 revenue.setId(null);
160 for (AffiliatedOrgInfo orgInfo : revenue.getAffiliatedOrgs()) {
161 orgInfo.setId(null);
162 }
163 }
164
165 for (CourseVariationInfo variation : course.getVariations()) {
166 variation.setId(null);
167 }
168 }
169
170 protected void recursivelyClobberLoIds(LoDisplayInfo lo) {
171 lo.getLoInfo().setId(null);
172 for (LoDisplayInfo nestedLo : lo.getLoDisplayInfoList()) {
173 recursivelyClobberLoIds(nestedLo);
174 }
175 }
176
177
178
179
180 public void resetRequisites(RuleManagementWrapper dataObject) {
181 for (AgendaEditor agenda : dataObject.getAgendas()) {
182 agenda.setContextId(null);
183 agenda.setFirstItemId(null);
184 agenda.setId(null);
185 agenda.setVersionNumber(null);
186 agenda.setName(null);
187
188 for (RuleEditor re : agenda.getRuleEditors().values()) {
189 re.setId(null);
190 re.setVersionNumber(null);
191 re.setName(null);
192 re.setPropId(null);
193
194 PropositionEditor pe = re.getPropositionEditor();
195 if (pe != null) {
196 pe.setId(null);
197 pe.setRuleId(null);
198 pe.setVersionNumber(null);
199
200 for (PropositionParameterEditor parameter : pe.getParameters()) {
201 parameter.setId(null);
202 parameter.setVersionNumber(null);
203 parameter.setPropId(null);
204 }
205
206 TermEditor te = pe.getTerm();
207 if (te != null) {
208 te.setId(null);
209 te.setVersionNumber(null);
210
211 for (TermParameterEditor parameter : te.getEditorParameters()) {
212 parameter.setId(null);
213 parameter.setVersionNumber(null);
214 parameter.setTermId(null);
215 }
216 }
217 }
218 }
219 }
220 }
221
222 public List<String> getIgnoreProperties() {
223 return ignoreProperties;
224 }
225
226 public void setIgnoreProperties(List<String> ignoreProperties) {
227 this.ignoreProperties = ignoreProperties;
228 }
229 }