View Javadoc

1   package org.kuali.student.enrollment.class2.acal.service.assembler;
2   
3   import java.util.ArrayList;
4   import org.kuali.student.enrollment.acal.dto.HolidayCalendarInfo;
5   import org.kuali.student.r2.common.assembler.AssemblyException;
6   import org.kuali.student.r2.common.assembler.DTOAssembler;
7   import org.kuali.student.r2.common.dto.AttributeInfo;
8   import org.kuali.student.r2.common.dto.ContextInfo;
9   import org.kuali.student.r2.core.constants.AtpServiceConstants;
10  import org.kuali.student.r2.core.atp.dto.AtpInfo;
11  
12  public class HolidayCalendarAssembler implements DTOAssembler<HolidayCalendarInfo, AtpInfo> {
13  
14      @Override
15      public HolidayCalendarInfo assemble(AtpInfo atp, ContextInfo context) throws AssemblyException {
16          if (atp != null) {
17              HolidayCalendarInfo holidayCalendarInfo = new HolidayCalendarInfo();
18              holidayCalendarInfo.setId(atp.getId());
19              holidayCalendarInfo.setName(atp.getName());
20              holidayCalendarInfo.setAdminOrgId(atp.getAdminOrgId());
21              holidayCalendarInfo.setDescr(atp.getDescr());
22              holidayCalendarInfo.setStartDate(atp.getStartDate());
23              holidayCalendarInfo.setEndDate(atp.getEndDate());
24              holidayCalendarInfo.setTypeKey(atp.getTypeKey());
25              holidayCalendarInfo.setStateKey(atp.getStateKey());
26              holidayCalendarInfo.setMeta(atp.getMeta());
27              for (AttributeInfo attr : atp.getAttributes()) {
28                  if (attr.getKey().equals(AtpServiceConstants.CAMPUS_LOCATION)) {
29                      holidayCalendarInfo.getCampusKeys().add(attr.getValue());
30                  } else {
31                      holidayCalendarInfo.getAttributes().add(attr);
32                  }
33              }
34              return holidayCalendarInfo;
35          } else {
36              return null;
37          }
38      }
39  
40      @Override
41      public AtpInfo disassemble(HolidayCalendarInfo holidayCalendarInfo, ContextInfo context) throws AssemblyException {
42          if (holidayCalendarInfo != null) {
43              AtpInfo atp = new AtpInfo();
44              atp.setId(holidayCalendarInfo.getId());
45              atp.setName(holidayCalendarInfo.getName());
46              atp.setAdminOrgId(holidayCalendarInfo.getAdminOrgId());
47              atp.setDescr(holidayCalendarInfo.getDescr());
48              atp.setStartDate(holidayCalendarInfo.getStartDate());
49              atp.setEndDate(holidayCalendarInfo.getEndDate());
50              atp.setTypeKey(AtpServiceConstants.ATP_HOLIDAY_CALENDAR_TYPE_KEY);
51              atp.setStateKey(holidayCalendarInfo.getStateKey());
52              atp.setMeta(holidayCalendarInfo.getMeta());
53              atp.getAttributes().addAll(holidayCalendarInfo.getAttributes());
54              // TODO: fix this essentially flawed mechanism -- that happens because of the assembler structure
55  //            it really should take in as a paraemter the existing ATP, if there is one
56  //            and find/match the campus keys there and update the set of attributes not replacing them
57  //            doing it this way we lose the original id of attribute on update 
58              // the making it hard (wrong?) to store it later
59              for (String campusKey : holidayCalendarInfo.getCampusKeys()) {
60                  AttributeInfo attr = new AttributeInfo();
61                  attr.setKey(AtpServiceConstants.CAMPUS_LOCATION);
62                  attr.setValue(campusKey);
63                  atp.getAttributes().add(attr);
64              }
65              return atp;
66          }
67  
68          return null;
69      }
70  }