1 package org.kuali.student.enrollment.class2.courseoffering.service.impl;
2
3 import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
4 import org.kuali.rice.krad.maintenance.MaintainableImpl;
5 import org.kuali.rice.krad.maintenance.MaintenanceDocument;
6 import org.kuali.rice.krad.util.KRADConstants;
7 import org.kuali.student.r2.common.util.ContextUtils;
8 import org.kuali.student.r2.core.class1.type.service.TypeService;
9 import org.kuali.student.r2.core.constants.FeeServiceConstants;
10 import org.kuali.student.r2.core.constants.TypeServiceConstants;
11 import org.kuali.student.r2.core.fee.dto.EnrollmentFeeInfo;
12 import org.kuali.student.r2.core.fee.service.FeeService;
13
14 import javax.xml.namespace.QName;
15 import java.util.Map;
16
17 public class EnrollmentFeeInfoMaintainableImpl extends MaintainableImpl {
18 private static final long serialVersionUID = 1L;
19
20 private transient TypeService typeService;
21
22 private FeeService feeService;
23
24
25 @Override
26 public void prepareForSave() {
27 System.out.println("This is prepareForSave");
28 }
29
30
31 @Override
32 public void saveDataObject() {
33 if(getMaintenanceAction().equals(KRADConstants.MAINTENANCE_NEW_ACTION) ||
34 getMaintenanceAction().equals(KRADConstants.MAINTENANCE_COPY_ACTION)) {
35 try {
36
37 EnrollmentFeeInfo efi = (EnrollmentFeeInfo) getDataObject();
38 efi.setTypeKey(FeeServiceConstants.FEE_ENROLLMENT_TYPE_KEY);
39 efi.setStateKey(FeeServiceConstants.FEE_ACTIVE_STATE_KEY);
40 EnrollmentFeeInfo feeInfo = getFeeService().createFee(efi.getTypeKey(), efi, ContextUtils.createDefaultContextInfo() );
41
42 setDataObject(new EnrollmentFeeInfo(feeInfo));
43 } catch (Exception e) {
44 throw new RuntimeException(e);
45 }
46 }
47 else {
48 EnrollmentFeeInfo efi = (EnrollmentFeeInfo) getDataObject();
49 try {
50 getFeeService().updateFee(efi.getId(), efi, ContextUtils.createDefaultContextInfo());
51 } catch (Exception e) {
52 throw new RuntimeException("Error updating Fee", e);
53 }
54 }
55 }
56
57 @Override
58 public Object retrieveObjectForEditOrCopy(MaintenanceDocument document, Map<String, String> dataObjectKeys) {
59 try {
60 EnrollmentFeeInfo efi = getFeeService().getFee(dataObjectKeys.get("id"), ContextUtils.createDefaultContextInfo());
61 document.getNewMaintainableObject().setDataObject(efi);
62 document.getOldMaintainableObject().setDataObject(efi);
63
64
65 return efi;
66 } catch (Exception e) {
67 throw new RuntimeException(e);
68 }
69 }
70
71 @Override
72 public void processAfterNew(MaintenanceDocument document, Map<String, String[]> requestParameters) {
73
74
75 document.getDocumentHeader().setDocumentDescription("Activity Offering");
76
77
78
79
80
81
82 }
83
84 public TypeService getTypeService() {
85 if(typeService == null) {
86 typeService = (TypeService) GlobalResourceLoader.getService(new QName(TypeServiceConstants.NAMESPACE, TypeServiceConstants.SERVICE_NAME_LOCAL_PART));
87 }
88 return this.typeService;
89 }
90
91 protected FeeService getFeeService() {
92 if (feeService == null) {
93 feeService = (FeeService) GlobalResourceLoader.getService(new QName(FeeServiceConstants.NAMESPACE, FeeServiceConstants.SERVICE_NAME_LOCAL_PART));
94 }
95 return feeService;
96 }
97 }