1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.student.lum.course.service.assembler; |
17 | |
|
18 | |
import java.util.ArrayList; |
19 | |
import java.util.Collections; |
20 | |
import java.util.Date; |
21 | |
import java.util.HashMap; |
22 | |
import java.util.HashSet; |
23 | |
import java.util.Iterator; |
24 | |
import java.util.List; |
25 | |
import java.util.Map; |
26 | |
import java.util.Map.Entry; |
27 | |
import java.util.Set; |
28 | |
|
29 | |
import org.apache.log4j.Logger; |
30 | |
import org.kuali.student.common.assembly.BOAssembler; |
31 | |
import org.kuali.student.common.assembly.BaseDTOAssemblyNode; |
32 | |
import org.kuali.student.common.assembly.BaseDTOAssemblyNode.NodeOperation; |
33 | |
import org.kuali.student.common.assembly.data.AssemblyException; |
34 | |
import org.kuali.student.common.dto.DtoConstants; |
35 | |
import org.kuali.student.common.dto.RichTextInfo; |
36 | |
import org.kuali.student.common.exceptions.DoesNotExistException; |
37 | |
import org.kuali.student.common.exceptions.InvalidParameterException; |
38 | |
import org.kuali.student.common.exceptions.MissingParameterException; |
39 | |
import org.kuali.student.common.exceptions.OperationFailedException; |
40 | |
import org.kuali.student.common.util.UUIDHelper; |
41 | |
import org.kuali.student.core.atp.dto.AtpInfo; |
42 | |
import org.kuali.student.core.atp.service.AtpService; |
43 | |
import org.kuali.student.lum.course.dto.CourseCrossListingInfo; |
44 | |
import org.kuali.student.lum.course.dto.CourseExpenditureInfo; |
45 | |
import org.kuali.student.lum.course.dto.CourseFeeInfo; |
46 | |
import org.kuali.student.lum.course.dto.CourseInfo; |
47 | |
import org.kuali.student.lum.course.dto.CourseJointInfo; |
48 | |
import org.kuali.student.lum.course.dto.CourseRevenueInfo; |
49 | |
import org.kuali.student.lum.course.dto.CourseVariationInfo; |
50 | |
import org.kuali.student.lum.course.dto.FormatInfo; |
51 | |
import org.kuali.student.lum.course.dto.LoDisplayInfo; |
52 | |
import org.kuali.student.lum.lo.dto.LoInfo; |
53 | |
import org.kuali.student.lum.lo.service.LearningObjectiveService; |
54 | |
import org.kuali.student.lum.lrc.dto.ResultComponentInfo; |
55 | |
import org.kuali.student.lum.lrc.service.LrcService; |
56 | |
import org.kuali.student.lum.lu.dto.AdminOrgInfo; |
57 | |
import org.kuali.student.lum.lu.dto.CluAccountingInfo; |
58 | |
import org.kuali.student.lum.lu.dto.CluCluRelationInfo; |
59 | |
import org.kuali.student.lum.lu.dto.CluFeeInfo; |
60 | |
import org.kuali.student.lum.lu.dto.CluFeeRecordInfo; |
61 | |
import org.kuali.student.lum.lu.dto.CluIdentifierInfo; |
62 | |
import org.kuali.student.lum.lu.dto.CluInfo; |
63 | |
import org.kuali.student.lum.lu.dto.CluLoRelationInfo; |
64 | |
import org.kuali.student.lum.lu.dto.CluResultInfo; |
65 | |
import org.kuali.student.lum.lu.dto.LuCodeInfo; |
66 | |
import org.kuali.student.lum.lu.dto.ResultOptionInfo; |
67 | |
import org.kuali.student.lum.lu.service.LuService; |
68 | |
import org.kuali.student.lum.service.assembler.CluAssemblerUtils; |
69 | |
import org.springframework.util.StringUtils; |
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | |
|
77 | 24 | public class CourseAssembler implements BOAssembler<CourseInfo, CluInfo> { |
78 | |
|
79 | 1 | final static Logger LOG = Logger.getLogger(CourseAssembler.class); |
80 | |
private LuService luService; |
81 | |
private FormatAssembler formatAssembler; |
82 | |
private CourseJointAssembler courseJointAssembler; |
83 | |
private LoAssembler loAssembler; |
84 | |
private LearningObjectiveService loService; |
85 | |
private CluAssemblerUtils cluAssemblerUtils; |
86 | |
private LrcService lrcService; |
87 | |
private AtpService atpService; |
88 | |
|
89 | |
@Override |
90 | |
public CourseInfo assemble(CluInfo clu, CourseInfo courseInfo, |
91 | |
boolean shallowBuild) throws AssemblyException { |
92 | |
|
93 | 45 | CourseInfo course = (null != courseInfo) ? courseInfo |
94 | |
: new CourseInfo(); |
95 | |
|
96 | |
|
97 | |
|
98 | 45 | course.setAttributes(clu.getAttributes()); |
99 | 45 | course.setCampusLocations(clu.getCampusLocations()); |
100 | 45 | course.setCode(clu.getOfficialIdentifier().getCode()); |
101 | 45 | course.setCourseNumberSuffix(clu.getOfficialIdentifier() |
102 | |
.getSuffixCode()); |
103 | 45 | course.setLevel(clu.getOfficialIdentifier().getLevel()); |
104 | 45 | course.setOutOfClassHours(clu.getIntensity()); |
105 | 45 | course.setInstructors(clu.getInstructors()); |
106 | 45 | course.setStartTerm(clu.getExpectedFirstAtp()); |
107 | 45 | course.setEndTerm(clu.getLastAtp()); |
108 | 45 | course.setCourseTitle(clu.getOfficialIdentifier().getLongName()); |
109 | |
|
110 | |
|
111 | 45 | List<CourseCrossListingInfo> crossListings = assembleCrossListings(clu.getAlternateIdentifiers()); |
112 | 45 | course.setCrossListings(crossListings); |
113 | |
|
114 | |
|
115 | 45 | List<CourseVariationInfo> variations = assembleVariations(clu.getAlternateIdentifiers()); |
116 | 45 | course.setVariations(variations); |
117 | |
|
118 | |
|
119 | 45 | if(course.getUnitsDeployment()==null){ |
120 | 0 | course.setUnitsDeployment(new ArrayList<String>()); |
121 | |
} |
122 | 45 | if(course.getUnitsContentOwner()==null){ |
123 | 0 | course.setUnitsContentOwner(new ArrayList<String>()); |
124 | |
} |
125 | 45 | List<String> courseAdminOrgs = new ArrayList<String>(); |
126 | 45 | List<String> courseSubjectOrgs = new ArrayList<String>(); |
127 | 45 | for(AdminOrgInfo adminOrg: clu.getAdminOrgs()){ |
128 | 178 | if(adminOrg.getType().equals(CourseAssemblerConstants.ADMIN_ORG)){ |
129 | 90 | courseAdminOrgs.add(adminOrg.getOrgId()); |
130 | |
} |
131 | 178 | if(adminOrg.getType().equals(CourseAssemblerConstants.SUBJECT_ORG)){ |
132 | 88 | courseSubjectOrgs.add(adminOrg.getOrgId()); |
133 | |
} |
134 | |
} |
135 | 45 | course.setUnitsDeployment(courseAdminOrgs); |
136 | 45 | course.setUnitsContentOwner(courseSubjectOrgs); |
137 | 45 | course.setDescr(clu.getDescr()); |
138 | 45 | course.setDuration(clu.getStdDuration()); |
139 | 45 | course.setEffectiveDate(clu.getEffectiveDate()); |
140 | 45 | course.setExpirationDate(clu.getExpirationDate()); |
141 | |
|
142 | |
|
143 | |
|
144 | 45 | List<CourseFeeInfo> fees = new ArrayList<CourseFeeInfo>(); |
145 | 45 | List<CourseRevenueInfo> revenues = new ArrayList<CourseRevenueInfo>(); |
146 | 45 | if(clu.getFeeInfo() != null){ |
147 | 45 | course.setFeeJustification(clu.getFeeInfo().getDescr()); |
148 | |
|
149 | |
|
150 | 45 | for(CluFeeRecordInfo cluFeeRecord: clu.getFeeInfo().getCluFeeRecords()){ |
151 | 178 | String feeType = cluFeeRecord.getFeeType(); |
152 | 178 | if(CourseAssemblerConstants.COURSE_FINANCIALS_REVENUE_TYPE.equals(feeType)){ |
153 | 90 | CourseRevenueInfo courseRevenue = new CourseRevenueInfo(); |
154 | 90 | courseRevenue.setFeeType(feeType); |
155 | 90 | courseRevenue.setAffiliatedOrgs(cluFeeRecord.getAffiliatedOrgs()); |
156 | 90 | courseRevenue.setAttributes(cluFeeRecord.getAttributes()); |
157 | 90 | courseRevenue.setId(cluFeeRecord.getId()); |
158 | 90 | courseRevenue.setMetaInfo(cluFeeRecord.getMetaInfo()); |
159 | 90 | revenues.add(courseRevenue); |
160 | 90 | }else{ |
161 | 88 | CourseFeeInfo courseFee = new CourseFeeInfo(); |
162 | 88 | courseFee.setFeeType(feeType); |
163 | 88 | courseFee.setRateType(cluFeeRecord.getRateType()); |
164 | 88 | courseFee.setDescr(cluFeeRecord.getDescr()); |
165 | 88 | courseFee.setMetaInfo(cluFeeRecord.getMetaInfo()); |
166 | 88 | courseFee.setId(cluFeeRecord.getId()); |
167 | 88 | courseFee.setFeeAmounts(cluFeeRecord.getFeeAmounts()); |
168 | 88 | courseFee.setAttributes(cluFeeRecord.getAttributes()); |
169 | 88 | fees.add(courseFee); |
170 | |
} |
171 | 178 | } |
172 | |
} |
173 | 45 | course.setFees(fees); |
174 | 45 | course.setRevenues(revenues); |
175 | |
|
176 | 45 | if(course.getExpenditure() == null || clu.getAccountingInfo() == null){ |
177 | 14 | course.setExpenditure(new CourseExpenditureInfo()); |
178 | |
} |
179 | 45 | if(clu.getAccountingInfo() != null){ |
180 | 45 | course.getExpenditure().setAffiliatedOrgs(clu.getAccountingInfo().getAffiliatedOrgs()); |
181 | |
} |
182 | |
|
183 | 45 | course.setId(clu.getId()); |
184 | 45 | course.setType(clu.getType()); |
185 | 45 | course.setTermsOffered(clu.getOfferedAtpTypes()); |
186 | 45 | course.setPrimaryInstructor(clu.getPrimaryInstructor()); |
187 | 45 | course.setInstructors(clu.getInstructors()); |
188 | 45 | course.setState(clu.getState()); |
189 | 45 | course.setSubjectArea(clu.getOfficialIdentifier().getDivision()); |
190 | 45 | course.setTranscriptTitle(clu.getOfficialIdentifier().getShortName()); |
191 | 45 | course.setMetaInfo(clu.getMetaInfo()); |
192 | 45 | course.setVersionInfo(clu.getVersionInfo()); |
193 | |
|
194 | |
|
195 | |
|
196 | 45 | course.setSpecialTopicsCourse(false); |
197 | 45 | for(LuCodeInfo luCode : clu.getLuCodes()){ |
198 | 3 | if(CourseAssemblerConstants.COURSE_CODE_SPECIAL_TOPICS.equals(luCode.getType())){ |
199 | 3 | course.setSpecialTopicsCourse(Boolean.parseBoolean(luCode.getValue())); |
200 | 3 | break; |
201 | |
} |
202 | |
} |
203 | |
|
204 | 45 | course.setPilotCourse(false); |
205 | 45 | for(LuCodeInfo luCode : clu.getLuCodes()){ |
206 | 6 | if(CourseAssemblerConstants.COURSE_CODE_PILOT_COURSE.equals(luCode.getType())){ |
207 | 3 | course.setPilotCourse(Boolean.parseBoolean(luCode.getValue())); |
208 | 3 | break; |
209 | |
} |
210 | |
} |
211 | |
|
212 | |
|
213 | 45 | if (!shallowBuild) { |
214 | |
try { |
215 | |
|
216 | |
|
217 | 14 | List<CluCluRelationInfo> cluClus = luService.getCluCluRelationsByClu(clu.getId()); |
218 | |
|
219 | 14 | for (CluCluRelationInfo cluRel : cluClus) { |
220 | 29 | if (cluRel.getType().equals(CourseAssemblerConstants.JOINT_RELATION_TYPE)) { |
221 | 0 | CourseJointInfo jointInfo = null; |
222 | 0 | if(cluRel.getCluId().equals(clu.getId())) |
223 | 0 | jointInfo = courseJointAssembler.assemble(cluRel, cluRel.getRelatedCluId(), null, false); |
224 | |
else |
225 | 0 | jointInfo = courseJointAssembler.assemble(cluRel, cluRel.getCluId(), null, false); |
226 | 0 | course.getJoints().add(jointInfo); |
227 | 29 | } |
228 | |
} |
229 | 0 | } catch (DoesNotExistException e) { |
230 | 0 | } catch (Exception e) { |
231 | 0 | throw new AssemblyException("Error getting course joints", e); |
232 | 14 | } |
233 | |
|
234 | |
try { |
235 | |
|
236 | |
|
237 | 14 | List<CluInfo> formats = luService.getRelatedClusByCluId(course |
238 | |
.getId(), |
239 | |
CourseAssemblerConstants.COURSE_FORMAT_RELATION_TYPE); |
240 | |
|
241 | 14 | for (CluInfo format : formats) { |
242 | 29 | FormatInfo formatInfo = formatAssembler.assemble(format, |
243 | |
null, false); |
244 | 29 | course.getFormats().add(formatInfo); |
245 | 29 | } |
246 | |
|
247 | 0 | } catch (DoesNotExistException e) { |
248 | 0 | } catch (Exception e) { |
249 | 0 | throw new AssemblyException("Error getting related formats", e); |
250 | 14 | } |
251 | |
|
252 | |
try{ |
253 | |
|
254 | 14 | List<CluResultInfo> cluResults = luService.getCluResultByClu(course.getId()); |
255 | |
|
256 | 14 | List<ResultComponentInfo> creditOptions = assembleCreditOptions(cluResults); |
257 | 14 | course.setCreditOptions(creditOptions); |
258 | |
|
259 | 14 | List<String> gradingOptions = assembleGradingOptions(cluResults); |
260 | |
|
261 | 14 | course.setGradingOptions(gradingOptions); |
262 | 0 | } catch (DoesNotExistException e){ |
263 | 0 | } catch (Exception e) { |
264 | 0 | throw new AssemblyException("Error getting course results", e); |
265 | 14 | } |
266 | |
|
267 | |
|
268 | 14 | course.getCourseSpecificLOs().addAll(cluAssemblerUtils.assembleLos(course.getId(), shallowBuild)); |
269 | |
|
270 | |
} |
271 | |
|
272 | |
|
273 | 45 | course.getGradingOptions().remove(CourseAssemblerConstants.COURSE_RESULT_COMP_GRADE_AUDIT); |
274 | |
|
275 | 45 | return course; |
276 | |
} |
277 | |
|
278 | |
@Override |
279 | |
public BaseDTOAssemblyNode<CourseInfo, CluInfo> disassemble( |
280 | |
CourseInfo course, NodeOperation operation) |
281 | |
throws AssemblyException { |
282 | |
|
283 | 25 | if (course == null) { |
284 | |
|
285 | |
|
286 | 0 | LOG.error("Course to disassemble is null!"); |
287 | 0 | throw new AssemblyException("Course can not be null"); |
288 | |
} |
289 | |
|
290 | 25 | BaseDTOAssemblyNode<CourseInfo, CluInfo> result = new BaseDTOAssemblyNode<CourseInfo, CluInfo>( |
291 | |
this); |
292 | |
|
293 | |
CluInfo clu; |
294 | |
try { |
295 | 25 | clu = (NodeOperation.UPDATE == operation) ? luService.getClu(course.getId()) : new CluInfo(); |
296 | 0 | } catch (Exception e) { |
297 | 0 | throw new AssemblyException("Error getting existing learning unit during course update", e); |
298 | 25 | } |
299 | |
|
300 | |
|
301 | |
|
302 | 25 | clu.setId(UUIDHelper.genStringUUID(course.getId())); |
303 | 25 | if (null == course.getId()) { |
304 | 14 | course.setId(clu.getId()); |
305 | |
} |
306 | 25 | clu.setType(CourseAssemblerConstants.COURSE_TYPE); |
307 | 25 | clu.setState(course.getState()); |
308 | |
|
309 | 25 | CluIdentifierInfo identifier = new CluIdentifierInfo(); |
310 | 25 | identifier.setType(CourseAssemblerConstants.COURSE_OFFICIAL_IDENT_TYPE); |
311 | 25 | identifier.setState(course.getState()); |
312 | 25 | identifier.setLongName(course.getCourseTitle()); |
313 | 25 | identifier.setShortName(course.getTranscriptTitle()); |
314 | 25 | identifier.setSuffixCode(course.getCourseNumberSuffix()); |
315 | 25 | identifier.setDivision(course.getSubjectArea()); |
316 | 25 | identifier.setCode(course.getCode()); |
317 | |
|
318 | |
|
319 | 25 | if(StringUtils.hasText(course.getLevel())) { |
320 | 25 | identifier.setLevel(course.getLevel()); |
321 | 0 | } else if(course.getCourseNumberSuffix()!=null&&course.getCourseNumberSuffix().length()>=3){ |
322 | 0 | identifier.setLevel(course.getCourseNumberSuffix().substring(0, 1)+"00"); |
323 | |
} |
324 | |
|
325 | 25 | clu.setOfficialIdentifier(identifier); |
326 | |
|
327 | 25 | clu.setAdminOrgs(new ArrayList<AdminOrgInfo>()); |
328 | |
|
329 | |
|
330 | |
|
331 | |
|
332 | |
|
333 | 25 | for(Iterator<CluIdentifierInfo> iter = clu.getAlternateIdentifiers().iterator();iter.hasNext();){ |
334 | 20 | CluIdentifierInfo cluIdentifier = iter.next(); |
335 | 20 | if(CourseAssemblerConstants.COURSE_VARIATION_IDENT_TYPE.equals(cluIdentifier.getType()) || |
336 | |
CourseAssemblerConstants.COURSE_CROSSLISTING_IDENT_TYPE.equals(cluIdentifier.getType()) ){ |
337 | 20 | iter.remove(); |
338 | |
} |
339 | 20 | } |
340 | |
|
341 | 25 | for(CourseVariationInfo variation:course.getVariations()){ |
342 | 50 | CluIdentifierInfo cluIdentifier = new CluIdentifierInfo(); |
343 | 50 | cluIdentifier.setId(variation.getId()); |
344 | 50 | cluIdentifier.setType(CourseAssemblerConstants.COURSE_VARIATION_IDENT_TYPE); |
345 | 50 | cluIdentifier.setCode(identifier.getCode()); |
346 | 50 | cluIdentifier.setSuffixCode(course.getCourseNumberSuffix()); |
347 | 50 | cluIdentifier.setDivision(course.getSubjectArea()); |
348 | 50 | cluIdentifier.setVariation(variation.getVariationCode()); |
349 | 50 | cluIdentifier.setLongName(variation.getVariationTitle()); |
350 | 50 | cluIdentifier.setState(course.getState()); |
351 | 50 | clu.getAlternateIdentifiers().add(cluIdentifier); |
352 | 50 | } |
353 | |
|
354 | 25 | for(CourseCrossListingInfo crossListing:course.getCrossListings()){ |
355 | 2 | CluIdentifierInfo cluIdentifier = new CluIdentifierInfo(); |
356 | 2 | cluIdentifier.setId(crossListing.getId()); |
357 | 2 | cluIdentifier.setType(CourseAssemblerConstants.COURSE_CROSSLISTING_IDENT_TYPE); |
358 | 2 | cluIdentifier.setSuffixCode(crossListing.getCourseNumberSuffix()); |
359 | 2 | cluIdentifier.setDivision(crossListing.getSubjectArea()); |
360 | 2 | cluIdentifier.setState(course.getState()); |
361 | 2 | cluIdentifier.setOrgId(crossListing.getDepartment()); |
362 | 2 | cluIdentifier.setAttributes(crossListing.getAttributes()); |
363 | 2 | cluIdentifier.setCode(crossListing.getCode()); |
364 | 2 | clu.getAlternateIdentifiers().add(cluIdentifier); |
365 | 2 | } |
366 | |
|
367 | 25 | List<AdminOrgInfo> adminOrgInfos = new ArrayList<AdminOrgInfo>(); |
368 | 25 | for(String org:course.getUnitsDeployment()){ |
369 | 50 | AdminOrgInfo adminOrg = new AdminOrgInfo(); |
370 | 50 | adminOrg.setType(CourseAssemblerConstants.ADMIN_ORG); |
371 | 50 | adminOrg.setOrgId(org); |
372 | 50 | adminOrgInfos.add(adminOrg); |
373 | 50 | } |
374 | 25 | clu.getAdminOrgs().addAll(adminOrgInfos); |
375 | |
|
376 | 25 | List<AdminOrgInfo> subjectOrgs = new ArrayList<AdminOrgInfo>(); |
377 | 25 | for (String subOrg : course.getUnitsContentOwner()) { |
378 | 48 | AdminOrgInfo subjectOrg = new AdminOrgInfo(); |
379 | 48 | subjectOrg.setType(CourseAssemblerConstants.SUBJECT_ORG); |
380 | 48 | subjectOrg.setOrgId(subOrg); |
381 | 48 | subjectOrgs.add(subjectOrg); |
382 | 48 | } |
383 | 25 | clu.getAdminOrgs().addAll(subjectOrgs); |
384 | |
|
385 | |
|
386 | 25 | clu.setAttributes(course.getAttributes()); |
387 | 25 | clu.setCampusLocations(course.getCampusLocations()); |
388 | 25 | clu.setDescr(course.getDescr()); |
389 | 25 | clu.setStdDuration(course.getDuration()); |
390 | |
|
391 | |
|
392 | 25 | if(course.getStartTerm() != null){ |
393 | |
try { |
394 | 17 | AtpInfo startAtp = atpService.getAtp(course.getStartTerm()); |
395 | 17 | course.setEffectiveDate(startAtp.getStartDate()); |
396 | 0 | } catch (Exception e) { |
397 | 0 | throw new AssemblyException("Error getting start term Atp.",e); |
398 | 17 | } |
399 | |
} |
400 | 25 | if(course.getEndTerm() != null){ |
401 | |
try { |
402 | 17 | AtpInfo endAtp = atpService.getAtp(course.getEndTerm()); |
403 | 17 | course.setExpirationDate(endAtp.getEndDate()); |
404 | 0 | } catch (Exception e) { |
405 | 0 | throw new AssemblyException("Error getting end term Atp.",e); |
406 | 17 | } |
407 | |
} |
408 | |
|
409 | 25 | clu.setEffectiveDate(course.getEffectiveDate()); |
410 | 25 | clu.setExpirationDate(course.getExpirationDate()); |
411 | |
|
412 | 25 | clu.setOfferedAtpTypes(course.getTermsOffered()); |
413 | 25 | clu.setPrimaryInstructor(course.getPrimaryInstructor()); |
414 | |
|
415 | 25 | clu.setIntensity(course.getOutOfClassHours()); |
416 | 25 | clu.setInstructors(course.getInstructors()); |
417 | |
|
418 | 25 | clu.setExpectedFirstAtp(course.getStartTerm()); |
419 | 25 | clu.setLastAtp(course.getEndTerm()); |
420 | |
|
421 | 25 | clu.setMetaInfo(course.getMetaInfo()); |
422 | 25 | clu.setVersionInfo(course.getVersionInfo()); |
423 | |
|
424 | |
|
425 | 25 | result.setNodeData(clu); |
426 | 25 | result.setOperation(operation); |
427 | 25 | result.setBusinessDTORef(course); |
428 | |
|
429 | |
|
430 | |
List<BaseDTOAssemblyNode<?, ?>> formatResults; |
431 | |
try { |
432 | 25 | formatResults = disassembleFormats(clu |
433 | |
.getId(), course, operation); |
434 | 25 | result.getChildNodes().addAll(formatResults); |
435 | |
|
436 | 0 | } catch (DoesNotExistException e) { |
437 | 0 | } catch (Exception e) { |
438 | 0 | throw new AssemblyException("Error while disassembling format", e); |
439 | 25 | } |
440 | |
|
441 | |
|
442 | |
|
443 | 25 | List<BaseDTOAssemblyNode<?, ?>> courseJointResults = disassembleJoints( |
444 | |
clu.getId(), course, operation); |
445 | 25 | result.getChildNodes().addAll(courseJointResults); |
446 | |
|
447 | |
|
448 | |
|
449 | 25 | if(course.getAttributes().containsKey(CourseAssemblerConstants.COURSE_RESULT_COMP_ATTR_AUDIT)&&"true".equals(course.getAttributes().get(CourseAssemblerConstants.COURSE_RESULT_COMP_ATTR_AUDIT))){ |
450 | 0 | if(!course.getGradingOptions().contains(CourseAssemblerConstants.COURSE_RESULT_COMP_GRADE_AUDIT)){ |
451 | 0 | course.getGradingOptions().add(CourseAssemblerConstants.COURSE_RESULT_COMP_GRADE_AUDIT); |
452 | |
} |
453 | |
} |
454 | |
|
455 | |
List<CluResultInfo> cluResultList; |
456 | |
try { |
457 | 25 | cluResultList = luService.getCluResultByClu(clu.getId()); |
458 | 0 | } catch (DoesNotExistException e) { |
459 | 0 | cluResultList = Collections.emptyList(); |
460 | 0 | } catch (Exception e) { |
461 | 0 | throw new AssemblyException("Error getting cluResults", e); |
462 | 25 | } |
463 | |
|
464 | 25 | List<BaseDTOAssemblyNode<?, ?>> creditOutcomes = disassembleCreditOutcomes(course, clu, cluResultList, operation); |
465 | 25 | result.getChildNodes().addAll(creditOutcomes); |
466 | |
|
467 | 25 | BaseDTOAssemblyNode<?, ?> gradingOptions = disassembleGradingOptions( |
468 | |
clu.getId(), course.getState(), course.getGradingOptions(), cluResultList, operation); |
469 | 25 | result.getChildNodes().add(gradingOptions); |
470 | |
|
471 | |
|
472 | |
try { |
473 | |
List<BaseDTOAssemblyNode<?, ?>> loResults; |
474 | 25 | loResults = disassembleLos(clu.getId(), course, operation); |
475 | 25 | result.getChildNodes().addAll(loResults); |
476 | 0 | } catch (Exception e) { |
477 | 0 | throw new AssemblyException("Error while disassembling los", e); |
478 | 25 | } |
479 | |
|
480 | |
|
481 | 25 | boolean alreadyHadSpecialTopicsCode = false; |
482 | 25 | for(Iterator<LuCodeInfo> luCodeIterator = clu.getLuCodes().iterator();luCodeIterator.hasNext();){ |
483 | 1 | LuCodeInfo luCode = luCodeIterator.next(); |
484 | 1 | if(CourseAssemblerConstants.COURSE_CODE_SPECIAL_TOPICS.equals(luCode.getType())){ |
485 | 1 | alreadyHadSpecialTopicsCode = true; |
486 | 1 | if(!course.isSpecialTopicsCourse()){ |
487 | 1 | luCodeIterator.remove(); |
488 | |
} |
489 | |
break; |
490 | |
} |
491 | 0 | } |
492 | 25 | if(!alreadyHadSpecialTopicsCode && course.isSpecialTopicsCourse()){ |
493 | 2 | LuCodeInfo luCode = new LuCodeInfo(); |
494 | 2 | luCode.setType(CourseAssemblerConstants.COURSE_CODE_SPECIAL_TOPICS); |
495 | 2 | luCode.setValue("true"); |
496 | 2 | clu.getLuCodes().add(luCode); |
497 | |
} |
498 | |
|
499 | |
|
500 | 25 | boolean alreadyHadPilotCourseCode = false; |
501 | 25 | for(Iterator<LuCodeInfo> luCodeIterator = clu.getLuCodes().iterator();luCodeIterator.hasNext();){ |
502 | 3 | LuCodeInfo luCode = luCodeIterator.next(); |
503 | 3 | if(CourseAssemblerConstants.COURSE_CODE_PILOT_COURSE.equals(luCode.getType())){ |
504 | 1 | alreadyHadPilotCourseCode = true; |
505 | 1 | if(!course.isPilotCourse()){ |
506 | 1 | luCodeIterator.remove(); |
507 | |
} |
508 | |
break; |
509 | |
} |
510 | 2 | } |
511 | 25 | if(!alreadyHadPilotCourseCode && course.isPilotCourse()){ |
512 | 2 | LuCodeInfo luCode = new LuCodeInfo(); |
513 | 2 | luCode.setType(CourseAssemblerConstants.COURSE_CODE_PILOT_COURSE); |
514 | 2 | luCode.setValue("true"); |
515 | 2 | clu.getLuCodes().add(luCode); |
516 | |
} |
517 | |
|
518 | |
|
519 | 25 | if(clu.getFeeInfo() == null){ |
520 | 15 | clu.setFeeInfo(new CluFeeInfo()); |
521 | |
} |
522 | 25 | clu.getFeeInfo().setDescr(course.getFeeJustification()); |
523 | 25 | clu.getFeeInfo().getCluFeeRecords().clear(); |
524 | 25 | for(CourseRevenueInfo courseRevenue:course.getRevenues()){ |
525 | 50 | CluFeeRecordInfo cluFeeRecord = new CluFeeRecordInfo(); |
526 | 50 | cluFeeRecord.setFeeType(CourseAssemblerConstants.COURSE_FINANCIALS_REVENUE_TYPE); |
527 | 50 | cluFeeRecord.setRateType(CourseAssemblerConstants.COURSE_FINANCIALS_REVENUE_TYPE); |
528 | 50 | cluFeeRecord.setAttributes(courseRevenue.getAttributes()); |
529 | 50 | cluFeeRecord.setAffiliatedOrgs(courseRevenue.getAffiliatedOrgs()); |
530 | 50 | cluFeeRecord.setId(courseRevenue.getId()); |
531 | 50 | cluFeeRecord.setMetaInfo(courseRevenue.getMetaInfo()); |
532 | 50 | clu.getFeeInfo().getCluFeeRecords().add(cluFeeRecord); |
533 | 50 | } |
534 | 25 | for(CourseFeeInfo courseFee : course.getFees()){ |
535 | 48 | CluFeeRecordInfo cluFeeRecord = new CluFeeRecordInfo(); |
536 | 48 | cluFeeRecord.setFeeType(courseFee.getFeeType()); |
537 | 48 | cluFeeRecord.setRateType(courseFee.getRateType()); |
538 | 48 | cluFeeRecord.setDescr(courseFee.getDescr()); |
539 | 48 | cluFeeRecord.setMetaInfo(courseFee.getMetaInfo()); |
540 | 48 | cluFeeRecord.setId(courseFee.getId()); |
541 | 48 | cluFeeRecord.setFeeAmounts(courseFee.getFeeAmounts()); |
542 | 48 | cluFeeRecord.setAttributes(courseFee.getAttributes()); |
543 | 48 | clu.getFeeInfo().getCluFeeRecords().add(cluFeeRecord); |
544 | 48 | } |
545 | 25 | if(clu.getAccountingInfo() == null || course.getExpenditure()== null){ |
546 | 15 | clu.setAccountingInfo( new CluAccountingInfo()); |
547 | |
} |
548 | 25 | if(course.getExpenditure() != null){ |
549 | 25 | clu.getAccountingInfo().setAffiliatedOrgs(course.getExpenditure().getAffiliatedOrgs()); |
550 | 25 | clu.getAccountingInfo().setAttributes(course.getExpenditure().getAttributes()); |
551 | |
} |
552 | |
|
553 | 25 | return result; |
554 | |
} |
555 | |
|
556 | |
private List<BaseDTOAssemblyNode<?, ?>> disassembleCreditOutcomes(CourseInfo course, CluInfo clu, List<CluResultInfo> currentCluResults, NodeOperation operation) throws AssemblyException, NumberFormatException { |
557 | |
|
558 | 25 | List<BaseDTOAssemblyNode<?, ?>> results = new ArrayList<BaseDTOAssemblyNode<?, ?>>(); |
559 | |
|
560 | 25 | String courseResultType = CourseAssemblerConstants.COURSE_RESULT_TYPE_CREDITS; |
561 | |
|
562 | |
|
563 | 25 | if(NodeOperation.DELETE!=operation){ |
564 | |
|
565 | 24 | Set<String> rsltComps = new HashSet<String>(); |
566 | |
|
567 | |
try{ |
568 | |
try { |
569 | 24 | rsltComps.addAll(lrcService.getResultComponentIdsByResultComponentType(CourseAssemblerConstants.COURSE_RESULT_COMP_TYPE_CREDIT_FIXED)); |
570 | 24 | } catch (DoesNotExistException e) {} |
571 | |
try { |
572 | 24 | rsltComps.addAll(lrcService.getResultComponentIdsByResultComponentType(CourseAssemblerConstants.COURSE_RESULT_COMP_TYPE_CREDIT_MULTIPLE)); |
573 | 24 | } catch (DoesNotExistException e) {} |
574 | |
try { |
575 | 24 | rsltComps.addAll(lrcService.getResultComponentIdsByResultComponentType(CourseAssemblerConstants.COURSE_RESULT_COMP_TYPE_CREDIT_VARIABLE)); |
576 | 24 | } catch (DoesNotExistException e) {} |
577 | |
|
578 | |
|
579 | 24 | for(ResultComponentInfo creditOption:course.getCreditOptions()){ |
580 | 49 | String id = null; |
581 | 49 | String type = null; |
582 | 49 | List<String> resultValues = null; |
583 | 49 | Map<String,String> attributes = null; |
584 | |
|
585 | 49 | if(CourseAssemblerConstants.COURSE_RESULT_COMP_TYPE_CREDIT_FIXED.equals(creditOption.getType())){ |
586 | 44 | float fixedCreditValue = Float.parseFloat(creditOption.getAttributes().get(CourseAssemblerConstants.COURSE_RESULT_COMP_ATTR_FIXED_CREDIT_VALUE)); |
587 | 44 | id = CourseAssemblerConstants.COURSE_RESULT_COMP_CREDIT_PREFIX + fixedCreditValue; |
588 | 44 | type = CourseAssemblerConstants.COURSE_RESULT_COMP_TYPE_CREDIT_FIXED; |
589 | 44 | resultValues = new ArrayList<String>(); |
590 | 44 | resultValues.add(String.valueOf(fixedCreditValue)); |
591 | 44 | attributes = new HashMap<String,String>(); |
592 | 44 | attributes.put(CourseAssemblerConstants.COURSE_RESULT_COMP_ATTR_FIXED_CREDIT_VALUE, String.valueOf(fixedCreditValue)); |
593 | 44 | }else if(CourseAssemblerConstants.COURSE_RESULT_COMP_TYPE_CREDIT_MULTIPLE.equals(creditOption.getType())){ |
594 | 3 | Collections.sort(creditOption.getResultValues()); |
595 | 3 | StringBuilder sb = new StringBuilder(CourseAssemblerConstants.COURSE_RESULT_COMP_CREDIT_PREFIX); |
596 | 3 | for(Iterator<String> iter = creditOption.getResultValues().iterator();iter.hasNext();){ |
597 | 7 | sb.append(iter.next()); |
598 | 7 | if(iter.hasNext()){ |
599 | 4 | sb.append(","); |
600 | |
} |
601 | |
} |
602 | 3 | id = sb.toString(); |
603 | 3 | type = CourseAssemblerConstants.COURSE_RESULT_COMP_TYPE_CREDIT_MULTIPLE; |
604 | 3 | resultValues = creditOption.getResultValues(); |
605 | 3 | }else if(CourseAssemblerConstants.COURSE_RESULT_COMP_TYPE_CREDIT_VARIABLE.equals(creditOption.getType())){ |
606 | |
|
607 | |
|
608 | |
|
609 | |
|
610 | |
|
611 | 2 | String minCreditValue = creditOption.getAttributes().get(CourseAssemblerConstants.COURSE_RESULT_COMP_ATTR_MIN_CREDIT_VALUE); |
612 | 2 | String maxCreditValue = creditOption.getAttributes().get(CourseAssemblerConstants.COURSE_RESULT_COMP_ATTR_MAX_CREDIT_VALUE); |
613 | 2 | String creditValueIncr = creditOption.getAttributes().get(CourseAssemblerConstants.COURSE_RESULT_COMP_ATTR_CREDIT_VALUE_INCR); |
614 | 2 | float minCredits = Float.parseFloat(minCreditValue); |
615 | 2 | float maxCredits = Float.parseFloat(maxCreditValue); |
616 | |
|
617 | 2 | float increment = (null != creditValueIncr && creditValueIncr.length() > 0 ) ? Float.parseFloat(creditValueIncr) : 1.0f ; |
618 | |
|
619 | 2 | id = CourseAssemblerConstants.COURSE_RESULT_COMP_CREDIT_PREFIX + minCreditValue + "-" + maxCreditValue; |
620 | 2 | type = CourseAssemblerConstants.COURSE_RESULT_COMP_TYPE_CREDIT_VARIABLE; |
621 | 2 | resultValues = new ArrayList<String>(); |
622 | 16 | for(float i = minCredits; i <= maxCredits; i+=increment){ |
623 | 14 | resultValues.add(String.valueOf(i)); |
624 | |
} |
625 | 2 | attributes = new HashMap<String,String>(); |
626 | 2 | attributes.put(CourseAssemblerConstants.COURSE_RESULT_COMP_ATTR_MIN_CREDIT_VALUE, minCreditValue); |
627 | 2 | attributes.put(CourseAssemblerConstants.COURSE_RESULT_COMP_ATTR_MAX_CREDIT_VALUE, maxCreditValue); |
628 | 2 | attributes.put(CourseAssemblerConstants.COURSE_RESULT_COMP_ATTR_CREDIT_VALUE_INCR, creditValueIncr); |
629 | |
} |
630 | |
|
631 | |
|
632 | 49 | creditOption.setId(id); |
633 | |
|
634 | |
|
635 | 49 | if(id != null && !rsltComps.contains(id)){ |
636 | |
|
637 | |
|
638 | 4 | ResultComponentInfo resultComponent = new ResultComponentInfo(); |
639 | 4 | resultComponent.setId(id); |
640 | 4 | resultComponent.setType(type); |
641 | 4 | resultComponent.setState (course.getState()); |
642 | 4 | resultComponent.setResultValues(resultValues); |
643 | 4 | resultComponent.setAttributes(attributes); |
644 | 4 | BaseDTOAssemblyNode<ResultComponentInfo, ResultComponentInfo> node = new BaseDTOAssemblyNode<ResultComponentInfo, ResultComponentInfo>(null); |
645 | 4 | node.setOperation(NodeOperation.CREATE); |
646 | 4 | node.setNodeData(resultComponent); |
647 | 4 | node.setBusinessDTORef(creditOption); |
648 | 4 | results.add(node); |
649 | |
|
650 | 4 | rsltComps.add(id); |
651 | |
} |
652 | 49 | } |
653 | 0 | }catch (NumberFormatException e){ |
654 | 0 | throw new AssemblyException("Invalid Arguments for credit outcome values",e); |
655 | 0 | }catch (Exception e){ |
656 | 0 | throw new AssemblyException("Error Assembling", e); |
657 | 24 | } |
658 | |
} |
659 | |
|
660 | |
|
661 | |
|
662 | |
|
663 | 25 | Map<String, List<CluResultInfo>> currentResults = new HashMap<String, List<CluResultInfo>>(); |
664 | |
|
665 | |
|
666 | 25 | if (!NodeOperation.CREATE.equals(operation)) { |
667 | 11 | for (CluResultInfo currentResult : currentCluResults) { |
668 | 9 | if (courseResultType.equals(currentResult.getType())) { |
669 | |
|
670 | 6 | if(currentResult.getResultOptions().size()==1){ |
671 | |
|
672 | 6 | String resultComponentId = currentResult.getResultOptions().get(0).getResultComponentId(); |
673 | 6 | if(!currentResults.containsKey(resultComponentId)){ |
674 | 4 | currentResults.put(resultComponentId, new ArrayList<CluResultInfo>()); |
675 | |
} |
676 | 6 | currentResults.get(resultComponentId).add(currentResult); |
677 | 6 | }else{ |
678 | 0 | LOG.warn("Credit Results should have exactly one result option each"); |
679 | |
} |
680 | |
} |
681 | |
} |
682 | |
} |
683 | |
|
684 | |
|
685 | 25 | for(ResultComponentInfo creditOption : course.getCreditOptions()){ |
686 | 51 | if (NodeOperation.CREATE == operation |
687 | |
|| (NodeOperation.UPDATE == operation && !currentResults.containsKey(creditOption.getId()) )) { |
688 | |
|
689 | 46 | ResultOptionInfo resultOption = new ResultOptionInfo(); |
690 | 46 | resultOption.setState(course.getState()); |
691 | 46 | resultOption.setResultComponentId(creditOption.getId()); |
692 | |
|
693 | 46 | CluResultInfo cluResult = new CluResultInfo(); |
694 | 46 | cluResult.setCluId(clu.getId()); |
695 | 46 | cluResult.setState(course.getState()); |
696 | 46 | cluResult.setType(courseResultType); |
697 | |
|
698 | 46 | cluResult.getResultOptions().add(resultOption); |
699 | |
|
700 | 46 | BaseDTOAssemblyNode<ResultComponentInfo, CluResultInfo> cluResultNode = new BaseDTOAssemblyNode<ResultComponentInfo, CluResultInfo>(null); |
701 | 46 | cluResultNode.setNodeData(cluResult); |
702 | 46 | cluResultNode.setOperation(NodeOperation.CREATE); |
703 | |
|
704 | 46 | results.add(cluResultNode); |
705 | 46 | } else if (NodeOperation.UPDATE == operation |
706 | |
&& currentResults.containsKey(creditOption.getId())) { |
707 | |
|
708 | 3 | List<CluResultInfo> cluResults = currentResults.get(creditOption.getId()); |
709 | 3 | cluResults.remove(cluResults.size()-1); |
710 | 3 | if(cluResults.isEmpty()){ |
711 | 2 | currentResults.remove(creditOption.getId()); |
712 | |
} |
713 | 51 | } |
714 | |
} |
715 | |
|
716 | |
|
717 | 25 | for(Entry<String,List<CluResultInfo>> entry:currentResults.entrySet()){ |
718 | 2 | for(CluResultInfo cluResult:entry.getValue()){ |
719 | 3 | BaseDTOAssemblyNode<ResultComponentInfo, CluResultInfo> cluResultNode = new BaseDTOAssemblyNode<ResultComponentInfo, CluResultInfo>(null); |
720 | 3 | cluResultNode.setNodeData(cluResult); |
721 | 3 | cluResultNode.setOperation(NodeOperation.DELETE); |
722 | 3 | results.add(cluResultNode); |
723 | 3 | } |
724 | |
} |
725 | |
|
726 | 25 | return results; |
727 | |
} |
728 | |
|
729 | |
private List<String> assembleGradingOptions(List<CluResultInfo> cluResults){ |
730 | |
|
731 | 14 | String courseResultType = CourseAssemblerConstants.COURSE_RESULT_TYPE_GRADE; |
732 | |
|
733 | 14 | List<String> results = new ArrayList<String>(); |
734 | |
|
735 | 14 | for(CluResultInfo cluResult:cluResults){ |
736 | 42 | if(courseResultType.equals(cluResult.getType())){ |
737 | |
|
738 | 14 | for(ResultOptionInfo resultOption: cluResult.getResultOptions()){ |
739 | 28 | results.add(resultOption.getResultComponentId()); |
740 | |
} |
741 | 14 | break; |
742 | |
} |
743 | |
} |
744 | 14 | return results; |
745 | |
} |
746 | |
|
747 | |
private List<ResultComponentInfo> assembleCreditOptions( |
748 | |
List<CluResultInfo> cluResults) throws AssemblyException { |
749 | 14 | String courseResultType = CourseAssemblerConstants.COURSE_RESULT_TYPE_CREDITS; |
750 | 14 | List<ResultComponentInfo> results = new ArrayList<ResultComponentInfo>(); |
751 | |
|
752 | 14 | for(CluResultInfo cluResult:cluResults){ |
753 | 43 | if(courseResultType.equals(cluResult.getType())){ |
754 | |
|
755 | 29 | for(ResultOptionInfo resultOption: cluResult.getResultOptions()){ |
756 | |
try { |
757 | 29 | ResultComponentInfo resultComponent = lrcService.getResultComponent(resultOption.getResultComponentId()); |
758 | 29 | results.add(resultComponent); |
759 | 0 | } catch (DoesNotExistException e) { |
760 | 0 | LOG.warn("Course Credit option:"+resultOption.getId()+" refers to non-existant ResultComponentInfo "+resultOption.getResultComponentId()); |
761 | 0 | } catch (Exception e) { |
762 | 0 | throw new AssemblyException("Error getting result components",e); |
763 | 29 | } |
764 | |
} |
765 | |
} |
766 | |
} |
767 | 14 | return results; |
768 | |
} |
769 | |
|
770 | |
|
771 | |
private List<BaseDTOAssemblyNode<?, ?>> disassembleLos(String cluId, |
772 | |
CourseInfo course, NodeOperation operation) throws AssemblyException { |
773 | |
|
774 | 25 | List<BaseDTOAssemblyNode<?, ?>> results = new ArrayList<BaseDTOAssemblyNode<?, ?>>(); |
775 | |
|
776 | |
|
777 | |
|
778 | 25 | Map<String, CluLoRelationInfo> currentCluLoRelations = new HashMap<String, CluLoRelationInfo>(); |
779 | |
try { |
780 | 25 | List<CluLoRelationInfo> cluLoRelations = luService.getCluLoRelationsByClu(cluId); |
781 | 25 | for(CluLoRelationInfo cluLoRelation:cluLoRelations){ |
782 | 6 | if(CourseAssemblerConstants.COURSE_LO_COURSE_SPECIFIC_RELATION.equals(cluLoRelation.getType())){ |
783 | 6 | currentCluLoRelations.put(cluLoRelation.getLoId(), cluLoRelation); |
784 | |
} |
785 | |
} |
786 | 0 | } catch (DoesNotExistException e) { |
787 | 0 | } catch (Exception e) { |
788 | 0 | throw new AssemblyException("Error finding related Los"); |
789 | 25 | } |
790 | |
|
791 | |
|
792 | 25 | for(LoDisplayInfo loDisplay : course.getCourseSpecificLOs()){ |
793 | |
|
794 | |
|
795 | 50 | if (NodeOperation.CREATE == operation |
796 | |
|| (NodeOperation.UPDATE == operation && !currentCluLoRelations.containsKey(loDisplay.getLoInfo().getId()))) { |
797 | |
|
798 | |
|
799 | |
|
800 | 45 | loDisplay.getLoInfo().setId(null); |
801 | 45 | loDisplay.getLoInfo().setState(course.getState()); |
802 | 45 | BaseDTOAssemblyNode<LoDisplayInfo, LoInfo> loNode = loAssembler |
803 | |
.disassemble(loDisplay, NodeOperation.CREATE); |
804 | 45 | results.add(loNode); |
805 | |
|
806 | |
|
807 | 45 | CluLoRelationInfo relation = new CluLoRelationInfo(); |
808 | 45 | relation.setCluId(cluId); |
809 | 45 | relation.setLoId(loNode.getNodeData().getId()); |
810 | 45 | relation |
811 | |
.setType(CourseAssemblerConstants.COURSE_LO_COURSE_SPECIFIC_RELATION); |
812 | 45 | relation.setState(course.getState()); |
813 | |
|
814 | 45 | BaseDTOAssemblyNode<LoDisplayInfo, CluLoRelationInfo> relationNode = new BaseDTOAssemblyNode<LoDisplayInfo, CluLoRelationInfo>( |
815 | |
null); |
816 | 45 | relationNode.setNodeData(relation); |
817 | 45 | relationNode.setOperation(NodeOperation.CREATE); |
818 | |
|
819 | 45 | results.add(relationNode); |
820 | 45 | } else if (NodeOperation.UPDATE == operation |
821 | |
&& currentCluLoRelations.containsKey(loDisplay.getLoInfo().getId())) { |
822 | 3 | loDisplay.getLoInfo().setState(course.getState()); |
823 | |
|
824 | 3 | BaseDTOAssemblyNode<LoDisplayInfo, LoInfo> loNode = loAssembler |
825 | |
.disassemble(loDisplay, NodeOperation.UPDATE); |
826 | 3 | results.add(loNode); |
827 | |
|
828 | |
|
829 | |
|
830 | 3 | currentCluLoRelations.remove(loDisplay.getLoInfo().getId()); |
831 | 3 | } else if (NodeOperation.DELETE == operation |
832 | |
&& currentCluLoRelations.containsKey(loDisplay.getLoInfo().getId())) { |
833 | |
|
834 | |
|
835 | 2 | CluLoRelationInfo relationToDelete = currentCluLoRelations.get(loDisplay.getLoInfo().getId()); |
836 | 2 | BaseDTOAssemblyNode<LoDisplayInfo, CluLoRelationInfo> relationToDeleteNode = new BaseDTOAssemblyNode<LoDisplayInfo, CluLoRelationInfo>( |
837 | |
null); |
838 | 2 | relationToDeleteNode.setNodeData(relationToDelete); |
839 | 2 | relationToDeleteNode.setOperation(NodeOperation.DELETE); |
840 | 2 | results.add(relationToDeleteNode); |
841 | |
|
842 | 2 | BaseDTOAssemblyNode<LoDisplayInfo, LoInfo> loNode = loAssembler |
843 | |
.disassemble(loDisplay, NodeOperation.DELETE); |
844 | 2 | results.add(loNode); |
845 | |
|
846 | |
|
847 | |
|
848 | 2 | currentCluLoRelations.remove(loDisplay.getLoInfo().getId()); |
849 | 50 | } |
850 | |
} |
851 | |
|
852 | |
|
853 | |
|
854 | 25 | for (Entry<String, CluLoRelationInfo> entry : currentCluLoRelations.entrySet()) { |
855 | |
|
856 | |
|
857 | 1 | CluLoRelationInfo relationToDelete = entry.getValue(); |
858 | 1 | BaseDTOAssemblyNode<LoDisplayInfo, CluLoRelationInfo> relationToDeleteNode = new BaseDTOAssemblyNode<LoDisplayInfo, CluLoRelationInfo>( |
859 | |
null); |
860 | 1 | relationToDeleteNode.setNodeData(relationToDelete); |
861 | 1 | relationToDeleteNode.setOperation(NodeOperation.DELETE); |
862 | 1 | results.add(relationToDeleteNode); |
863 | |
|
864 | |
try{ |
865 | 1 | LoInfo loToDelete = loService.getLo(entry.getKey()); |
866 | |
|
867 | 1 | LoDisplayInfo loDisplayToDelete = loAssembler.assemble(loToDelete, null, false); |
868 | 1 | BaseDTOAssemblyNode<LoDisplayInfo, LoInfo> loNode = loAssembler |
869 | |
.disassemble(loDisplayToDelete, NodeOperation.DELETE); |
870 | 1 | results.add(loNode); |
871 | 0 | } catch (DoesNotExistException e){ |
872 | 0 | LOG.warn("Trying to delete non exsistant LO:"+entry.getKey()); |
873 | 0 | } catch (Exception e) { |
874 | 0 | throw new AssemblyException("Error disassembling LOs",e); |
875 | 1 | } |
876 | 1 | } |
877 | |
|
878 | 25 | return results; |
879 | |
} |
880 | |
|
881 | |
private BaseDTOAssemblyNode<?, ?> disassembleGradingOptions(String cluId, |
882 | |
String courseState, List<String> options, List<CluResultInfo> currentCluResults, NodeOperation operation) throws AssemblyException { |
883 | 25 | BaseDTOAssemblyNode<List<String>, CluResultInfo> cluResultNode = new BaseDTOAssemblyNode<List<String>, CluResultInfo>(null); |
884 | |
|
885 | 25 | String courseResultType=CourseAssemblerConstants.COURSE_RESULT_TYPE_GRADE; |
886 | 25 | String resultsDescription="Grading options"; |
887 | 25 | String resultDescription="Grading option"; |
888 | |
|
889 | |
|
890 | 25 | Map<String, ResultOptionInfo> currentResults = new HashMap<String, ResultOptionInfo>(); |
891 | |
|
892 | 25 | CluResultInfo cluResult = null; |
893 | |
|
894 | |
|
895 | 25 | if (!NodeOperation.CREATE.equals(operation)) { |
896 | 11 | for (CluResultInfo currentResult : currentCluResults) { |
897 | 8 | if (courseResultType.equals(currentResult.getType())) { |
898 | 3 | cluResult = currentResult; |
899 | 3 | if(NodeOperation.DELETE.equals(operation)){ |
900 | |
|
901 | 1 | cluResultNode.setOperation(NodeOperation.DELETE); |
902 | |
}else{ |
903 | |
|
904 | 2 | cluResultNode.setOperation(NodeOperation.UPDATE); |
905 | 2 | for(ResultOptionInfo resultOption:currentResult.getResultOptions()){ |
906 | 4 | currentResults.put(resultOption.getResultComponentId(), resultOption); |
907 | |
} |
908 | |
} |
909 | 2 | break; |
910 | |
} |
911 | |
} |
912 | |
} |
913 | |
|
914 | |
|
915 | 25 | if(!NodeOperation.DELETE.equals(operation)){ |
916 | 24 | if(cluResult == null){ |
917 | |
|
918 | 22 | cluResult = new CluResultInfo(); |
919 | 22 | cluResult.setCluId(cluId); |
920 | 22 | cluResult.setState(courseState); |
921 | 22 | cluResult.setType(courseResultType); |
922 | 22 | RichTextInfo desc = new RichTextInfo(); |
923 | 22 | desc.setPlain(resultsDescription); |
924 | 22 | cluResult.setDesc(desc); |
925 | 22 | cluResult.setEffectiveDate(new Date()); |
926 | 22 | cluResultNode.setOperation(NodeOperation.CREATE); |
927 | |
} |
928 | |
|
929 | 24 | cluResult.setResultOptions(new ArrayList<ResultOptionInfo>()); |
930 | |
|
931 | |
|
932 | 24 | for (String optionType : options) { |
933 | 48 | if(currentResults.containsKey(optionType)){ |
934 | |
|
935 | 3 | ResultOptionInfo resultOptionInfo = currentResults.get(optionType); |
936 | 3 | cluResult.getResultOptions().add(resultOptionInfo); |
937 | 3 | }else{ |
938 | |
|
939 | 45 | ResultOptionInfo resultOptionInfo = new ResultOptionInfo(); |
940 | 45 | RichTextInfo desc = new RichTextInfo(); |
941 | 45 | desc.setPlain(resultDescription); |
942 | 45 | resultOptionInfo.setDesc(desc); |
943 | 45 | resultOptionInfo.setResultComponentId(optionType); |
944 | 45 | resultOptionInfo.setState(courseState); |
945 | |
|
946 | 45 | cluResult.getResultOptions().add(resultOptionInfo); |
947 | 48 | } |
948 | |
} |
949 | |
} |
950 | |
|
951 | 25 | cluResultNode.setNodeData(cluResult); |
952 | 25 | return cluResultNode; |
953 | |
} |
954 | |
|
955 | |
|
956 | |
|
957 | |
private List<BaseDTOAssemblyNode<?, ?>> disassembleFormats(String nodeId, |
958 | |
CourseInfo course, NodeOperation operation) |
959 | |
throws AssemblyException, DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException { |
960 | |
|
961 | 25 | List<BaseDTOAssemblyNode<?, ?>> results = new ArrayList<BaseDTOAssemblyNode<?, ?>>(); |
962 | |
|
963 | |
|
964 | |
|
965 | 25 | Map<String, String> currentformatIds = new HashMap<String, String>(); |
966 | |
|
967 | 25 | if (!NodeOperation.CREATE.equals(operation)) { |
968 | |
try { |
969 | 11 | List<CluCluRelationInfo> formatRelationships = luService |
970 | |
.getCluCluRelationsByClu(course.getId()); |
971 | |
|
972 | |
|
973 | |
|
974 | 11 | for (CluCluRelationInfo formatRelation : formatRelationships) { |
975 | 7 | if (CourseAssemblerConstants.COURSE_FORMAT_RELATION_TYPE |
976 | |
.equals(formatRelation.getType())) { |
977 | 7 | currentformatIds.put(formatRelation.getRelatedCluId(), |
978 | |
formatRelation.getId()); |
979 | |
} |
980 | |
} |
981 | 0 | } catch (DoesNotExistException e) { |
982 | 0 | } catch (InvalidParameterException e) { |
983 | 0 | throw new AssemblyException("Error getting related formats", e); |
984 | 0 | } catch (MissingParameterException e) { |
985 | 0 | throw new AssemblyException("Error getting related formats", e); |
986 | 0 | } catch (OperationFailedException e) { |
987 | 0 | throw new AssemblyException("Error getting related formats", e); |
988 | 11 | } |
989 | |
} |
990 | |
|
991 | |
|
992 | 25 | for (FormatInfo format : course.getFormats()) { |
993 | |
|
994 | |
|
995 | 51 | if (NodeOperation.CREATE == operation |
996 | |
|| (NodeOperation.UPDATE == operation && !currentformatIds.containsKey(format.getId()) )) { |
997 | |
|
998 | |
|
999 | 45 | format.setState(course.getState()); |
1000 | 45 | BaseDTOAssemblyNode<FormatInfo, CluInfo> formatNode = formatAssembler |
1001 | |
.disassemble(format, NodeOperation.CREATE); |
1002 | 45 | results.add(formatNode); |
1003 | |
|
1004 | |
|
1005 | |
|
1006 | 45 | CluCluRelationInfo relation = new CluCluRelationInfo(); |
1007 | 45 | relation.setCluId(nodeId); |
1008 | 45 | relation.setRelatedCluId(formatNode.getNodeData().getId()); |
1009 | |
|
1010 | |
|
1011 | |
|
1012 | |
|
1013 | 45 | relation |
1014 | |
.setType(CourseAssemblerConstants.COURSE_FORMAT_RELATION_TYPE); |
1015 | 45 | relation.setState(course.getState()); |
1016 | |
|
1017 | 45 | BaseDTOAssemblyNode<CourseInfo, CluCluRelationInfo> relationNode = new BaseDTOAssemblyNode<CourseInfo, CluCluRelationInfo>( |
1018 | |
null); |
1019 | 45 | relationNode.setNodeData(relation); |
1020 | 45 | relationNode.setOperation(NodeOperation.CREATE); |
1021 | |
|
1022 | 45 | results.add(relationNode); |
1023 | 45 | } else if (NodeOperation.UPDATE == operation |
1024 | |
&& currentformatIds.containsKey(format.getId())) { |
1025 | |
|
1026 | |
|
1027 | 4 | format.setState(course.getState()); |
1028 | 4 | BaseDTOAssemblyNode<FormatInfo, CluInfo> formatNode = formatAssembler |
1029 | |
.disassemble(format, NodeOperation.UPDATE); |
1030 | 4 | results.add(formatNode); |
1031 | |
|
1032 | |
|
1033 | |
|
1034 | 4 | currentformatIds.remove(format.getId()); |
1035 | 4 | } else if (NodeOperation.DELETE == operation |
1036 | |
&& currentformatIds.containsKey(format.getId())) { |
1037 | |
|
1038 | 2 | CluCluRelationInfo relationToDelete = new CluCluRelationInfo(); |
1039 | 2 | relationToDelete.setId( currentformatIds.get(format.getId()) ); |
1040 | 2 | BaseDTOAssemblyNode<CourseInfo, CluCluRelationInfo> relationToDeleteNode = new BaseDTOAssemblyNode<CourseInfo, CluCluRelationInfo>( |
1041 | |
null); |
1042 | 2 | relationToDeleteNode.setNodeData(relationToDelete); |
1043 | 2 | relationToDeleteNode.setOperation(NodeOperation.DELETE); |
1044 | 2 | results.add(relationToDeleteNode); |
1045 | |
|
1046 | 2 | BaseDTOAssemblyNode<FormatInfo, CluInfo> formatNode = formatAssembler |
1047 | |
.disassemble(format, NodeOperation.DELETE); |
1048 | 2 | results.add(formatNode); |
1049 | |
|
1050 | |
|
1051 | |
|
1052 | 2 | currentformatIds.remove(format.getId()); |
1053 | 51 | } |
1054 | |
} |
1055 | |
|
1056 | |
|
1057 | |
|
1058 | 25 | for (Entry<String, String> entry : currentformatIds.entrySet()) { |
1059 | |
|
1060 | |
|
1061 | 1 | CluCluRelationInfo relationToDelete = new CluCluRelationInfo(); |
1062 | 1 | relationToDelete.setId( entry.getValue() ); |
1063 | 1 | BaseDTOAssemblyNode<CourseInfo, CluCluRelationInfo> relationToDeleteNode = new BaseDTOAssemblyNode<CourseInfo, CluCluRelationInfo>( |
1064 | |
null); |
1065 | 1 | relationToDeleteNode.setNodeData(relationToDelete); |
1066 | 1 | relationToDeleteNode.setOperation(NodeOperation.DELETE); |
1067 | 1 | results.add(relationToDeleteNode); |
1068 | |
|
1069 | 1 | CluInfo formatCluToDelete = luService.getClu(entry.getKey()); |
1070 | 1 | FormatInfo formatToDelete = formatAssembler.assemble(formatCluToDelete, null, false); |
1071 | 1 | BaseDTOAssemblyNode<FormatInfo, CluInfo> formatNode = formatAssembler |
1072 | |
.disassemble(formatToDelete, NodeOperation.DELETE); |
1073 | 1 | results.add(formatNode); |
1074 | 1 | } |
1075 | |
|
1076 | 25 | return results; |
1077 | |
} |
1078 | |
|
1079 | |
private List<CourseVariationInfo> assembleVariations(List<CluIdentifierInfo> cluIdents) { |
1080 | 45 | List<CourseVariationInfo> variations = new ArrayList<CourseVariationInfo>(); |
1081 | 45 | if (cluIdents != null) { |
1082 | 45 | for (CluIdentifierInfo cluIdent : cluIdents) { |
1083 | 94 | if (cluIdent.getType() != null && |
1084 | |
cluIdent.getType().equals(CourseAssemblerConstants.COURSE_VARIATION_IDENT_TYPE)) { |
1085 | 90 | CourseVariationInfo variation = new CourseVariationInfo(); |
1086 | 90 | variation.setId(cluIdent.getId()); |
1087 | 90 | variation.setType(cluIdent.getType()); |
1088 | 90 | variation.setCourseNumberSuffix(cluIdent.getSuffixCode()); |
1089 | 90 | variation.setSubjectArea(cluIdent.getDivision()); |
1090 | 90 | variation.setVariationCode(cluIdent.getVariation()); |
1091 | 90 | variation.setVariationTitle(cluIdent.getLongName()); |
1092 | 90 | variations.add(variation); |
1093 | 94 | } |
1094 | |
} |
1095 | |
} |
1096 | 45 | return variations; |
1097 | |
} |
1098 | |
|
1099 | |
private List<CourseCrossListingInfo> assembleCrossListings(List<CluIdentifierInfo> cluIdents) { |
1100 | 45 | List<CourseCrossListingInfo> crossListings = new ArrayList<CourseCrossListingInfo>(); |
1101 | 45 | if (cluIdents != null) { |
1102 | 45 | for (CluIdentifierInfo cluIdent : cluIdents) { |
1103 | 94 | if (cluIdent.getType() != null && |
1104 | |
cluIdent.getType().equals(CourseAssemblerConstants.COURSE_CROSSLISTING_IDENT_TYPE)) { |
1105 | 4 | CourseCrossListingInfo crosslisting = new CourseCrossListingInfo(); |
1106 | 4 | crosslisting.setId(cluIdent.getId()); |
1107 | 4 | crosslisting.setCode(cluIdent.getCode()); |
1108 | 4 | crosslisting.setAttributes(cluIdent.getAttributes()); |
1109 | 4 | crosslisting.setType(cluIdent.getType()); |
1110 | 4 | crosslisting.setCourseNumberSuffix(cluIdent.getSuffixCode()); |
1111 | 4 | crosslisting.setSubjectArea(cluIdent.getDivision()); |
1112 | 4 | crosslisting.setDepartment(cluIdent.getOrgId()); |
1113 | 4 | crossListings.add(crosslisting); |
1114 | 94 | } |
1115 | |
} |
1116 | |
} |
1117 | 45 | return crossListings; |
1118 | |
} |
1119 | |
|
1120 | |
|
1121 | |
|
1122 | |
private List<BaseDTOAssemblyNode<?, ?>> disassembleJoints(String nodeId, |
1123 | |
CourseInfo course, NodeOperation operation) |
1124 | |
throws AssemblyException { |
1125 | |
|
1126 | 25 | List<BaseDTOAssemblyNode<?, ?>> results = new ArrayList<BaseDTOAssemblyNode<?, ?>>(); |
1127 | |
|
1128 | |
|
1129 | |
|
1130 | 25 | Map<String, CluCluRelationInfo> currentJointIds = new HashMap<String, CluCluRelationInfo>(); |
1131 | |
|
1132 | 25 | if (!NodeOperation.CREATE.equals(operation)) { |
1133 | |
try { |
1134 | 11 | List<CluCluRelationInfo> jointRelationships = luService.getCluCluRelationsByClu(course.getId()); |
1135 | 11 | for (CluCluRelationInfo jointRelation : jointRelationships) { |
1136 | 7 | if (CourseAssemblerConstants.JOINT_RELATION_TYPE.equals(jointRelation.getType())) { |
1137 | 0 | if(jointRelation.getCluId().equals(course.getId())) { |
1138 | 0 | CluInfo clu = luService.getClu(jointRelation.getRelatedCluId()); |
1139 | 0 | if (clu.getState().equals(DtoConstants.STATE_ACTIVE) || clu.getState().equals(DtoConstants.STATE_SUPERSEDED) || |
1140 | |
clu.getState().equals(DtoConstants.STATE_APPROVED) || clu.getState().equals(DtoConstants.STATE_SUSPENDED)) |
1141 | 0 | currentJointIds.put(jointRelation.getId(),jointRelation); |
1142 | 0 | } else { |
1143 | 0 | CluInfo clu = luService.getClu(jointRelation.getCluId()); |
1144 | 0 | if (clu.getState().equals(DtoConstants.STATE_ACTIVE) || clu.getState().equals(DtoConstants.STATE_SUPERSEDED) || |
1145 | |
clu.getState().equals(DtoConstants.STATE_APPROVED) || clu.getState().equals(DtoConstants.STATE_SUSPENDED)) |
1146 | 0 | currentJointIds.put(jointRelation.getId(),jointRelation); |
1147 | 7 | } |
1148 | |
} |
1149 | |
} |
1150 | 0 | } catch (DoesNotExistException e) { |
1151 | 0 | } catch (InvalidParameterException e) { |
1152 | 0 | throw new AssemblyException("Error getting related formats", e); |
1153 | 0 | } catch (MissingParameterException e) { |
1154 | 0 | throw new AssemblyException("Error getting related formats", e); |
1155 | 0 | } catch (OperationFailedException e) { |
1156 | 0 | throw new AssemblyException("Error getting related formats", e); |
1157 | 11 | } |
1158 | |
} |
1159 | |
|
1160 | |
|
1161 | 25 | for (CourseJointInfo joint : course.getJoints()) { |
1162 | |
|
1163 | 0 | if (NodeOperation.UPDATE.equals(operation) && joint.getRelationId() != null |
1164 | |
&& currentJointIds.containsKey(joint.getRelationId())) { |
1165 | |
|
1166 | |
|
1167 | 0 | CluCluRelationInfo relation = currentJointIds.remove(joint.getRelationId()); |
1168 | 0 | relation.setRelatedCluId(joint.getCourseId()); |
1169 | 0 | relation.setState(course.getState()); |
1170 | 0 | BaseDTOAssemblyNode<CourseJointInfo, CluCluRelationInfo> jointNode = new BaseDTOAssemblyNode<CourseJointInfo, CluCluRelationInfo>(courseJointAssembler); |
1171 | 0 | jointNode.setBusinessDTORef(joint); |
1172 | 0 | jointNode.setNodeData(relation); |
1173 | 0 | jointNode.setOperation(NodeOperation.UPDATE); |
1174 | 0 | results.add(jointNode); |
1175 | 0 | } else if (!NodeOperation.DELETE.equals(operation)) { |
1176 | |
|
1177 | 0 | BaseDTOAssemblyNode<CourseJointInfo, CluCluRelationInfo> jointNode = courseJointAssembler |
1178 | |
.disassemble(joint, NodeOperation.CREATE); |
1179 | 0 | jointNode.getNodeData().setCluId(nodeId); |
1180 | 0 | jointNode.getNodeData().setState(course.getState()); |
1181 | 0 | results.add(jointNode); |
1182 | 0 | } |
1183 | |
} |
1184 | |
|
1185 | |
|
1186 | |
|
1187 | 25 | for (String id : currentJointIds.keySet()) { |
1188 | |
|
1189 | |
|
1190 | 0 | CluCluRelationInfo relationToDelete = new CluCluRelationInfo(); |
1191 | 0 | relationToDelete.setId(id); |
1192 | 0 | BaseDTOAssemblyNode<CourseJointInfo, CluCluRelationInfo> relationToDeleteNode = new BaseDTOAssemblyNode<CourseJointInfo, CluCluRelationInfo>( |
1193 | |
courseJointAssembler); |
1194 | 0 | relationToDeleteNode.setNodeData(relationToDelete); |
1195 | 0 | relationToDeleteNode.setOperation(NodeOperation.DELETE); |
1196 | 0 | results.add(relationToDeleteNode); |
1197 | 0 | } |
1198 | |
|
1199 | 25 | return results; |
1200 | |
} |
1201 | |
|
1202 | |
public void setLuService(LuService luService) { |
1203 | 1 | this.luService = luService; |
1204 | 1 | } |
1205 | |
|
1206 | |
public void setFormatAssembler(FormatAssembler formatAssembler) { |
1207 | 1 | this.formatAssembler = formatAssembler; |
1208 | 1 | } |
1209 | |
|
1210 | |
public void setCourseJointAssembler( |
1211 | |
CourseJointAssembler courseJointAssembler) { |
1212 | 1 | this.courseJointAssembler = courseJointAssembler; |
1213 | 1 | } |
1214 | |
|
1215 | |
public void setLoAssembler(LoAssembler loAssembler) { |
1216 | 1 | this.loAssembler = loAssembler; |
1217 | 1 | } |
1218 | |
|
1219 | |
public void setLoService(LearningObjectiveService loService) { |
1220 | 1 | this.loService = loService; |
1221 | 1 | } |
1222 | |
|
1223 | |
public void setCluAssemblerUtils(CluAssemblerUtils cluAssemblerUtils) { |
1224 | 1 | this.cluAssemblerUtils = cluAssemblerUtils; |
1225 | 1 | } |
1226 | |
|
1227 | |
public void setLrcService(LrcService lrcService) { |
1228 | 1 | this.lrcService = lrcService; |
1229 | 1 | } |
1230 | |
|
1231 | |
public void setAtpService(AtpService atpService) { |
1232 | 1 | this.atpService = atpService; |
1233 | 1 | } |
1234 | |
} |