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.common.assembly.BOAssembler;
22 import org.kuali.student.common.assembly.BaseDTOAssemblyNode;
23 import org.kuali.student.common.assembly.BaseDTOAssemblyNode.NodeOperation;
24 import org.kuali.student.common.assembly.data.AssemblyException;
25 import org.kuali.student.common.dto.AmountInfo;
26 import org.kuali.student.common.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 clu.setState(variation.getState());
94 programAssemblerUtils.disassembleBasics(clu, variation);
95 if (variation.getId() == null)
96 variation.setId(clu.getId());
97 programAssemblerUtils.disassembleIdentifiers(clu, variation, operation);
98 programAssemblerUtils.disassembleAdminOrgs(clu, variation, operation);
99 programAssemblerUtils.disassembleAtps(clu, variation, operation);
100 programAssemblerUtils.disassembleLuCodes(clu, variation, operation);
101 programAssemblerUtils.disassemblePublications(clu, variation, operation, result);
102
103 if(variation.getProgramRequirements() != null && !variation.getProgramRequirements().isEmpty()) {
104 programAssemblerUtils.disassembleRequirements(clu, variation, operation, result, stateChanged);
105 }
106
107 if (variation.getResultOptions() != null) {
108 disassembleResultOptions(variation, operation, result);
109 }
110
111 if (variation.getLearningObjectives() != null) {
112 disassembleLearningObjectives(variation, operation, result);
113 }
114
115 AmountInfo intensity = new AmountInfo();
116 intensity.setUnitType(variation.getIntensity());
117 clu.setIntensity(intensity);
118 clu.setStdDuration(variation.getStdDuration());
119 clu.setCampusLocations(variation.getCampusLocations());
120 clu.setEffectiveDate(variation.getEffectiveDate());
121 clu.setDescr(variation.getDescr());
122 clu.setVersionInfo(variation.getVersionInfo());
123
124
125 result.setNodeData(clu);
126 result.setOperation(operation);
127 result.setBusinessDTORef(variation);
128 return result;
129
130 }
131
132 private void disassembleLearningObjectives(ProgramVariationInfo variation, NodeOperation operation, BaseDTOAssemblyNode<ProgramVariationInfo, CluInfo> result) throws AssemblyException {
133 try {
134 List<BaseDTOAssemblyNode<?, ?>> loResults = cluAssemblerUtils.disassembleLos(variation.getId(), variation.getState(), variation.getLearningObjectives(), operation);
135 if (loResults != null) {
136 result.getChildNodes().addAll(loResults);
137 }
138 } catch (DoesNotExistException e) {
139 } catch (Exception e) {
140 throw new AssemblyException("Error while disassembling los", e);
141 }
142 }
143
144 private void disassembleResultOptions(ProgramVariationInfo variation, NodeOperation operation, BaseDTOAssemblyNode<ProgramVariationInfo, CluInfo> result) throws AssemblyException {
145 BaseDTOAssemblyNode<?, ?> resultOptions = cluAssemblerUtils.disassembleCluResults(
146 variation.getId(), variation.getState(), variation.getResultOptions(), operation, ProgramAssemblerConstants.DEGREE_RESULTS, "Result options", "Result option");
147 if (resultOptions != null) {
148 result.getChildNodes().add(resultOptions);
149 }
150 }
151
152
153 public void setLuService(LuService luService) {
154 this.luService = luService;
155 }
156
157 public void setCluAssemblerUtils(CluAssemblerUtils cluAssemblerUtils) {
158 this.cluAssemblerUtils = cluAssemblerUtils;
159 }
160
161 public void setProgramAssemblerUtils(ProgramAssemblerUtils programAssemblerUtils) {
162 this.programAssemblerUtils = programAssemblerUtils;
163 }
164 }