1 | |
package org.kuali.student.enrollment.class2.acal.service.assembler; |
2 | |
|
3 | |
import org.kuali.student.enrollment.acal.dto.AcademicCalendarInfo; |
4 | |
import org.kuali.student.r2.common.assembler.AssemblyException; |
5 | |
import org.kuali.student.r2.common.assembler.DTOAssembler; |
6 | |
import org.kuali.student.r2.common.dto.AttributeInfo; |
7 | |
import org.kuali.student.r2.common.dto.ContextInfo; |
8 | |
import org.kuali.student.r2.common.util.constants.AtpServiceConstants; |
9 | |
import org.kuali.student.r2.core.atp.dto.AtpAtpRelationInfo; |
10 | |
import org.kuali.student.r2.core.atp.dto.AtpInfo; |
11 | |
import org.kuali.student.r2.core.atp.service.AtpService; |
12 | |
|
13 | |
import java.util.ArrayList; |
14 | |
import java.util.List; |
15 | |
|
16 | 0 | public class AcademicCalendarAssembler implements DTOAssembler<AcademicCalendarInfo, AtpInfo> { |
17 | |
|
18 | |
private AtpService atpService; |
19 | |
|
20 | |
public AtpService getAtpService() { |
21 | 0 | return atpService; |
22 | |
} |
23 | |
|
24 | |
public void setAtpService(AtpService atpService) { |
25 | 0 | this.atpService = atpService; |
26 | 0 | } |
27 | |
|
28 | |
@Override |
29 | |
public AcademicCalendarInfo assemble(AtpInfo atp, ContextInfo context) throws AssemblyException { |
30 | |
|
31 | 0 | AcademicCalendarInfo acal = new AcademicCalendarInfo(); |
32 | 0 | acal.setId(atp.getId()); |
33 | 0 | acal.setName(atp.getName()); |
34 | 0 | acal.setDescr(atp.getDescr()); |
35 | 0 | acal.setStartDate(atp.getStartDate()); |
36 | 0 | acal.setEndDate(atp.getEndDate()); |
37 | 0 | acal.setTypeKey(atp.getTypeKey()); |
38 | 0 | acal.setStateKey(atp.getStateKey()); |
39 | 0 | acal.setMeta(atp.getMeta()); |
40 | 0 | acal.getAttributes().addAll(atp.getAttributes()); |
41 | 0 | acal.setAdminOrgId(atp.getAdminOrgId()); |
42 | 0 | acal.getHolidayCalendarIds().addAll(assembleHolidayCalendarIdsFromRelations(atp.getId(), |
43 | |
AtpServiceConstants.ATP_HOLIDAY_CALENDAR_TYPE_KEY, |
44 | |
context)); |
45 | 0 | return acal; |
46 | |
} |
47 | |
|
48 | |
private List<String> assembleHolidayCalendarIdsFromRelations(String atpId, |
49 | |
String relatedAtpType, |
50 | |
ContextInfo context) |
51 | |
throws AssemblyException { |
52 | 0 | List<String> holidayCalendarIds = new ArrayList<String>(); |
53 | |
List<AtpAtpRelationInfo> atpRels; |
54 | |
try { |
55 | 0 | atpRels = atpService.getAtpAtpRelationsByAtp(atpId, context); |
56 | 0 | for (AtpAtpRelationInfo atpRelInfo : atpRels) { |
57 | 0 | if (atpRelInfo.getAtpId().equals(atpId)) { |
58 | 0 | if (atpRelInfo.getTypeKey().equals(AtpServiceConstants.ATP_ATP_RELATION_ASSOCIATED_TYPE_KEY)) { |
59 | 0 | AtpInfo atp = atpService.getAtp(atpRelInfo.getRelatedAtpId(), context); |
60 | 0 | if (atp.getTypeKey().equals(relatedAtpType)) { |
61 | 0 | holidayCalendarIds.add(atpRelInfo.getRelatedAtpId()); |
62 | |
} |
63 | 0 | } |
64 | |
} |
65 | |
} |
66 | 0 | } catch (Exception e) { |
67 | 0 | throw new AssemblyException(e.getMessage()); |
68 | 0 | } |
69 | 0 | return holidayCalendarIds; |
70 | |
} |
71 | |
|
72 | |
@Override |
73 | |
public AtpInfo disassemble(AcademicCalendarInfo acal, ContextInfo context) throws AssemblyException { |
74 | 0 | AtpInfo atp = new AtpInfo(); |
75 | 0 | atp.setId(acal.getId()); |
76 | 0 | atp.setName(acal.getName()); |
77 | 0 | atp.setDescr(acal.getDescr()); |
78 | 0 | atp.setAdminOrgId(acal.getAdminOrgId()); |
79 | 0 | atp.setStartDate(acal.getStartDate()); |
80 | 0 | atp.setEndDate(acal.getEndDate()); |
81 | 0 | atp.setTypeKey(AtpServiceConstants.ATP_ACADEMIC_CALENDAR_TYPE_KEY); |
82 | 0 | atp.setStateKey(acal.getStateKey()); |
83 | 0 | atp.setMeta(acal.getMeta()); |
84 | 0 | atp.getAttributes().addAll(acal.getAttributes()); |
85 | |
|
86 | 0 | return atp; |
87 | |
} |
88 | |
} |