1
2
3
4
5
6
7
8
9
10
11
12
13
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
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
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 }