1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
package org.kuali.student.enrollment.class2.courseoffering.service.impl; |
18 | |
|
19 | |
import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader; |
20 | |
import org.kuali.rice.krad.maintenance.MaintainableImpl; |
21 | |
import org.kuali.rice.krad.maintenance.MaintenanceDocument; |
22 | |
import org.kuali.rice.krad.util.GlobalVariables; |
23 | |
import org.kuali.rice.krad.util.KRADConstants; |
24 | |
import org.kuali.student.enrollment.class2.courseoffering.dto.FormatOfferingInfoFormObject; |
25 | |
import org.kuali.student.enrollment.courseoffering.dto.FormatOfferingInfo; |
26 | |
import org.kuali.student.enrollment.courseoffering.service.CourseOfferingService; |
27 | |
import org.kuali.student.r2.common.dto.ContextInfo; |
28 | |
import org.kuali.student.r2.common.dto.LocaleInfo; |
29 | |
import org.kuali.student.r2.common.exceptions.*; |
30 | |
import org.kuali.student.r2.common.util.constants.AtpServiceConstants; |
31 | |
import org.kuali.student.r2.common.util.constants.CourseOfferingServiceConstants; |
32 | |
import org.kuali.student.r2.common.util.constants.LuiServiceConstants; |
33 | |
import org.kuali.student.r2.core.state.service.StateService; |
34 | |
import org.kuali.student.r2.core.type.service.TypeService; |
35 | |
|
36 | |
import javax.xml.namespace.QName; |
37 | |
import java.util.Locale; |
38 | |
import java.util.Map; |
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | 0 | public class FormatOfferingInfoMaintainableImpl extends MaintainableImpl { |
46 | |
private static final long serialVersionUID = 1L; |
47 | |
|
48 | |
private static final String DEFAULT_DOCUMENT_DESC_FOR_CREATING_FORMAT_OFFERING = |
49 | |
"Create a new Format offering"; |
50 | |
private static final String DEFAULT_DOCUMENT_DESC_FOR_EDITING_FORMAT_OFFERING = |
51 | |
"Edit an existing Format offering"; |
52 | |
private static final String DEFAULT_DOCUMENT_DESC_FOR_COPYING_FORMAT_OFFERING = |
53 | |
"Copy from an existing Format offering to create a new one"; |
54 | |
|
55 | |
private transient CourseOfferingService courseOfferingService; |
56 | |
private ContextInfo contextInfo; |
57 | |
|
58 | |
@Override |
59 | |
public void saveDataObject() { |
60 | 0 | FormatOfferingInfo formatOfferingInfoMaintenance = (FormatOfferingInfo) getDataObject(); |
61 | 0 | if(getMaintenanceAction().equals(KRADConstants.MAINTENANCE_NEW_ACTION) || |
62 | |
getMaintenanceAction().equals(KRADConstants.MAINTENANCE_COPY_ACTION)) { |
63 | |
try { |
64 | 0 | FormatOfferingInfo formatOfferingInfoCreated = getCourseOfferingService().createFormatOffering(formatOfferingInfoMaintenance.getCourseOfferingId(), formatOfferingInfoMaintenance.getFormatId(), |
65 | |
LuiServiceConstants.FORMAT_OFFERING_TYPE_KEY, formatOfferingInfoMaintenance, getContextInfo()); |
66 | 0 | setDataObject(new FormatOfferingInfo(formatOfferingInfoCreated)); |
67 | 0 | } catch (Exception e) { |
68 | 0 | throw new RuntimeException(e); |
69 | 0 | } |
70 | |
} |
71 | |
else { |
72 | |
try { |
73 | 0 | FormatOfferingInfo formatOfferingInfoUpdated = getCourseOfferingService().updateFormatOffering(formatOfferingInfoMaintenance.getId(), formatOfferingInfoMaintenance, getContextInfo()); |
74 | 0 | } catch (Exception e) { |
75 | 0 | throw new RuntimeException(e); |
76 | 0 | } |
77 | |
} |
78 | 0 | } |
79 | |
|
80 | |
|
81 | |
|
82 | |
|
83 | |
@Override |
84 | |
public void prepareForSave() { |
85 | 0 | System.out.println (">>> in prepareForSave "); |
86 | 0 | if (getMaintenanceAction().equalsIgnoreCase(KRADConstants.MAINTENANCE_NEW_ACTION)) { |
87 | 0 | FormatOfferingInfo formatOfferingInfoMaintenance = (FormatOfferingInfo) getDataObject(); |
88 | 0 | formatOfferingInfoMaintenance.setTypeKey("kuali.atp.type.FormatOfferingInfo"); |
89 | 0 | formatOfferingInfoMaintenance.setStateKey(AtpServiceConstants.ATP_OFFICIAL_STATE_KEY); |
90 | |
} |
91 | 0 | super.prepareForSave(); |
92 | 0 | } |
93 | |
|
94 | |
@Override |
95 | |
public Object retrieveObjectForEditOrCopy(MaintenanceDocument document, Map<String, String> dataObjectKeys) { |
96 | |
try { |
97 | 0 | FormatOfferingInfo info = getCourseOfferingService().getFormatOffering(dataObjectKeys.get("formatOfferingInfo.id"), getContextInfo()); |
98 | 0 | FormatOfferingInfoFormObject formObject = new FormatOfferingInfoFormObject(info); |
99 | 0 | document.getNewMaintainableObject().setDataObject(formObject); |
100 | 0 | document.getOldMaintainableObject().setDataObject(formObject); |
101 | |
|
102 | |
|
103 | 0 | return formObject; |
104 | 0 | } catch (Exception e) { |
105 | 0 | throw new RuntimeException(e); |
106 | |
} |
107 | |
} |
108 | |
|
109 | |
|
110 | |
|
111 | |
|
112 | |
@Override |
113 | |
public void processAfterCopy(MaintenanceDocument document, Map<String, String[]> requestParameters) { |
114 | |
|
115 | 0 | document.getDocumentHeader().setDocumentDescription(DEFAULT_DOCUMENT_DESC_FOR_COPYING_FORMAT_OFFERING); |
116 | 0 | } |
117 | |
|
118 | |
|
119 | |
|
120 | |
|
121 | |
@Override |
122 | |
public void processAfterEdit(MaintenanceDocument document, Map<String, String[]> requestParameters) { |
123 | |
|
124 | 0 | document.getDocumentHeader().setDocumentDescription(DEFAULT_DOCUMENT_DESC_FOR_EDITING_FORMAT_OFFERING); |
125 | |
|
126 | 0 | } |
127 | |
|
128 | |
|
129 | |
|
130 | |
|
131 | |
@Override |
132 | |
public void processAfterNew(MaintenanceDocument document, Map<String, String[]> requestParameters) { |
133 | |
|
134 | 0 | document.getDocumentHeader().setDocumentDescription(DEFAULT_DOCUMENT_DESC_FOR_CREATING_FORMAT_OFFERING); |
135 | |
|
136 | 0 | } |
137 | |
|
138 | |
public ContextInfo getContextInfo() { |
139 | 0 | if (null == contextInfo) { |
140 | 0 | contextInfo = new ContextInfo(); |
141 | 0 | contextInfo.setAuthenticatedPrincipalId(GlobalVariables.getUserSession().getPrincipalId()); |
142 | 0 | contextInfo.setPrincipalId(GlobalVariables.getUserSession().getPrincipalId()); |
143 | 0 | LocaleInfo localeInfo = new LocaleInfo(); |
144 | 0 | localeInfo.setLocaleLanguage(Locale.getDefault().getLanguage()); |
145 | 0 | localeInfo.setLocaleRegion(Locale.getDefault().getCountry()); |
146 | 0 | contextInfo.setLocale(localeInfo); |
147 | |
} |
148 | 0 | return contextInfo; |
149 | |
} |
150 | |
|
151 | |
protected CourseOfferingService getCourseOfferingService() { |
152 | 0 | if (courseOfferingService == null) { |
153 | 0 | courseOfferingService = (CourseOfferingService) GlobalResourceLoader.getService(new QName(CourseOfferingServiceConstants.NAMESPACE, "CourseOfferingService")); |
154 | |
} |
155 | 0 | return courseOfferingService; |
156 | |
} |
157 | |
} |
158 | |
|