Clover Coverage Report - KS LUM 1.2.1-SNAPSHOT (Aggregated)
Coverage timestamp: Wed Nov 2 2011 05:59:10 EST
../../../../../../../img/srcFileCovDistChart9.png 31% of files have more coverage
66   164   22   9.43
22   114   0.33   7
7     3.14  
1    
 
  ProgramVariationAssembler       Line # 36 66 0% 22 9 90.5% 0.9052632
 
  (10)
 
1    /*
2    * Copyright 2007 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 1.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl1.php
9    *
10    * Unless required by applicable law or agreed to in writing, software
11    * distributed under the License is distributed on an "AS IS" BASIS,
12    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13    * See the License for the specific language governing permissions and
14    * limitations under the License.
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    * @author KS
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  67 toggle @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    // Copy all the data from the clu to the programvariation
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  24 toggle @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    // FIXME Unsure now if this is an exception or just return null or
79    // empty assemblyNode
80  0 LOG.error("Variation to disassemble is null!");
81  0 throw new AssemblyException("Variation can not be null");
82    }
83   
84  24 CluInfo clu;
85  24 try {
86  24 clu = (NodeOperation.UPDATE == operation) ? luService.getClu(variation.getId()) : new CluInfo();
87    } catch (Exception e) {
88  0 throw new AssemblyException("Error getting existing learning unit during variation update", e);
89    }
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    // Add the Clu to the result
125  24 result.setNodeData(clu);
126  24 result.setOperation(operation);
127  24 result.setBusinessDTORef(variation);
128  24 return result;
129   
130    }
131   
 
132  24 toggle private void disassembleLearningObjectives(ProgramVariationInfo variation, NodeOperation operation, BaseDTOAssemblyNode<ProgramVariationInfo, CluInfo> result) throws AssemblyException {
133  24 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    } catch (DoesNotExistException e) {
139    } catch (Exception e) {
140  0 throw new AssemblyException("Error while disassembling los", e);
141    }
142    }
143   
 
144  23 toggle 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    }
151   
152    // Spring setter
 
153  1 toggle public void setLuService(LuService luService) {
154  1 this.luService = luService;
155    }
156   
 
157  1 toggle public void setCluAssemblerUtils(CluAssemblerUtils cluAssemblerUtils) {
158  1 this.cluAssemblerUtils = cluAssemblerUtils;
159    }
160   
 
161  1 toggle public void setProgramAssemblerUtils(ProgramAssemblerUtils programAssemblerUtils) {
162  1 this.programAssemblerUtils = programAssemblerUtils;
163    }
164    }