1 | |
package org.kuali.student.enrollment.class2.acal.service.decorators; |
2 | |
|
3 | |
import java.util.Date; |
4 | |
import java.util.List; |
5 | |
|
6 | |
import javax.jws.WebParam; |
7 | |
|
8 | |
import org.apache.commons.lang.StringUtils; |
9 | |
import org.kuali.student.enrollment.acal.dto.AcademicCalendarInfo; |
10 | |
import org.kuali.student.enrollment.acal.dto.HolidayCalendarInfo; |
11 | |
import org.kuali.student.enrollment.acal.dto.TermInfo; |
12 | |
import org.kuali.student.enrollment.acal.dto.HolidayInfo; |
13 | |
import org.kuali.student.enrollment.acal.dto.KeyDateInfo; |
14 | |
import org.kuali.student.r2.common.datadictionary.DataDictionaryValidator; |
15 | |
import org.kuali.student.r2.common.datadictionary.service.DataDictionaryService; |
16 | |
import org.kuali.student.r2.common.dto.ContextInfo; |
17 | |
import org.kuali.student.r2.common.dto.ValidationResultInfo; |
18 | |
import org.kuali.student.r2.common.exceptions.DataValidationErrorException; |
19 | |
import org.kuali.student.r2.common.exceptions.DoesNotExistException; |
20 | |
import org.kuali.student.r2.common.exceptions.InvalidParameterException; |
21 | |
import org.kuali.student.r2.common.exceptions.MissingParameterException; |
22 | |
import org.kuali.student.r2.common.exceptions.OperationFailedException; |
23 | |
import org.kuali.student.r2.common.exceptions.PermissionDeniedException; |
24 | |
import org.kuali.student.r2.common.exceptions.ReadOnlyException; |
25 | |
import org.kuali.student.r2.common.exceptions.VersionMismatchException; |
26 | |
import org.kuali.student.r2.common.infc.HoldsDataDictionaryService; |
27 | |
import org.kuali.student.r2.common.infc.HoldsValidator; |
28 | |
import org.kuali.student.r2.core.class1.util.ValidationUtils; |
29 | |
|
30 | 0 | public class AcademicCalendarServiceValidationDecorator extends AcademicCalendarServiceDecorator implements HoldsValidator, HoldsDataDictionaryService { |
31 | |
private DataDictionaryValidator validator; |
32 | |
private DataDictionaryService dataDictionaryService; |
33 | |
|
34 | |
@Override |
35 | |
public DataDictionaryValidator getValidator() { |
36 | 0 | return validator; |
37 | |
} |
38 | |
|
39 | |
@Override |
40 | |
public void setValidator(DataDictionaryValidator validator) { |
41 | 0 | this.validator = validator; |
42 | 0 | } |
43 | |
|
44 | |
@Override |
45 | |
public DataDictionaryService getDataDictionaryService() { |
46 | 0 | return dataDictionaryService; |
47 | |
} |
48 | |
|
49 | |
@Override |
50 | |
public void setDataDictionaryService(DataDictionaryService dataDictionaryService) { |
51 | 0 | this.dataDictionaryService = dataDictionaryService; |
52 | 0 | } |
53 | |
|
54 | |
@Override |
55 | |
public AcademicCalendarInfo createAcademicCalendar(String academicCalendarKey, AcademicCalendarInfo academicCalendarInfo, ContextInfo context) throws DataValidationErrorException, |
56 | |
InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, DoesNotExistException, ReadOnlyException { |
57 | 0 | _academicCalendarFullValidation(academicCalendarKey, academicCalendarInfo, context); |
58 | 0 | return getNextDecorator().createAcademicCalendar(academicCalendarKey, academicCalendarInfo, context); |
59 | |
} |
60 | |
|
61 | |
@Override |
62 | |
public AcademicCalendarInfo updateAcademicCalendar(String academicCalendarKey, AcademicCalendarInfo academicCalendarInfo, ContextInfo context) throws DataValidationErrorException, |
63 | |
DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, VersionMismatchException, ReadOnlyException { |
64 | 0 | _academicCalendarFullValidation(academicCalendarKey, academicCalendarInfo, context); |
65 | 0 | return this.getNextDecorator().updateAcademicCalendar(academicCalendarKey, academicCalendarInfo, context); |
66 | |
} |
67 | |
|
68 | |
private void _academicCalendarFullValidation(String academicCalendarTypeKey, AcademicCalendarInfo academicCalendarInfo, ContextInfo context) throws DataValidationErrorException, |
69 | |
OperationFailedException, InvalidParameterException, MissingParameterException, PermissionDeniedException { |
70 | |
try { |
71 | 0 | List<ValidationResultInfo> errors = this |
72 | |
.validateAcademicCalendar(DataDictionaryValidator.ValidationType.FULL_VALIDATION.toString(), academicCalendarTypeKey, academicCalendarInfo, context); |
73 | 0 | if (!errors.isEmpty()) { |
74 | 0 | throw new DataValidationErrorException("Error(s) occurred validating academic calendar", errors); |
75 | |
} |
76 | 0 | } catch (DoesNotExistException ex) { |
77 | 0 | throw new OperationFailedException("Error validating academic calendar", ex); |
78 | 0 | } |
79 | 0 | } |
80 | |
|
81 | |
@Override |
82 | |
public List<ValidationResultInfo> validateAcademicCalendar(String validationTypeKey, String academicCalendarTypeKey, AcademicCalendarInfo academicCalendarInfo, ContextInfo contextInfo) |
83 | |
throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
84 | |
List<ValidationResultInfo> errors; |
85 | |
try { |
86 | 0 | errors = ValidationUtils.validateInfo(validator, validationTypeKey, academicCalendarInfo, contextInfo); |
87 | 0 | List<ValidationResultInfo> nextDecoratorErrors = getNextDecorator().validateAcademicCalendar(validationTypeKey, academicCalendarTypeKey, academicCalendarInfo, contextInfo); |
88 | 0 | if (null != nextDecoratorErrors) { |
89 | 0 | errors.addAll(nextDecoratorErrors); |
90 | |
} |
91 | 0 | } catch (DoesNotExistException ex) { |
92 | 0 | throw new OperationFailedException("Error validating academic calendar", ex); |
93 | 0 | } |
94 | 0 | return errors; |
95 | |
} |
96 | |
|
97 | |
@Override |
98 | |
public HolidayCalendarInfo createHolidayCalendar(String holidayCalendarTypeKey, HolidayCalendarInfo holidayCalendarInfo, ContextInfo context) throws DataValidationErrorException, |
99 | |
DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, ReadOnlyException { |
100 | 0 | _holidayCalendarFullValidation(holidayCalendarInfo, context); |
101 | 0 | return this.getNextDecorator().createHolidayCalendar(holidayCalendarTypeKey, holidayCalendarInfo, context); |
102 | |
} |
103 | |
|
104 | |
@Override |
105 | |
public HolidayCalendarInfo updateHolidayCalendar(String holidayCalendarId, HolidayCalendarInfo holidayCalendarInfo, ContextInfo contextInfo) throws DataValidationErrorException, |
106 | |
DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, ReadOnlyException, VersionMismatchException { |
107 | 0 | return this.getNextDecorator().updateHolidayCalendar(holidayCalendarId, holidayCalendarInfo, contextInfo); |
108 | |
} |
109 | |
|
110 | |
private void _holidayCalendarFullValidation(HolidayCalendarInfo holidayCalendarInfo, ContextInfo context) throws DataValidationErrorException, OperationFailedException, InvalidParameterException, |
111 | |
MissingParameterException, PermissionDeniedException { |
112 | |
try { |
113 | 0 | List<ValidationResultInfo> errors = this.validateHolidayCalendar(DataDictionaryValidator.ValidationType.FULL_VALIDATION.toString(), null, holidayCalendarInfo, context); |
114 | 0 | if (!errors.isEmpty()) { |
115 | 0 | throw new DataValidationErrorException("Error(s) occurred validating holiday calendar", errors); |
116 | |
} |
117 | 0 | } catch (DoesNotExistException ex) { |
118 | 0 | throw new OperationFailedException("Error validating holiday calendar", ex); |
119 | 0 | } |
120 | 0 | } |
121 | |
|
122 | |
@Override |
123 | |
public List<ValidationResultInfo> validateHolidayCalendar(String validationTypeKey, String holidayCalendarTypeKey, HolidayCalendarInfo holidayCalendarInfo, |
124 | |
@WebParam(name = "contextInfo") ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, |
125 | |
PermissionDeniedException { |
126 | |
List<ValidationResultInfo> errors; |
127 | |
try { |
128 | 0 | errors = ValidationUtils.validateInfo(validator, validationTypeKey, holidayCalendarInfo, contextInfo); |
129 | |
|
130 | 0 | List<ValidationResultInfo> nextDecoratorErrors = getNextDecorator().validateHolidayCalendar(validationTypeKey, holidayCalendarTypeKey, holidayCalendarInfo, contextInfo); |
131 | 0 | if (null != nextDecoratorErrors) { |
132 | 0 | errors.addAll(nextDecoratorErrors); |
133 | |
} |
134 | 0 | } catch (DoesNotExistException ex) { |
135 | 0 | throw new OperationFailedException("Error validating holiday calendar", ex); |
136 | 0 | } |
137 | 0 | return errors; |
138 | |
} |
139 | |
|
140 | |
@Override |
141 | |
public TermInfo createTerm(String termTypeKey, TermInfo termInfo, ContextInfo context) throws DataValidationErrorException, InvalidParameterException, MissingParameterException, |
142 | |
OperationFailedException, PermissionDeniedException, DoesNotExistException, ReadOnlyException { |
143 | 0 | _termFullValidation(termInfo, context); |
144 | 0 | if (termInfo.getId() != null) { |
145 | 0 | throw new ReadOnlyException("ID not allowed when creating term."); |
146 | |
} |
147 | 0 | return this.getNextDecorator().createTerm(termTypeKey, termInfo, context); |
148 | |
} |
149 | |
|
150 | |
@Override |
151 | |
public TermInfo updateTerm(String termId, TermInfo termInfo, ContextInfo context) throws DataValidationErrorException, DoesNotExistException, InvalidParameterException, MissingParameterException, |
152 | |
OperationFailedException, PermissionDeniedException, VersionMismatchException, ReadOnlyException { |
153 | 0 | _termFullValidation(termInfo, context); |
154 | 0 | return this.getNextDecorator().updateTerm(termId, termInfo, context); |
155 | |
} |
156 | |
|
157 | |
private void _termFullValidation(TermInfo termInfo, ContextInfo context) throws DataValidationErrorException, OperationFailedException, InvalidParameterException, MissingParameterException, |
158 | |
PermissionDeniedException { |
159 | |
try { |
160 | 0 | List<ValidationResultInfo> errors = this.validateTerm(DataDictionaryValidator.ValidationType.FULL_VALIDATION.toString(), termInfo.getTypeKey(), termInfo, context); |
161 | 0 | if (!errors.isEmpty()) { |
162 | 0 | throw new DataValidationErrorException("Error(s) occurred validating term", errors); |
163 | |
} |
164 | 0 | } catch (DoesNotExistException ex) { |
165 | 0 | throw new OperationFailedException("Error validating term", ex); |
166 | 0 | } |
167 | 0 | } |
168 | |
|
169 | |
@Override |
170 | |
public List<ValidationResultInfo> validateTerm(String validationTypeKey, String termTypeKey, TermInfo termInfo, ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, |
171 | |
MissingParameterException, OperationFailedException, PermissionDeniedException { |
172 | |
List<ValidationResultInfo> errors; |
173 | |
try { |
174 | 0 | errors = ValidationUtils.validateInfo(validator, validationTypeKey, termInfo, contextInfo); |
175 | 0 | List<ValidationResultInfo> nextDecoratorErrors = getNextDecorator().validateTerm(validationTypeKey, termTypeKey, termInfo, contextInfo); |
176 | 0 | if (null != nextDecoratorErrors) { |
177 | 0 | errors.addAll(nextDecoratorErrors); |
178 | |
} |
179 | 0 | } catch (DoesNotExistException ex) { |
180 | 0 | throw new OperationFailedException("Error validating term", ex); |
181 | 0 | } |
182 | 0 | return errors; |
183 | |
} |
184 | |
|
185 | |
@Override |
186 | |
public KeyDateInfo updateKeyDate(String keyDateId, KeyDateInfo keyDateInfo, ContextInfo context) throws DataValidationErrorException, DoesNotExistException, InvalidParameterException, |
187 | |
MissingParameterException, OperationFailedException, PermissionDeniedException, VersionMismatchException, ReadOnlyException { |
188 | 0 | _keyDateFullValidation(keyDateInfo, context); |
189 | 0 | return this.getNextDecorator().updateKeyDate(keyDateId, keyDateInfo, context); |
190 | |
} |
191 | |
|
192 | |
@Override |
193 | |
public KeyDateInfo calculateKeyDate(String keyDateId, ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, |
194 | |
PermissionDeniedException { |
195 | 0 | if (StringUtils.isEmpty(keyDateId)) { |
196 | 0 | throw new MissingParameterException("keyDateId"); |
197 | |
} |
198 | 0 | if (null == contextInfo) { |
199 | 0 | throw new MissingParameterException("contextInfo"); |
200 | |
} |
201 | 0 | return this.getNextDecorator().calculateKeyDate(keyDateId, contextInfo); |
202 | |
} |
203 | |
|
204 | |
private void _keyDateFullValidation(KeyDateInfo keyDateInfo, ContextInfo context) throws DataValidationErrorException, OperationFailedException, InvalidParameterException, |
205 | |
MissingParameterException, PermissionDeniedException { |
206 | |
try { |
207 | 0 | List<ValidationResultInfo> errors = this.validateKeyDate(DataDictionaryValidator.ValidationType.FULL_VALIDATION.toString(), null, keyDateInfo.getTypeKey(), keyDateInfo, context); |
208 | 0 | if (!errors.isEmpty()) { |
209 | 0 | throw new DataValidationErrorException("Error(s) occurred validating key date", errors); |
210 | |
} |
211 | 0 | } catch (DoesNotExistException ex) { |
212 | 0 | throw new OperationFailedException("Error validating key date", ex); |
213 | 0 | } |
214 | 0 | } |
215 | |
|
216 | |
@Override |
217 | |
public List<ValidationResultInfo> validateKeyDate(String validationTypeKey, String termId, String keyDateTypeKey, KeyDateInfo keyDateInfo, ContextInfo contextInfo) throws DoesNotExistException, |
218 | |
InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
219 | |
List<ValidationResultInfo> errors; |
220 | |
try { |
221 | 0 | errors = ValidationUtils.validateInfo(validator, validationTypeKey, keyDateInfo, contextInfo); |
222 | 0 | List<ValidationResultInfo> nextDecoratorErrors = getNextDecorator().validateKeyDate(validationTypeKey, termId, keyDateTypeKey, keyDateInfo, contextInfo); |
223 | 0 | if (null != nextDecoratorErrors) { |
224 | 0 | errors.addAll(nextDecoratorErrors); |
225 | |
} |
226 | 0 | } catch (DoesNotExistException ex) { |
227 | 0 | throw new OperationFailedException("Error validating key date", ex); |
228 | 0 | } |
229 | 0 | return errors; |
230 | |
} |
231 | |
|
232 | |
@Override |
233 | |
public HolidayInfo createHoliday(String holidayCalendarId, String holidayTypeKey, HolidayInfo holidayInfo, ContextInfo contextInfo) throws DataValidationErrorException, DoesNotExistException, |
234 | |
InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, ReadOnlyException { |
235 | 0 | _holidayFullValidation(holidayInfo, contextInfo); |
236 | 0 | return this.getNextDecorator().createHoliday(holidayCalendarId, holidayTypeKey, holidayInfo, contextInfo); |
237 | |
} |
238 | |
|
239 | |
@Override |
240 | |
public HolidayInfo updateHoliday(String holidayId, HolidayInfo holidayInfo, ContextInfo context) throws DataValidationErrorException, DoesNotExistException, InvalidParameterException, |
241 | |
MissingParameterException, OperationFailedException, PermissionDeniedException, VersionMismatchException, ReadOnlyException { |
242 | 0 | _holidayFullValidation(holidayInfo, context); |
243 | 0 | return this.getNextDecorator().updateHoliday(holidayId, holidayInfo, context); |
244 | |
} |
245 | |
|
246 | |
private void _holidayFullValidation(HolidayInfo holidayInfo, ContextInfo context) throws DataValidationErrorException, OperationFailedException, InvalidParameterException, |
247 | |
MissingParameterException, PermissionDeniedException { |
248 | |
try { |
249 | 0 | List<ValidationResultInfo> errors = this.validateHoliday(DataDictionaryValidator.ValidationType.FULL_VALIDATION.toString(), null, null, holidayInfo, context); |
250 | 0 | if (!errors.isEmpty()) { |
251 | 0 | throw new DataValidationErrorException("Error(s) occurred validating holiday", errors); |
252 | |
} |
253 | 0 | } catch (DoesNotExistException ex) { |
254 | 0 | throw new OperationFailedException("Error validating holiday", ex); |
255 | 0 | } |
256 | 0 | } |
257 | |
|
258 | |
@Override |
259 | |
public List<ValidationResultInfo> validateHoliday(String validationTypeKey, String holidayCalendarId, String holidayTypeKey, HolidayInfo holidayInfo, ContextInfo contextInfo) |
260 | |
throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
261 | |
List<ValidationResultInfo> errors; |
262 | |
try { |
263 | 0 | errors = ValidationUtils.validateInfo(validator, validationTypeKey, holidayInfo, contextInfo); |
264 | 0 | List<ValidationResultInfo> nextDecoratorErrors = getNextDecorator().validateHoliday(validationTypeKey, holidayCalendarId, holidayTypeKey, holidayInfo, contextInfo); |
265 | 0 | if (null != nextDecoratorErrors) { |
266 | 0 | errors.addAll(nextDecoratorErrors); |
267 | |
} |
268 | 0 | } catch (DoesNotExistException ex) { |
269 | 0 | throw new OperationFailedException("Error validating holiday", ex); |
270 | 0 | } |
271 | 0 | return errors; |
272 | |
} |
273 | |
|
274 | |
@Override |
275 | |
public List<HolidayInfo> getHolidaysByDateForAcademicCalendar(String academicCalendarId, Date startDate, Date endDate, ContextInfo contextInfo) throws DoesNotExistException, |
276 | |
InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
277 | |
|
278 | 0 | AcademicCalendarInfo academicCalendar = getAcademicCalendar(academicCalendarId, contextInfo); |
279 | |
|
280 | 0 | if(academicCalendar == null) |
281 | 0 | throw new DoesNotExistException("Invalid academicCalendarId in the input parameter"); |
282 | |
|
283 | 0 | if (startDate == null || endDate == null) { |
284 | 0 | throw new OperationFailedException("Null dates in the input parameter"); |
285 | |
} |
286 | |
|
287 | 0 | if (startDate.before(academicCalendar.getStartDate()) || endDate.after(academicCalendar.getEndDate())) { |
288 | 0 | throw new OperationFailedException("Invalid date in the input parameter"); |
289 | |
} |
290 | |
|
291 | 0 | return this.getNextDecorator().getHolidaysByDateForAcademicCalendar(academicCalendarId, startDate, endDate, contextInfo); |
292 | |
} |
293 | |
|
294 | |
} |