001 package org.kuali.student.enrollment.class2.acal.service.assembler; 002 003 import java.util.ArrayList; 004 import org.kuali.student.enrollment.acal.dto.HolidayCalendarInfo; 005 import org.kuali.student.r2.common.assembler.AssemblyException; 006 import org.kuali.student.r2.common.assembler.DTOAssembler; 007 import org.kuali.student.r2.common.dto.AttributeInfo; 008 import org.kuali.student.r2.common.dto.ContextInfo; 009 import org.kuali.student.r2.core.constants.AtpServiceConstants; 010 import org.kuali.student.r2.core.atp.dto.AtpInfo; 011 012 public class HolidayCalendarAssembler implements DTOAssembler<HolidayCalendarInfo, AtpInfo> { 013 014 @Override 015 public HolidayCalendarInfo assemble(AtpInfo atp, ContextInfo context) throws AssemblyException { 016 if (atp != null) { 017 HolidayCalendarInfo holidayCalendarInfo = new HolidayCalendarInfo(); 018 holidayCalendarInfo.setId(atp.getId()); 019 holidayCalendarInfo.setName(atp.getName()); 020 holidayCalendarInfo.setAdminOrgId(atp.getAdminOrgId()); 021 holidayCalendarInfo.setDescr(atp.getDescr()); 022 holidayCalendarInfo.setStartDate(atp.getStartDate()); 023 holidayCalendarInfo.setEndDate(atp.getEndDate()); 024 holidayCalendarInfo.setTypeKey(atp.getTypeKey()); 025 holidayCalendarInfo.setStateKey(atp.getStateKey()); 026 holidayCalendarInfo.setMeta(atp.getMeta()); 027 for (AttributeInfo attr : atp.getAttributes()) { 028 if (attr.getKey().equals(AtpServiceConstants.CAMPUS_LOCATION)) { 029 holidayCalendarInfo.getCampusKeys().add(attr.getValue()); 030 } else { 031 holidayCalendarInfo.getAttributes().add(attr); 032 } 033 } 034 return holidayCalendarInfo; 035 } else { 036 return null; 037 } 038 } 039 040 @Override 041 public AtpInfo disassemble(HolidayCalendarInfo holidayCalendarInfo, ContextInfo context) throws AssemblyException { 042 if (holidayCalendarInfo != null) { 043 AtpInfo atp = new AtpInfo(); 044 atp.setId(holidayCalendarInfo.getId()); 045 atp.setName(holidayCalendarInfo.getName()); 046 atp.setAdminOrgId(holidayCalendarInfo.getAdminOrgId()); 047 atp.setDescr(holidayCalendarInfo.getDescr()); 048 atp.setStartDate(holidayCalendarInfo.getStartDate()); 049 atp.setEndDate(holidayCalendarInfo.getEndDate()); 050 atp.setTypeKey(AtpServiceConstants.ATP_HOLIDAY_CALENDAR_TYPE_KEY); 051 atp.setStateKey(holidayCalendarInfo.getStateKey()); 052 atp.setMeta(holidayCalendarInfo.getMeta()); 053 atp.getAttributes().addAll(holidayCalendarInfo.getAttributes()); 054 // TODO: fix this essentially flawed mechanism -- that happens because of the assembler structure 055 // it really should take in as a paraemter the existing ATP, if there is one 056 // and find/match the campus keys there and update the set of attributes not replacing them 057 // doing it this way we lose the original id of attribute on update 058 // the making it hard (wrong?) to store it later 059 for (String campusKey : holidayCalendarInfo.getCampusKeys()) { 060 AttributeInfo attr = new AttributeInfo(); 061 attr.setKey(AtpServiceConstants.CAMPUS_LOCATION); 062 attr.setValue(campusKey); 063 atp.getAttributes().add(attr); 064 } 065 return atp; 066 } 067 068 return null; 069 } 070 }