Coverage Report - org.kuali.student.lum.lu.ui.course.server.gwt.CourseDataService
 
Classes in this File Line Coverage Branch Coverage Complexity
CourseDataService
0%
0/27
0%
0/8
2
 
 1  
 /**
 2  
  * Copyright 2010 The Kuali Foundation Licensed under the
 3  
  * Educational Community License, Version 2.0 (the "License"); you may
 4  
  * not use this file except in compliance with the License. You may
 5  
  * obtain a copy of the License at
 6  
  *
 7  
  * http://www.osedu.org/licenses/ECL-2.0
 8  
  *
 9  
  * Unless required by applicable law or agreed to in writing,
 10  
  * software distributed under the License is distributed on an "AS IS"
 11  
  * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 12  
  * or implied. See the License for the specific language governing
 13  
  * permissions and limitations under the License.
 14  
  */
 15  
 
 16  
 package org.kuali.student.lum.lu.ui.course.server.gwt;
 17  
 
 18  
 import java.util.Map;
 19  
 
 20  
 import org.apache.log4j.Logger;
 21  
 import org.kuali.student.common.ui.server.gwt.AbstractDataService;
 22  
 import org.kuali.student.core.assembly.data.Data;
 23  
 import org.kuali.student.core.assembly.transform.ProposalWorkflowFilter;
 24  
 import org.kuali.student.core.exceptions.DoesNotExistException;
 25  
 import org.kuali.student.core.exceptions.OperationFailedException;
 26  
 import org.kuali.student.lum.course.dto.CourseInfo;
 27  
 import org.kuali.student.lum.course.service.CourseService;
 28  
 
 29  0
 public class CourseDataService extends AbstractDataService {
 30  
 
 31  
         private static final long serialVersionUID = 1L;
 32  0
         final static Logger LOG = Logger.getLogger(CourseDataService.class);
 33  
 
 34  
         private static final String DEFAULT_METADATA_STATE = "draft";
 35  
         
 36  
         private CourseService courseService;
 37  
         
 38  
 
 39  
         @Override
 40  
         protected Object get(String id) throws Exception {
 41  0
                 CourseInfo courseInfo = null;
 42  
 
 43  
                 try {
 44  0
                         courseInfo = courseService.getCourse(id);
 45  0
                 } catch (DoesNotExistException dne) {
 46  0
                         LOG.info("Course not found for key " + id + ". Course loaded from proposal instead.");
 47  0
                 }                
 48  
                 
 49  0
                 return courseInfo; 
 50  
         }
 51  
 
 52  
         @Override
 53  
         protected Object save(Object dto, Map<String, Object> properties) throws Exception {
 54  0
                 CourseInfo courseInfo = (CourseInfo)dto;
 55  0
                 if(properties!=null&&"kuali.proposal.type.course.modify".equals((String)properties.get(ProposalWorkflowFilter.WORKFLOW_DOC_TYPE))){
 56  
                         //For Modify Course, see if we need to create a new version instead of create
 57  0
                         if(courseInfo.getId() == null){
 58  0
                                 courseInfo = courseService.createNewCourseVersion(courseInfo.getVersionInfo().getVersionIndId(), courseInfo.getVersionInfo().getVersionComment());
 59  
                         }else{
 60  0
                                 courseInfo = courseService.updateCourse(courseInfo);
 61  
                         }
 62  
                 }else{
 63  0
                         if (courseInfo.getId() == null){
 64  0
                                 courseInfo = courseService.createCourse(courseInfo);
 65  
                         } else {
 66  0
                                 courseInfo = courseService.updateCourse(courseInfo);
 67  
                         }
 68  
                 }
 69  0
                 return courseInfo;
 70  
         }
 71  
         
 72  
         @Override
 73  
         protected String getDefaultMetaDataState() {
 74  0
                 return DEFAULT_METADATA_STATE;
 75  
         }
 76  
 
 77  
         @Override
 78  
         protected String getDefaultWorkflowDocumentType() {
 79  0
                 return "kuali.proposal.type.course.create";
 80  
         }
 81  
 
 82  
         @Override
 83  
         protected boolean checkDocumentLevelPermissions() {
 84  0
                 return true;
 85  
         }
 86  
 
 87  
         @Override
 88  
         protected Class<?> getDtoClass() {
 89  0
                 return CourseInfo.class;
 90  
         }
 91  
 
 92  
         public void setCourseService(CourseService courseService) {
 93  0
                 this.courseService = courseService;
 94  0
         }
 95  
 
 96  
         public Data createNewCourseVersion(String courseId, String versionComment) throws OperationFailedException {
 97  
                 try {
 98  
                         //FIXME calling getData after createNewCourseVersion is inefficient, but we need to have the transformations/filters be applied
 99  0
                         CourseInfo course = this.courseService.createNewCourseVersion(courseId, versionComment);
 100  0
                         return getData(course.getId());
 101  0
                 } catch (Exception e) {
 102  0
                         throw new OperationFailedException("Error getting data",e);
 103  
                 } 
 104  
                 
 105  
         }        
 106  
 
 107  
 }