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