1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.student.lum.program.service.assembler;
17
18 import java.util.List;
19
20 import org.apache.log4j.Logger;
21 import org.kuali.student.core.assembly.BOAssembler;
22 import org.kuali.student.core.assembly.BaseDTOAssemblyNode;
23 import org.kuali.student.core.assembly.BaseDTOAssemblyNode.NodeOperation;
24 import org.kuali.student.core.assembly.data.AssemblyException;
25 import org.kuali.student.core.dto.AmountInfo;
26 import org.kuali.student.core.exceptions.DoesNotExistException;
27 import org.kuali.student.lum.lu.dto.CluInfo;
28 import org.kuali.student.lum.lu.service.LuService;
29 import org.kuali.student.lum.program.dto.ProgramVariationInfo;
30 import org.kuali.student.lum.service.assembler.CluAssemblerUtils;
31
32
33
34
35
36 public class ProgramVariationAssembler implements BOAssembler<ProgramVariationInfo, CluInfo> {
37 final static Logger LOG = Logger.getLogger(ProgramVariationAssembler.class);
38
39 private LuService luService;
40 private CluAssemblerUtils cluAssemblerUtils;
41 private ProgramAssemblerUtils programAssemblerUtils;
42
43 @Override
44 public ProgramVariationInfo assemble(CluInfo clu, ProgramVariationInfo programVariation, boolean shallowBuild) throws AssemblyException {
45
46 ProgramVariationInfo pvInfo = (null != programVariation) ? programVariation : new ProgramVariationInfo();
47
48
49 programAssemblerUtils.assembleBasics(clu, pvInfo);
50 programAssemblerUtils.assembleIdentifiers(clu, pvInfo);
51 programAssemblerUtils.assembleBasicAdminOrgs(clu, pvInfo);
52 programAssemblerUtils.assembleFullOrgs(clu, pvInfo);
53 programAssemblerUtils.assembleAtps(clu, pvInfo);
54 programAssemblerUtils.assembleLuCodes(clu, pvInfo);
55 programAssemblerUtils.assemblePublications(clu, pvInfo);
56
57 if (!shallowBuild) {
58 programAssemblerUtils.assembleRequirements(clu, pvInfo);
59 pvInfo.setResultOptions(programAssemblerUtils.assembleResultOptions(clu.getId()));
60 pvInfo.setLearningObjectives(cluAssemblerUtils.assembleLos(clu.getId(), shallowBuild));
61 }
62
63 pvInfo.setIntensity((null != clu.getIntensity()) ? clu.getIntensity().getUnitType() : null);
64 pvInfo.setStdDuration(clu.getStdDuration());
65 pvInfo.setCampusLocations(clu.getCampusLocations());
66 pvInfo.setEffectiveDate(clu.getEffectiveDate());
67 pvInfo.setDescr(clu.getDescr());
68 pvInfo.setVersionInfo(clu.getVersionInfo());
69
70 return pvInfo;
71 }
72
73 @Override
74 public BaseDTOAssemblyNode<ProgramVariationInfo, CluInfo> disassemble(ProgramVariationInfo variation, NodeOperation operation) throws AssemblyException {
75 BaseDTOAssemblyNode<ProgramVariationInfo, CluInfo> result = new BaseDTOAssemblyNode<ProgramVariationInfo, CluInfo>(this);
76
77 if (variation == null) {
78
79
80 LOG.error("Variation to disassemble is null!");
81 throw new AssemblyException("Variation can not be null");
82 }
83
84 CluInfo clu;
85 try {
86 clu = (NodeOperation.UPDATE == operation) ? luService.getClu(variation.getId()) : new CluInfo();
87 } catch (Exception e) {
88 throw new AssemblyException("Error getting existing learning unit during variation update", e);
89 }
90
91 boolean stateChanged = NodeOperation.UPDATE == operation && variation.getState() != null && !variation.getState().equals(clu.getState());
92
93 programAssemblerUtils.disassembleBasics(clu, variation);
94 if (variation.getId() == null)
95 variation.setId(clu.getId());
96 programAssemblerUtils.disassembleIdentifiers(clu, variation, operation);
97 programAssemblerUtils.disassembleAdminOrgs(clu, variation, operation);
98 programAssemblerUtils.disassembleAtps(clu, variation, operation);
99 programAssemblerUtils.disassembleLuCodes(clu, variation, operation);
100 programAssemblerUtils.disassemblePublications(clu, variation, operation, result);
101
102 if(variation.getProgramRequirements() != null && !variation.getProgramRequirements().isEmpty()) {
103 programAssemblerUtils.disassembleRequirements(clu, variation, operation, result, stateChanged);
104 }
105
106 if (variation.getResultOptions() != null) {
107 disassembleResultOptions(variation, operation, result);
108 }
109
110 if (variation.getLearningObjectives() != null) {
111 disassembleLearningObjectives(variation, operation, result);
112 }
113
114 AmountInfo intensity = new AmountInfo();
115 intensity.setUnitType(variation.getIntensity());
116 clu.setIntensity(intensity);
117 clu.setStdDuration(variation.getStdDuration());
118 clu.setCampusLocations(variation.getCampusLocations());
119 clu.setEffectiveDate(variation.getEffectiveDate());
120 clu.setDescr(variation.getDescr());
121 clu.setVersionInfo(variation.getVersionInfo());
122
123
124 result.setNodeData(clu);
125 result.setOperation(operation);
126 result.setBusinessDTORef(variation);
127 return result;
128
129 }
130
131 private void disassembleLearningObjectives(ProgramVariationInfo variation, NodeOperation operation, BaseDTOAssemblyNode<ProgramVariationInfo, CluInfo> result) throws AssemblyException {
132 try {
133 List<BaseDTOAssemblyNode<?, ?>> loResults = cluAssemblerUtils.disassembleLos(variation.getId(), variation.getState(), variation.getLearningObjectives(), operation);
134 if (loResults != null) {
135 result.getChildNodes().addAll(loResults);
136 }
137 } catch (DoesNotExistException e) {
138 } catch (Exception e) {
139 throw new AssemblyException("Error while disassembling los", e);
140 }
141 }
142
143 private void disassembleResultOptions(ProgramVariationInfo variation, NodeOperation operation, BaseDTOAssemblyNode<ProgramVariationInfo, CluInfo> result) throws AssemblyException {
144 BaseDTOAssemblyNode<?, ?> resultOptions = cluAssemblerUtils.disassembleCluResults(
145 variation.getId(), variation.getState(), variation.getResultOptions(), operation, ProgramAssemblerConstants.DEGREE_RESULTS, "Result options", "Result option");
146 if (resultOptions != null) {
147 result.getChildNodes().add(resultOptions);
148 }
149 }
150
151
152 public void setLuService(LuService luService) {
153 this.luService = luService;
154 }
155
156 public void setCluAssemblerUtils(CluAssemblerUtils cluAssemblerUtils) {
157 this.cluAssemblerUtils = cluAssemblerUtils;
158 }
159
160 public void setProgramAssemblerUtils(ProgramAssemblerUtils programAssemblerUtils) {
161 this.programAssemblerUtils = programAssemblerUtils;
162 }
163 }