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.ArrayList; |
19 | |
import java.util.List; |
20 | |
import java.util.Map; |
21 | |
|
22 | |
import org.apache.log4j.Logger; |
23 | |
import org.kuali.student.core.assembly.BOAssembler; |
24 | |
import org.kuali.student.core.assembly.BaseDTOAssemblyNode; |
25 | |
import org.kuali.student.core.assembly.BaseDTOAssemblyNode.NodeOperation; |
26 | |
import org.kuali.student.core.assembly.data.AssemblyException; |
27 | |
import org.kuali.student.core.dto.AmountInfo; |
28 | |
import org.kuali.student.core.exceptions.DataValidationErrorException; |
29 | |
import org.kuali.student.core.exceptions.DoesNotExistException; |
30 | |
import org.kuali.student.core.exceptions.InvalidParameterException; |
31 | |
import org.kuali.student.core.exceptions.MissingParameterException; |
32 | |
import org.kuali.student.core.exceptions.OperationFailedException; |
33 | |
import org.kuali.student.lum.course.service.assembler.CourseAssembler; |
34 | |
import org.kuali.student.lum.lu.dto.CluCluRelationInfo; |
35 | |
import org.kuali.student.lum.lu.dto.CluInfo; |
36 | |
import org.kuali.student.lum.lu.service.LuService; |
37 | |
import org.kuali.student.lum.program.dto.CoreProgramInfo; |
38 | |
import org.kuali.student.lum.program.dto.MajorDisciplineInfo; |
39 | |
import org.kuali.student.lum.program.dto.ProgramVariationInfo; |
40 | |
import org.kuali.student.lum.service.assembler.CluAssemblerUtils; |
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | 12 | public class MajorDisciplineAssembler implements BOAssembler<MajorDisciplineInfo, CluInfo> { |
48 | 1 | final static Logger LOG = Logger.getLogger(CourseAssembler.class); |
49 | |
|
50 | |
private LuService luService; |
51 | |
|
52 | |
private ProgramVariationAssembler programVariationAssembler; |
53 | |
private CoreProgramAssembler coreProgramAssembler; |
54 | |
private CluAssemblerUtils cluAssemblerUtils; |
55 | |
private ProgramAssemblerUtils programAssemblerUtils; |
56 | |
|
57 | |
@Override |
58 | |
public MajorDisciplineInfo assemble(CluInfo clu, MajorDisciplineInfo majorDiscipline, boolean shallowBuild) throws AssemblyException { |
59 | 27 | MajorDisciplineInfo mdInfo = (null != majorDiscipline) ? majorDiscipline : new MajorDisciplineInfo(); |
60 | |
|
61 | |
|
62 | 27 | programAssemblerUtils.assembleBasics(clu, mdInfo); |
63 | 27 | programAssemblerUtils.assembleIdentifiers(clu, mdInfo); |
64 | 27 | programAssemblerUtils.assembleBasicAdminOrgs(clu, mdInfo); |
65 | 27 | programAssemblerUtils.assembleFullOrgs(clu, mdInfo); |
66 | 27 | programAssemblerUtils.assembleAtps(clu, mdInfo); |
67 | 27 | programAssemblerUtils.assembleLuCodes(clu, mdInfo); |
68 | |
|
69 | 27 | mdInfo.setIntensity((null != clu.getIntensity()) ? clu.getIntensity().getUnitType() : null); |
70 | 27 | mdInfo.setStdDuration(clu.getStdDuration()); |
71 | 27 | mdInfo.setPublishedInstructors(clu.getInstructors()); |
72 | 27 | mdInfo.setCampusLocations(clu.getCampusLocations()); |
73 | 27 | mdInfo.setAccreditingAgencies(clu.getAccreditations()); |
74 | 27 | mdInfo.setEffectiveDate(clu.getEffectiveDate()); |
75 | 27 | mdInfo.setDescr(clu.getDescr()); |
76 | 27 | mdInfo.setVersionInfo(clu.getVersionInfo()); |
77 | 27 | mdInfo.setNextReviewPeriod(clu.getNextReviewPeriod()); |
78 | |
|
79 | 27 | if (!shallowBuild) { |
80 | 14 | programAssemblerUtils.assembleRequirements(clu, mdInfo); |
81 | 14 | mdInfo.setCredentialProgramId(programAssemblerUtils.getCredentialProgramID(clu.getId())); |
82 | 14 | mdInfo.setResultOptions(programAssemblerUtils.assembleResultOptions(clu.getId())); |
83 | 14 | mdInfo.setLearningObjectives(cluAssemblerUtils.assembleLos(clu.getId(), shallowBuild)); |
84 | 14 | mdInfo.setVariations(assembleVariations(clu.getId(), shallowBuild)); |
85 | 14 | mdInfo.setOrgCoreProgram(assembleCoreProgram(clu.getId(), shallowBuild)); |
86 | 14 | programAssemblerUtils.assemblePublications(clu, mdInfo); |
87 | |
} |
88 | |
|
89 | 27 | return mdInfo; |
90 | |
} |
91 | |
|
92 | |
private CoreProgramInfo assembleCoreProgram(String cluId, boolean shallowBuild) throws AssemblyException { |
93 | 14 | CoreProgramInfo coreProgramInfo = null; |
94 | |
try { |
95 | 14 | List<CluInfo> corePrograms = luService.getRelatedClusByCluId(cluId, ProgramAssemblerConstants.HAS_CORE_PROGRAM); |
96 | |
|
97 | 14 | if (corePrograms.size() == 1) { |
98 | 12 | coreProgramInfo = coreProgramAssembler.assemble(corePrograms.get(0), null, shallowBuild); |
99 | 2 | } else if (corePrograms.size() > 1) { |
100 | 0 | throw new AssemblyException(new DataValidationErrorException("MajorDiscipline has more than one associated Core Program")); |
101 | |
} |
102 | 0 | } catch (Exception e) { |
103 | 0 | throw new AssemblyException(e); |
104 | 14 | } |
105 | 14 | return coreProgramInfo; |
106 | |
} |
107 | |
|
108 | |
private List<ProgramVariationInfo> assembleVariations(String cluId, boolean shallowBuild) throws AssemblyException { |
109 | 14 | List<ProgramVariationInfo> variations = new ArrayList<ProgramVariationInfo>(); |
110 | |
|
111 | |
try { |
112 | 14 | Map<String, CluCluRelationInfo> currentRelations = null; |
113 | 14 | currentRelations = programAssemblerUtils.getCluCluActiveRelations(cluId, ProgramAssemblerConstants.HAS_PROGRAM_VARIATION); |
114 | |
|
115 | 14 | if(currentRelations != null && !currentRelations.isEmpty()){ |
116 | 14 | for (String variationId : currentRelations.keySet()) { |
117 | 30 | CluInfo variationClu = luService.getClu(variationId); |
118 | 30 | variations.add(programVariationAssembler.assemble(variationClu, null, shallowBuild)); |
119 | 30 | } |
120 | |
} |
121 | 0 | } catch (Exception e) { |
122 | 0 | throw new AssemblyException(e); |
123 | 14 | } |
124 | 14 | return variations; |
125 | |
} |
126 | |
|
127 | |
@Override |
128 | |
public BaseDTOAssemblyNode<MajorDisciplineInfo, CluInfo> disassemble(MajorDisciplineInfo major, NodeOperation operation) throws AssemblyException { |
129 | 11 | if (major == null) { |
130 | 0 | LOG.error("Major for disassemble is null!"); |
131 | 0 | throw new AssemblyException("Major cannot be null"); |
132 | |
} |
133 | |
|
134 | |
|
135 | |
|
136 | 11 | BaseDTOAssemblyNode<MajorDisciplineInfo, CluInfo> result = new BaseDTOAssemblyNode<MajorDisciplineInfo, CluInfo>( |
137 | |
this); |
138 | |
|
139 | |
CluInfo clu; |
140 | |
try { |
141 | 11 | clu = (NodeOperation.UPDATE == operation) ? luService.getClu(major.getId()) : new CluInfo(); |
142 | 0 | } catch (Exception e) { |
143 | 0 | throw new AssemblyException("Error getting existing learning unit during major update", e); |
144 | 11 | } |
145 | |
|
146 | 11 | boolean stateChanged = NodeOperation.UPDATE == operation && major.getState() != null && !major.getState().equals(clu.getState()); |
147 | |
|
148 | 11 | programAssemblerUtils.disassembleBasics(clu, major); |
149 | 11 | if (major.getId() == null) |
150 | 3 | major.setId(clu.getId()); |
151 | 11 | programAssemblerUtils.disassembleLuCodes(clu, major, operation); |
152 | 11 | programAssemblerUtils.disassembleAdminOrgs(clu, major, operation); |
153 | 11 | programAssemblerUtils.disassembleAtps(clu, major, operation); |
154 | 11 | programAssemblerUtils.disassembleIdentifiers(clu, major, operation); |
155 | 11 | programAssemblerUtils.disassemblePublications(clu, major, operation, result); |
156 | |
|
157 | 11 | if(major.getProgramRequirements() != null && !major.getProgramRequirements().isEmpty()) { |
158 | 4 | programAssemblerUtils.disassembleRequirements(clu, major, operation, result, stateChanged); |
159 | |
} |
160 | |
|
161 | 11 | if (major.getVariations() != null && !major.getVariations().isEmpty()) { |
162 | |
try { |
163 | 11 | disassembleVariations(major, operation, result); |
164 | 0 | } catch (Exception e) { |
165 | 0 | throw new AssemblyException("Error diassembling Variations during major update", e); |
166 | 11 | } |
167 | |
} |
168 | 11 | if (major.getOrgCoreProgram() != null ) { |
169 | 9 | disassembleCoreProgram(major, operation, result); |
170 | |
} |
171 | 11 | if (major.getCredentialProgramId() != null) { |
172 | 11 | disassembleCredentialProgram(major, operation, result); |
173 | |
} |
174 | 11 | if (major.getResultOptions() != null) { |
175 | 11 | disassembleResultOptions(major, operation, result); |
176 | |
} |
177 | 11 | if (major.getLearningObjectives() != null) { |
178 | 11 | disassembleLearningObjectives(major, operation, result); |
179 | |
} |
180 | |
|
181 | 11 | AmountInfo intensity = new AmountInfo(); |
182 | 11 | intensity.setUnitType(major.getIntensity()); |
183 | 11 | clu.setIntensity(intensity); |
184 | 11 | clu.setStdDuration(major.getStdDuration()); |
185 | 11 | clu.setInstructors(major.getPublishedInstructors()); |
186 | |
|
187 | 11 | clu.setNextReviewPeriod(major.getNextReviewPeriod()); |
188 | 11 | clu.setEffectiveDate(major.getEffectiveDate()); |
189 | |
|
190 | 11 | clu.setCampusLocations(major.getCampusLocations()); |
191 | 11 | clu.setDescr(major.getDescr()); |
192 | |
|
193 | 11 | clu.setAccreditations(major.getAccreditingAgencies()); |
194 | 11 | clu.setNextReviewPeriod(major.getNextReviewPeriod()); |
195 | |
|
196 | |
|
197 | 11 | result.setNodeData(clu); |
198 | 11 | result.setOperation(operation); |
199 | 11 | result.setBusinessDTORef(major); |
200 | |
|
201 | 11 | return result; |
202 | |
} |
203 | |
|
204 | |
private void disassembleLearningObjectives(MajorDisciplineInfo major, NodeOperation operation, BaseDTOAssemblyNode<MajorDisciplineInfo, CluInfo> result) throws AssemblyException { |
205 | |
try { |
206 | 11 | List<BaseDTOAssemblyNode<?, ?>> loResults = cluAssemblerUtils.disassembleLos(major.getId(), major.getState(), major.getLearningObjectives(), operation); |
207 | 11 | if (loResults != null) { |
208 | 11 | result.getChildNodes().addAll(loResults); |
209 | |
} |
210 | 0 | } catch (DoesNotExistException e) { |
211 | 0 | } catch (Exception e) { |
212 | 0 | throw new AssemblyException("Error while disassembling los", e); |
213 | 11 | } |
214 | 11 | } |
215 | |
|
216 | |
private void disassembleResultOptions(MajorDisciplineInfo major, NodeOperation operation, BaseDTOAssemblyNode<MajorDisciplineInfo, CluInfo> result) throws AssemblyException { |
217 | |
|
218 | |
|
219 | 11 | BaseDTOAssemblyNode<?, ?> degreeResults = cluAssemblerUtils.disassembleCluResults( |
220 | |
major.getId(), major.getState(), major.getResultOptions(), operation, ProgramAssemblerConstants.DEGREE_RESULTS, "Result options", "Result option"); |
221 | 11 | if (degreeResults != null) { |
222 | 11 | result.getChildNodes().add(degreeResults); |
223 | |
} |
224 | 11 | } |
225 | |
|
226 | |
private void disassembleCredentialProgram(MajorDisciplineInfo major, NodeOperation operation, BaseDTOAssemblyNode<MajorDisciplineInfo, CluInfo> result) throws AssemblyException { |
227 | |
|
228 | |
List<BaseDTOAssemblyNode<?,?>> credentialResults; |
229 | |
try { |
230 | 11 | credentialResults = programAssemblerUtils.disassembleCredentialProgram(major, operation, ProgramAssemblerConstants.HAS_MAJOR_PROGRAM); |
231 | 11 | if (credentialResults != null) { |
232 | 11 | result.getChildNodes().addAll(credentialResults); |
233 | |
} |
234 | 0 | } catch (Exception e) { |
235 | 0 | throw new AssemblyException("Error while disassembling Credential program", e); |
236 | 11 | } |
237 | 11 | } |
238 | |
|
239 | |
private void disassembleVariations(MajorDisciplineInfo major, NodeOperation operation, BaseDTOAssemblyNode<MajorDisciplineInfo, CluInfo> result) throws AssemblyException, DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException { |
240 | 11 | Map<String, CluCluRelationInfo> currentRelations = null; |
241 | 11 | List<BaseDTOAssemblyNode<?, ?>> nodes = new ArrayList<BaseDTOAssemblyNode<?, ?>>(); |
242 | |
|
243 | 11 | if (!NodeOperation.CREATE.equals(operation)){ |
244 | 8 | currentRelations = programAssemblerUtils.getCluCluActiveRelations(major.getId(), ProgramAssemblerConstants.HAS_PROGRAM_VARIATION); |
245 | |
} |
246 | |
|
247 | |
|
248 | 11 | for (ProgramVariationInfo variation : major.getVariations()) { |
249 | |
BaseDTOAssemblyNode<?,?> variationNode; |
250 | |
try { |
251 | 23 | if (NodeOperation.UPDATE.equals(operation) && variation.getId() != null |
252 | |
&& (currentRelations != null && currentRelations.containsKey(variation.getId()))) { |
253 | |
|
254 | |
|
255 | 16 | variationNode = programVariationAssembler.disassemble(variation, operation); |
256 | 16 | if (variationNode != null) nodes.add(variationNode); |
257 | 16 | currentRelations.remove(variation.getId()); |
258 | 7 | } else if (!NodeOperation.DELETE.equals(operation)) { |
259 | |
|
260 | 7 | variationNode = programVariationAssembler.disassemble(variation, NodeOperation.CREATE); |
261 | 7 | if (variationNode != null) nodes.add(variationNode); |
262 | 7 | programAssemblerUtils.addCreateRelationNode(major.getId(), variation.getId(), ProgramAssemblerConstants.HAS_PROGRAM_VARIATION, nodes); |
263 | |
} |
264 | 0 | } catch (Exception e) { |
265 | 0 | throw new AssemblyException("Error while disassembling Variation", e); |
266 | 23 | } |
267 | |
} |
268 | |
|
269 | |
|
270 | 11 | if(currentRelations != null && currentRelations.size() > 0){ |
271 | 1 | programAssemblerUtils.addInactiveRelationNodes(currentRelations, nodes); |
272 | 1 | addInactivateVariationNodes(currentRelations, nodes); |
273 | |
} |
274 | |
|
275 | 11 | result.getChildNodes().addAll(nodes); |
276 | 11 | } |
277 | |
|
278 | |
private void addInactivateVariationNodes(Map<String, CluCluRelationInfo> currentRelations, List<BaseDTOAssemblyNode<?, ?>> nodes) throws AssemblyException{ |
279 | 1 | for (String variationId : currentRelations.keySet()) { |
280 | |
CluInfo variationClu; |
281 | |
try { |
282 | 1 | variationClu = luService.getClu(variationId); |
283 | 1 | ProgramVariationInfo delVariation = programVariationAssembler.assemble(variationClu, null, true); |
284 | 1 | delVariation.setState(ProgramAssemblerConstants.INACTIVE); |
285 | 1 | BaseDTOAssemblyNode<?,?> variationNode = programVariationAssembler.disassemble(delVariation , NodeOperation.UPDATE); |
286 | 1 | if (variationNode != null) nodes.add(variationNode); |
287 | 0 | } catch (Exception e) { |
288 | 0 | throw new AssemblyException("Error while disassembling variation, deactivateVariations", e); |
289 | 1 | } |
290 | 1 | } |
291 | 1 | } |
292 | |
|
293 | |
private void disassembleCoreProgram(MajorDisciplineInfo major, NodeOperation operation, BaseDTOAssemblyNode<MajorDisciplineInfo, CluInfo> result) throws AssemblyException { |
294 | |
|
295 | |
BaseDTOAssemblyNode<?,?> coreResults; |
296 | |
try { |
297 | 9 | coreResults = coreProgramAssembler.disassemble(major.getOrgCoreProgram(), operation); |
298 | 9 | if (coreResults != null) { |
299 | 9 | result.getChildNodes().add(coreResults); |
300 | |
} |
301 | 0 | } catch (Exception e) { |
302 | 0 | throw new AssemblyException("Error while disassembling Core program", e); |
303 | 9 | } |
304 | 9 | } |
305 | |
|
306 | |
|
307 | |
public void setLuService(LuService luService) { |
308 | 1 | this.luService = luService; |
309 | 1 | } |
310 | |
|
311 | |
public void setProgramVariationAssembler(ProgramVariationAssembler programVariationAssembler) { |
312 | 1 | this.programVariationAssembler = programVariationAssembler; |
313 | 1 | } |
314 | |
|
315 | |
public ProgramVariationAssembler getProgramVariationAssembler() { |
316 | 12 | return programVariationAssembler; |
317 | |
} |
318 | |
|
319 | |
public void setCoreProgramAssembler(CoreProgramAssembler coreProgramAssembler) { |
320 | 1 | this.coreProgramAssembler = coreProgramAssembler; |
321 | 1 | } |
322 | |
|
323 | |
public void setCluAssemblerUtils(CluAssemblerUtils cluAssemblerUtils) { |
324 | 1 | this.cluAssemblerUtils = cluAssemblerUtils; |
325 | 1 | } |
326 | |
|
327 | |
public void setProgramAssemblerUtils(ProgramAssemblerUtils programAssemblerUtils) { |
328 | 1 | this.programAssemblerUtils = programAssemblerUtils; |
329 | 1 | } |
330 | |
} |