Coverage Report - org.kuali.student.lum.program.service.assembler.CoreProgramAssembler
 
Classes in this File Line Coverage Branch Coverage Complexity
CoreProgramAssembler
87%
48/55
75%
18/24
3.833
 
 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.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.exceptions.DoesNotExistException;
 26  
 import org.kuali.student.lum.course.service.assembler.CourseAssembler;
 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.CoreProgramInfo;
 30  
 import org.kuali.student.lum.service.assembler.CluAssemblerUtils;
 31  
 
 32  
 /**
 33  
  * @author KS
 34  
  *
 35  
  */
 36  16
 public class CoreProgramAssembler implements BOAssembler<CoreProgramInfo, CluInfo> {
 37  1
     final static Logger LOG = Logger.getLogger(CourseAssembler.class);
 38  
 
 39  
     private LuService luService;
 40  
     private ProgramAssemblerUtils programAssemblerUtils;
 41  
     private CluAssemblerUtils cluAssemblerUtils;
 42  
 
 43  
 
 44  
 
 45  
     @Override
 46  
     public CoreProgramInfo assemble(CluInfo clu, CoreProgramInfo coreProgram, boolean shallowBuild) throws AssemblyException {
 47  
 
 48  35
         CoreProgramInfo cpInfo = (null != coreProgram) ? coreProgram : new CoreProgramInfo();
 49  
 
 50  
         // Copy all the data from the clu to the coreprogram
 51  35
         programAssemblerUtils.assembleBasics(clu, cpInfo);
 52  35
         programAssemblerUtils.assembleIdentifiers(clu, cpInfo);
 53  35
         programAssemblerUtils.assembleBasicAdminOrgs(clu, cpInfo);
 54  35
         programAssemblerUtils.assembleAtps(clu, cpInfo);
 55  35
         programAssemblerUtils.assembleLuCodes(clu, cpInfo);
 56  35
         programAssemblerUtils.assemblePublications(clu, cpInfo);
 57  
 
 58  35
         cpInfo.setDescr(clu.getDescr());
 59  35
         cpInfo.setVersionInfo(clu.getVersionInfo());
 60  
         
 61  35
         if (!shallowBuild) {
 62  18
                 programAssemblerUtils.assembleRequirements(clu, cpInfo);
 63  18
                 cpInfo.setLearningObjectives(cluAssemblerUtils.assembleLos(clu.getId(), shallowBuild));
 64  
         }
 65  
         
 66  35
         return cpInfo;
 67  
     }
 68  
 
 69  
     @Override
 70  
     public BaseDTOAssemblyNode<CoreProgramInfo, CluInfo> disassemble(CoreProgramInfo core, NodeOperation operation) throws AssemblyException {
 71  15
             BaseDTOAssemblyNode<CoreProgramInfo, CluInfo> result = new BaseDTOAssemblyNode<CoreProgramInfo, CluInfo>(this);
 72  
             
 73  15
             if (core == null) {
 74  
                         // FIXME Unsure now if this is an exception or just return null or
 75  
                         // empty assemblyNode
 76  0
                     LOG.error("CoreProgram to disassemble is null!");
 77  0
                         throw new AssemblyException("CoreProgram can not be null");
 78  
                 }
 79  
 
 80  
                 CluInfo clu;
 81  
                 try {
 82  15
                         clu = (NodeOperation.UPDATE == operation) ? luService.getClu(core.getId()) : new CluInfo();
 83  0
         } catch (Exception e) {
 84  0
                         throw new AssemblyException("Error getting existing learning unit during CoreProgram update", e);
 85  15
         } 
 86  
         
 87  15
         boolean stateChanged = NodeOperation.UPDATE == operation && core.getState() != null && !core.getState().equals(core.getState());
 88  
         
 89  15
         programAssemblerUtils.disassembleBasics(clu, core);
 90  15
         if (core.getId() == null)
 91  6
                 core.setId(clu.getId());
 92  15
         programAssemblerUtils.disassembleIdentifiers(clu, core, operation);
 93  15
         programAssemblerUtils.disassembleAdminOrgs(clu, core, operation);
 94  15
         programAssemblerUtils.disassembleAtps(clu, core, operation);    
 95  15
         programAssemblerUtils.disassembleLuCodes(clu, core, operation);
 96  15
         programAssemblerUtils.disassemblePublications(clu, core, operation, result);
 97  
         
 98  15
         if(core.getProgramRequirements() != null && !core.getProgramRequirements().isEmpty()) {
 99  5
                 programAssemblerUtils.disassembleRequirements(clu, core, operation, result, stateChanged);
 100  
         }
 101  
         
 102  15
         if (core.getLearningObjectives() != null) {
 103  15
             disassembleLearningObjectives(core, operation, result);
 104  
         }
 105  
         
 106  15
         clu.setDescr(core.getDescr());
 107  
         
 108  
                 // Add the Clu to the result
 109  15
                 result.setNodeData(clu);
 110  15
                 result.setOperation(operation);
 111  15
                 result.setBusinessDTORef(core);
 112  15
                 return result;
 113  
 
 114  
     }
 115  
 
 116  
     private void disassembleLearningObjectives(CoreProgramInfo core, NodeOperation operation, BaseDTOAssemblyNode<CoreProgramInfo, CluInfo> result) throws AssemblyException {
 117  
         try {
 118  15
             List<BaseDTOAssemblyNode<?, ?>> loResults = cluAssemblerUtils.disassembleLos(core.getId(), core.getState(),  core.getLearningObjectives(), operation);
 119  15
             if (loResults != null) {
 120  15
                 result.getChildNodes().addAll(loResults);
 121  
             }
 122  0
         } catch (DoesNotExistException e) {
 123  0
         } catch (Exception e) {
 124  0
             throw new AssemblyException("Error while disassembling los", e);
 125  15
         }
 126  15
     }
 127  
     
 128  
     // Spring setter
 129  
     public void setLuService(LuService luService) {
 130  1
         this.luService = luService;
 131  1
     }
 132  
 
 133  
     public void setProgramAssemblerUtils(ProgramAssemblerUtils programAssemblerUtils) {
 134  1
         this.programAssemblerUtils = programAssemblerUtils;
 135  1
     }
 136  
 
 137  
     public void setCluAssemblerUtils(CluAssemblerUtils cluAssemblerUtils) {
 138  1
         this.cluAssemblerUtils = cluAssemblerUtils;
 139  1
     }
 140  
 }