001 package org.kuali.student.enrollment.class2.appointment.keyvalue; 002 003 import org.apache.log4j.Logger; 004 import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader; 005 import org.kuali.rice.core.api.util.ConcreteKeyValue; 006 import org.kuali.rice.core.api.util.KeyValue; 007 import org.kuali.rice.krad.uif.control.UifKeyValuesFinderBase; 008 import org.kuali.rice.krad.uif.view.ViewModel; 009 import org.kuali.student.r2.core.acal.dto.KeyDateInfo; 010 import org.kuali.student.r2.core.acal.dto.TermInfo; 011 import org.kuali.student.r2.core.acal.service.AcademicCalendarService; 012 import org.kuali.student.enrollment.class2.appointment.form.RegistrationWindowsManagementForm; 013 import org.kuali.student.mock.utilities.TestHelper; 014 import org.kuali.student.r2.common.dto.ContextInfo; 015 import org.kuali.student.r2.core.constants.AcademicCalendarServiceConstants; 016 import org.kuali.student.r2.core.class1.type.dto.TypeTypeRelationInfo; 017 import org.kuali.student.r2.core.class1.type.service.TypeService; 018 import org.kuali.student.r2.core.constants.AtpServiceConstants; 019 import org.kuali.student.r2.core.constants.TypeServiceConstants; 020 021 import javax.xml.namespace.QName; 022 import java.io.Serializable; 023 import java.util.ArrayList; 024 import java.util.List; 025 026 public class PeriodForAppWindowKeyDatesFinder extends UifKeyValuesFinderBase implements Serializable { 027 private static final long serialVersionUID = 1L; 028 029 private static final Logger LOG = Logger.getLogger(PeriodForAppWindowKeyDatesFinder.class); 030 031 private transient AcademicCalendarService acalService; 032 private transient TypeService typeService; 033 034 @Override 035 public List<KeyValue> getKeyValues(ViewModel model) { 036 List<KeyValue> keyValues = new ArrayList<KeyValue>(); 037 RegistrationWindowsManagementForm form = (RegistrationWindowsManagementForm)model; 038 039 ContextInfo context = TestHelper.getContext1(); 040 try { 041 TermInfo term = form.getTermInfo(); 042 if (term.getId() != null && !term.getId().isEmpty()) { 043 List<KeyDateInfo> keyDateInfoList = getAcalService().getKeyDatesForTerm(term.getId(), context); 044 if (!keyDateInfoList.isEmpty()) 045 keyValues.add(new ConcreteKeyValue("", "Select Period...")); 046 try{ 047 List<TypeTypeRelationInfo> relations = getTypeService().getTypeTypeRelationsByOwnerAndType("kuali.milestone.type.group.appt.regperiods","kuali.type.type.relation.type.group",context); 048 for (KeyDateInfo keyDateInfo : keyDateInfoList) { 049 for (TypeTypeRelationInfo relationInfo : relations) { 050 String relatedTypeKey = relationInfo.getRelatedTypeKey(); 051 if (keyDateInfo.getTypeKey().equals(relatedTypeKey) && 052 (AtpServiceConstants.ATP_OFFICIAL_STATE_KEY.equals(keyDateInfo.getStateKey()) || 053 AtpServiceConstants.ATP_OFFICIAL_STATE_KEY.equals(keyDateInfo.getStateKey()))) { 054 keyValues.add(new ConcreteKeyValue(keyDateInfo.getId(), keyDateInfo.getName())); 055 break; 056 } 057 } 058 } 059 060 }catch (Exception e){ 061 LOG.error("Error getting periods", e); 062 } 063 064 } 065 }catch (Exception e){ 066 LOG.error("Error getting periods", e); 067 } 068 return keyValues; 069 } 070 071 public AcademicCalendarService getAcalService() { 072 if(acalService == null) { 073 acalService = (AcademicCalendarService) GlobalResourceLoader.getService(new QName(AcademicCalendarServiceConstants.NAMESPACE, AcademicCalendarServiceConstants.SERVICE_NAME_LOCAL_PART)); 074 } 075 return this.acalService; 076 } 077 078 public TypeService getTypeService() { 079 if(typeService == null) { 080 typeService = (TypeService) GlobalResourceLoader.getService(new QName(TypeServiceConstants.NAMESPACE, TypeServiceConstants.SERVICE_NAME_LOCAL_PART)); 081 } 082 return this.typeService; 083 } 084 085 }