Clover Coverage Report - KS LUM Impl 1.2-M2-SNAPSHOT
Coverage timestamp: Fri Apr 22 2011 05:39:19 EST
../../../../../../../img/srcFileCovDistChart8.png 33% of files have more coverage
119   302   50   6.26
44   238   0.42   19
19     2.63  
1    
 
  ProgramRequirementAssembler       Line # 44 119 0% 50 35 80.8% 0.8076923
 
  (7)
 
1    /**
2    *
3    */
4    package org.kuali.student.lum.program.service.impl;
5   
6    import static org.apache.commons.collections.CollectionUtils.isEmpty;
7    import static org.apache.commons.lang.StringUtils.isEmpty;
8   
9    import java.util.HashMap;
10    import java.util.List;
11    import java.util.Map;
12   
13    import org.apache.log4j.Logger;
14    import org.kuali.student.common.assembly.BOAssembler;
15    import org.kuali.student.common.assembly.BaseDTOAssemblyNode;
16    import org.kuali.student.common.assembly.BaseDTOAssemblyNode.NodeOperation;
17    import org.kuali.student.common.assembly.data.AssemblyException;
18    import org.kuali.student.common.dto.DtoConstants;
19    import org.kuali.student.common.exceptions.DoesNotExistException;
20    import org.kuali.student.common.exceptions.InvalidParameterException;
21    import org.kuali.student.common.exceptions.MissingParameterException;
22    import org.kuali.student.common.exceptions.OperationFailedException;
23    import org.kuali.student.common.util.UUIDHelper;
24    import org.kuali.student.core.statement.dto.RefStatementRelationInfo;
25    import org.kuali.student.core.statement.dto.StatementTreeViewInfo;
26    import org.kuali.student.core.statement.service.StatementService;
27    import org.kuali.student.core.statement.service.assembler.StatementTreeViewAssembler;
28    import org.kuali.student.lum.course.service.assembler.LoAssembler;
29    import org.kuali.student.lum.lo.service.LearningObjectiveService;
30    import org.kuali.student.lum.lu.dto.CluCluRelationInfo;
31    import org.kuali.student.lum.lu.dto.CluIdentifierInfo;
32    import org.kuali.student.lum.lu.dto.CluInfo;
33    import org.kuali.student.lum.lu.service.LuService;
34    import org.kuali.student.lum.program.dto.ProgramRequirementInfo;
35    import org.kuali.student.lum.program.service.assembler.ProgramAssemblerConstants;
36    import org.kuali.student.lum.program.service.assembler.ProgramAssemblerUtils;
37    import org.kuali.student.lum.service.assembler.CluAssemblerUtils;
38   
39   
40    /**
41    * @author glindholm
42    *
43    */
 
