| 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 | 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 | |
|
| 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 | |
|
| 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 | |
} |