1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.student.r2.lum.course.service.assembler;
17
18 import org.kuali.student.common.util.UUIDHelper;
19 import org.kuali.student.r1.common.assembly.BOAssembler;
20 import org.kuali.student.r1.common.assembly.BaseDTOAssemblyNode;
21 import org.kuali.student.r1.common.assembly.BaseDTOAssemblyNode.NodeOperation;
22 import org.kuali.student.r2.common.assembler.AssemblyException;
23 import org.kuali.student.r2.common.dto.ContextInfo;
24 import org.kuali.student.r2.lum.clu.dto.CluCluRelationInfo;
25 import org.kuali.student.r2.lum.clu.dto.CluInfo;
26 import org.kuali.student.r2.lum.clu.service.CluService;
27 import org.kuali.student.r2.lum.course.dto.CourseJointInfo;
28
29
30
31
32
33
34 public class CourseJointAssembler implements BOAssembler<CourseJointInfo, CluCluRelationInfo> {
35
36 CluService cluService;
37
38
39
40
41 public CluService getCluService() {
42 return cluService;
43 }
44
45
46
47
48 public void setCluService(CluService cluService) {
49 this.cluService = cluService;
50 }
51
52 @Override
53 public CourseJointInfo assemble(CluCluRelationInfo cluRel, CourseJointInfo jointInfo, boolean shallowBuild, ContextInfo contextInfo) throws AssemblyException {
54 if(null == cluRel) {
55 return null;
56 }
57
58 CourseJointInfo joint = (jointInfo != null) ? jointInfo : new CourseJointInfo();
59
60 CluInfo clu = null;
61 try {
62 clu = cluService.getClu(cluRel.getRelatedCluId() , contextInfo);
63
64 joint.setCourseId(clu.getId());
65
66 joint.setTypeKey(clu.getTypeKey());
67 joint.setSubjectArea(clu.getOfficialIdentifier().getDivision());
68 joint.setCourseTitle(clu.getOfficialIdentifier().getLongName());
69 joint.setCourseNumberSuffix(clu.getOfficialIdentifier().getSuffixCode());
70 joint.setRelationId(cluRel.getId());
71
72 } catch (Exception e) {
73 throw new AssemblyException("Error getting related clus", e);
74 }
75
76 return joint;
77 }
78
79
80 public CourseJointInfo assemble(CluCluRelationInfo cluRel, String cluId, CourseJointInfo jointInfo, boolean shallowBuild, ContextInfo contextInfo) throws AssemblyException {
81 if(null == cluRel) {
82 return null;
83 }
84
85 CourseJointInfo joint = (jointInfo != null) ? jointInfo : new CourseJointInfo();
86
87 CluInfo clu = null;
88 try {
89 clu = cluService.getClu(cluId , contextInfo);
90
91 joint.setCourseId(clu.getId());
92 joint.setTypeKey(clu.getTypeKey());
93 joint.setSubjectArea(clu.getOfficialIdentifier().getDivision());
94 joint.setCourseTitle(clu.getOfficialIdentifier().getLongName());
95 joint.setCourseNumberSuffix(clu.getOfficialIdentifier().getSuffixCode());
96 joint.setRelationId(cluRel.getId());
97
98 } catch (Exception e) {
99 throw new AssemblyException("Error getting related clus", e);
100 }
101
102 return joint;
103 }
104
105 @Override
106 public BaseDTOAssemblyNode<CourseJointInfo, CluCluRelationInfo> disassemble(
107 CourseJointInfo joint, NodeOperation operation,ContextInfo contextInfo) throws AssemblyException {
108
109 if(null == joint){
110
111 throw new AssemblyException("Activity can not be null");
112 }
113
114 BaseDTOAssemblyNode<CourseJointInfo, CluCluRelationInfo> result = new BaseDTOAssemblyNode<CourseJointInfo, CluCluRelationInfo>(this);
115 result.setBusinessDTORef(joint);
116 result.setOperation(operation);
117
118 CluCluRelationInfo cluRel = new CluCluRelationInfo();
119 cluRel.setId(UUIDHelper.genStringUUID(joint.getRelationId()));
120 cluRel.setRelatedCluId(joint.getCourseId());
121
122 cluRel.setTypeKey(CourseAssemblerConstants.JOINT_RELATION_TYPE);
123 result.setNodeData(cluRel);
124
125
126 return result;
127 }
128 }