1 | |
package org.kuali.student.enrollment.class2.acal.service.impl; |
2 | |
|
3 | |
|
4 | |
import org.apache.commons.lang.StringUtils; |
5 | |
import org.joda.time.Days; |
6 | |
import org.joda.time.Period; |
7 | |
import org.joda.time.Weeks; |
8 | |
import org.kuali.rice.core.api.criteria.QueryByCriteria; |
9 | |
import org.kuali.student.enrollment.acal.dto.*; |
10 | |
import org.kuali.student.enrollment.acal.service.AcademicCalendarService; |
11 | |
import org.kuali.student.enrollment.class2.acal.service.assembler.*; |
12 | |
import org.kuali.student.r2.common.assembler.AssemblyException; |
13 | |
import org.kuali.student.r2.common.datadictionary.service.DataDictionaryService; |
14 | |
import org.kuali.student.r2.common.dto.ContextInfo; |
15 | |
import org.kuali.student.r2.common.dto.DateRangeInfo; |
16 | |
import org.kuali.student.r2.common.dto.StatusInfo; |
17 | |
import org.kuali.student.r2.common.dto.ValidationResultInfo; |
18 | |
import org.kuali.student.r2.common.exceptions.*; |
19 | |
import org.kuali.student.r2.common.util.constants.AtpServiceConstants; |
20 | |
import org.kuali.student.r2.common.util.constants.TypeServiceConstants; |
21 | |
import org.kuali.student.r2.core.atp.dto.AtpAtpRelationInfo; |
22 | |
import org.kuali.student.r2.core.atp.dto.AtpInfo; |
23 | |
import org.kuali.student.r2.core.atp.dto.MilestoneInfo; |
24 | |
import org.kuali.student.r2.core.atp.service.AtpService; |
25 | |
import org.kuali.student.r2.core.state.dto.StateInfo; |
26 | |
import org.kuali.student.r2.core.state.service.StateService; |
27 | |
import org.kuali.student.r2.core.type.dto.TypeInfo; |
28 | |
import org.kuali.student.r2.core.type.dto.TypeTypeRelationInfo; |
29 | |
import org.kuali.student.r2.core.type.service.TypeService; |
30 | |
import org.springframework.transaction.annotation.Transactional; |
31 | |
|
32 | |
import java.util.*; |
33 | |
|
34 | |
@Transactional(readOnly = true, noRollbackFor = {DoesNotExistException.class}, rollbackFor = {Throwable.class}) |
35 | 0 | public class AcademicCalendarServiceImpl implements AcademicCalendarService { |
36 | |
|
37 | |
private AtpService atpService; |
38 | |
private StateService stateService; |
39 | |
private TypeService typeService; |
40 | |
private AcademicCalendarAssembler acalAssembler; |
41 | |
private TermAssembler termAssembler; |
42 | |
private DataDictionaryService dataDictionaryService; |
43 | |
private HolidayCalendarAssembler holidayCalendarAssembler; |
44 | |
private HolidayAssembler holidayAssembler; |
45 | |
private KeyDateAssembler keyDateAssembler; |
46 | |
private AcalEventAssembler acalEventAssembler; |
47 | |
|
48 | |
public AcalEventAssembler getAcalEventAssembler() { |
49 | 0 | return acalEventAssembler; |
50 | |
} |
51 | |
|
52 | |
public void setAcalEventAssembler(AcalEventAssembler acalEventAssembler) { |
53 | 0 | this.acalEventAssembler = acalEventAssembler; |
54 | 0 | } |
55 | |
|
56 | |
public KeyDateAssembler getKeyDateAssembler() { |
57 | 0 | return keyDateAssembler; |
58 | |
} |
59 | |
|
60 | |
public void setKeyDateAssembler(KeyDateAssembler keyDateAssembler) { |
61 | 0 | this.keyDateAssembler = keyDateAssembler; |
62 | 0 | } |
63 | |
|
64 | |
public HolidayAssembler getHolidayAssembler() { |
65 | 0 | return holidayAssembler; |
66 | |
} |
67 | |
|
68 | |
public void setHolidayAssembler(HolidayAssembler holidayAssembler) { |
69 | 0 | this.holidayAssembler = holidayAssembler; |
70 | 0 | } |
71 | |
|
72 | |
public HolidayCalendarAssembler getHolidayCalendarAssembler() { |
73 | 0 | return holidayCalendarAssembler; |
74 | |
} |
75 | |
|
76 | |
public void setHolidayCalendarAssembler(HolidayCalendarAssembler holidayCalendarAssembler) { |
77 | 0 | this.holidayCalendarAssembler = holidayCalendarAssembler; |
78 | 0 | } |
79 | |
|
80 | |
public DataDictionaryService getDataDictionaryService() { |
81 | 0 | return dataDictionaryService; |
82 | |
} |
83 | |
|
84 | |
public void setDataDictionaryService(DataDictionaryService dataDictionaryService) { |
85 | 0 | this.dataDictionaryService = dataDictionaryService; |
86 | 0 | } |
87 | |
|
88 | |
public TypeService getTypeService() { |
89 | 0 | return typeService; |
90 | |
} |
91 | |
|
92 | |
public void setTypeService(TypeService typeService) { |
93 | 0 | this.typeService = typeService; |
94 | 0 | } |
95 | |
|
96 | |
public StateService getStateService() { |
97 | 0 | return stateService; |
98 | |
} |
99 | |
|
100 | |
public void setStateService(StateService stateService) { |
101 | 0 | this.stateService = stateService; |
102 | 0 | } |
103 | |
|
104 | |
@Override |
105 | |
public TypeInfo getAcademicCalendarType(String academicCalendarTypeKey, ContextInfo context) throws DoesNotExistException, InvalidParameterException, MissingParameterException, |
106 | |
OperationFailedException { |
107 | |
|
108 | 0 | return null; |
109 | |
} |
110 | |
|
111 | |
@Override |
112 | |
public List<TypeInfo> getAcademicCalendarTypes(ContextInfo context) throws InvalidParameterException, MissingParameterException, OperationFailedException { |
113 | |
|
114 | 0 | return new ArrayList<TypeInfo>(); |
115 | |
} |
116 | |
|
117 | |
@Override |
118 | |
public StateInfo getAcademicCalendarState(String academicCalendarStateKey, ContextInfo context) throws DoesNotExistException, InvalidParameterException, MissingParameterException, |
119 | |
OperationFailedException { |
120 | |
|
121 | 0 | return null; |
122 | |
} |
123 | |
|
124 | |
private List<StateInfo> getAtpStates(ContextInfo context) throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
125 | |
List<StateInfo> results; |
126 | |
try { |
127 | 0 | results = stateService.getStatesByLifecycle(AtpServiceConstants.ATP_LIFECYCLE_KEY, context); |
128 | 0 | } catch (DoesNotExistException ex) { |
129 | 0 | throw new OperationFailedException(AtpServiceConstants.ATP_LIFECYCLE_KEY, ex); |
130 | 0 | } |
131 | |
|
132 | 0 | return results; |
133 | |
} |
134 | |
|
135 | |
@Override |
136 | |
public List<StateInfo> getAcademicCalendarStates(ContextInfo context) throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
137 | 0 | return getAtpStates(context); |
138 | |
} |
139 | |
|
140 | |
@Override |
141 | |
public AcademicCalendarInfo getAcademicCalendar(String academicCalendarKey, ContextInfo context) throws DoesNotExistException, InvalidParameterException, MissingParameterException, |
142 | |
OperationFailedException, PermissionDeniedException { |
143 | 0 | AtpInfo atp = atpService.getAtp(academicCalendarKey, context); |
144 | |
AcademicCalendarInfo acal; |
145 | |
|
146 | |
try { |
147 | 0 | acal = acalAssembler.assemble(atp, context); |
148 | 0 | } catch (AssemblyException e) { |
149 | 0 | throw new OperationFailedException("AssemblyException : " + e.getMessage()); |
150 | 0 | } |
151 | |
|
152 | 0 | return acal; |
153 | |
} |
154 | |
|
155 | |
@Override |
156 | |
public List<AcademicCalendarInfo> getAcademicCalendarsByIds(List<String> academicCalendarKeyList, ContextInfo context) throws DoesNotExistException, InvalidParameterException, |
157 | |
MissingParameterException, OperationFailedException, PermissionDeniedException { |
158 | 0 | List<AcademicCalendarInfo> academicCalendars = new ArrayList<AcademicCalendarInfo>(); |
159 | 0 | List<AtpInfo> atps = atpService.getAtpsByIds(academicCalendarKeyList, context); |
160 | 0 | for (AtpInfo atp : atps) { |
161 | |
try { |
162 | 0 | academicCalendars.add(acalAssembler.assemble(atp, context)); |
163 | 0 | } catch (AssemblyException e) { |
164 | 0 | throw new OperationFailedException("AssemblyException : " + e.getMessage()); |
165 | 0 | } |
166 | |
} |
167 | 0 | return academicCalendars; |
168 | |
} |
169 | |
|
170 | |
@Override |
171 | |
public List<String> getAcademicCalendarIdsByType(String academicCalendarTypeKey, ContextInfo context) throws InvalidParameterException, MissingParameterException, OperationFailedException, |
172 | |
PermissionDeniedException { |
173 | |
|
174 | 0 | return new ArrayList<String>(); |
175 | |
} |
176 | |
|
177 | |
@Override |
178 | |
public List<AcademicCalendarInfo> getAcademicCalendarsByStartYear(Integer year, ContextInfo context) throws InvalidParameterException, MissingParameterException, OperationFailedException, |
179 | |
PermissionDeniedException { |
180 | |
final Date yearBegin, yearEnd; |
181 | |
|
182 | 0 | Calendar cal = Calendar.getInstance(); |
183 | 0 | cal.clear(); |
184 | 0 | cal.set(year, 0, 1); |
185 | 0 | yearBegin = cal.getTime(); |
186 | 0 | cal.add(Calendar.YEAR, 1); |
187 | 0 | cal.add(Calendar.MILLISECOND, -1); |
188 | 0 | yearEnd = cal.getTime(); |
189 | |
|
190 | 0 | Set<AtpInfo> atpInfos = new TreeSet<AtpInfo>(new Comparator<AtpInfo>() { |
191 | |
|
192 | |
@Override |
193 | |
public int compare(AtpInfo atpInfo1, AtpInfo atpInfo2) { |
194 | 0 | return atpInfo1.getId().compareTo(atpInfo2.getId()); |
195 | |
} |
196 | |
}); |
197 | |
|
198 | 0 | atpInfos.addAll(atpService.getAtpsByStartDateRangeAndType(yearBegin, yearEnd, AtpServiceConstants.ATP_ACADEMIC_CALENDAR_TYPE_KEY, context)); |
199 | |
|
200 | 0 | List<AcademicCalendarInfo> acalInfos = new ArrayList<AcademicCalendarInfo>(); |
201 | 0 | for (AtpInfo atpInfo : atpInfos) { |
202 | |
try { |
203 | 0 | acalInfos.add(acalAssembler.assemble(atpInfo, context)); |
204 | 0 | } catch (AssemblyException e) { |
205 | 0 | throw new OperationFailedException("AssemblyException : " + e.getMessage()); |
206 | 0 | } |
207 | |
} |
208 | 0 | return acalInfos; |
209 | |
} |
210 | |
|
211 | |
@Override |
212 | |
@Transactional(readOnly = false) |
213 | |
public AcademicCalendarInfo createAcademicCalendar(String academicCalendarTypeKey, AcademicCalendarInfo academicCalendarInfo, ContextInfo context) throws DataValidationErrorException, |
214 | |
InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
215 | |
|
216 | |
|
217 | |
try { |
218 | 0 | AtpInfo toCreate = acalAssembler.disassemble(academicCalendarInfo, context); |
219 | 0 | AtpInfo createdAtp = atpService.createAtp(toCreate.getTypeKey(), toCreate, context); |
220 | |
try { |
221 | 0 | createDeleteAtpAtpRelations(createdAtp.getId(), |
222 | |
academicCalendarInfo.getHolidayCalendarIds(), |
223 | |
AtpServiceConstants.ATP_HOLIDAY_CALENDAR_TYPE_KEY, |
224 | |
context); |
225 | 0 | } catch (VersionMismatchException e) { |
226 | 0 | throw new OperationFailedException(); |
227 | 0 | } |
228 | 0 | return acalAssembler.assemble(createdAtp, context); |
229 | 0 | } catch (AlreadyExistsException e) { |
230 | 0 | throw new OperationFailedException("Unexpected", e); |
231 | 0 | } catch (AssemblyException e) { |
232 | 0 | throw new OperationFailedException("Unexpected", e); |
233 | 0 | } catch (ReadOnlyException e) { |
234 | 0 | throw new OperationFailedException("Unexpected", e); |
235 | |
} |
236 | |
|
237 | |
} |
238 | |
|
239 | |
@Override |
240 | |
@Transactional(readOnly = false) |
241 | |
public AcademicCalendarInfo updateAcademicCalendar(String academicCalendarId, AcademicCalendarInfo academicCalendarInfo, ContextInfo context) throws DataValidationErrorException, |
242 | |
DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, VersionMismatchException { |
243 | |
|
244 | |
|
245 | |
try { |
246 | 0 | AtpInfo toUpdate = acalAssembler.disassemble(academicCalendarInfo, context); |
247 | 0 | AtpInfo updated = atpService.updateAtp(academicCalendarId, toUpdate, context); |
248 | |
try { |
249 | 0 | createDeleteAtpAtpRelations(academicCalendarId, |
250 | |
academicCalendarInfo.getHolidayCalendarIds(), |
251 | |
AtpServiceConstants.ATP_HOLIDAY_CALENDAR_TYPE_KEY, |
252 | |
context); |
253 | 0 | } catch (VersionMismatchException e) { |
254 | 0 | throw new OperationFailedException(); |
255 | 0 | } |
256 | 0 | return acalAssembler.assemble(updated, context); |
257 | 0 | } catch (Exception e) { |
258 | 0 | throw new OperationFailedException("Unexpected", e); |
259 | |
} |
260 | |
} |
261 | |
|
262 | |
|
263 | |
@Override |
264 | |
@Transactional(readOnly = false) |
265 | |
public StatusInfo deleteAcademicCalendar(String academicCalendarKey, ContextInfo context) throws DoesNotExistException, InvalidParameterException, MissingParameterException, |
266 | |
OperationFailedException, PermissionDeniedException { |
267 | |
|
268 | 0 | StatusInfo status = new StatusInfo(); |
269 | 0 | status.setSuccess(Boolean.TRUE); |
270 | |
|
271 | 0 | AtpInfo atp = atpService.getAtp(academicCalendarKey, context); |
272 | |
|
273 | 0 | if (atp != null) { |
274 | |
|
275 | 0 | atpService.deleteAtp(academicCalendarKey, context); |
276 | |
} |
277 | |
|
278 | 0 | return status; |
279 | |
} |
280 | |
|
281 | |
@Override |
282 | |
public AcademicCalendarInfo copyAcademicCalendar(String academicCalendarId, Date startDate, Date endDate, ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, |
283 | |
MissingParameterException, OperationFailedException, PermissionDeniedException { |
284 | 0 | throw new OperationFailedException("Method implemented in calculation decorator."); |
285 | |
} |
286 | |
|
287 | |
@Override |
288 | |
@Transactional(readOnly = true) |
289 | |
public HolidayCalendarInfo getHolidayCalendar(String holidayCalendarId, ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, |
290 | |
OperationFailedException, PermissionDeniedException { |
291 | 0 | AtpInfo atp = atpService.getAtp(holidayCalendarId, contextInfo); |
292 | |
HolidayCalendarInfo ccal; |
293 | |
try { |
294 | 0 | ccal = holidayCalendarAssembler.assemble(atp, contextInfo); |
295 | 0 | } catch (AssemblyException e) { |
296 | 0 | throw new OperationFailedException("AssemblyException : " + e.getMessage()); |
297 | 0 | } |
298 | |
|
299 | 0 | return ccal; |
300 | |
} |
301 | |
|
302 | |
@Override |
303 | |
public List<HolidayCalendarInfo> getHolidayCalendarsByIds(List<String> holidayCalendarIds, ContextInfo context) throws DoesNotExistException, InvalidParameterException, MissingParameterException, |
304 | |
OperationFailedException, PermissionDeniedException { |
305 | 0 | List<AtpInfo> atps = atpService.getAtpsByIds(holidayCalendarIds, context); |
306 | 0 | List<HolidayCalendarInfo> holidayCalendarInfos = new ArrayList<HolidayCalendarInfo>(); |
307 | 0 | for (AtpInfo atp : atps) { |
308 | |
try { |
309 | 0 | holidayCalendarInfos.add(holidayCalendarAssembler.assemble(atp, context)); |
310 | 0 | } catch (AssemblyException e) { |
311 | 0 | throw new OperationFailedException("AssemblyException : " + e.getMessage()); |
312 | 0 | } |
313 | |
} |
314 | 0 | return holidayCalendarInfos; |
315 | |
} |
316 | |
|
317 | |
@Override |
318 | |
@Transactional(readOnly = false) |
319 | |
public HolidayCalendarInfo createHolidayCalendar(String holidayCalendarTypeKey, HolidayCalendarInfo holidayCalendarInfo, ContextInfo context) throws DataValidationErrorException, |
320 | |
InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
321 | |
|
322 | |
AtpInfo atpInfo; |
323 | |
try { |
324 | 0 | atpInfo = holidayCalendarAssembler.disassemble(holidayCalendarInfo, context); |
325 | 0 | } catch (AssemblyException ex) { |
326 | 0 | throw new OperationFailedException("Unexpected", ex); |
327 | 0 | } |
328 | |
try { |
329 | 0 | System.out.println("AcademicCalendarServiceImp: creating atp for holiday calendar "); |
330 | 0 | atpInfo = atpService.createAtp(atpInfo.getTypeKey(), atpInfo, context); |
331 | 0 | System.out.println("atp created for holiday calendar " + atpInfo.getId()); |
332 | 0 | } catch (ReadOnlyException ex) { |
333 | 0 | throw new OperationFailedException("Unexpected", ex); |
334 | 0 | } |
335 | |
HolidayCalendarInfo newHolidayCalendar; |
336 | |
try { |
337 | 0 | newHolidayCalendar = holidayCalendarAssembler.assemble(atpInfo, context); |
338 | 0 | } catch (AssemblyException ex) { |
339 | 0 | throw new OperationFailedException("unexpected", ex); |
340 | 0 | } |
341 | |
|
342 | 0 | return newHolidayCalendar; |
343 | |
} |
344 | |
|
345 | |
@Override |
346 | |
@Transactional(readOnly = false) |
347 | |
public HolidayCalendarInfo copyHolidayCalendar(String holidayCalendarId, Date startDate, Date endDate, ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
348 | 0 | throw new OperationFailedException("Method implemented in calculation decorator."); |
349 | |
} |
350 | |
|
351 | |
@Override |
352 | |
@Transactional(readOnly = false) |
353 | |
public HolidayCalendarInfo updateHolidayCalendar(String holidayCalendarId, HolidayCalendarInfo holidayCalendarInfo, ContextInfo contextInfo) throws DataValidationErrorException, |
354 | |
DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, ReadOnlyException, VersionMismatchException { |
355 | |
|
356 | |
try { |
357 | 0 | AtpInfo toUpdate = holidayCalendarAssembler.disassemble(holidayCalendarInfo, contextInfo); |
358 | 0 | AtpInfo updated = atpService.updateAtp(holidayCalendarId, toUpdate, contextInfo); |
359 | 0 | return holidayCalendarAssembler.assemble(updated, contextInfo); |
360 | 0 | } catch (AssemblyException e) { |
361 | 0 | throw new OperationFailedException("AssemblyException : " + e.getMessage()); |
362 | 0 | } catch (DoesNotExistException e) { |
363 | 0 | throw new OperationFailedException("Failed to update ATP - " + e.getMessage(), e); |
364 | 0 | } catch (ReadOnlyException e) { |
365 | 0 | throw new OperationFailedException("Failed to update ATP - " + e.getMessage(), e); |
366 | |
} |
367 | |
} |
368 | |
|
369 | |
@Override |
370 | |
@Transactional(readOnly = false) |
371 | |
public StatusInfo deleteHolidayCalendar(String holidayCalendarId, ContextInfo context) throws DoesNotExistException, InvalidParameterException, MissingParameterException, |
372 | |
OperationFailedException, PermissionDeniedException { |
373 | 0 | return atpService.deleteAtp(holidayCalendarId, context); |
374 | |
} |
375 | |
|
376 | |
@Override |
377 | |
public TypeInfo getTermType(String termTypeKey, ContextInfo context) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, |
378 | |
PermissionDeniedException { |
379 | 0 | TypeInfo type = typeService.getType(termTypeKey, context); |
380 | |
|
381 | 0 | if (!checkTypeForTermType(termTypeKey, context)) { |
382 | 0 | throw new InvalidParameterException(termTypeKey + " is not a Term type"); |
383 | |
} |
384 | |
|
385 | 0 | return type; |
386 | |
} |
387 | |
|
388 | |
@Override |
389 | |
public List<TypeInfo> getTermTypes(ContextInfo context) throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
390 | |
|
391 | 0 | List<TypeTypeRelationInfo> relations = null; |
392 | |
try { |
393 | 0 | relations = typeService.getTypeTypeRelationsByOwnerAndType(AtpServiceConstants.ATP_TERM_GROUPING_TYPE_KEY, TypeServiceConstants.TYPE_TYPE_RELATION_GROUP_TYPE_KEY, context); |
394 | 0 | } catch (DoesNotExistException e) { |
395 | 0 | throw new OperationFailedException(e.getMessage(), e); |
396 | 0 | } |
397 | |
|
398 | 0 | if (relations != null) { |
399 | 0 | List<TypeInfo> results = new ArrayList<TypeInfo>(relations.size()); |
400 | 0 | for (TypeTypeRelationInfo rel : relations) { |
401 | |
try { |
402 | 0 | results.add(typeService.getType(rel.getRelatedTypeKey(), context)); |
403 | 0 | } catch (DoesNotExistException e) { |
404 | 0 | throw new OperationFailedException(e.getMessage(), e); |
405 | 0 | } |
406 | |
} |
407 | |
|
408 | 0 | return results; |
409 | |
} |
410 | |
|
411 | 0 | return null; |
412 | |
} |
413 | |
|
414 | |
@Override |
415 | |
public List<TypeInfo> getTermTypesForAcademicCalendarType(String academicCalendarTypeKey, ContextInfo context) throws DoesNotExistException, InvalidParameterException, MissingParameterException, |
416 | |
OperationFailedException, PermissionDeniedException { |
417 | |
|
418 | 0 | TypeInfo acalType = typeService.getType(academicCalendarTypeKey, context); |
419 | |
|
420 | 0 | return typeService.getAllowedTypesForType(acalType.getKey(), context); |
421 | |
} |
422 | |
|
423 | |
@Override |
424 | |
public List<TypeInfo> getTermTypesForTermType(String termTypeKey, ContextInfo context) throws DoesNotExistException, InvalidParameterException, MissingParameterException, |
425 | |
OperationFailedException, PermissionDeniedException { |
426 | 0 | TypeInfo termType = getTermType(termTypeKey, context); |
427 | |
|
428 | 0 | return typeService.getAllowedTypesForType(termType.getKey(), context); |
429 | |
} |
430 | |
|
431 | |
@Override |
432 | |
public StateInfo getTermState(String termStateKey, ContextInfo context) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, |
433 | |
PermissionDeniedException { |
434 | |
|
435 | 0 | StateInfo termState = stateService.getState(termStateKey, context); |
436 | |
|
437 | 0 | return termState; |
438 | |
} |
439 | |
|
440 | |
@Override |
441 | |
public List<StateInfo> getTermStates(ContextInfo context) throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
442 | |
|
443 | |
List<StateInfo> results; |
444 | |
try { |
445 | 0 | results = stateService.getStatesByLifecycle(AtpServiceConstants.ATP_LIFECYCLE_KEY, context); |
446 | 0 | } catch (DoesNotExistException ex) { |
447 | 0 | throw new OperationFailedException(AtpServiceConstants.ATP_LIFECYCLE_KEY, ex); |
448 | 0 | } |
449 | |
|
450 | 0 | return results; |
451 | |
} |
452 | |
|
453 | |
@Override |
454 | |
public TermInfo getTerm(String termId, ContextInfo context) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
455 | 0 | AtpInfo atp = atpService.getAtp(termId, context); |
456 | 0 | TermInfo term = null; |
457 | |
|
458 | 0 | if (atp != null && checkTypeForTermType(atp.getTypeKey(), context)) { |
459 | |
try { |
460 | 0 | term = termAssembler.assemble(atp, context); |
461 | 0 | } catch (AssemblyException e) { |
462 | 0 | throw new OperationFailedException("AssemblyException : " + e.getMessage()); |
463 | 0 | } |
464 | |
} else { |
465 | 0 | throw new DoesNotExistException("This is either not valid Atp or not valid Term. " + termId); |
466 | |
} |
467 | |
|
468 | 0 | return term; |
469 | |
} |
470 | |
|
471 | |
@Override |
472 | |
public List<TermInfo> getTermsByIds(List<String> termIds, ContextInfo context) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, |
473 | |
PermissionDeniedException { |
474 | |
|
475 | 0 | List<AtpInfo> results = atpService.getAtpsByIds(termIds, context); |
476 | |
|
477 | 0 | List<TermInfo> terms = new ArrayList<TermInfo>(); |
478 | |
|
479 | 0 | for (AtpInfo atp : results) { |
480 | |
try { |
481 | 0 | terms.add(termAssembler.assemble(atp, context)); |
482 | 0 | } catch (AssemblyException e) { |
483 | 0 | throw new OperationFailedException("AssemblyException : " + e.getMessage()); |
484 | 0 | } |
485 | |
} |
486 | |
|
487 | 0 | return terms; |
488 | |
} |
489 | |
|
490 | |
@Override |
491 | |
public List<TermInfo> getTermsForAcademicCalendar(String academicCalendarId, ContextInfo context) throws DoesNotExistException, InvalidParameterException, MissingParameterException, |
492 | |
OperationFailedException, PermissionDeniedException { |
493 | |
|
494 | 0 | List<AtpAtpRelationInfo> results = atpService.getAtpAtpRelationsByTypeAndAtp(academicCalendarId, |
495 | |
AtpServiceConstants.ATP_ATP_RELATION_INCLUDES_TYPE_KEY, |
496 | |
context); |
497 | 0 | List<TermInfo> terms = new ArrayList<TermInfo>(results.size()); |
498 | 0 | for (AtpAtpRelationInfo atpRelation : results) { |
499 | 0 | if (atpRelation.getAtpId().equals(academicCalendarId)) { |
500 | 0 | AtpInfo possibleTerm = atpService.getAtp(atpRelation.getRelatedAtpId(), context); |
501 | 0 | if (checkTypeForTermType(possibleTerm.getTypeKey(), context)) { |
502 | |
try { |
503 | 0 | terms.add(termAssembler.assemble(possibleTerm, context)); |
504 | 0 | } catch (AssemblyException e) { |
505 | 0 | throw new OperationFailedException("AssemblyException : " + e.getMessage()); |
506 | 0 | } |
507 | |
} |
508 | 0 | } |
509 | |
} |
510 | 0 | return terms; |
511 | |
} |
512 | |
|
513 | |
@Override |
514 | |
public List<TermInfo> getCurrentTerms(String processKey, ContextInfo context) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, |
515 | |
PermissionDeniedException { |
516 | |
|
517 | 0 | List<AcademicCalendarInfo> currentACInfos = getAcademicCalendarsByStartYear(new Integer(Calendar.getInstance().get(Calendar.YEAR)), context); |
518 | 0 | List<TermInfo> terms = getTermsForAcademicCalendar(currentACInfos.get(0).getId(), context); |
519 | 0 | if (terms == null || terms.size() == 0) { |
520 | 0 | throw new DoesNotExistException("This academic calendar doesn't contain any terms : " + currentACInfos.get(0).getId()); |
521 | |
} |
522 | 0 | return terms; |
523 | |
} |
524 | |
|
525 | |
@Override |
526 | |
public List<TermInfo> getIncludedTermsInTerm(String termId, ContextInfo context) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, |
527 | |
PermissionDeniedException { |
528 | |
|
529 | |
|
530 | 0 | TermInfo parentTerm = getTerm(termId, context); |
531 | |
|
532 | 0 | List<AtpAtpRelationInfo> results = atpService.getAtpAtpRelationsByTypeAndAtp(parentTerm.getId(), AtpServiceConstants.ATP_ATP_RELATION_INCLUDES_TYPE_KEY, context); |
533 | |
|
534 | 0 | List<TermInfo> terms = new ArrayList<TermInfo>(results.size()); |
535 | |
|
536 | 0 | for (AtpAtpRelationInfo atpRelation : results) { |
537 | 0 | if (atpRelation.getAtpId().equals(termId)) { |
538 | 0 | AtpInfo possibleTerm = atpService.getAtp(atpRelation.getRelatedAtpId(), context); |
539 | |
|
540 | 0 | if (checkTypeForTermType(possibleTerm.getTypeKey(), context)) { |
541 | |
try { |
542 | 0 | terms.add(termAssembler.assemble(possibleTerm, context)); |
543 | 0 | } catch (AssemblyException e) { |
544 | 0 | throw new OperationFailedException("AssemblyException : " + e.getMessage()); |
545 | 0 | } |
546 | |
} |
547 | 0 | } |
548 | |
|
549 | |
} |
550 | |
|
551 | 0 | return terms; |
552 | |
} |
553 | |
|
554 | |
@Override |
555 | |
public List<TermInfo> getContainingTerms(String termId, ContextInfo context) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, |
556 | |
PermissionDeniedException { |
557 | |
|
558 | |
|
559 | 0 | TermInfo term = getTerm(termId, context); |
560 | |
|
561 | 0 | List<AtpAtpRelationInfo> results = atpService.getAtpAtpRelationsByAtp(term.getId(), context); |
562 | |
|
563 | 0 | List<TermInfo> terms = new ArrayList<TermInfo>(results.size()); |
564 | |
|
565 | |
|
566 | |
|
567 | 0 | for (AtpAtpRelationInfo atpRelation : results) { |
568 | 0 | if (atpRelation.getRelatedAtpId().equals(termId)) { |
569 | 0 | AtpInfo possibleTerm = atpService.getAtp(atpRelation.getAtpId(), context); |
570 | |
|
571 | 0 | if (checkTypeForTermType(possibleTerm.getTypeKey(), context)) { |
572 | |
try { |
573 | 0 | terms.add(termAssembler.assemble(possibleTerm, context)); |
574 | 0 | } catch (AssemblyException e) { |
575 | 0 | throw new OperationFailedException("AssemblyException : " + e.getMessage()); |
576 | 0 | } |
577 | |
} |
578 | 0 | } |
579 | |
|
580 | |
} |
581 | |
|
582 | 0 | return terms; |
583 | |
} |
584 | |
|
585 | |
@Override |
586 | |
public List<ValidationResultInfo> validateTerm(String validationTypeKey, String termTypeKey, TermInfo termInfo, ContextInfo context) throws DoesNotExistException, InvalidParameterException, |
587 | |
MissingParameterException, OperationFailedException { |
588 | |
|
589 | 0 | return new ArrayList<ValidationResultInfo>(); |
590 | |
} |
591 | |
|
592 | |
@Override |
593 | |
@Transactional(readOnly = false) |
594 | |
public TermInfo createTerm(String termTypeKey, TermInfo termInfo, ContextInfo context) throws DataValidationErrorException, InvalidParameterException, MissingParameterException, |
595 | |
OperationFailedException, PermissionDeniedException { |
596 | |
AtpInfo atp; |
597 | |
|
598 | 0 | if (checkTypeForTermType(termTypeKey, context)) { |
599 | |
try { |
600 | 0 | atp = termAssembler.disassemble(termInfo, context); |
601 | 0 | } catch (AssemblyException e) { |
602 | 0 | throw new OperationFailedException("AssemblyException : " + e.getMessage()); |
603 | 0 | } |
604 | |
|
605 | |
try { |
606 | 0 | AtpInfo newAtp = atpService.createAtp(atp.getTypeKey(), atp, context); |
607 | 0 | termInfo = termAssembler.assemble(newAtp, context); |
608 | 0 | } catch (AssemblyException e) { |
609 | 0 | throw new OperationFailedException("Error assembling term", e); |
610 | 0 | } catch (ReadOnlyException e) { |
611 | 0 | throw new OperationFailedException("Error assembling term", e); |
612 | 0 | } |
613 | |
} else { |
614 | 0 | throw new InvalidParameterException("Term type not found: '" + termTypeKey + "'"); |
615 | |
} |
616 | |
|
617 | 0 | return termInfo; |
618 | |
} |
619 | |
|
620 | |
@Override |
621 | |
@Transactional(readOnly = false) |
622 | |
public TermInfo updateTerm(String termId, TermInfo termInfo, ContextInfo context) throws DataValidationErrorException, DoesNotExistException, InvalidParameterException, MissingParameterException, |
623 | |
OperationFailedException, PermissionDeniedException, VersionMismatchException { |
624 | |
|
625 | |
|
626 | |
TermInfo updatedTerm; |
627 | |
|
628 | |
try { |
629 | 0 | AtpInfo toUpdate = termAssembler.disassemble(termInfo, context); |
630 | |
|
631 | 0 | AtpInfo updated = atpService.updateAtp(termId, toUpdate, context); |
632 | |
|
633 | 0 | updatedTerm = termAssembler.assemble(updated, context); |
634 | 0 | } catch (AssemblyException e) { |
635 | 0 | throw new OperationFailedException("AssemblyException : " + e.getMessage()); |
636 | 0 | } catch (ReadOnlyException e) { |
637 | 0 | throw new OperationFailedException("Error updating ATP - " + e.getMessage(), e); |
638 | 0 | } |
639 | |
|
640 | 0 | return updatedTerm; |
641 | |
} |
642 | |
|
643 | |
@Override |
644 | |
@Transactional(readOnly = false) |
645 | |
public StatusInfo deleteTerm(String termId, ContextInfo context) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, |
646 | |
PermissionDeniedException { |
647 | |
|
648 | 0 | AtpInfo atp = atpService.getAtp(termId, context); |
649 | |
|
650 | 0 | if (atp == null) { |
651 | 0 | throw new DoesNotExistException(termId); |
652 | |
} |
653 | |
|
654 | 0 | if (!checkTypeForTermType(atp.getTypeKey(), context)) { |
655 | 0 | throw new InvalidParameterException("Invalid termId: " + termId + " Given key does not map to a Term"); |
656 | |
} |
657 | |
|
658 | 0 | StatusInfo result = atpService.deleteAtp(termId, context); |
659 | |
|
660 | 0 | return result; |
661 | |
} |
662 | |
|
663 | |
@Override |
664 | |
@Transactional(readOnly = false) |
665 | |
public StatusInfo addTermToAcademicCalendar(String academicCalendarId, |
666 | |
String termId, ContextInfo context) throws DoesNotExistException, |
667 | |
InvalidParameterException, |
668 | |
MissingParameterException, |
669 | |
OperationFailedException, PermissionDeniedException, |
670 | |
AlreadyExistsException { |
671 | |
|
672 | 0 | AtpInfo acal = atpService.getAtp(academicCalendarId, context); |
673 | 0 | if (!isAcademicCalendar(acal.getTypeKey())) { |
674 | 0 | throw new DoesNotExistException("AcademicCalendar with id = " + academicCalendarId + " is not an academic calendar " + acal.getTypeKey()); |
675 | |
} |
676 | |
|
677 | 0 | AtpInfo term = atpService.getAtp(termId, context); |
678 | 0 | if (!checkTypeForTermType(term.getTypeKey(), context)) { |
679 | 0 | throw new DoesNotExistException("ter with id = " + termId + " is not an academic calendar " + term.getTypeKey()); |
680 | |
} |
681 | |
|
682 | 0 | if (termAlreadyExists(academicCalendarId, termId, context)) { |
683 | 0 | throw new AlreadyExistsException("Term with id = " + termId + " is already associated with academic calendar " + academicCalendarId); |
684 | |
} |
685 | |
|
686 | |
try { |
687 | 0 | createAtpAtpRelation(academicCalendarId, termId, AtpServiceConstants.ATP_ATP_RELATION_INCLUDES_TYPE_KEY, context); |
688 | 0 | } catch (DataValidationErrorException ex) { |
689 | 0 | throw new OperationFailedException("unexpected", ex); |
690 | 0 | } |
691 | 0 | StatusInfo status = new StatusInfo(); |
692 | 0 | status.setSuccess(Boolean.TRUE); |
693 | 0 | return status; |
694 | |
} |
695 | |
|
696 | |
private boolean isAcademicCalendar(String acalType) { |
697 | 0 | return acalType.equals(AtpServiceConstants.ATP_ACADEMIC_CALENDAR_TYPE_KEY); |
698 | |
} |
699 | |
|
700 | |
private boolean termAlreadyExists(String parentTermOrAcalId, String termId, ContextInfo context) |
701 | |
throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, |
702 | |
PermissionDeniedException { |
703 | 0 | List<AtpAtpRelationInfo> atpRels = atpService.getAtpAtpRelationsByTypeAndAtp(parentTermOrAcalId, AtpServiceConstants.ATP_ATP_RELATION_INCLUDES_TYPE_KEY, context); |
704 | 0 | for (AtpAtpRelationInfo atpRelInfo : atpRels) { |
705 | 0 | if (atpRelInfo.getAtpId().equals(parentTermOrAcalId)) { |
706 | 0 | if (atpRelInfo.getRelatedAtpId().equals(termId)) { |
707 | 0 | return true; |
708 | |
} |
709 | |
} |
710 | |
} |
711 | 0 | return false; |
712 | |
} |
713 | |
|
714 | |
@Override |
715 | |
@Transactional(readOnly = false) |
716 | |
public StatusInfo removeTermFromAcademicCalendar(String academicCalendarKey, String termId, ContextInfo context) throws DoesNotExistException, InvalidParameterException, |
717 | |
MissingParameterException, OperationFailedException, PermissionDeniedException { |
718 | |
|
719 | 0 | AtpInfo acal = atpService.getAtp(academicCalendarKey, context); |
720 | |
|
721 | 0 | if (acal == null) { |
722 | 0 | throw new InvalidParameterException("Invalid academicCalendarKey: " + academicCalendarKey); |
723 | |
} |
724 | |
|
725 | 0 | AtpInfo term = atpService.getAtp(termId, context); |
726 | |
|
727 | 0 | if (term == null) { |
728 | 0 | throw new InvalidParameterException("Invalid termId: " + termId); |
729 | |
} |
730 | |
|
731 | 0 | List<AtpAtpRelationInfo> relations = atpService.getAtpAtpRelationsByTypeAndAtp(academicCalendarKey, AtpServiceConstants.ATP_ATP_RELATION_INCLUDES_TYPE_KEY, context); |
732 | 0 | if (relations == null || relations.isEmpty()) { |
733 | 0 | throw new DoesNotExistException("No relationship exists between academic calendar: " + academicCalendarKey + " and term: " + termId); |
734 | |
} |
735 | |
|
736 | 0 | AtpAtpRelationInfo relationToRemove = null; |
737 | |
|
738 | 0 | for (AtpAtpRelationInfo rel : relations) { |
739 | 0 | if (rel.getAtpId().equals(academicCalendarKey)) { |
740 | 0 | if (rel.getRelatedAtpId().equals(termId)) { |
741 | |
|
742 | |
|
743 | |
|
744 | 0 | relationToRemove = rel; |
745 | 0 | break; |
746 | |
} |
747 | |
} |
748 | |
} |
749 | |
|
750 | 0 | if (relationToRemove == null) { |
751 | 0 | throw new DoesNotExistException("No relationship exists between academic calendar: " + academicCalendarKey + " and term: " + termId); |
752 | |
} |
753 | |
|
754 | 0 | StatusInfo resultStatus = atpService.deleteAtpAtpRelation(relationToRemove.getId(), context); |
755 | |
|
756 | 0 | return resultStatus; |
757 | |
} |
758 | |
|
759 | |
@Override |
760 | |
@Transactional(readOnly = false) |
761 | |
public StatusInfo addTermToTerm(String termId, String includedTermId, ContextInfo context) throws AlreadyExistsException, DoesNotExistException, InvalidParameterException, |
762 | |
MissingParameterException, OperationFailedException, PermissionDeniedException { |
763 | |
|
764 | 0 | TermInfo term = getTerm(termId, context); |
765 | |
|
766 | 0 | TermInfo includedTerm = getTerm(includedTermId, context); |
767 | |
|
768 | |
|
769 | 0 | List<TermInfo> terms = getIncludedTermsInTerm(term.getId(), context); |
770 | 0 | for (TermInfo t : terms) { |
771 | 0 | if (t.getId().equals(includedTerm.getId())) { |
772 | 0 | throw new AlreadyExistsException("A relationship already exists exists between term: " + termId + " and included term: " + includedTermId); |
773 | |
} |
774 | |
} |
775 | |
|
776 | 0 | StatusInfo resultStatus = new StatusInfo(); |
777 | |
|
778 | |
try { |
779 | 0 | createAtpAtpRelation(termId, includedTermId, AtpServiceConstants.ATP_ATP_RELATION_INCLUDES_TYPE_KEY, context); |
780 | 0 | } catch (DataValidationErrorException e) { |
781 | 0 | resultStatus.setSuccess(false); |
782 | 0 | resultStatus.setMessage("Creation of AtpAtpRelation failed due to DataValidationErrorExecption: " + e.getMessage()); |
783 | 0 | } |
784 | |
|
785 | 0 | return resultStatus; |
786 | |
} |
787 | |
|
788 | |
@Override |
789 | |
@Transactional(readOnly = false) |
790 | |
public StatusInfo removeTermFromTerm(String termId, String includedTermId, ContextInfo context) throws DoesNotExistException, InvalidParameterException, MissingParameterException, |
791 | |
OperationFailedException, PermissionDeniedException { |
792 | |
|
793 | |
try { |
794 | 0 | atpService.getAtp(termId, context); |
795 | 0 | } catch (DoesNotExistException e) { |
796 | 0 | throw new InvalidParameterException("Invalid termId: " + termId); |
797 | 0 | } |
798 | |
|
799 | |
try { |
800 | 0 | atpService.getAtp(includedTermId, context); |
801 | 0 | } catch (DoesNotExistException e) { |
802 | 0 | throw new InvalidParameterException("Invalid includedTermId: " + includedTermId); |
803 | 0 | } |
804 | |
|
805 | 0 | List<AtpAtpRelationInfo> relations = atpService.getAtpAtpRelationsByTypeAndAtp(termId, AtpServiceConstants.ATP_ATP_RELATION_INCLUDES_TYPE_KEY, context); |
806 | 0 | if (relations == null || relations.isEmpty()) { |
807 | 0 | throw new DoesNotExistException("No relationship exists between term: " + termId + " and included term: " + includedTermId); |
808 | |
} |
809 | |
|
810 | 0 | AtpAtpRelationInfo relationToRemove = null; |
811 | |
|
812 | 0 | for (AtpAtpRelationInfo rel : relations) { |
813 | 0 | if (rel.getAtpId().equals(termId)) { |
814 | 0 | if (rel.getRelatedAtpId().equals(includedTermId)) { |
815 | |
|
816 | |
|
817 | |
|
818 | 0 | relationToRemove = rel; |
819 | 0 | break; |
820 | |
} |
821 | |
} |
822 | |
} |
823 | |
|
824 | 0 | if (relationToRemove == null) { |
825 | 0 | throw new DoesNotExistException("No relationship exists between term: " + termId + " and included term: " + includedTermId); |
826 | |
} |
827 | |
|
828 | 0 | StatusInfo resultStatus = atpService.deleteAtpAtpRelation(relationToRemove.getId(), context); |
829 | |
|
830 | 0 | return resultStatus; |
831 | |
} |
832 | |
|
833 | |
@Override |
834 | |
public TypeInfo getKeyDateType(String keyDateTypeKey, ContextInfo context) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException { |
835 | |
|
836 | 0 | return null; |
837 | |
} |
838 | |
|
839 | |
@Override |
840 | |
public List<TypeInfo> getKeyDateTypesForTermType(String termTypeKey, ContextInfo context) |
841 | |
throws DoesNotExistException, InvalidParameterException, MissingParameterException, |
842 | |
OperationFailedException { |
843 | 0 | List<TypeInfo> types = null; |
844 | |
try { |
845 | |
|
846 | 0 | types = this.typeService.getAllowedTypesForType(termTypeKey, context); |
847 | 0 | } catch (PermissionDeniedException ex) { |
848 | 0 | throw new OperationFailedException("TODO: change the contract to allow this method, getKeyDateTypesForTermType, to throw the PermissionDeniedException", ex); |
849 | 0 | } |
850 | |
|
851 | 0 | List<TypeInfo> list = new ArrayList<TypeInfo>(types.size()); |
852 | 0 | for (TypeInfo type : types) { |
853 | 0 | if (type.getRefObjectUri() == null) { |
854 | 0 | throw new NullPointerException(type.getKey()); |
855 | |
} |
856 | 0 | if (type.getRefObjectUri().equals(AtpServiceConstants.REF_OBJECT_URI_MILESTONE)) { |
857 | 0 | list.add(type); |
858 | |
} |
859 | |
} |
860 | 0 | return list; |
861 | |
} |
862 | |
|
863 | |
@Override |
864 | |
public KeyDateInfo getKeyDate(String keyDateId, ContextInfo context) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, |
865 | |
PermissionDeniedException { |
866 | 0 | MilestoneInfo ms = atpService.getMilestone(keyDateId, context); |
867 | 0 | return (null != ms) ? fromMilestoneInfo(ms) : null; |
868 | |
} |
869 | |
|
870 | |
@Override |
871 | |
public List<KeyDateInfo> getKeyDatesByIds(List<String> keyDateIds, ContextInfo context) throws DoesNotExistException, InvalidParameterException, MissingParameterException, |
872 | |
OperationFailedException, PermissionDeniedException { |
873 | 0 | return new ArrayList<KeyDateInfo>(); |
874 | |
} |
875 | |
|
876 | |
@Override |
877 | |
public List<KeyDateInfo> getKeyDatesForTerm(String termId, ContextInfo context) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, |
878 | |
PermissionDeniedException { |
879 | |
|
880 | 0 | AtpInfo termAtp = atpService.getAtp(termId, context); |
881 | 0 | if (termAtp == null) { |
882 | 0 | throw new DoesNotExistException(termId); |
883 | |
} |
884 | |
|
885 | 0 | List<MilestoneInfo> milestones = atpService.getMilestonesForAtp(termId, context); |
886 | |
|
887 | 0 | if (milestones == null || milestones.isEmpty()) { |
888 | 0 | return Collections.emptyList(); |
889 | |
} |
890 | |
|
891 | 0 | List<KeyDateInfo> keyDates = new ArrayList<KeyDateInfo>(milestones.size()); |
892 | |
|
893 | 0 | for (MilestoneInfo milestone : milestones) { |
894 | 0 | keyDates.add(fromMilestoneInfo(milestone)); |
895 | |
} |
896 | |
|
897 | 0 | return keyDates; |
898 | |
} |
899 | |
|
900 | |
@Override |
901 | |
public List<KeyDateInfo> getKeyDatesForTermByDate(String termId, Date startDate, Date endDate, ContextInfo context) throws DoesNotExistException, InvalidParameterException, |
902 | |
MissingParameterException, OperationFailedException, PermissionDeniedException { |
903 | 0 | List<MilestoneInfo> milestoneInfos = atpService.getMilestonesByDatesForAtp(termId, startDate, endDate, context); |
904 | 0 | List<KeyDateInfo> keyDates = new ArrayList<KeyDateInfo>(); |
905 | 0 | for (MilestoneInfo milestoneInfo : milestoneInfos) { |
906 | 0 | keyDates.add(fromMilestoneInfo(milestoneInfo)); |
907 | |
} |
908 | 0 | return keyDates; |
909 | |
} |
910 | |
|
911 | |
@Override |
912 | |
public List<KeyDateInfo> getImpactedKeyDates(String keyDateId, ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, |
913 | |
OperationFailedException, PermissionDeniedException { |
914 | 0 | List<KeyDateInfo> impactedKeyDates = new ArrayList<KeyDateInfo>(); |
915 | 0 | List<MilestoneInfo> impactedMilestones = atpService.getImpactedMilestones(keyDateId, contextInfo); |
916 | 0 | for (MilestoneInfo impactedMilestone : impactedMilestones) { |
917 | 0 | impactedKeyDates.add(fromMilestoneInfo(impactedMilestone)); |
918 | |
} |
919 | 0 | return impactedKeyDates; |
920 | |
} |
921 | |
|
922 | |
private MilestoneInfo toMilestoneInfo(KeyDateInfo keyDateInfo) { |
923 | 0 | if (keyDateInfo != null) { |
924 | 0 | MilestoneInfo msInfo = new MilestoneInfo(); |
925 | 0 | msInfo.setIsAllDay(keyDateInfo.getIsAllDay()); |
926 | 0 | msInfo.setAttributes(keyDateInfo.getAttributes()); |
927 | 0 | msInfo.setIsDateRange(keyDateInfo.getIsDateRange()); |
928 | 0 | msInfo.setDescr(keyDateInfo.getDescr()); |
929 | 0 | msInfo.setId(keyDateInfo.getId()); |
930 | 0 | msInfo.setMeta(keyDateInfo.getMeta()); |
931 | 0 | msInfo.setName(keyDateInfo.getName()); |
932 | 0 | msInfo.setStartDate(keyDateInfo.getStartDate()); |
933 | 0 | msInfo.setEndDate(keyDateInfo.getEndDate()); |
934 | 0 | msInfo.setStateKey(keyDateInfo.getStateKey()); |
935 | 0 | msInfo.setTypeKey(keyDateInfo.getTypeKey()); |
936 | |
|
937 | 0 | return msInfo; |
938 | |
} else { |
939 | 0 | return null; |
940 | |
} |
941 | |
} |
942 | |
|
943 | |
private KeyDateInfo fromMilestoneInfo(MilestoneInfo milestoneInfo) { |
944 | 0 | if (milestoneInfo != null) { |
945 | 0 | KeyDateInfo keyInfo = new KeyDateInfo(); |
946 | 0 | keyInfo.setIsAllDay(milestoneInfo.getIsAllDay()); |
947 | 0 | keyInfo.setAttributes(milestoneInfo.getAttributes()); |
948 | 0 | keyInfo.setIsDateRange(milestoneInfo.getIsDateRange()); |
949 | 0 | keyInfo.setDescr(milestoneInfo.getDescr()); |
950 | 0 | keyInfo.setId(milestoneInfo.getId()); |
951 | 0 | keyInfo.setMeta(milestoneInfo.getMeta()); |
952 | 0 | keyInfo.setName(milestoneInfo.getName()); |
953 | 0 | keyInfo.setStartDate(milestoneInfo.getStartDate()); |
954 | 0 | keyInfo.setEndDate(milestoneInfo.getEndDate()); |
955 | 0 | keyInfo.setStateKey(milestoneInfo.getStateKey()); |
956 | 0 | keyInfo.setTypeKey(milestoneInfo.getTypeKey()); |
957 | 0 | keyInfo.setIsRelativeToKeyDate(milestoneInfo.getIsRelative()); |
958 | 0 | keyInfo.setRelativeAnchorKeyDateId(milestoneInfo.getRelativeAnchorMilestoneId()); |
959 | |
|
960 | 0 | return keyInfo; |
961 | |
} else { |
962 | 0 | return null; |
963 | |
} |
964 | |
} |
965 | |
|
966 | |
@Override |
967 | |
@Transactional(readOnly = false) |
968 | |
public KeyDateInfo updateKeyDate(String keyDateId, KeyDateInfo keyDateInfo, ContextInfo context) throws DataValidationErrorException, DoesNotExistException, InvalidParameterException, |
969 | |
MissingParameterException, OperationFailedException, PermissionDeniedException, VersionMismatchException { |
970 | |
|
971 | 0 | MilestoneInfo toUpdate = toMilestoneInfo(keyDateInfo); |
972 | 0 | MilestoneInfo newMilestone = null; |
973 | |
try { |
974 | 0 | newMilestone = atpService.updateMilestone(keyDateId, toUpdate, context); |
975 | 0 | } catch (ReadOnlyException e) { |
976 | 0 | throw new OperationFailedException("Error updating milestone", e); |
977 | 0 | } |
978 | |
|
979 | 0 | return fromMilestoneInfo(newMilestone); |
980 | |
} |
981 | |
|
982 | |
@Override |
983 | |
@Transactional(readOnly = false) |
984 | |
public StatusInfo deleteKeyDate(String keyDateId, ContextInfo context) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, |
985 | |
PermissionDeniedException { |
986 | 0 | return atpService.deleteMilestone(keyDateId, context); |
987 | |
} |
988 | |
|
989 | |
@Override |
990 | |
@Transactional(readOnly = false) |
991 | |
public KeyDateInfo calculateKeyDate(String keyDateId, ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, |
992 | |
PermissionDeniedException { |
993 | 0 | MilestoneInfo milestone = atpService.calculateMilestone(keyDateId, contextInfo); |
994 | 0 | return fromMilestoneInfo(milestone); |
995 | |
} |
996 | |
|
997 | |
@Override |
998 | |
public TypeInfo getHolidayType(String holidayTypeKey, ContextInfo context) throws DoesNotExistException, InvalidParameterException, |
999 | |
MissingParameterException, OperationFailedException, PermissionDeniedException { |
1000 | 0 | TypeInfo type = typeService.getType(holidayTypeKey, context); |
1001 | |
|
1002 | |
|
1003 | 0 | if (!checkTypeForHolidayType(holidayTypeKey, context)) { |
1004 | 0 | throw new InvalidParameterException(holidayTypeKey + " is not a Holiday type"); |
1005 | |
} |
1006 | |
|
1007 | 0 | return type; |
1008 | |
} |
1009 | |
|
1010 | |
@Override |
1011 | |
@Transactional(readOnly = false) |
1012 | |
public HolidayInfo updateHoliday(String holidayId, HolidayInfo holidayInfo, ContextInfo context) throws DataValidationErrorException, DoesNotExistException, InvalidParameterException, |
1013 | |
MissingParameterException, OperationFailedException, PermissionDeniedException, VersionMismatchException { |
1014 | |
|
1015 | |
try { |
1016 | 0 | MilestoneInfo toUpdate = holidayAssembler.disassemble(holidayInfo, context); |
1017 | 0 | MilestoneInfo updated = null; |
1018 | |
try { |
1019 | 0 | updated = atpService.updateMilestone(holidayId, toUpdate, context); |
1020 | 0 | } catch (ReadOnlyException e) { |
1021 | 0 | throw new OperationFailedException("Error updating milestone", e); |
1022 | 0 | } |
1023 | |
|
1024 | 0 | return holidayAssembler.assemble(updated, context); |
1025 | 0 | } catch (AssemblyException e) { |
1026 | 0 | throw new OperationFailedException("AssemblyException : " + e.getMessage()); |
1027 | |
} |
1028 | |
} |
1029 | |
|
1030 | |
@Override |
1031 | |
@Transactional(readOnly = false) |
1032 | |
public StatusInfo deleteHoliday(String holidayId, ContextInfo context) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, |
1033 | |
PermissionDeniedException { |
1034 | 0 | return atpService.deleteMilestone(holidayId, context); |
1035 | |
} |
1036 | |
|
1037 | |
@Override |
1038 | |
@Transactional(readOnly = false) |
1039 | |
public HolidayInfo calculateHoliday(String holidayId, ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, |
1040 | |
PermissionDeniedException { |
1041 | 0 | return getHoliday(holidayId, contextInfo); |
1042 | |
} |
1043 | |
|
1044 | |
|
1045 | |
private DateRangeInfo getDateRangeFromKeyDate(KeyDateInfo keyDate) { |
1046 | 0 | DateRangeInfo dateRange = null; |
1047 | 0 | if (keyDate != null) { |
1048 | 0 | dateRange = new DateRangeInfo(); |
1049 | 0 | dateRange.setStartDate(keyDate.getStartDate()); |
1050 | 0 | dateRange.setEndDate(keyDate.getEndDate()); |
1051 | |
} |
1052 | 0 | return dateRange; |
1053 | |
} |
1054 | |
|
1055 | |
private KeyDateInfo getKeyDatePrepairedFromDateRange(KeyDateInfo keyDate, DateRangeInfo dateRange) { |
1056 | 0 | if (null == dateRange) { |
1057 | 0 | return null; |
1058 | |
} |
1059 | 0 | if (keyDate == null) { |
1060 | 0 | keyDate = new KeyDateInfo(); |
1061 | |
} |
1062 | 0 | keyDate.setStartDate(dateRange.getStartDate()); |
1063 | 0 | keyDate.setEndDate(dateRange.getEndDate()); |
1064 | 0 | keyDate.setIsDateRange(Boolean.TRUE); |
1065 | 0 | return keyDate; |
1066 | |
} |
1067 | |
|
1068 | |
private KeyDateInfo getKeyDatePrepairedFromDate(KeyDateInfo keyDate, Date date) { |
1069 | 0 | if (null == date) { |
1070 | 0 | return null; |
1071 | |
} |
1072 | 0 | if (keyDate == null) { |
1073 | 0 | keyDate = new KeyDateInfo(); |
1074 | |
} |
1075 | 0 | keyDate.setStartDate(date); |
1076 | 0 | keyDate.setEndDate(date); |
1077 | 0 | keyDate.setIsAllDay(Boolean.FALSE); |
1078 | 0 | keyDate.setIsDateRange(Boolean.FALSE); |
1079 | 0 | return keyDate; |
1080 | |
} |
1081 | |
|
1082 | |
|
1083 | |
public AtpService getAtpService() { |
1084 | 0 | return atpService; |
1085 | |
} |
1086 | |
|
1087 | |
public void setAtpService(AtpService atpService) { |
1088 | 0 | this.atpService = atpService; |
1089 | 0 | } |
1090 | |
|
1091 | |
public AcademicCalendarAssembler getAcalAssembler() { |
1092 | 0 | return acalAssembler; |
1093 | |
} |
1094 | |
|
1095 | |
public void setAcalAssembler(AcademicCalendarAssembler acalAssembler) { |
1096 | 0 | this.acalAssembler = acalAssembler; |
1097 | 0 | } |
1098 | |
|
1099 | |
public TermAssembler getTermAssembler() { |
1100 | 0 | return termAssembler; |
1101 | |
} |
1102 | |
|
1103 | |
public void setTermAssembler(TermAssembler termAssembler) { |
1104 | 0 | this.termAssembler = termAssembler; |
1105 | 0 | } |
1106 | |
|
1107 | |
@Override |
1108 | |
public List<AcademicCalendarInfo> searchForAcademicCalendars(QueryByCriteria criteria, ContextInfo context) throws InvalidParameterException, MissingParameterException, OperationFailedException, |
1109 | |
PermissionDeniedException { |
1110 | |
|
1111 | 0 | List<AcademicCalendarInfo> academicCalendars = new ArrayList<AcademicCalendarInfo>(); |
1112 | 0 | List<AtpInfo> atps = atpService.searchForAtps(criteria, context); |
1113 | |
|
1114 | 0 | for (AtpInfo atp : atps) { |
1115 | |
try { |
1116 | 0 | academicCalendars.add(acalAssembler.assemble(atp, context)); |
1117 | 0 | } catch (AssemblyException e) { |
1118 | 0 | throw new OperationFailedException("AssemblyException : " + e.getMessage()); |
1119 | 0 | } |
1120 | |
} |
1121 | |
|
1122 | 0 | return academicCalendars; |
1123 | |
} |
1124 | |
|
1125 | |
@Override |
1126 | |
public List<TermInfo> searchForTerms(QueryByCriteria criteria, ContextInfo context) throws InvalidParameterException, MissingParameterException, OperationFailedException, |
1127 | |
PermissionDeniedException { |
1128 | |
|
1129 | 0 | List<AtpInfo> results = atpService.searchForAtps(criteria, context); |
1130 | 0 | List<TermInfo> terms = new ArrayList<TermInfo>(results.size()); |
1131 | |
|
1132 | 0 | for (AtpInfo atp : results) { |
1133 | |
try { |
1134 | 0 | terms.add(termAssembler.assemble(atp, context)); |
1135 | 0 | } catch (AssemblyException e) { |
1136 | 0 | throw new OperationFailedException("AssemblyException : " + e.getMessage()); |
1137 | 0 | } |
1138 | |
} |
1139 | |
|
1140 | 0 | return terms; |
1141 | |
} |
1142 | |
|
1143 | |
@Override |
1144 | |
public List<KeyDateInfo> searchForKeyDates(QueryByCriteria criteria, ContextInfo context) throws InvalidParameterException, MissingParameterException, OperationFailedException, |
1145 | |
PermissionDeniedException { |
1146 | |
|
1147 | 0 | return new ArrayList<KeyDateInfo>(); |
1148 | |
} |
1149 | |
|
1150 | |
@Override |
1151 | |
public List<HolidayInfo> searchForHolidays(QueryByCriteria criteria, ContextInfo context) throws InvalidParameterException, MissingParameterException, OperationFailedException, |
1152 | |
PermissionDeniedException { |
1153 | |
|
1154 | 0 | List<MilestoneInfo> milestoneInfos = atpService.searchForMilestones(criteria, context); |
1155 | 0 | List<HolidayInfo> holidayInfos = new ArrayList<HolidayInfo>(); |
1156 | |
|
1157 | 0 | for (MilestoneInfo milestoneInfo : milestoneInfos) { |
1158 | |
try { |
1159 | 0 | holidayInfos.add(holidayAssembler.assemble(milestoneInfo, context)); |
1160 | 0 | } catch (AssemblyException e) { |
1161 | 0 | throw new OperationFailedException("Error assembling holiday with Id " + milestoneInfo.getId(), e); |
1162 | 0 | } |
1163 | |
} |
1164 | |
|
1165 | 0 | return holidayInfos; |
1166 | |
} |
1167 | |
|
1168 | |
private boolean checkTypeForTermType(String typeKey, ContextInfo context) throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
1169 | 0 | List<TypeInfo> types = getTermTypes(context); |
1170 | 0 | return checkTypeInTypes(typeKey, types); |
1171 | |
} |
1172 | |
|
1173 | |
private boolean checkTypeForHolidayType(String typeKey, ContextInfo context) throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
1174 | 0 | List<TypeInfo> types = getHolidayTypes(context); |
1175 | 0 | return checkTypeInTypes(typeKey, types); |
1176 | |
} |
1177 | |
|
1178 | |
private boolean checkTypeInTypes(String typeKey, List<TypeInfo> types) { |
1179 | 0 | if (types != null && !types.isEmpty()) { |
1180 | 0 | for (TypeInfo type : types) { |
1181 | 0 | if (type.getKey().equals(typeKey)) { |
1182 | 0 | return true; |
1183 | |
} |
1184 | |
} |
1185 | |
} |
1186 | |
|
1187 | 0 | return false; |
1188 | |
} |
1189 | |
|
1190 | |
private void createDeleteAtpAtpRelations(String fromAtpId, |
1191 | |
List<String> newRelatedAtpIds, |
1192 | |
String relatedAtpType, |
1193 | |
ContextInfo context) |
1194 | |
throws AlreadyExistsException, DataValidationErrorException, |
1195 | |
InvalidParameterException, MissingParameterException, OperationFailedException, |
1196 | |
PermissionDeniedException, VersionMismatchException { |
1197 | |
|
1198 | 0 | List<AtpAtpRelationInfo> atpRels = atpService.getAtpAtpRelationsByAtp(fromAtpId, context); |
1199 | 0 | Map<String, String> existing = new HashMap<String, String>(); |
1200 | 0 | for (AtpAtpRelationInfo atpRelInfo : atpRels) { |
1201 | 0 | if (AtpServiceConstants.ATP_ATP_RELATION_ASSOCIATED_TYPE_KEY.equals(atpRelInfo.getTypeKey())) { |
1202 | 0 | AtpInfo atp = null; |
1203 | |
try { |
1204 | 0 | atp = atpService.getAtp(atpRelInfo.getRelatedAtpId(), context); |
1205 | 0 | } catch (DoesNotExistException ex) { |
1206 | 0 | throw new OperationFailedException(atpRelInfo.getRelatedAtpId(), ex); |
1207 | 0 | } |
1208 | 0 | if (atp.getTypeKey().equals(relatedAtpType)) { |
1209 | 0 | existing.put(atpRelInfo.getRelatedAtpId(), atpRelInfo.getId()); |
1210 | |
} |
1211 | 0 | } |
1212 | |
} |
1213 | |
|
1214 | 0 | for (String relatedAtpId : newRelatedAtpIds) { |
1215 | 0 | if (!existing.containsKey(relatedAtpId)) { |
1216 | 0 | createAtpAtpRelation(fromAtpId, relatedAtpId, AtpServiceConstants.ATP_ATP_RELATION_ASSOCIATED_TYPE_KEY, context); |
1217 | |
} |
1218 | |
} |
1219 | |
|
1220 | 0 | for (String existingAtpId : existing.keySet()) { |
1221 | 0 | if (!newRelatedAtpIds.contains(existingAtpId)) { |
1222 | 0 | String atpAtpRelationId = existing.get(existingAtpId); |
1223 | |
try { |
1224 | 0 | StatusInfo status = atpService.deleteAtpAtpRelation(atpAtpRelationId, context); |
1225 | 0 | } catch (DoesNotExistException ex) { |
1226 | 0 | throw new OperationFailedException("Unexpected", ex); |
1227 | 0 | } |
1228 | 0 | } |
1229 | |
} |
1230 | 0 | } |
1231 | |
|
1232 | |
private AtpAtpRelationInfo createAtpAtpRelation(String atpId, |
1233 | |
String relatedAtpId, |
1234 | |
String relationType, |
1235 | |
ContextInfo context) |
1236 | |
throws AlreadyExistsException, DataValidationErrorException, |
1237 | |
InvalidParameterException, MissingParameterException, |
1238 | |
OperationFailedException, PermissionDeniedException { |
1239 | 0 | AtpAtpRelationInfo atpRel = new AtpAtpRelationInfo(); |
1240 | 0 | atpRel.setAtpId(atpId); |
1241 | 0 | atpRel.setRelatedAtpId(relatedAtpId); |
1242 | 0 | atpRel.setTypeKey(relationType); |
1243 | 0 | atpRel.setStateKey(AtpServiceConstants.ATP_ATP_RELATION_ACTIVE_STATE_KEY); |
1244 | 0 | atpRel.setEffectiveDate(new Date()); |
1245 | |
try { |
1246 | 0 | atpRel = atpService.createAtpAtpRelation(atpRel.getAtpId(), atpRel.getRelatedAtpId(), atpRel.getTypeKey(), atpRel, context); |
1247 | 0 | } catch (DoesNotExistException e) { |
1248 | 0 | throw new OperationFailedException("Error creating atp-atp relation", e); |
1249 | 0 | } catch (ReadOnlyException e) { |
1250 | 0 | throw new OperationFailedException("Error creating atp-atp relation", e); |
1251 | 0 | } |
1252 | 0 | return atpRel; |
1253 | |
} |
1254 | |
|
1255 | |
@Override |
1256 | |
public List<String> searchForAcademicCalendarIds(QueryByCriteria criteria, ContextInfo contextInfo) throws InvalidParameterException, MissingParameterException, OperationFailedException, |
1257 | |
PermissionDeniedException { |
1258 | |
|
1259 | 0 | return null; |
1260 | |
} |
1261 | |
|
1262 | |
@Override |
1263 | |
public List<ValidationResultInfo> validateAcademicCalendar(String validationTypeKey, String academicCalendarTypeKey, AcademicCalendarInfo academicCalendarInfo, ContextInfo contextInfo) |
1264 | |
throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
1265 | |
|
1266 | 0 | return null; |
1267 | |
} |
1268 | |
|
1269 | |
@Override |
1270 | |
public TypeInfo getHolidayCalendarType(String holidayCalendarTypeKey, ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, |
1271 | |
OperationFailedException { |
1272 | |
TypeInfo type; |
1273 | |
try { |
1274 | 0 | type = typeService.getType(holidayCalendarTypeKey, contextInfo); |
1275 | 0 | } catch (PermissionDeniedException ex) { |
1276 | 0 | throw new OperationFailedException("Permission Denied"); |
1277 | 0 | } |
1278 | |
|
1279 | 0 | return type; |
1280 | |
|
1281 | |
} |
1282 | |
|
1283 | |
@Override |
1284 | |
public List<TypeInfo> getHolidayCalendarTypes(ContextInfo contextInfo) throws InvalidParameterException, MissingParameterException, OperationFailedException { |
1285 | |
|
1286 | 0 | return null; |
1287 | |
} |
1288 | |
|
1289 | |
@Override |
1290 | |
public StateInfo getHolidayCalendarState(String holidayCalendarStateKey, ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, PermissionDeniedException, |
1291 | |
OperationFailedException { |
1292 | 0 | StateInfo hcState = stateService.getState(holidayCalendarStateKey, contextInfo); |
1293 | |
|
1294 | 0 | return hcState; |
1295 | |
} |
1296 | |
|
1297 | |
@Override |
1298 | |
public List<StateInfo> getHolidayCalendarStates(ContextInfo contextInfo) throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
1299 | 0 | return getAtpStates(contextInfo); |
1300 | |
} |
1301 | |
|
1302 | |
@Override |
1303 | |
public List<String> getHolidayCalendarIdsByType(String holidayCalendarTypeKey, ContextInfo contextInfo) throws InvalidParameterException, MissingParameterException, OperationFailedException, |
1304 | |
PermissionDeniedException { |
1305 | |
|
1306 | 0 | return null; |
1307 | |
} |
1308 | |
|
1309 | |
@Override |
1310 | |
public List<HolidayCalendarInfo> getHolidayCalendarsByStartYear(Integer year, ContextInfo contextInfo) throws InvalidParameterException, MissingParameterException, OperationFailedException, |
1311 | |
PermissionDeniedException { |
1312 | |
|
1313 | |
|
1314 | |
final Date yearBegin, yearEnd; |
1315 | |
|
1316 | 0 | Calendar cal = Calendar.getInstance(); |
1317 | 0 | cal.clear(); |
1318 | 0 | cal.set(year, 0, 1); |
1319 | 0 | yearBegin = cal.getTime(); |
1320 | 0 | cal.add(Calendar.YEAR, 1); |
1321 | 0 | cal.add(Calendar.MILLISECOND, -1); |
1322 | 0 | yearEnd = cal.getTime(); |
1323 | |
|
1324 | 0 | Set<AtpInfo> atpInfos = new TreeSet<AtpInfo>(new Comparator<AtpInfo>() { |
1325 | |
|
1326 | |
@Override |
1327 | |
public int compare(AtpInfo atpInfo1, AtpInfo atpInfo2) { |
1328 | 0 | return atpInfo1.getId().compareTo(atpInfo2.getId()); |
1329 | |
} |
1330 | |
}); |
1331 | |
|
1332 | 0 | atpInfos.addAll(atpService.getAtpsByStartDateRangeAndType(yearBegin, yearEnd, AtpServiceConstants.ATP_HOLIDAY_CALENDAR_TYPE_KEY, contextInfo)); |
1333 | |
|
1334 | 0 | List<HolidayCalendarInfo> hcalInfos = new ArrayList<HolidayCalendarInfo>(); |
1335 | 0 | for (AtpInfo atpInfo : atpInfos) { |
1336 | |
try { |
1337 | 0 | hcalInfos.add(holidayCalendarAssembler.assemble(atpInfo, contextInfo)); |
1338 | 0 | } catch (AssemblyException e) { |
1339 | 0 | throw new OperationFailedException("AssemblyException : " + e.getMessage()); |
1340 | 0 | } |
1341 | |
} |
1342 | 0 | return hcalInfos; |
1343 | |
} |
1344 | |
|
1345 | |
@Override |
1346 | |
public List<String> searchForHolidayCalendarIds(QueryByCriteria criteria, ContextInfo contextInfo) throws InvalidParameterException, MissingParameterException, OperationFailedException, |
1347 | |
PermissionDeniedException { |
1348 | |
|
1349 | 0 | return null; |
1350 | |
} |
1351 | |
|
1352 | |
@Override |
1353 | |
public List<HolidayCalendarInfo> searchForHolidayCalendars(QueryByCriteria criteria, ContextInfo contextInfo) |
1354 | |
throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
1355 | 0 | List<HolidayCalendarInfo> holidayCalendars = new ArrayList<HolidayCalendarInfo>(); |
1356 | 0 | List<AtpInfo> atps = atpService.searchForAtps(criteria, contextInfo); |
1357 | |
|
1358 | 0 | for (AtpInfo atp : atps) { |
1359 | |
try { |
1360 | 0 | holidayCalendars.add(holidayCalendarAssembler.assemble(atp, contextInfo)); |
1361 | 0 | } catch (AssemblyException e) { |
1362 | 0 | throw new OperationFailedException("AssemblyException : " + e.getMessage()); |
1363 | 0 | } |
1364 | |
} |
1365 | |
|
1366 | 0 | return holidayCalendars; |
1367 | |
} |
1368 | |
|
1369 | |
@Override |
1370 | |
public List<ValidationResultInfo> validateHolidayCalendar(String validationTypeKey, String holidayCalendarTypeKey, HolidayCalendarInfo holidayCalendarInfo, ContextInfo contextInfo) |
1371 | |
throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
1372 | |
|
1373 | 0 | return null; |
1374 | |
} |
1375 | |
|
1376 | |
@Override |
1377 | |
public List<String> getTermIdsByType(String termTypeKey, ContextInfo contextInfo) throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
1378 | |
|
1379 | 0 | return atpService.getAtpIdsByType(termTypeKey, contextInfo); |
1380 | |
} |
1381 | |
|
1382 | |
@Override |
1383 | |
public List<TermInfo> getTermsByCode(String code, ContextInfo contextInfo) throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
1384 | |
|
1385 | 0 | return null; |
1386 | |
} |
1387 | |
|
1388 | |
@Override |
1389 | |
public List<String> searchForTermIds(QueryByCriteria criteria, ContextInfo contextInfo) throws InvalidParameterException, MissingParameterException, OperationFailedException, |
1390 | |
PermissionDeniedException { |
1391 | |
|
1392 | 0 | return null; |
1393 | |
} |
1394 | |
|
1395 | |
@Override |
1396 | |
public List<TypeInfo> getKeyDateTypes(ContextInfo contextInfo) throws InvalidParameterException, MissingParameterException, OperationFailedException { |
1397 | |
|
1398 | 0 | return null; |
1399 | |
} |
1400 | |
|
1401 | |
@Override |
1402 | |
public StateInfo getKeyDateState(String keyDateStateKey, ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException { |
1403 | |
|
1404 | 0 | return null; |
1405 | |
} |
1406 | |
|
1407 | |
@Override |
1408 | |
public List<StateInfo> getKeyDateStates(ContextInfo contextInfo) throws InvalidParameterException, MissingParameterException, OperationFailedException { |
1409 | |
|
1410 | 0 | return null; |
1411 | |
} |
1412 | |
|
1413 | |
@Override |
1414 | |
public List<String> getKeyDateIdsByType(String keyDateTypeKey, ContextInfo contextInfo) throws InvalidParameterException, MissingParameterException, OperationFailedException, |
1415 | |
PermissionDeniedException { |
1416 | |
|
1417 | 0 | return null; |
1418 | |
} |
1419 | |
|
1420 | |
@Override |
1421 | |
public List<String> getKeyDateIdsByTypeForTerm(String keyDateTypeKey, String termId, ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
1422 | |
|
1423 | 0 | return null; |
1424 | |
} |
1425 | |
|
1426 | |
@Override |
1427 | |
public List<String> searchForKeyDateIds(QueryByCriteria criteria, ContextInfo contextInfo) throws InvalidParameterException, MissingParameterException, OperationFailedException, |
1428 | |
PermissionDeniedException { |
1429 | |
|
1430 | 0 | return null; |
1431 | |
} |
1432 | |
|
1433 | |
@Override |
1434 | |
public List<ValidationResultInfo> validateKeyDate(String validationTypeKey, String termId, String keyDateTypeKey, KeyDateInfo keyDateInfo, ContextInfo contextInfo) throws DoesNotExistException, |
1435 | |
InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
1436 | |
|
1437 | 0 | return null; |
1438 | |
} |
1439 | |
|
1440 | |
@Override |
1441 | |
@Transactional(readOnly = false) |
1442 | |
public KeyDateInfo createKeyDate(String termId, String keyDateTypeKey, KeyDateInfo keyDateInfo, ContextInfo contextInfo) throws DataValidationErrorException, DoesNotExistException, |
1443 | |
InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, ReadOnlyException { |
1444 | 0 | KeyDateInfo newKeyDateInfo = null; |
1445 | 0 | MilestoneInfo milestoneInfo = null; |
1446 | |
|
1447 | |
try { |
1448 | 0 | milestoneInfo = keyDateAssembler.disassemble(keyDateInfo, contextInfo); |
1449 | 0 | } catch (AssemblyException e) { |
1450 | 0 | throw new OperationFailedException("AssemblyException in disassembling: " + e.getMessage()); |
1451 | 0 | } |
1452 | |
|
1453 | 0 | if (milestoneInfo != null) { |
1454 | 0 | if (StringUtils.isBlank(milestoneInfo.getTypeKey())) { |
1455 | 0 | milestoneInfo.setTypeKey(keyDateTypeKey); |
1456 | |
} |
1457 | 0 | MilestoneInfo newMilestone = null; |
1458 | |
try { |
1459 | 0 | newMilestone = atpService.createMilestone(keyDateTypeKey, milestoneInfo, contextInfo); |
1460 | 0 | newKeyDateInfo = keyDateAssembler.assemble(newMilestone, contextInfo); |
1461 | 0 | } catch (ReadOnlyException e) { |
1462 | 0 | throw new OperationFailedException("Error creating milestone", e); |
1463 | 0 | } catch (AssemblyException e) { |
1464 | 0 | throw new OperationFailedException("AssemblyException in assembling: " + e.getMessage()); |
1465 | 0 | } |
1466 | |
|
1467 | |
try { |
1468 | 0 | atpService.addMilestoneToAtp(newMilestone.getId(), termId, contextInfo); |
1469 | 0 | } catch (AlreadyExistsException e) { |
1470 | 0 | throw new OperationFailedException("Error creating ATP-Milestone relation", e); |
1471 | 0 | } |
1472 | |
|
1473 | |
} |
1474 | |
|
1475 | 0 | return newKeyDateInfo; |
1476 | |
} |
1477 | |
|
1478 | |
@Override |
1479 | |
public TypeInfo getAcalEventType(String acalEventTypeKey, ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException { |
1480 | |
|
1481 | 0 | return null; |
1482 | |
} |
1483 | |
|
1484 | |
@Override |
1485 | |
public List<TypeInfo> getAcalEventTypes(ContextInfo contextInfo) throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
1486 | |
|
1487 | 0 | List<TypeTypeRelationInfo> relations = null; |
1488 | |
|
1489 | |
try { |
1490 | |
|
1491 | |
|
1492 | 0 | relations = typeService.getTypeTypeRelationsByOwnerAndType(AtpServiceConstants.MILESTONE_EVENT_GROUPING_TYPE_KEY, |
1493 | |
TypeServiceConstants.TYPE_TYPE_RELATION_GROUP_TYPE_KEY, contextInfo); |
1494 | 0 | } catch (DoesNotExistException e) { |
1495 | 0 | throw new OperationFailedException(e.getMessage(), e); |
1496 | 0 | } |
1497 | |
|
1498 | 0 | if (relations != null) { |
1499 | 0 | List<TypeInfo> results = new ArrayList<TypeInfo>(relations.size()); |
1500 | 0 | for (TypeTypeRelationInfo rel : relations) { |
1501 | |
try { |
1502 | 0 | results.add(typeService.getType(rel.getRelatedTypeKey(), contextInfo)); |
1503 | 0 | } catch (DoesNotExistException e) { |
1504 | 0 | throw new OperationFailedException(e.getMessage(), e); |
1505 | 0 | } |
1506 | |
} |
1507 | |
|
1508 | 0 | return results; |
1509 | |
} |
1510 | |
|
1511 | 0 | return null; |
1512 | |
} |
1513 | |
|
1514 | |
@Override |
1515 | |
public List<TypeInfo> getAcalEventTypesForAcademicCalendarType(String academicCalendarTypeKey, ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, |
1516 | |
MissingParameterException, OperationFailedException { |
1517 | |
|
1518 | 0 | return null; |
1519 | |
} |
1520 | |
|
1521 | |
@Override |
1522 | |
public StateInfo getAcalEventState(String acalEventStateKey, ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException { |
1523 | |
|
1524 | 0 | return null; |
1525 | |
} |
1526 | |
|
1527 | |
@Override |
1528 | |
public List<StateInfo> getAcalEventStates(ContextInfo contextInfo) throws InvalidParameterException, MissingParameterException, OperationFailedException { |
1529 | |
|
1530 | 0 | return null; |
1531 | |
} |
1532 | |
|
1533 | |
@Override |
1534 | |
public AcalEventInfo getAcalEvent(String acalEventId, ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, |
1535 | |
PermissionDeniedException { |
1536 | 0 | MilestoneInfo milestoneInfo = atpService.getMilestone(acalEventId, contextInfo); |
1537 | |
|
1538 | 0 | if (milestoneInfo == null) { |
1539 | 0 | throw new DoesNotExistException(acalEventId); |
1540 | |
} |
1541 | |
|
1542 | |
try { |
1543 | 0 | return acalEventAssembler.assemble(milestoneInfo, contextInfo); |
1544 | 0 | } catch (AssemblyException e) { |
1545 | 0 | throw new OperationFailedException("Error assembling AcalEvent", e); |
1546 | |
} |
1547 | |
} |
1548 | |
|
1549 | |
@Override |
1550 | |
public List<AcalEventInfo> getAcalEventsByIds(List<String> acalEventIds, ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, |
1551 | |
OperationFailedException, PermissionDeniedException { |
1552 | |
|
1553 | 0 | List<MilestoneInfo> milestoneInfos = atpService.getMilestonesByIds(acalEventIds, contextInfo); |
1554 | 0 | List<AcalEventInfo> acalEventInfos = new ArrayList<AcalEventInfo>(); |
1555 | |
|
1556 | 0 | for (MilestoneInfo milestoneInfo : milestoneInfos) { |
1557 | |
try { |
1558 | 0 | acalEventInfos.add(acalEventAssembler.assemble(milestoneInfo, contextInfo)); |
1559 | 0 | } catch (AssemblyException e) { |
1560 | 0 | throw new OperationFailedException("Error assembling AcalEvent", e); |
1561 | 0 | } |
1562 | |
} |
1563 | |
|
1564 | 0 | return acalEventInfos; |
1565 | |
} |
1566 | |
|
1567 | |
@Override |
1568 | |
public List<String> getAcalEventIdsByType(String acalEventTypeKey, ContextInfo contextInfo) throws InvalidParameterException, MissingParameterException, OperationFailedException, |
1569 | |
PermissionDeniedException { |
1570 | 0 | return atpService.getMilestoneIdsByType(acalEventTypeKey, contextInfo); |
1571 | |
} |
1572 | |
|
1573 | |
@Override |
1574 | |
public List<AcalEventInfo> getAcalEventsForAcademicCalendar(String academicCalendarId, ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, |
1575 | |
OperationFailedException, PermissionDeniedException { |
1576 | |
|
1577 | 0 | List<MilestoneInfo> milestoneInfos = atpService.getMilestonesForAtp(academicCalendarId, contextInfo); |
1578 | 0 | List<AcalEventInfo> acalEventInfos = new ArrayList<AcalEventInfo>(); |
1579 | |
|
1580 | 0 | for (MilestoneInfo milestoneInfo : milestoneInfos) { |
1581 | |
try { |
1582 | 0 | acalEventInfos.add(acalEventAssembler.assemble(milestoneInfo, contextInfo)); |
1583 | 0 | } catch (AssemblyException e) { |
1584 | 0 | throw new OperationFailedException("Error assembling AcalEvent", e); |
1585 | 0 | } |
1586 | |
} |
1587 | |
|
1588 | 0 | return acalEventInfos; |
1589 | |
} |
1590 | |
|
1591 | |
@Override |
1592 | |
public List<AcalEventInfo> getAcalEventsForAcademicCalendarByDate(String academicCalendarId, Date startDate, Date endDate, ContextInfo contextInfo) throws DoesNotExistException, |
1593 | |
InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
1594 | |
|
1595 | 0 | List<MilestoneInfo> milestoneInfos = atpService.getMilestonesByDatesForAtp(academicCalendarId, startDate, endDate, contextInfo); |
1596 | 0 | List<AcalEventInfo> acalEventInfos = new ArrayList<AcalEventInfo>(); |
1597 | |
|
1598 | 0 | for (MilestoneInfo milestoneInfo : milestoneInfos) { |
1599 | |
try { |
1600 | 0 | acalEventInfos.add(acalEventAssembler.assemble(milestoneInfo, contextInfo)); |
1601 | 0 | } catch (AssemblyException e) { |
1602 | 0 | throw new OperationFailedException("Error assembling AcalEvent", e); |
1603 | 0 | } |
1604 | |
} |
1605 | |
|
1606 | 0 | return acalEventInfos; |
1607 | |
} |
1608 | |
|
1609 | |
@Override |
1610 | |
public List<AcalEventInfo> getImpactedAcalEvents(String acalEventId, ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, |
1611 | |
OperationFailedException, PermissionDeniedException { |
1612 | |
|
1613 | 0 | return new ArrayList<AcalEventInfo>(); |
1614 | |
} |
1615 | |
|
1616 | |
@Override |
1617 | |
public List<String> searchForAcalEventIds(QueryByCriteria criteria, ContextInfo contextInfo) throws InvalidParameterException, MissingParameterException, OperationFailedException, |
1618 | |
PermissionDeniedException { |
1619 | |
|
1620 | 0 | return null; |
1621 | |
} |
1622 | |
|
1623 | |
@Override |
1624 | |
public List<AcalEventInfo> searchForAcalEvents(QueryByCriteria criteria, ContextInfo contextInfo) throws InvalidParameterException, MissingParameterException, OperationFailedException, |
1625 | |
PermissionDeniedException { |
1626 | |
|
1627 | 0 | List<MilestoneInfo> milestoneInfos = atpService.searchForMilestones(criteria, contextInfo); |
1628 | 0 | List<AcalEventInfo> acalEventInfos = new ArrayList<AcalEventInfo>(); |
1629 | |
|
1630 | 0 | for (MilestoneInfo milestoneInfo : milestoneInfos) { |
1631 | |
try { |
1632 | 0 | acalEventInfos.add(acalEventAssembler.assemble(milestoneInfo, contextInfo)); |
1633 | 0 | } catch (AssemblyException e) { |
1634 | 0 | throw new OperationFailedException("Error assembling AcalEvent", e); |
1635 | 0 | } |
1636 | |
} |
1637 | |
|
1638 | 0 | return acalEventInfos; |
1639 | |
} |
1640 | |
|
1641 | |
@Override |
1642 | |
public List<ValidationResultInfo> validateAcalEvent(String validationTypeKey, String termId, String acalEventTypeKey, AcalEventInfo acalEventInfo, ContextInfo contextInfo) |
1643 | |
throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
1644 | |
|
1645 | 0 | return null; |
1646 | |
} |
1647 | |
|
1648 | |
@Override |
1649 | |
@Transactional(readOnly = false) |
1650 | |
public AcalEventInfo createAcalEvent(String academicCalendarId, String acalEventTypeKey, AcalEventInfo acalEventInfo, ContextInfo contextInfo) throws DataValidationErrorException, |
1651 | |
DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, ReadOnlyException { |
1652 | |
|
1653 | |
try { |
1654 | 0 | MilestoneInfo milestoneInfo = acalEventAssembler.disassemble(acalEventInfo, contextInfo); |
1655 | 0 | if (StringUtils.isBlank(milestoneInfo.getTypeKey())) { |
1656 | 0 | milestoneInfo.setTypeKey(acalEventTypeKey); |
1657 | |
} |
1658 | |
|
1659 | 0 | MilestoneInfo newMilestone = atpService.createMilestone(acalEventTypeKey, milestoneInfo, contextInfo); |
1660 | |
|
1661 | 0 | atpService.addMilestoneToAtp(newMilestone.getId(), academicCalendarId, contextInfo); |
1662 | 0 | return acalEventAssembler.assemble(newMilestone, contextInfo); |
1663 | |
|
1664 | 0 | } catch (AssemblyException e) { |
1665 | 0 | throw new OperationFailedException("Error disassembling AcalEvent", e); |
1666 | 0 | } catch (AlreadyExistsException e) { |
1667 | 0 | throw new OperationFailedException("Error associating AcalEvent with AcademicCalendar", e); |
1668 | |
} |
1669 | |
|
1670 | |
} |
1671 | |
|
1672 | |
@Override |
1673 | |
@Transactional(readOnly = false) |
1674 | |
public AcalEventInfo updateAcalEvent(String acalEventId, AcalEventInfo acalEventInfo, ContextInfo contextInfo) throws DataValidationErrorException, DoesNotExistException, |
1675 | |
InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, ReadOnlyException, VersionMismatchException { |
1676 | |
|
1677 | |
|
1678 | |
try { |
1679 | 0 | MilestoneInfo milestoneInfo = acalEventAssembler.disassemble(acalEventInfo, contextInfo); |
1680 | 0 | MilestoneInfo newMilestone = atpService.updateMilestone(acalEventId, milestoneInfo, contextInfo); |
1681 | 0 | return acalEventAssembler.assemble(newMilestone, contextInfo); |
1682 | 0 | } catch (AssemblyException e) { |
1683 | 0 | throw new OperationFailedException("Error assembling AcalEvent", e); |
1684 | |
} |
1685 | |
|
1686 | |
} |
1687 | |
|
1688 | |
@Override |
1689 | |
@Transactional(readOnly = false) |
1690 | |
public StatusInfo deleteAcalEvent(String acalEventId, ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, |
1691 | |
PermissionDeniedException { |
1692 | 0 | MilestoneInfo existingMilestone = atpService.getMilestone(acalEventId, contextInfo); |
1693 | |
|
1694 | 0 | if (existingMilestone == null) { |
1695 | 0 | throw new DoesNotExistException("AcalEvent doesnt exists " + acalEventId); |
1696 | |
} |
1697 | |
|
1698 | 0 | StatusInfo status = atpService.deleteMilestone(acalEventId, contextInfo); |
1699 | 0 | return status; |
1700 | |
|
1701 | |
} |
1702 | |
|
1703 | |
@Override |
1704 | |
@Transactional(readOnly = false) |
1705 | |
public AcalEventInfo calculateAcalEvent(String acalEventId, ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, |
1706 | |
PermissionDeniedException { |
1707 | |
|
1708 | 0 | return getAcalEvent(acalEventId, contextInfo); |
1709 | |
} |
1710 | |
|
1711 | |
@Override |
1712 | |
public List<TypeInfo> getHolidayTypes(ContextInfo contextInfo) throws InvalidParameterException, MissingParameterException, |
1713 | |
OperationFailedException, PermissionDeniedException { |
1714 | 0 | List<TypeTypeRelationInfo> relations = null; |
1715 | |
|
1716 | |
try { |
1717 | 0 | relations = typeService.getTypeTypeRelationsByOwnerAndType(AtpServiceConstants.MILESTONE_HOLIDAY_GROUPING_TYPE_KEY, |
1718 | |
TypeServiceConstants.TYPE_TYPE_RELATION_GROUP_TYPE_KEY, contextInfo); |
1719 | 0 | } catch (DoesNotExistException e) { |
1720 | 0 | throw new OperationFailedException(e.getMessage(), e); |
1721 | 0 | } |
1722 | |
|
1723 | 0 | if (relations != null) { |
1724 | 0 | List<TypeInfo> results = new ArrayList<TypeInfo>(relations.size()); |
1725 | 0 | for (TypeTypeRelationInfo rel : relations) { |
1726 | |
try { |
1727 | 0 | results.add(typeService.getType(rel.getRelatedTypeKey(), contextInfo)); |
1728 | 0 | } catch (DoesNotExistException e) { |
1729 | 0 | throw new OperationFailedException(e.getMessage(), e); |
1730 | 0 | } |
1731 | |
} |
1732 | |
|
1733 | 0 | return results; |
1734 | |
} |
1735 | |
|
1736 | 0 | return null; |
1737 | |
} |
1738 | |
|
1739 | |
@Override |
1740 | |
public List<TypeInfo> getHolidayTypesForHolidayCalendarType(String holidayCalendarTypeKey, ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, |
1741 | |
MissingParameterException, OperationFailedException { |
1742 | |
|
1743 | 0 | return null; |
1744 | |
} |
1745 | |
|
1746 | |
@Override |
1747 | |
public StateInfo getHolidayState(String holidayStateKey, ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
1748 | 0 | StateInfo holidayState = stateService.getState(holidayStateKey, contextInfo); |
1749 | |
|
1750 | 0 | return holidayState; |
1751 | |
} |
1752 | |
|
1753 | |
@Override |
1754 | |
public List<StateInfo> getHolidayStates(ContextInfo contextInfo) throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
1755 | |
List<StateInfo> results; |
1756 | |
try { |
1757 | 0 | results = stateService.getStatesByLifecycle(AtpServiceConstants.MILESTONE_PROCESS_KEY, contextInfo); |
1758 | 0 | } catch (DoesNotExistException ex) { |
1759 | 0 | throw new OperationFailedException(AtpServiceConstants.MILESTONE_PROCESS_KEY, ex); |
1760 | 0 | } |
1761 | |
|
1762 | 0 | return results; |
1763 | |
|
1764 | |
} |
1765 | |
|
1766 | |
@Override |
1767 | |
public HolidayInfo getHoliday(String holidayId, ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, |
1768 | |
PermissionDeniedException { |
1769 | |
|
1770 | 0 | MilestoneInfo milestoneInfo = atpService.getMilestone(holidayId, contextInfo); |
1771 | |
|
1772 | 0 | if (milestoneInfo == null) { |
1773 | 0 | throw new DoesNotExistException(holidayId); |
1774 | |
} |
1775 | |
|
1776 | |
try { |
1777 | 0 | return holidayAssembler.assemble(milestoneInfo, contextInfo); |
1778 | 0 | } catch (AssemblyException e) { |
1779 | 0 | throw new OperationFailedException("Error assembling Holiday", e); |
1780 | |
} |
1781 | |
} |
1782 | |
|
1783 | |
@Override |
1784 | |
public List<HolidayInfo> getHolidaysByIds(List<String> holidayIds, ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, |
1785 | |
OperationFailedException, PermissionDeniedException { |
1786 | |
|
1787 | 0 | List<MilestoneInfo> milestoneInfos = atpService.getMilestonesByIds(holidayIds, contextInfo); |
1788 | |
|
1789 | 0 | List<HolidayInfo> holidayInfos = new ArrayList<HolidayInfo>(); |
1790 | |
|
1791 | 0 | for (MilestoneInfo milestoneInfo : milestoneInfos) { |
1792 | |
try { |
1793 | 0 | holidayInfos.add(holidayAssembler.assemble(milestoneInfo, contextInfo)); |
1794 | 0 | } catch (AssemblyException e) { |
1795 | 0 | throw new OperationFailedException("Error assembling holiday with Id " + milestoneInfo.getId(), e); |
1796 | 0 | } |
1797 | |
} |
1798 | |
|
1799 | 0 | return holidayInfos; |
1800 | |
} |
1801 | |
|
1802 | |
@Override |
1803 | |
public List<String> getHolidayIdsByType(String holidayTypeKey, ContextInfo contextInfo) throws InvalidParameterException, MissingParameterException, OperationFailedException, |
1804 | |
PermissionDeniedException { |
1805 | 0 | return atpService.getMilestoneIdsByType(holidayTypeKey, contextInfo); |
1806 | |
} |
1807 | |
|
1808 | |
@Override |
1809 | |
public List<HolidayInfo> getHolidaysForHolidayCalendar(String holidayCalendarId, ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, |
1810 | |
OperationFailedException, PermissionDeniedException { |
1811 | 0 | List<MilestoneInfo> milestoneInfos = atpService.getMilestonesForAtp(holidayCalendarId, contextInfo); |
1812 | 0 | List<HolidayInfo> holidayInfos = new ArrayList<HolidayInfo>(); |
1813 | 0 | for (MilestoneInfo milestoneInfo : milestoneInfos) { |
1814 | |
try { |
1815 | 0 | holidayInfos.add(holidayAssembler.assemble(milestoneInfo, contextInfo)); |
1816 | 0 | } catch (AssemblyException e) { |
1817 | 0 | throw new OperationFailedException("Error assembling holiday" + milestoneInfo.getId(), e); |
1818 | 0 | } |
1819 | |
} |
1820 | |
|
1821 | 0 | return holidayInfos; |
1822 | |
} |
1823 | |
|
1824 | |
@Override |
1825 | |
public List<HolidayInfo> getHolidaysForHolidayCalendarByDate(String holidayCalendarId, Date startDate, Date endDate, ContextInfo contextInfo) throws DoesNotExistException, |
1826 | |
InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
1827 | 0 | List<MilestoneInfo> milestoneInfos = atpService.getMilestonesByDatesForAtp(holidayCalendarId, startDate, endDate, contextInfo); |
1828 | 0 | List<HolidayInfo> holidayInfos = new ArrayList<HolidayInfo>(); |
1829 | 0 | for (MilestoneInfo milestoneInfo : milestoneInfos) { |
1830 | |
try { |
1831 | 0 | holidayInfos.add(holidayAssembler.assemble(milestoneInfo, contextInfo)); |
1832 | 0 | } catch (AssemblyException e) { |
1833 | 0 | throw new OperationFailedException("Error assembling holiday" + milestoneInfo.getId(), e); |
1834 | 0 | } |
1835 | |
} |
1836 | |
|
1837 | 0 | return holidayInfos; |
1838 | |
} |
1839 | |
|
1840 | |
@Override |
1841 | |
public List<HolidayInfo> getImpactedHolidays(String holidayId, ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, |
1842 | |
OperationFailedException, PermissionDeniedException { |
1843 | |
|
1844 | 0 | return new ArrayList<HolidayInfo>(); |
1845 | |
} |
1846 | |
|
1847 | |
@Override |
1848 | |
public List<String> searchForHolidayIds(QueryByCriteria criteria, ContextInfo contextInfo) throws InvalidParameterException, MissingParameterException, OperationFailedException, |
1849 | |
PermissionDeniedException { |
1850 | |
|
1851 | 0 | return null; |
1852 | |
} |
1853 | |
|
1854 | |
@Override |
1855 | |
public List<ValidationResultInfo> validateHoliday(String validationTypeKey, String holidayCalendarId, String holidayTypeKey, HolidayInfo holidayInfo, ContextInfo contextInfo) |
1856 | |
throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
1857 | |
|
1858 | 0 | return null; |
1859 | |
} |
1860 | |
|
1861 | |
@Override |
1862 | |
@Transactional(readOnly = false) |
1863 | |
public HolidayInfo createHoliday(String holidayCalendarId, String holidayTypeKey, HolidayInfo holidayInfo, ContextInfo contextInfo) throws DataValidationErrorException, DoesNotExistException, |
1864 | |
InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, ReadOnlyException { |
1865 | 0 | HolidayInfo newHolidayInfo = null; |
1866 | 0 | MilestoneInfo milestoneInfo = null; |
1867 | |
|
1868 | |
try { |
1869 | 0 | milestoneInfo = holidayAssembler.disassemble(holidayInfo, contextInfo); |
1870 | 0 | } catch (AssemblyException e) { |
1871 | 0 | throw new OperationFailedException("AssemblyException in disassembling: " + e.getMessage()); |
1872 | 0 | } |
1873 | |
|
1874 | 0 | if (milestoneInfo != null) { |
1875 | 0 | if (StringUtils.isBlank(milestoneInfo.getTypeKey())) { |
1876 | 0 | milestoneInfo.setTypeKey(holidayTypeKey); |
1877 | |
} |
1878 | 0 | MilestoneInfo newMilestone = null; |
1879 | |
try { |
1880 | 0 | newMilestone = atpService.createMilestone(holidayTypeKey, milestoneInfo, contextInfo); |
1881 | 0 | newHolidayInfo = holidayAssembler.assemble(newMilestone, contextInfo); |
1882 | 0 | } catch (ReadOnlyException e) { |
1883 | 0 | throw new OperationFailedException("Error creating milestone", e); |
1884 | 0 | } catch (AssemblyException e) { |
1885 | 0 | throw new OperationFailedException("AssemblyException in assembling: " + e.getMessage()); |
1886 | 0 | } |
1887 | |
|
1888 | |
try { |
1889 | 0 | atpService.addMilestoneToAtp(newMilestone.getId(), holidayCalendarId, contextInfo); |
1890 | 0 | } catch (AlreadyExistsException e) { |
1891 | 0 | throw new OperationFailedException("Error creating ATP-Milestone relation", e); |
1892 | 0 | } |
1893 | |
|
1894 | |
} |
1895 | |
|
1896 | 0 | return newHolidayInfo; |
1897 | |
} |
1898 | |
|
1899 | |
@Override |
1900 | |
public String getAcademicCalendarData(String academicCalendarId, String calendarDataFormatTypeKey, ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, |
1901 | |
MissingParameterException, OperationFailedException, PermissionDeniedException { |
1902 | |
|
1903 | 0 | return null; |
1904 | |
} |
1905 | |
|
1906 | |
@Override |
1907 | |
public Integer getInstructionalDaysForTerm(String termId, ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, |
1908 | |
PermissionDeniedException { |
1909 | |
|
1910 | 0 | KeyDateInfo instructionalPeriodKeyDate = null; |
1911 | |
|
1912 | 0 | List<KeyDateInfo> keyDates = getKeyDatesForTerm(termId, contextInfo); |
1913 | |
|
1914 | 0 | for (KeyDateInfo keyDate : keyDates) { |
1915 | 0 | if (keyDate.getTypeKey().equals(AtpServiceConstants.MILESTONE_INSTRUCTIONAL_PERIOD_TYPE_KEY)) { |
1916 | |
|
1917 | 0 | instructionalPeriodKeyDate = new KeyDateInfo(keyDate); |
1918 | |
|
1919 | |
} |
1920 | |
|
1921 | |
} |
1922 | |
|
1923 | 0 | Period instructionalPeriodInterval = new Period(instructionalPeriodKeyDate.getStartDate().getTime(), instructionalPeriodKeyDate.getEndDate().getTime()); |
1924 | |
|
1925 | 0 | Days totalDays = instructionalPeriodInterval.toStandardDays(); |
1926 | |
|
1927 | 0 | Weeks weeks = instructionalPeriodInterval.toStandardWeeks(); |
1928 | |
|
1929 | 0 | int approxWeekends = weeks.getWeeks() * 2; |
1930 | |
|
1931 | 0 | int totalDaysInTerm = totalDays.getDays(); |
1932 | |
|
1933 | 0 | return totalDaysInTerm - (approxWeekends + getNumberOfHolidayDatesInTerm(termId, instructionalPeriodKeyDate, contextInfo)); |
1934 | |
|
1935 | |
} |
1936 | |
|
1937 | |
private Integer getNumberOfHolidayDatesInTerm(String termId, KeyDateInfo instructionalPeriodKeyDate, ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, |
1938 | |
MissingParameterException, OperationFailedException, PermissionDeniedException { |
1939 | 0 | List<AcademicCalendarInfo> acalsForTerm = getAcademicCalendarsForTerm(termId, contextInfo); |
1940 | 0 | int numberOfHolidayDays = 0; |
1941 | 0 | for (AcademicCalendarInfo acal : acalsForTerm) { |
1942 | |
|
1943 | 0 | List<HolidayInfo> holidays = getHolidaysByDateForAcademicCalendar(acal.getId(), instructionalPeriodKeyDate.getStartDate(), instructionalPeriodKeyDate.getEndDate(), contextInfo); |
1944 | |
|
1945 | 0 | for (HolidayInfo holiday : holidays) { |
1946 | |
Period holidayPeriod; |
1947 | 0 | if (holiday.getIsDateRange()){ |
1948 | 0 | holidayPeriod = new Period(holiday.getStartDate().getTime(), holiday.getEndDate().getTime()); |
1949 | 0 | numberOfHolidayDays = numberOfHolidayDays + holidayPeriod.toStandardDays().getDays(); |
1950 | |
}else{ |
1951 | 0 | numberOfHolidayDays = numberOfHolidayDays + 1; |
1952 | |
} |
1953 | |
} |
1954 | 0 | } |
1955 | 0 | return numberOfHolidayDays; |
1956 | |
|
1957 | |
} |
1958 | |
|
1959 | |
@Override |
1960 | |
public List<AcademicCalendarInfo> getAcademicCalendarsForTerm(String termId, ContextInfo contextInfo) throws InvalidParameterException, MissingParameterException, OperationFailedException, |
1961 | |
PermissionDeniedException, DoesNotExistException { |
1962 | |
|
1963 | 0 | List<AtpAtpRelationInfo> atpAtpRelationsForTerm = this.atpService.getAtpAtpRelationsByAtps(termId, contextInfo); |
1964 | |
|
1965 | 0 | List<AcademicCalendarInfo> academicCalendars = new ArrayList<AcademicCalendarInfo>(); |
1966 | |
|
1967 | 0 | for (AtpAtpRelationInfo atpRelationForTerm : atpAtpRelationsForTerm) { |
1968 | 0 | if (atpRelationForTerm.getTypeKey().equals(AtpServiceConstants.ATP_ATP_RELATION_INCLUDES_TYPE_KEY)) { |
1969 | |
try { |
1970 | 0 | AtpInfo acalAtp = this.atpService.getAtp(atpRelationForTerm.getAtpId(), contextInfo); |
1971 | 0 | if (acalAtp.getTypeKey().equals(AtpServiceConstants.ATP_ACADEMIC_CALENDAR_TYPE_KEY)) { |
1972 | 0 | academicCalendars.add(this.acalAssembler.assemble(acalAtp, contextInfo)); |
1973 | |
} |
1974 | 0 | } catch (AssemblyException e) { |
1975 | 0 | throw new OperationFailedException(e.getMessage()); |
1976 | 0 | } |
1977 | |
} |
1978 | |
} |
1979 | |
|
1980 | 0 | return academicCalendars; |
1981 | |
} |
1982 | |
|
1983 | |
@Override |
1984 | |
public List<HolidayInfo> getHolidaysByDateForAcademicCalendar(String academicCalendarId, Date startDate, Date endDate, ContextInfo contextInfo) throws DoesNotExistException, |
1985 | |
InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
1986 | 0 | AcademicCalendarInfo acInfo = getAcademicCalendar(academicCalendarId, contextInfo); |
1987 | 0 | List<HolidayInfo> holidaysForAcal = new ArrayList<HolidayInfo>(); |
1988 | 0 | for (String holidayCalendarId : acInfo.getHolidayCalendarIds()) { |
1989 | |
|
1990 | 0 | List<HolidayInfo> holidays = getHolidaysForHolidayCalendar(holidayCalendarId, contextInfo); |
1991 | |
|
1992 | 0 | for (HolidayInfo holiday : holidays) { |
1993 | 0 | if (holiday.getStartDate().after(startDate)){ |
1994 | 0 | if (holiday.getIsDateRange()){ |
1995 | 0 | if (holiday.getEndDate().before(endDate)){ |
1996 | 0 | holidaysForAcal.add(holiday); |
1997 | |
} |
1998 | |
}else{ |
1999 | 0 | holidaysForAcal.add(holiday); |
2000 | |
} |
2001 | |
} |
2002 | |
} |
2003 | |
|
2004 | 0 | } |
2005 | |
|
2006 | 0 | return holidaysForAcal; |
2007 | |
} |
2008 | |
} |