Coverage Report - org.kuali.student.enrollment.class2.acal.keyvalue.TermKeyValues
 
Classes in this File Line Coverage Branch Coverage Complexity
TermKeyValues
0%
0/36
0%
0/12
9
 
 1  
 package org.kuali.student.enrollment.class2.acal.keyvalue;
 2  
 
 3  
 /*
 4  
  * Copyright 2007 The Kuali Foundation
 5  
  *
 6  
  * Licensed under the Educational Community License, Version 1.0 (the "License");
 7  
  * you may not use this file except in compliance with the License.
 8  
  * You may obtain a copy of the License at
 9  
  *
 10  
  * http://www.opensource.org/licenses/ecl1.php
 11  
  *
 12  
  * Unless required by applicable law or agreed to in writing, software
 13  
  * distributed under the License is distributed on an "AS IS" BASIS,
 14  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 15  
  * See the License for the specific language governing permissions and
 16  
  * limitations under the License.
 17  
  */
 18  
 
 19  
 import org.apache.commons.lang.StringUtils;
 20  
 import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
 21  
 import org.kuali.rice.core.api.util.ConcreteKeyValue;
 22  
 import org.kuali.rice.core.api.util.KeyValue;
 23  
 import org.kuali.rice.krad.keyvalues.KeyValuesBase;
 24  
 import org.kuali.student.enrollment.acal.dto.AcademicCalendarInfo;
 25  
 import org.kuali.student.enrollment.acal.dto.TermInfo;
 26  
 import org.kuali.student.enrollment.acal.service.AcademicCalendarService;
 27  
 import org.kuali.student.r2.common.dto.ContextInfo;
 28  
 import org.kuali.student.r2.common.exceptions.*;
 29  
 import org.kuali.student.r2.common.util.constants.AtpServiceConstants;
 30  
 
 31  
 import javax.xml.namespace.QName;
 32  
 import java.io.Serializable;
 33  
 import java.util.ArrayList;
 34  
 import java.util.Calendar;
 35  
 import java.util.Date;
 36  
 import java.util.List;
 37  
 
 38  
 //Core slice class.
 39  
 @Deprecated
 40  0
 public class TermKeyValues extends KeyValuesBase implements Serializable {
 41  
 
 42  
     private static final long serialVersionUID = 1L;
 43  
 
 44  
     private transient AcademicCalendarService acalService;
 45  
 
 46  
 
 47  
     @Override
 48  
     /*
 49  
      * Return a list of terms that belong to the Academic Year with the start year equal to the current year.
 50  
      *
 51  
      * From Bonnie: The current implementation has some problems.
 52  
      * For instance, in Jan 2012, although we are still in Academic Calendar 2011 - 2012, probably the term of
 53  
      * Spring 2012, the current implementation can't display terms of Academic Calendar 2011 - 2012, but can
 54  
      * only display terms of Academic Calendar 2012 - 2013.
 55  
      */
 56  
     public List<KeyValue> getKeyValues() {
 57  
 
 58  0
         List<AcademicCalendarInfo> acals = new ArrayList<AcademicCalendarInfo>();
 59  0
         ContextInfo context = new ContextInfo();
 60  
 
 61  
 
 62  0
         List<TermInfo> terms = new ArrayList<TermInfo>();
 63  
         try {
 64  0
             Calendar nowCal = Calendar.getInstance();
 65  0
             nowCal.setTime(new Date());
 66  0
             int year = nowCal.get(Calendar.YEAR);
 67  0
             acals.addAll(getAcalService().getAcademicCalendarsByStartYear(year - 1, context));
 68  0
             acals.addAll(getAcalService().getAcademicCalendarsByStartYear(year, context));
 69  0
             acals.addAll(getAcalService().getAcademicCalendarsByStartYear(year+1, context));
 70  0
             for (AcademicCalendarInfo acal : acals) {
 71  0
                 if (StringUtils.equals(acal.getStateKey(), AtpServiceConstants.ATP_OFFICIAL_STATE_KEY)){
 72  0
                     terms.addAll(getAcalService().getTermsForAcademicCalendar(acal.getId(), context));
 73  
                 }
 74  
             }
 75  
 
 76  
             // TODO: remove this when we figure out why KRAD defaultValue property is not working
 77  0
             for (TermInfo term : terms) {
 78  0
                 if ("testTermId1".equals(term.getId())) {
 79  0
                     terms.remove(term);
 80  0
                     terms.add(0, term);
 81  0
                     break;
 82  
                 }
 83  
             }
 84  0
         } catch (DoesNotExistException e) {
 85  0
             throw new RuntimeException("No Terms found for current AcademicCalendar(s)! There should be some in the database.", e);
 86  0
         } catch (InvalidParameterException e) {
 87  0
             throw new RuntimeException(e);
 88  0
         } catch (MissingParameterException e) {
 89  0
             throw new RuntimeException(e);
 90  0
         } catch (OperationFailedException e) {
 91  0
             throw new RuntimeException(e);
 92  0
         } catch (PermissionDeniedException e) {
 93  0
             throw new RuntimeException(e);
 94  0
         }
 95  
 
 96  0
         List<KeyValue> keyValues = new ArrayList<KeyValue>();
 97  
 
 98  0
         for(TermInfo term : terms) {
 99  0
             keyValues.add(new ConcreteKeyValue(term.getId(), term.getName()));
 100  
         }
 101  
 
 102  0
         return keyValues;
 103  
     }
 104  
 
 105  
     protected AcademicCalendarService getAcalService() {
 106  0
         if(acalService == null) {
 107  0
             acalService = (AcademicCalendarService) GlobalResourceLoader.getService(new QName("http://student.kuali.org/wsdl/acal", "AcademicCalendarService"));
 108  
         }
 109  0
         return this.acalService;
 110  
     }
 111  
 }