View Javadoc

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  public class CourseDataService extends AbstractDataService {
30  
31  	private static final long serialVersionUID = 1L;
32  	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  		CourseInfo courseInfo = null;
42  
43  		try {
44  			courseInfo = courseService.getCourse(id);
45  		} catch (DoesNotExistException dne) {
46  			LOG.info("Course not found for key " + id + ". Course loaded from proposal instead.");
47  		}		
48  		
49  		return courseInfo; 
50  	}
51  
52  	@Override
53  	protected Object save(Object dto, Map<String, Object> properties) throws Exception {
54  		CourseInfo courseInfo = (CourseInfo)dto;
55  		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  			if(courseInfo.getId() == null){
58  				courseInfo = courseService.createNewCourseVersion(courseInfo.getVersionInfo().getVersionIndId(), courseInfo.getVersionInfo().getVersionComment());
59  			}else{
60  				courseInfo = courseService.updateCourse(courseInfo);
61  			}
62  		}else{
63  			if (courseInfo.getId() == null){
64  				courseInfo = courseService.createCourse(courseInfo);
65  			} else {
66  				courseInfo = courseService.updateCourse(courseInfo);
67  			}
68  		}
69  		return courseInfo;
70  	}
71  	
72  	@Override
73  	protected String getDefaultMetaDataState() {
74  		return DEFAULT_METADATA_STATE;
75  	}
76  
77  	@Override
78  	protected String getDefaultWorkflowDocumentType() {
79  		return "kuali.proposal.type.course.create";
80  	}
81  
82  	@Override
83  	protected boolean checkDocumentLevelPermissions() {
84  		return true;
85  	}
86  
87  	@Override
88  	protected Class<?> getDtoClass() {
89  		return CourseInfo.class;
90  	}
91  
92  	public void setCourseService(CourseService courseService) {
93  		this.courseService = courseService;
94  	}
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  			CourseInfo course = this.courseService.createNewCourseVersion(courseId, versionComment);
100 			return getData(course.getId());
101 		} catch (Exception e) {
102 			throw new OperationFailedException("Error getting data",e);
103 		} 
104 		
105 	}	
106 
107 }