| 1 | |
package org.kuali.student.enrollment.class2.appointment.keyvalue; |
| 2 | |
|
| 3 | |
import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader; |
| 4 | |
import org.kuali.rice.core.api.util.ConcreteKeyValue; |
| 5 | |
import org.kuali.rice.core.api.util.KeyValue; |
| 6 | |
import org.kuali.rice.krad.uif.control.UifKeyValuesFinderBase; |
| 7 | |
import org.kuali.rice.krad.uif.view.ViewModel; |
| 8 | |
import org.kuali.student.enrollment.acal.constants.AcademicCalendarServiceConstants; |
| 9 | |
import org.kuali.student.enrollment.acal.dto.KeyDateInfo; |
| 10 | |
import org.kuali.student.enrollment.acal.dto.TermInfo; |
| 11 | |
import org.kuali.student.enrollment.acal.service.AcademicCalendarService; |
| 12 | |
import org.kuali.student.enrollment.class2.appointment.form.RegistrationWindowsManagementForm; |
| 13 | |
import org.kuali.student.r2.common.dto.ContextInfo; |
| 14 | |
import org.kuali.student.r2.common.exceptions.*; |
| 15 | |
import org.kuali.student.r2.common.util.constants.AtpServiceConstants; |
| 16 | |
import org.kuali.student.r2.common.util.constants.TypeServiceConstants; |
| 17 | |
import org.kuali.student.r2.core.type.dto.TypeTypeRelationInfo; |
| 18 | |
import org.kuali.student.r2.core.type.service.TypeService; |
| 19 | |
import org.kuali.student.mock.utilities.TestHelper; |
| 20 | |
|
| 21 | |
import javax.xml.namespace.QName; |
| 22 | |
import java.io.Serializable; |
| 23 | |
import java.util.ArrayList; |
| 24 | |
import java.util.List; |
| 25 | |
|
| 26 | 0 | public class PeriodForAppWindowKeyDatesFinder extends UifKeyValuesFinderBase implements Serializable { |
| 27 | |
private static final long serialVersionUID = 1L; |
| 28 | |
private transient AcademicCalendarService acalService; |
| 29 | |
private transient TypeService typeService; |
| 30 | |
private ContextInfo contextInfo; |
| 31 | |
|
| 32 | |
@Override |
| 33 | |
public List<KeyValue> getKeyValues(ViewModel model) { |
| 34 | 0 | List<KeyValue> keyValues = new ArrayList<KeyValue>(); |
| 35 | 0 | RegistrationWindowsManagementForm form = (RegistrationWindowsManagementForm)model; |
| 36 | |
|
| 37 | 0 | ContextInfo context = TestHelper.getContext1(); |
| 38 | |
try { |
| 39 | 0 | TermInfo term = form.getTermInfo(); |
| 40 | 0 | if (term.getId() != null && !term.getId().isEmpty()) { |
| 41 | 0 | List<KeyDateInfo> keyDateInfoList = getAcalService().getKeyDatesForTerm(term.getId(), context); |
| 42 | 0 | if (!keyDateInfoList.isEmpty()) |
| 43 | 0 | keyValues.add(new ConcreteKeyValue("", "Select Period...")); |
| 44 | |
try{ |
| 45 | 0 | List<TypeTypeRelationInfo> relations = getTypeService().getTypeTypeRelationsByOwnerAndType("kuali.milestone.type.group.appt.regperiods","kuali.type.type.relation.type.group",context); |
| 46 | 0 | for (KeyDateInfo keyDateInfo : keyDateInfoList) { |
| 47 | 0 | for (TypeTypeRelationInfo relationInfo : relations) { |
| 48 | 0 | String relatedTypeKey = relationInfo.getRelatedTypeKey(); |
| 49 | 0 | if (keyDateInfo.getTypeKey().equals(relatedTypeKey) && |
| 50 | |
(AtpServiceConstants.ATP_OFFICIAL_STATE_KEY.equals(keyDateInfo.getStateKey()) || |
| 51 | |
AtpServiceConstants.ATP_OFFICIAL_STATE_KEY.equals(keyDateInfo.getStateKey()))) { |
| 52 | 0 | keyValues.add(new ConcreteKeyValue(keyDateInfo.getId(), keyDateInfo.getName())); |
| 53 | 0 | break; |
| 54 | |
} |
| 55 | 0 | } |
| 56 | |
} |
| 57 | |
|
| 58 | 0 | }catch (Exception e){ |
| 59 | |
|
| 60 | 0 | } |
| 61 | |
|
| 62 | |
|
| 63 | |
|
| 64 | |
|
| 65 | |
|
| 66 | |
|
| 67 | |
|
| 68 | |
|
| 69 | |
} |
| 70 | 0 | }catch (DoesNotExistException dnee){ |
| 71 | 0 | System.out.println("call getAcalService().getKeyDatesForTerm(term.getId(), context), and get DoesNotExistException: "+dnee.toString()); |
| 72 | 0 | }catch (InvalidParameterException ipe){ |
| 73 | 0 | System.out.println("call getAcalService().getKeyDatesForTerm(term.getId(), context), and get InvalidParameterException: "+ipe.toString()); |
| 74 | 0 | }catch (MissingParameterException mpe){ |
| 75 | 0 | System.out.println("call getAcalService().getKeyDatesForTerm(term.getId(), context), and get MissingParameterException: "+mpe.toString()); |
| 76 | 0 | }catch (OperationFailedException ofe){ |
| 77 | 0 | System.out.println("call getAcalService().getKeyDatesForTerm(term.getId(), context), and get OperationFailedException: "+ofe.toString()); |
| 78 | 0 | }catch (PermissionDeniedException pde){ |
| 79 | 0 | System.out.println("call getAcalService().getKeyDatesForTerm(term.getId(), context), and get PermissionDeniedException: "+pde.toString()); |
| 80 | 0 | } |
| 81 | 0 | return keyValues; |
| 82 | |
} |
| 83 | |
|
| 84 | |
public AcademicCalendarService getAcalService() { |
| 85 | 0 | if(acalService == null) { |
| 86 | 0 | acalService = (AcademicCalendarService) GlobalResourceLoader.getService(new QName(AcademicCalendarServiceConstants.NAMESPACE, AcademicCalendarServiceConstants.SERVICE_NAME_LOCAL_PART)); |
| 87 | |
} |
| 88 | 0 | return this.acalService; |
| 89 | |
} |
| 90 | |
|
| 91 | |
public TypeService getTypeService() { |
| 92 | 0 | if(typeService == null) { |
| 93 | 0 | typeService = (TypeService) GlobalResourceLoader.getService(new QName(TypeServiceConstants.NAMESPACE, TypeServiceConstants.SERVICE_NAME_LOCAL_PART)); |
| 94 | |
} |
| 95 | 0 | return this.typeService; |
| 96 | |
} |
| 97 | |
|
| 98 | |
private ContextInfo getContextInfo() { |
| 99 | 0 | if (null == contextInfo) { |
| 100 | |
|
| 101 | 0 | contextInfo = TestHelper.getContext1(); |
| 102 | |
} |
| 103 | 0 | return contextInfo; |
| 104 | |
} |
| 105 | |
} |