Coverage Report - org.kuali.student.lum.course.service.assembler.ActivityAssembler
 
Classes in this File Line Coverage Branch Coverage Complexity
ActivityAssembler
0%
0/37
0%
0/12
3.75
 
 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.ActivityInfo;
 24  
 import org.kuali.student.lum.lu.dto.CluInfo;
 25  
 import org.kuali.student.lum.lu.service.LuService;
 26  
 
 27  
 /**
 28  
  * Assembles/Disassembles ActivityInfo DTO from/To CluInfo 
 29  
  * 
 30  
  * @author Kuali Student Team
 31  
  *
 32  
  */
 33  0
 public class ActivityAssembler implements BOAssembler<ActivityInfo, CluInfo> {
 34  
 
 35  
     private LuService luService;
 36  
     
 37  
         @Override
 38  
         public ActivityInfo assemble(CluInfo clu, ActivityInfo activity, boolean shallowBuild) {
 39  0
                 if(clu == null){
 40  0
                         return null;
 41  
                 }
 42  
                 
 43  0
                 ActivityInfo activityInfo = (null != activity) ? activity : new ActivityInfo();
 44  
             
 45  0
                 activityInfo.setId(clu.getId());
 46  0
                 activityInfo.setActivityType(clu.getType());
 47  0
                 activityInfo.setState(clu.getState());
 48  0
                 activityInfo.setDefaultEnrollmentEstimate(clu.getDefaultEnrollmentEstimate());
 49  0
                 activityInfo.setDuration(clu.getStdDuration());
 50  0
                 activityInfo.setContactHours(clu.getIntensity());
 51  0
                 activityInfo.setMetaInfo(clu.getMetaInfo());
 52  0
         activityInfo.setAttributes(clu.getAttributes());
 53  0
                 return activityInfo;
 54  
         }
 55  
 
 56  
         @Override
 57  
         public BaseDTOAssemblyNode<ActivityInfo,CluInfo> disassemble(
 58  
                         ActivityInfo activity, NodeOperation operation) throws AssemblyException {
 59  0
                 if (activity==null) {
 60  
                         //FIXME Unsure now if this is an exception or just return null or empty assemblyNode 
 61  0
                         throw new AssemblyException("Activity can not be null");
 62  
                 }
 63  0
                 if (NodeOperation.CREATE != operation && null == activity.getId()) {
 64  0
                         throw new AssemblyException("Activity's id can not be null");
 65  
                 }
 66  
                 
 67  0
                 BaseDTOAssemblyNode<ActivityInfo,CluInfo> result = new BaseDTOAssemblyNode<ActivityInfo,CluInfo>(this);
 68  
                 
 69  
                 CluInfo clu;
 70  
         try {
 71  0
             clu = (NodeOperation.UPDATE == operation) ? luService.getClu(activity.getId()) : new CluInfo();
 72  0
         } catch (Exception e) {
 73  0
             throw new AssemblyException("Error retrieving activity learning unit during update", e);
 74  0
         }
 75  
         
 76  
                 //Copy all fields 
 77  0
                 clu.setId(UUIDHelper.genStringUUID(activity.getId()));//Create the id if it's not there already(important for creating relations)
 78  0
                 clu.setType(activity.getActivityType());
 79  0
                 clu.setState(activity.getState());
 80  0
                 clu.setDefaultEnrollmentEstimate(activity.getDefaultEnrollmentEstimate());
 81  0
                 clu.setStdDuration(activity.getDuration());
 82  0
                 clu.setIntensity(activity.getContactHours());
 83  0
                 clu.setMetaInfo(activity.getMetaInfo());
 84  0
                 clu.setAttributes(activity.getAttributes());
 85  
                                 
 86  
                 //Add the Clu to the result 
 87  0
                 result.setNodeData(clu);
 88  
 
 89  
                 // Add refernce to Activity
 90  0
                 result.setBusinessDTORef(activity);
 91  
                 
 92  0
                 result.setOperation(operation);
 93  
 
 94  0
                 return result;
 95  
         }
 96  
 
 97  
     public void setLuService(LuService luService) {
 98  0
         this.luService = luService;
 99  0
     }
 100  
 
 101  
     public LuService getLuService() {
 102  0
         return luService;
 103  
     }
 104  
 }