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