1 package org.kuali.student.enrollment.class2.courseoffering.service.impl;
2
3 import org.kuali.rice.krad.maintenance.MaintainableImpl;
4 import org.kuali.rice.krad.maintenance.MaintenanceDocument;
5 import org.kuali.rice.krad.util.KRADConstants;
6 import org.kuali.student.enrollment.class2.courseoffering.util.CourseOfferingManagementUtil;
7 import org.kuali.student.r2.common.util.ContextUtils;
8 import org.kuali.student.r2.core.constants.FeeServiceConstants;
9 import org.kuali.student.r2.core.fee.dto.EnrollmentFeeInfo;
10
11 import javax.xml.namespace.QName;
12 import java.util.Map;
13
14 public class EnrollmentFeeInfoMaintainableImpl extends MaintainableImpl {
15 private static final long serialVersionUID = 1L;
16
17 @Override
18 public void prepareForSave() {
19 System.out.println("This is prepareForSave");
20 }
21
22 @Override
23 public void saveDataObject() {
24 if(getMaintenanceAction().equals(KRADConstants.MAINTENANCE_NEW_ACTION) ||
25 getMaintenanceAction().equals(KRADConstants.MAINTENANCE_COPY_ACTION)) {
26 try {
27
28 EnrollmentFeeInfo efi = (EnrollmentFeeInfo) getDataObject();
29 efi.setTypeKey(FeeServiceConstants.FEE_ENROLLMENT_TYPE_KEY);
30 efi.setStateKey(FeeServiceConstants.FEE_ACTIVE_STATE_KEY);
31 EnrollmentFeeInfo feeInfo = CourseOfferingManagementUtil.getFeeService().createFee(efi.getTypeKey(), efi, ContextUtils.createDefaultContextInfo() );
32
33 setDataObject(new EnrollmentFeeInfo(feeInfo));
34 } catch (Exception e) {
35 throw new RuntimeException(e);
36 }
37 }
38 else {
39 EnrollmentFeeInfo efi = (EnrollmentFeeInfo) getDataObject();
40 try {
41 CourseOfferingManagementUtil.getFeeService().updateFee(efi.getId(), efi, ContextUtils.createDefaultContextInfo());
42 } catch (Exception e) {
43 throw new RuntimeException("Error updating Fee", e);
44 }
45 }
46 }
47
48 @Override
49 public Object retrieveObjectForEditOrCopy(MaintenanceDocument document, Map<String, String> dataObjectKeys) {
50 try {
51 EnrollmentFeeInfo efi = CourseOfferingManagementUtil.getFeeService().getFee(dataObjectKeys.get("id"), ContextUtils.createDefaultContextInfo());
52 document.getNewMaintainableObject().setDataObject(efi);
53 document.getOldMaintainableObject().setDataObject(efi);
54 return efi;
55 } catch (Exception e) {
56 throw new RuntimeException(e);
57 }
58 }
59
60 @Override
61 public void processAfterNew(MaintenanceDocument document, Map<String, String[]> requestParameters) {
62 document.getDocumentHeader().setDocumentDescription("Activity Offering");
63 }
64 }