| 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 | 25 | public class ProgramVariationAssembler implements BOAssembler<ProgramVariationInfo, CluInfo> { |
| 37 | 1 | 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 | 67 | ProgramVariationInfo pvInfo = (null != programVariation) ? programVariation : new ProgramVariationInfo(); |
| 47 | |
|
| 48 | |
|
| 49 | 67 | programAssemblerUtils.assembleBasics(clu, pvInfo); |
| 50 | 67 | programAssemblerUtils.assembleIdentifiers(clu, pvInfo); |
| 51 | 67 | programAssemblerUtils.assembleBasicAdminOrgs(clu, pvInfo); |
| 52 | 67 | programAssemblerUtils.assembleFullOrgs(clu, pvInfo); |
| 53 | 67 | programAssemblerUtils.assembleAtps(clu, pvInfo); |
| 54 | 67 | programAssemblerUtils.assembleLuCodes(clu, pvInfo); |
| 55 | 67 | programAssemblerUtils.assemblePublications(clu, pvInfo); |
| 56 | |
|
| 57 | 67 | if (!shallowBuild) { |
| 58 | 42 | programAssemblerUtils.assembleRequirements(clu, pvInfo); |
| 59 | 42 | pvInfo.setResultOptions(programAssemblerUtils.assembleResultOptions(clu.getId())); |
| 60 | 42 | pvInfo.setLearningObjectives(cluAssemblerUtils.assembleLos(clu.getId(), shallowBuild)); |
| 61 | |
} |
| 62 | |
|
| 63 | 67 | pvInfo.setIntensity((null != clu.getIntensity()) ? clu.getIntensity().getUnitType() : null); |
| 64 | 67 | pvInfo.setStdDuration(clu.getStdDuration()); |
| 65 | 67 | pvInfo.setCampusLocations(clu.getCampusLocations()); |
| 66 | 67 | pvInfo.setEffectiveDate(clu.getEffectiveDate()); |
| 67 | 67 | pvInfo.setDescr(clu.getDescr()); |
| 68 | 67 | pvInfo.setVersionInfo(clu.getVersionInfo()); |
| 69 | |
|
| 70 | 67 | return pvInfo; |
| 71 | |
} |
| 72 | |
|
| 73 | |
@Override |
| 74 | |
public BaseDTOAssemblyNode<ProgramVariationInfo, CluInfo> disassemble(ProgramVariationInfo variation, NodeOperation operation) throws AssemblyException { |
| 75 | 24 | BaseDTOAssemblyNode<ProgramVariationInfo, CluInfo> result = new BaseDTOAssemblyNode<ProgramVariationInfo, CluInfo>(this); |
| 76 | |
|
| 77 | 24 | if (variation == null) { |
| 78 | |
|
| 79 | |
|
| 80 | 0 | LOG.error("Variation to disassemble is null!"); |
| 81 | 0 | throw new AssemblyException("Variation can not be null"); |
| 82 | |
} |
| 83 | |
|
| 84 | |
CluInfo clu; |
| 85 | |
try { |
| 86 | 24 | clu = (NodeOperation.UPDATE == operation) ? luService.getClu(variation.getId()) : new CluInfo(); |
| 87 | 0 | } catch (Exception e) { |
| 88 | 0 | throw new AssemblyException("Error getting existing learning unit during variation update", e); |
| 89 | 24 | } |
| 90 | |
|
| 91 | 24 | boolean stateChanged = NodeOperation.UPDATE == operation && variation.getState() != null && !variation.getState().equals(clu.getState()); |
| 92 | |
|
| 93 | 24 | clu.setState(variation.getState()); |
| 94 | 24 | programAssemblerUtils.disassembleBasics(clu, variation); |
| 95 | 24 | if (variation.getId() == null) |
| 96 | 7 | variation.setId(clu.getId()); |
| 97 | 24 | programAssemblerUtils.disassembleIdentifiers(clu, variation, operation); |
| 98 | 24 | programAssemblerUtils.disassembleAdminOrgs(clu, variation, operation); |
| 99 | 24 | programAssemblerUtils.disassembleAtps(clu, variation, operation); |
| 100 | 24 | programAssemblerUtils.disassembleLuCodes(clu, variation, operation); |
| 101 | 24 | programAssemblerUtils.disassemblePublications(clu, variation, operation, result); |
| 102 | |
|
| 103 | 24 | if(variation.getProgramRequirements() != null && !variation.getProgramRequirements().isEmpty()) { |
| 104 | 4 | programAssemblerUtils.disassembleRequirements(clu, variation, operation, result, stateChanged); |
| 105 | |
} |
| 106 | |
|
| 107 | 24 | if (variation.getResultOptions() != null) { |
| 108 | 23 | disassembleResultOptions(variation, operation, result); |
| 109 | |
} |
| 110 | |
|
| 111 | 24 | if (variation.getLearningObjectives() != null) { |
| 112 | 24 | disassembleLearningObjectives(variation, operation, result); |
| 113 | |
} |
| 114 | |
|
| 115 | 24 | AmountInfo intensity = new AmountInfo(); |
| 116 | 24 | intensity.setUnitType(variation.getIntensity()); |
| 117 | 24 | clu.setIntensity(intensity); |
| 118 | 24 | clu.setStdDuration(variation.getStdDuration()); |
| 119 | 24 | clu.setCampusLocations(variation.getCampusLocations()); |
| 120 | 24 | clu.setEffectiveDate(variation.getEffectiveDate()); |
| 121 | 24 | clu.setDescr(variation.getDescr()); |
| 122 | 24 | clu.setVersionInfo(variation.getVersionInfo()); |
| 123 | |
|
| 124 | |
|
| 125 | 24 | result.setNodeData(clu); |
| 126 | 24 | result.setOperation(operation); |
| 127 | 24 | result.setBusinessDTORef(variation); |
| 128 | 24 | return result; |
| 129 | |
|
| 130 | |
} |
| 131 | |
|
| 132 | |
private void disassembleLearningObjectives(ProgramVariationInfo variation, NodeOperation operation, BaseDTOAssemblyNode<ProgramVariationInfo, CluInfo> result) throws AssemblyException { |
| 133 | |
try { |
| 134 | 24 | List<BaseDTOAssemblyNode<?, ?>> loResults = cluAssemblerUtils.disassembleLos(variation.getId(), variation.getState(), variation.getLearningObjectives(), operation); |
| 135 | 24 | if (loResults != null) { |
| 136 | 24 | result.getChildNodes().addAll(loResults); |
| 137 | |
} |
| 138 | 0 | } catch (DoesNotExistException e) { |
| 139 | 0 | } catch (Exception e) { |
| 140 | 0 | throw new AssemblyException("Error while disassembling los", e); |
| 141 | 24 | } |
| 142 | 24 | } |
| 143 | |
|
| 144 | |
private void disassembleResultOptions(ProgramVariationInfo variation, NodeOperation operation, BaseDTOAssemblyNode<ProgramVariationInfo, CluInfo> result) throws AssemblyException { |
| 145 | 23 | BaseDTOAssemblyNode<?, ?> resultOptions = cluAssemblerUtils.disassembleCluResults( |
| 146 | |
variation.getId(), variation.getState(), variation.getResultOptions(), operation, ProgramAssemblerConstants.DEGREE_RESULTS, "Result options", "Result option"); |
| 147 | 23 | if (resultOptions != null) { |
| 148 | 23 | result.getChildNodes().add(resultOptions); |
| 149 | |
} |
| 150 | 23 | } |
| 151 | |
|
| 152 | |
|
| 153 | |
public void setLuService(LuService luService) { |
| 154 | 1 | this.luService = luService; |
| 155 | 1 | } |
| 156 | |
|
| 157 | |
public void setCluAssemblerUtils(CluAssemblerUtils cluAssemblerUtils) { |
| 158 | 1 | this.cluAssemblerUtils = cluAssemblerUtils; |
| 159 | 1 | } |
| 160 | |
|
| 161 | |
public void setProgramAssemblerUtils(ProgramAssemblerUtils programAssemblerUtils) { |
| 162 | 1 | this.programAssemblerUtils = programAssemblerUtils; |
| 163 | 1 | } |
| 164 | |
} |