Coverage Report - org.kuali.student.lum.course.service.assembler.CourseJointAssembler
 
Classes in this File Line Coverage Branch Coverage Complexity
CourseJointAssembler
6%
3/43
0%
0/10
3.4
 
 1  
 /*
 2  
  * Copyright 2008 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.course.service.assembler;
 17  
 
 18  
 import org.kuali.student.common.assembly.BOAssembler;
 19  
 import org.kuali.student.common.assembly.BaseDTOAssemblyNode;
 20  
 import org.kuali.student.common.assembly.BaseDTOAssemblyNode.NodeOperation;
 21  
 import org.kuali.student.common.assembly.data.AssemblyException;
 22  
 import org.kuali.student.common.util.UUIDHelper;
 23  
 import org.kuali.student.lum.course.dto.CourseJointInfo;
 24  
 import org.kuali.student.lum.lu.dto.CluCluRelationInfo;
 25  
 import org.kuali.student.lum.lu.dto.CluInfo;
 26  
 import org.kuali.student.lum.lu.service.LuService;
 27  
 
 28  
 /**
 29  
  * Assembles/Disassembles CourseJointInfo DTO from/to CluCluRelationInfo 
 30  
  * 
 31  
  * @author Kuali Student Team
 32  
  *
 33  
  */
 34  1
 public class CourseJointAssembler implements BOAssembler<CourseJointInfo, CluCluRelationInfo> {
 35  
                 
 36  
         LuService luService;                
 37  
         
 38  
         /**
 39  
          * @return the luService
 40  
          */
 41  
         public LuService getLuService() {
 42  0
                 return luService;
 43  
         }
 44  
 
 45  
         /**
 46  
          * @param luService the luService to set
 47  
          */
 48  
         public void setLuService(LuService luService) {
 49  1
                 this.luService = luService;
 50  1
         }
 51  
 
 52  
         @Override
 53  
         public CourseJointInfo assemble(CluCluRelationInfo cluRel, CourseJointInfo jointInfo, boolean shallowBuild) throws AssemblyException {
 54  0
                 if(null == cluRel) {
 55  0
                         return null;
 56  
                 }
 57  
                 
 58  0
                 CourseJointInfo joint = (jointInfo != null) ? jointInfo : new CourseJointInfo();
 59  
 
 60  
                 CluInfo clu;
 61  
                 try {
 62  0
                         clu = luService.getClu(cluRel.getRelatedCluId());
 63  
 
 64  0
                         joint.setCourseId(clu.getId());
 65  0
                         joint.setType(clu.getType());//FIXME is this ever used?
 66  0
                         joint.setSubjectArea(clu.getOfficialIdentifier().getDivision());
 67  0
                         joint.setCourseTitle(clu.getOfficialIdentifier().getLongName());
 68  0
                         joint.setCourseNumberSuffix(clu.getOfficialIdentifier().getSuffixCode());
 69  0
                         joint.setRelationId(cluRel.getId());
 70  
 
 71  0
                 } catch (Exception e) {
 72  0
                         throw new AssemblyException("Error getting related clus", e);
 73  0
                 } 
 74  
                 
 75  0
                 return joint;
 76  
         }
 77  
 
 78  
         public CourseJointInfo assemble(CluCluRelationInfo cluRel, String cluId, CourseJointInfo jointInfo, boolean shallowBuild) throws AssemblyException {
 79  0
                 if(null == cluRel) {
 80  0
                         return null;
 81  
                 }
 82  
                 
 83  0
                 CourseJointInfo joint = (jointInfo != null) ? jointInfo : new CourseJointInfo();
 84  
 
 85  
                 CluInfo clu;
 86  
                 try {
 87  0
                         clu = luService.getClu(cluId);
 88  
                         
 89  0
                         joint.setCourseId(clu.getId());
 90  0
                         joint.setType(clu.getType());
 91  0
                         joint.setSubjectArea(clu.getOfficialIdentifier().getDivision());
 92  0
                         joint.setCourseTitle(clu.getOfficialIdentifier().getLongName());
 93  0
                         joint.setCourseNumberSuffix(clu.getOfficialIdentifier().getSuffixCode());
 94  0
                         joint.setRelationId(cluRel.getId());
 95  
                         
 96  0
                 } catch (Exception e) {
 97  0
                         throw new AssemblyException("Error getting related clus", e);
 98  0
                 } 
 99  
                 
 100  0
                 return joint;
 101  
         }
 102  
 
 103  
         @Override
 104  
         public BaseDTOAssemblyNode<CourseJointInfo, CluCluRelationInfo> disassemble(
 105  
                         CourseJointInfo joint, NodeOperation operation) throws AssemblyException {
 106  
                 
 107  0
                 if(null == joint){
 108  
                         //FIXME Unsure now if this is an exception or just return null or empty assemblyNode 
 109  0
                         throw new AssemblyException("Activity can not be null");
 110  
                 }
 111  
                                 
 112  0
                 BaseDTOAssemblyNode<CourseJointInfo, CluCluRelationInfo> result = new BaseDTOAssemblyNode<CourseJointInfo, CluCluRelationInfo>(this);
 113  0
                 result.setBusinessDTORef(joint);
 114  0
                 result.setOperation(operation);
 115  
                 
 116  0
                 CluCluRelationInfo cluRel = new CluCluRelationInfo();
 117  0
                 cluRel.setId(UUIDHelper.genStringUUID(joint.getRelationId()));
 118  0
                 cluRel.setRelatedCluId(joint.getCourseId());
 119  0
                 cluRel.setType(CourseAssemblerConstants.JOINT_RELATION_TYPE);
 120  0
                 result.setNodeData(cluRel);
 121  
                 // The caller is required to set the CluId on the cluCluRelation
 122  
                 
 123  0
                 return result;
 124  
         }
 125  
 }