44    public class ProgramRequirementAssembler implements BOAssembler<ProgramRequirementInfo, CluInfo> {
45    final static Logger LOG = Logger.getLogger(ProgramRequirementAssembler.class);
46   
47    private StatementService statementService;
48    private StatementTreeViewAssembler statementTreeViewAssembler;
49    private LearningObjectiveService loService;
50    private LuService luService;
51    private LoAssembler loAssembler;
52    private CluAssemblerUtils cluAssemblerUtils;
53    private ProgramAssemblerUtils programAssemblerUtils;
54   
55   
 
56  12 toggle @Override
57    public ProgramRequirementInfo assemble(CluInfo clu,
58    ProgramRequirementInfo progReqInfo, boolean shallowBuild)
59    throws AssemblyException {
60  12 ProgramRequirementInfo progReq = (progReqInfo != null ? progReqInfo : new ProgramRequirementInfo());
61   
62  12 if (clu.getOfficialIdentifier() != null) {
63  12 progReq.setShortTitle(clu.getOfficialIdentifier().getShortName());
64  12 progReq.setLongTitle(clu.getOfficialIdentifier().getLongName());
65    }
66  12 progReq.setDescr(clu.getDescr());
67   
68    //assembling minCredits & maxCredits
69  12 assembleCredits(clu, progReq);
70   
71  12 if (progReq.getStatement() == null) {
72  5 try {
73  5 List<RefStatementRelationInfo> relations = statementService.getRefStatementRelationsByRef(ProgramAssemblerConstants.PROGRAM_REQUIREMENT, clu.getId());
74   
75   
76  5 StatementTreeViewInfo statementTree = new StatementTreeViewInfo();
77  5 if (relations != null) {
78  5 statementTreeViewAssembler.assemble(statementService.getStatementTreeView(relations.get(0).getStatementId()), statementTree, shallowBuild);
79    }
80  5 progReq.setStatement(statementTree);
81    } catch (AssemblyException e) {
82  0 throw e;
83    } catch (Exception e) {
84  0 throw new AssemblyException(e);
85    }
86    }
87   
88  12 if (isEmpty(progReq.getLearningObjectives())) {
89  5 progReq.setLearningObjectives(cluAssemblerUtils.assembleLos(clu.getId(), shallowBuild));
90    }
91   
92  12 progReq.setMetaInfo(clu.getMetaInfo());
93  12 progReq.setType(clu.getType());
94  12 progReq.setAttributes(clu.getAttributes());
95  12 progReq.setId(clu.getId());
96   
97  12 return progReq;
98    }
99   
 
100  9 toggle @Override
101    public BaseDTOAssemblyNode<ProgramRequirementInfo, CluInfo> disassemble(
102    ProgramRequirementInfo progReq, NodeOperation operation)
103    throws AssemblyException {
104   
105  9 if (progReq == null) {
106    // FIXME Unsure now if this is an exception or just return null or
107    // empty assemblyNode
108  0 LOG.error("ProgramRequirementInfo to disassemble is null!");
109  0 throw new AssemblyException("ProgramRequirementInfo can not be null");
110    }
111   
112  9 BaseDTOAssemblyNode<ProgramRequirementInfo, CluInfo> result = new BaseDTOAssemblyNode<ProgramRequirementInfo, CluInfo>(null);
113   
114    // Create the Statement Tree
115  9 StatementTreeViewInfo statement = progReq.getStatement();
116  9 statement.setId(UUIDHelper.genStringUUID(statement.getId()));
117  9 BaseDTOAssemblyNode<StatementTreeViewInfo, StatementTreeViewInfo> statementTree;
118  9 try {
119  9 statementTree = statementTreeViewAssembler.disassemble(statement, operation);
120    } catch (AssemblyException e) {
121  0 throw e;
122    } catch (Exception e) {
123  0 throw new AssemblyException(e);
124    }
125  9 result.getChildNodes().add(statementTree);
126   
127  9 CluInfo clu;
128  9 try {
129  9 clu = (NodeOperation.UPDATE == operation) ? luService.getClu(progReq.getId()) : new CluInfo();
130    } catch (Exception e) {
131  0 throw new AssemblyException("Error getting existing learning unit during program requirement update", e);
132    }
133   
134  9 if (operation.equals(NodeOperation.DELETE)) {
135  2 try {
136  2 final List<CluCluRelationInfo> relations = luService.getCluCluRelationsByClu(progReq.getId());
137  2 final BaseDTOAssemblyNode<ProgramRequirementInfo, CluCluRelationInfo> cluRelation = new BaseDTOAssemblyNode<ProgramRequirementInfo, CluCluRelationInfo>(null);
138  2 if (relations.size() > 1) {
139  0 throw new AssemblyException("Unable to dissamble ProgramRequirement, more than one CluCluRelation found");
140  2 } else if (relations.size() == 1) {
141  1 cluRelation.setNodeData(relations.get(0));
142  1 cluRelation.setOperation(operation);
143  1 result.getChildNodes().add(cluRelation);
144    }
145    } catch (Exception e) {
146  0 throw new AssemblyException(e);
147    }
148    }
149   
150  9 BaseDTOAssemblyNode<ProgramRequirementInfo, CluInfo> cluResult = new BaseDTOAssemblyNode<ProgramRequirementInfo, CluInfo>(this);
151   
152  9 cluResult.setNodeData(clu);
153  9 cluResult.setBusinessDTORef(progReq);
154  9 cluResult.setOperation(operation);
155  9 result.getChildNodes().add(cluResult);
156   
157  9 programAssemblerUtils.disassembleBasics(clu, progReq);
158   
159    //disassembling minCredits & maxCredits
160  9 disassembleCredits(clu, progReq);
161   
162  9 progReq.setId(clu.getId());
163  9 CluIdentifierInfo official = null != clu.getOfficialIdentifier() ? clu.getOfficialIdentifier() : new CluIdentifierInfo();
164  9 official.setLongName(progReq.getLongTitle());
165  9 official.setShortName(progReq.getShortTitle());
166  9 official.setState(!isEmpty(clu.getState()) ? clu.getState() : DtoConstants.STATE_ACTIVE);
167    // gotta be this type
168  9 official.setType(ProgramAssemblerConstants.OFFICIAL);
169  9 clu.setOfficialIdentifier(official);
170   
171  9 clu.setDescr(progReq.getDescr());
172  9 clu.setState(!isEmpty(clu.getState()) ? clu.getState() : DtoConstants.STATE_ACTIVE);
173  9 if (progReq.getLearningObjectives() != null) {
174  9 disassembleLearningObjectives(progReq, operation, result);
175    }
176   
177  9 RefStatementRelationInfo relation;
178  9 if (operation == NodeOperation.CREATE) {
179  6 relation = new RefStatementRelationInfo();
180  6 relation.setId(UUIDHelper.genStringUUID(null));
181    } else {
182  3 try {
183  3 relation = statementService.getRefStatementRelationsByRef(ProgramAssemblerConstants.PROGRAM_REQUIREMENT, clu.getId()).get(0);
184    } catch (Exception e) {
185  0 throw new AssemblyException("Unable to find RefStatementRelation", e);
186    }
187    }
188    //relation.setType("clu.prerequisites"); // FIXME Derive from statement and rule types
189  9 relation.setType(ProgramAssemblerConstants.PROGRAM_REFERENCE_TYPE);
190  9 relation.setRefObjectId(clu.getId());
191  9 relation.setRefObjectTypeKey(ProgramAssemblerConstants.PROGRAM_REQUIREMENT);
192  9 relation.setStatementId(statement.getId());
193  9 relation.setState(DtoConstants.STATE_ACTIVE);
194   
195  9 BaseDTOAssemblyNode<ProgramRequirementInfo, RefStatementRelationInfo> relationNode = new BaseDTOAssemblyNode<ProgramRequirementInfo, RefStatementRelationInfo>(null);
196  9 relationNode.setNodeData(relation);
197  9 relationNode.setOperation(operation);
198   
199  9 result.getChildNodes().add(relationNode);
200  9 result.setBusinessDTORef(progReq);
201  9 result.setOperation(operation);
202  9 return result;
203    }
204   
 
205  9 toggle private void disassembleLearningObjectives(ProgramRequirementInfo progReq,
206    NodeOperation operation,
207    BaseDTOAssemblyNode<ProgramRequirementInfo, CluInfo> result) throws AssemblyException {
208  9 try {
209  9 List<BaseDTOAssemblyNode<?, ?>> loResults = cluAssemblerUtils.disassembleLos(progReq.getId(), progReq.getState(), progReq.getLearningObjectives(), operation);
210  9 if (loResults != null) {
211  9 result.getChildNodes().addAll(loResults);
212    }
213    } catch (DoesNotExistException e) {
214    } catch (Exception e) {
215  0 throw new AssemblyException("Error while disassembling los", e);
216    }
217    }
218   
 
219  9 toggle private void disassembleCredits(CluInfo clu, ProgramRequirementInfo progReq){
220  9 Map<String,String> attributes = null != clu.getAttributes() ? clu.getAttributes() : new HashMap<String,String>();
221   
222  9 if(progReq.getMinCredits() != null){
223  1 attributes.put(ProgramAssemblerConstants.MIN_CREDITS, Integer.toString(progReq.getMinCredits()));
224    }else{
225  8 attributes.put(ProgramAssemblerConstants.MIN_CREDITS, null);
226    }
227  9 if(progReq.getMaxCredits() != null) {
228  1 attributes.put(ProgramAssemblerConstants.MAX_CREDITS, Integer.toString(progReq.getMaxCredits()));
229    }else{
230  8 attributes.put(ProgramAssemblerConstants.MAX_CREDITS, null);
231    }
232   
233  9 clu.setAttributes(attributes);
234    }
235   
 
236  12 toggle private void assembleCredits(CluInfo clu, ProgramRequirementInfo progReq){
237  12 Map<String,String> attributes = clu.getAttributes();
238  12 if(attributes != null){
239  12 String minCredits = attributes.get(ProgramAssemblerConstants.MIN_CREDITS);
240  12 String maxCredits = attributes.get(ProgramAssemblerConstants.MAX_CREDITS);
241  12 progReq.setMinCredits(isEmpty(minCredits)?null:Integer.parseInt(minCredits));
242  12 progReq.setMaxCredits(isEmpty(maxCredits)?null:Integer.parseInt(maxCredits));
243    }
244    }
245   
 
246  0 toggle public StatementTreeViewAssembler getStatementTreeViewAssembler() {
247  0 return statementTreeViewAssembler;
248    }
249   
 
250  1 toggle public void setStatementTreeViewAssembler(
251    StatementTreeViewAssembler statementTreeViewAssembler) {
252  1 this.statementTreeViewAssembler = statementTreeViewAssembler;
253    }
254   
 
255  0 toggle public StatementService getStatementService() {
256  0 return statementService;
257    }
258   
 
259  1 toggle public void setStatementService(StatementService statementService) {
260  1 this.statementService = statementService;
261    }
262   
 
263  0 toggle public LearningObjectiveService getLoService() {
264  0 return loService;
265    }
266   
 
267  1 toggle public void setLoService(LearningObjectiveService loService) {
268  1 this.loService = loService;
269    }
270   
 
271  0 toggle public LuService getLuService() {
272  0 return luService;
273    }
274   
 
275  1 toggle public void setLuService(LuService luService) {
276  1 this.luService = luService;
277    }
278   
 
279  0 toggle public LoAssembler getLoAssembler() {
280  0 return loAssembler;
281    }
282   
 
283  1 toggle public void setLoAssembler(LoAssembler loAssembler) {
284  1 this.loAssembler = loAssembler;
285    }
286   
 
287  0 toggle public CluAssemblerUtils getCluAssemblerUtils() {
288  0 return cluAssemblerUtils;
289    }
290   
 
291  1 toggle public void setCluAssemblerUtils(CluAssemblerUtils cluAssemblerUtils) {
292  1 this.cluAssemblerUtils = cluAssemblerUtils;
293    }
294   
 
295  0 toggle public ProgramAssemblerUtils getProgramAssemblerUtils() {
296  0 return programAssemblerUtils;
297    }
298   
 
299  1 toggle public void setProgramAssemblerUtils(ProgramAssemblerUtils programAssemblerUtils) {
300  1 this.programAssemblerUtils = programAssemblerUtils;
301    }
302    }