| 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.assembly.data.Data; |
| 22 | |
import org.kuali.student.common.dto.DtoConstants; |
| 23 | |
import org.kuali.student.common.exceptions.DoesNotExistException; |
| 24 | |
import org.kuali.student.common.exceptions.OperationFailedException; |
| 25 | |
import org.kuali.student.common.ui.server.gwt.AbstractDataService; |
| 26 | |
import org.kuali.student.core.assembly.transform.ProposalWorkflowFilter; |
| 27 | |
import org.kuali.student.lum.course.dto.CourseCrossListingInfo; |
| 28 | |
import org.kuali.student.lum.course.dto.CourseInfo; |
| 29 | |
import org.kuali.student.lum.course.service.CourseService; |
| 30 | |
import org.springframework.util.StringUtils; |
| 31 | |
|
| 32 | 0 | public class CourseDataService extends AbstractDataService { |
| 33 | |
|
| 34 | |
private static final long serialVersionUID = 1L; |
| 35 | 0 | final static Logger LOG = Logger.getLogger(CourseDataService.class); |
| 36 | |
|
| 37 | |
private static final String DEFAULT_METADATA_STATE = DtoConstants.STATE_DRAFT; |
| 38 | |
|
| 39 | |
private CourseService courseService; |
| 40 | |
|
| 41 | |
|
| 42 | |
@Override |
| 43 | |
protected Object get(String id) throws Exception { |
| 44 | 0 | CourseInfo courseInfo = null; |
| 45 | |
|
| 46 | |
try { |
| 47 | 0 | courseInfo = courseService.getCourse(id); |
| 48 | 0 | } catch (DoesNotExistException dne) { |
| 49 | 0 | LOG.info("Course not found for key " + id + ". Course loaded from proposal instead."); |
| 50 | 0 | } |
| 51 | |
|
| 52 | 0 | return courseInfo; |
| 53 | |
} |
| 54 | |
|
| 55 | |
@Override |
| 56 | |
protected Object save(Object dto, Map<String, Object> properties) throws Exception { |
| 57 | 0 | CourseInfo courseInfo = (CourseInfo)dto; |
| 58 | |
|
| 59 | |
|
| 60 | 0 | courseInfo = calculateCourseDerivedFields(courseInfo); |
| 61 | |
|
| 62 | 0 | if(properties!=null&&"kuali.proposal.type.course.modify".equals((String)properties.get(ProposalWorkflowFilter.WORKFLOW_DOC_TYPE))){ |
| 63 | |
|
| 64 | 0 | if(courseInfo.getId() == null){ |
| 65 | 0 | courseInfo = courseService.createNewCourseVersion(courseInfo.getVersionInfo().getVersionIndId(), courseInfo.getVersionInfo().getVersionComment()); |
| 66 | |
}else{ |
| 67 | 0 | courseInfo = courseService.updateCourse(courseInfo); |
| 68 | |
} |
| 69 | |
}else{ |
| 70 | 0 | if (courseInfo.getId() == null){ |
| 71 | 0 | courseInfo = courseService.createCourse(courseInfo); |
| 72 | |
} else { |
| 73 | 0 | courseInfo = courseService.updateCourse(courseInfo); |
| 74 | |
} |
| 75 | |
} |
| 76 | 0 | return courseInfo; |
| 77 | |
} |
| 78 | |
|
| 79 | |
@Override |
| 80 | |
protected String getDefaultMetaDataState() { |
| 81 | 0 | return DEFAULT_METADATA_STATE; |
| 82 | |
} |
| 83 | |
|
| 84 | |
@Override |
| 85 | |
protected String getDefaultWorkflowDocumentType() { |
| 86 | 0 | return "kuali.proposal.type.course.create"; |
| 87 | |
} |
| 88 | |
|
| 89 | |
@Override |
| 90 | |
protected boolean checkDocumentLevelPermissions() { |
| 91 | 0 | return true; |
| 92 | |
} |
| 93 | |
|
| 94 | |
@Override |
| 95 | |
protected Class<?> getDtoClass() { |
| 96 | 0 | return CourseInfo.class; |
| 97 | |
} |
| 98 | |
|
| 99 | |
public void setCourseService(CourseService courseService) { |
| 100 | 0 | this.courseService = courseService; |
| 101 | 0 | } |
| 102 | |
|
| 103 | |
public Data createNewCourseVersion(String courseId, String versionComment) throws OperationFailedException { |
| 104 | |
try { |
| 105 | |
|
| 106 | 0 | CourseInfo course = this.courseService.createNewCourseVersion(courseId, versionComment); |
| 107 | 0 | return getData(course.getId()); |
| 108 | 0 | } catch (Exception e) { |
| 109 | 0 | throw new OperationFailedException("Error getting data",e); |
| 110 | |
} |
| 111 | |
|
| 112 | |
} |
| 113 | |
|
| 114 | |
|
| 115 | |
|
| 116 | |
|
| 117 | |
|
| 118 | |
protected CourseInfo calculateCourseDerivedFields(CourseInfo courseInfo){ |
| 119 | |
|
| 120 | 0 | if(StringUtils.hasText(courseInfo.getCourseNumberSuffix()) && StringUtils.hasText(courseInfo.getSubjectArea())){ |
| 121 | 0 | courseInfo.setCode(calculateCourseCode(courseInfo.getSubjectArea(),courseInfo.getCourseNumberSuffix())); |
| 122 | |
} |
| 123 | |
|
| 124 | |
|
| 125 | 0 | for(CourseCrossListingInfo crossListing:courseInfo.getCrossListings()){ |
| 126 | 0 | if(StringUtils.hasText(crossListing.getCourseNumberSuffix()) && StringUtils.hasText(crossListing.getSubjectArea())){ |
| 127 | 0 | crossListing.setCode(calculateCourseCode(crossListing.getSubjectArea(), crossListing.getCourseNumberSuffix())); |
| 128 | |
} |
| 129 | |
} |
| 130 | |
|
| 131 | 0 | return courseInfo; |
| 132 | |
} |
| 133 | |
|
| 134 | |
|
| 135 | |
|
| 136 | |
|
| 137 | |
|
| 138 | |
|
| 139 | |
|
| 140 | |
|
| 141 | |
|
| 142 | |
private String calculateCourseCode(String subjectArea, String suffixNumber) { |
| 143 | 0 | return subjectArea + suffixNumber; |
| 144 | |
} |
| 145 | |
|
| 146 | |
} |