| 1 | |
package org.kuali.student.enrollment.class2.acal.keyvalue; |
| 2 | |
|
| 3 | |
import org.apache.commons.lang.StringUtils; |
| 4 | |
import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader; |
| 5 | |
import org.kuali.rice.core.api.util.ConcreteKeyValue; |
| 6 | |
import org.kuali.rice.core.api.util.KeyValue; |
| 7 | |
import org.kuali.rice.krad.uif.control.UifKeyValuesFinderBase; |
| 8 | |
import org.kuali.rice.krad.uif.view.ViewModel; |
| 9 | |
import org.kuali.student.enrollment.acal.dto.HolidayCalendarInfo; |
| 10 | |
import org.kuali.student.enrollment.acal.dto.HolidayInfo; |
| 11 | |
import org.kuali.student.enrollment.acal.service.AcademicCalendarService; |
| 12 | |
import org.kuali.student.enrollment.class2.acal.dto.HolidayCalendarWrapper; |
| 13 | |
import org.kuali.student.enrollment.class2.acal.dto.HolidayWrapper; |
| 14 | |
import org.kuali.student.enrollment.class2.acal.form.AcademicCalendarForm; |
| 15 | |
import org.kuali.student.r2.common.constants.CommonServiceConstants; |
| 16 | |
import org.kuali.student.r2.common.dto.ContextInfo; |
| 17 | |
import org.kuali.student.r2.common.exceptions.*; |
| 18 | |
import org.kuali.student.r2.common.util.constants.AtpServiceConstants; |
| 19 | |
import org.kuali.student.r2.core.type.dto.TypeInfo; |
| 20 | |
|
| 21 | |
import javax.xml.namespace.QName; |
| 22 | |
import java.io.Serializable; |
| 23 | |
import java.util.ArrayList; |
| 24 | |
import java.util.List; |
| 25 | |
import java.util.Date; |
| 26 | |
import java.text.SimpleDateFormat; |
| 27 | |
|
| 28 | |
|
| 29 | 0 | public class HolidayWrapperListFinder extends UifKeyValuesFinderBase implements Serializable { |
| 30 | |
|
| 31 | |
private static final long serialVersionUID = 1L; |
| 32 | |
private transient AcademicCalendarService acalService; |
| 33 | |
|
| 34 | |
@Override |
| 35 | |
public List<KeyValue> getKeyValues(ViewModel model) { |
| 36 | |
|
| 37 | 0 | List<KeyValue> keyValues = new ArrayList<KeyValue>(); |
| 38 | 0 | AcademicCalendarForm acalForm = (AcademicCalendarForm)model; |
| 39 | 0 | Date startDate = acalForm.getAcademicCalendarInfo().getStartDate(); |
| 40 | 0 | Date endDate = acalForm.getAcademicCalendarInfo().getEndDate(); |
| 41 | 0 | SimpleDateFormat simpleDateformat = new SimpleDateFormat("yyyy"); |
| 42 | 0 | List<HolidayCalendarInfo> holidayCalendarInfoList = new ArrayList<HolidayCalendarInfo>(); |
| 43 | |
|
| 44 | |
|
| 45 | 0 | if (startDate == null && endDate == null ) { |
| 46 | 0 | startDate = new Date(); |
| 47 | |
} |
| 48 | |
|
| 49 | |
|
| 50 | |
|
| 51 | 0 | if ((startDate != null && endDate == null) || (startDate == null && endDate != null) ){ |
| 52 | |
Integer theStartYear; |
| 53 | 0 | if (startDate != null) |
| 54 | 0 | theStartYear = new Integer(simpleDateformat.format(startDate)); |
| 55 | |
else |
| 56 | 0 | theStartYear = new Integer(simpleDateformat.format(endDate)); |
| 57 | 0 | holidayCalendarInfoList = _buildOfficialHolidayCalendarInfoList (theStartYear); |
| 58 | |
} |
| 59 | |
|
| 60 | |
|
| 61 | 0 | if (startDate != null && endDate != null) { |
| 62 | 0 | Integer theStartYear = new Integer(simpleDateformat.format(startDate)); |
| 63 | 0 | Integer theEndYear = new Integer(simpleDateformat.format(endDate)); |
| 64 | 0 | if (theEndYear <= theStartYear){ |
| 65 | |
|
| 66 | 0 | holidayCalendarInfoList = _buildOfficialHolidayCalendarInfoList (theStartYear); |
| 67 | |
|
| 68 | |
}else{ |
| 69 | 0 | for (int year=theStartYear.intValue(); year<=theEndYear.intValue(); year++ ){ |
| 70 | |
try{ |
| 71 | 0 | holidayCalendarInfoList.addAll(_buildOfficialHolidayCalendarInfoList(new Integer(year))); |
| 72 | 0 | }catch (Exception e){ |
| 73 | |
|
| 74 | 0 | } |
| 75 | |
} |
| 76 | |
} |
| 77 | |
} |
| 78 | |
|
| 79 | 0 | for(HolidayCalendarInfo holidayCalendarInfo:holidayCalendarInfoList){ |
| 80 | 0 | ConcreteKeyValue keyValue = new ConcreteKeyValue(); |
| 81 | 0 | keyValue.setKey(holidayCalendarInfo.getId()); |
| 82 | 0 | keyValue.setValue(holidayCalendarInfo.getName()); |
| 83 | 0 | keyValues.add(keyValue); |
| 84 | 0 | } |
| 85 | 0 | return keyValues; |
| 86 | |
|
| 87 | |
|
| 88 | |
} |
| 89 | |
|
| 90 | |
|
| 91 | |
private List<HolidayCalendarInfo> _buildOfficialHolidayCalendarInfoList (Integer theStartYear){ |
| 92 | 0 | List<HolidayCalendarInfo> hcList = new ArrayList<HolidayCalendarInfo>(); |
| 93 | 0 | List<HolidayCalendarInfo> hcOfficialList = new ArrayList<HolidayCalendarInfo>(); |
| 94 | |
try{ |
| 95 | 0 | hcList = getAcalService().getHolidayCalendarsByStartYear(theStartYear, new ContextInfo()); |
| 96 | 0 | for(HolidayCalendarInfo hc : hcList) { |
| 97 | 0 | if (StringUtils.equals(hc.getStateKey(), AtpServiceConstants.ATP_OFFICIAL_STATE_KEY)){ |
| 98 | 0 | hcOfficialList.add(hc); |
| 99 | |
} |
| 100 | |
} |
| 101 | 0 | }catch (InvalidParameterException ipe){ |
| 102 | 0 | System.out.println("call AcademicCalendarService.getHolidayCalendarsByStartYear(startYear, context), and get InvalidParameterException: "+ipe.toString()); |
| 103 | 0 | }catch (MissingParameterException mpe){ |
| 104 | 0 | System.out.println("call AcademicCalendarService.getHolidayCalendarsByStartYear(startYear, context), and get MissingParameterException: "+mpe.toString()); |
| 105 | 0 | }catch (OperationFailedException ofe){ |
| 106 | 0 | System.out.println("call AcademicCalendarService.getHolidayCalendarsByStartYear(startYear, context), and get OperationFailedException: "+ofe.toString()); |
| 107 | 0 | }catch (PermissionDeniedException pde){ |
| 108 | 0 | System.out.println("call AcademicCalendarService.getHolidayCalendarsByStartYear(startYear, context), and get PermissionDeniedException: "+pde.toString()); |
| 109 | 0 | } |
| 110 | 0 | return hcOfficialList; |
| 111 | |
|
| 112 | |
} |
| 113 | |
|
| 114 | |
public AcademicCalendarService getAcalService() { |
| 115 | 0 | if(acalService == null) { |
| 116 | 0 | acalService = (AcademicCalendarService) GlobalResourceLoader.getService(new QName(CommonServiceConstants.REF_OBJECT_URI_GLOBAL_PREFIX + "acal", "AcademicCalendarService")); |
| 117 | |
} |
| 118 | 0 | return this.acalService; |
| 119 | |
} |
| 120 | |
} |