Coverage Report - org.kuali.student.enrollment.class2.acal.service.AcademicTermLookupableImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
AcademicTermLookupableImpl
0%
0/66
0%
0/22
6
 
 1  
 package org.kuali.student.enrollment.class2.acal.service;
 2  
 
 3  
 import org.apache.commons.lang.StringUtils;
 4  
 import org.kuali.rice.core.api.criteria.Predicate;
 5  
 import org.kuali.rice.core.api.criteria.QueryByCriteria;
 6  
 import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
 7  
 import org.kuali.rice.krad.lookup.LookupableImpl;
 8  
 import org.kuali.rice.krad.uif.UifParameters;
 9  
 import org.kuali.rice.krad.util.KRADConstants;
 10  
 import org.kuali.rice.krad.util.UrlFactory;
 11  
 import org.kuali.rice.krad.web.form.LookupForm;
 12  
 import org.kuali.student.enrollment.acal.constants.AcademicCalendarServiceConstants;
 13  
 import org.kuali.student.enrollment.acal.dto.AcademicCalendarInfo;
 14  
 import org.kuali.student.enrollment.acal.dto.TermInfo;
 15  
 import org.kuali.student.enrollment.acal.service.AcademicCalendarService;
 16  
 import org.kuali.student.mock.utilities.TestHelper;
 17  
 import org.kuali.student.r2.common.dto.ContextInfo;
 18  
 
 19  
 import javax.xml.namespace.QName;
 20  
 import java.text.ParseException;
 21  
 import java.text.SimpleDateFormat;
 22  
 import java.util.ArrayList;
 23  
 import java.util.List;
 24  
 import java.util.Map;
 25  
 import java.util.Properties;
 26  
 
 27  
 import static org.kuali.rice.core.api.criteria.PredicateFactory.*;
 28  
 
 29  
 //Core slice class.
 30  
 @Deprecated
 31  0
 public class AcademicTermLookupableImpl  extends LookupableImpl {
 32  
 
 33  
     public final static String TERM_TYPE = "typeKey";
 34  
     public final static String TERM_NAME = "name";
 35  
     public final static String TERM_START_DATE = "startDate";
 36  
     public final static String TERM_END_DATE = "endDate";
 37  
     public final static String TERM_STATE = "stateKey";
 38  
 
 39  
          private transient AcademicCalendarService academicCalendarService;
 40  
 
 41  
     @Override
 42  
     protected List<?> getSearchResults(LookupForm lookupForm, Map<String, String> fieldValues, boolean unbounded) {
 43  
 
 44  0
             TermInfo termInfo = null;
 45  0
             List<TermInfo> termInfoList = new ArrayList<TermInfo>();
 46  0
         List<AcademicCalendarInfo> acalInfoList = new ArrayList<AcademicCalendarInfo>();
 47  
 
 48  0
             String termName = fieldValues.get(TERM_NAME);
 49  0
         String termType = fieldValues.get(TERM_TYPE);
 50  0
         String termState = fieldValues.get(TERM_STATE);
 51  0
         String termStartDate = fieldValues.get(TERM_START_DATE);
 52  0
         String termEndDate = fieldValues.get(TERM_END_DATE);
 53  
 
 54  0
             ContextInfo context = new ContextInfo();
 55  
 
 56  
 
 57  0
         QueryByCriteria.Builder qBuilder = QueryByCriteria.Builder.create();
 58  0
         List<Predicate> pList = new ArrayList<Predicate>();
 59  
         Predicate p;
 60  
 
 61  0
         qBuilder.setPredicates();
 62  0
         if (StringUtils.isNotBlank(termName)){
 63  0
             p = equal(TERM_NAME, termName);
 64  0
                     pList.add(p);
 65  
         }
 66  
 
 67  0
         if (StringUtils.isNotBlank(termType)){
 68  0
             p = equal("atpType", termType);
 69  0
                     pList.add(p);
 70  
         }
 71  
 
 72  0
         if (StringUtils.isNotBlank(termState)){
 73  0
             p = equal("atpState", termState);
 74  0
                     pList.add(p);
 75  
         }
 76  
 
 77  0
         if (StringUtils.isNotBlank(termStartDate)){
 78  
             try {
 79  0
                 p = greaterThanOrEqual(TERM_START_DATE, new SimpleDateFormat("MM/dd/yyyy").parse(termStartDate));
 80  0
             } catch (ParseException e) {
 81  0
                 throw new RuntimeException(e);
 82  0
             }
 83  0
             pList.add(p);
 84  
         }
 85  
 
 86  0
         if (StringUtils.isNotBlank(termEndDate)){
 87  
             try{
 88  0
                 p = lessThanOrEqual(TERM_END_DATE,  new SimpleDateFormat("MM/dd/yyyy").parse(termEndDate));
 89  0
             } catch (ParseException e) {
 90  0
                 throw new RuntimeException(e);
 91  0
             }
 92  0
                     pList.add(p);
 93  
         }
 94  
 
 95  0
         if (!pList.isEmpty()){
 96  0
             Predicate[] preds = new Predicate[pList.size()];
 97  0
             pList.toArray(preds);
 98  0
             qBuilder.setPredicates(and(preds));
 99  
         }
 100  
 
 101  
         try {
 102  0
             termInfoList = getAcademicCalendarService().searchForTerms(qBuilder.build(),context);
 103  0
         } catch (Exception e) {
 104  0
             e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
 105  0
         }
 106  
 
 107  0
         return termInfoList;
 108  
     }
 109  
 
 110  
 
 111  
     @Override
 112  
     public boolean allowsMaintenanceNewOrCopyAction() {
 113  0
         return false;
 114  
     }
 115  
 
 116  
     @Override
 117  
     protected String getActionUrlHref(LookupForm lookupForm, Object dataObject, String methodToCall,
 118  
             List<String> pkNames) {
 119  
 
 120  0
         if (dataObject == null){
 121  0
             return StringUtils.EMPTY;
 122  
         }
 123  
 
 124  0
         TermInfo term = (TermInfo)dataObject;
 125  
 
 126  0
         String acalId = null;
 127  
         try {
 128  0
             List<AcademicCalendarInfo> atps = getAcademicCalendarService().getAcademicCalendarsForTerm(term.getId(), TestHelper.getContext1());
 129  0
             if (!atps.isEmpty()){
 130  0
                 acalId = atps.get(0).getId();
 131  
             }
 132  0
         } catch (Exception e) {
 133  0
             throw new RuntimeException(e);
 134  0
         }
 135  
 
 136  0
         if (StringUtils.isBlank(acalId)){
 137  0
            return StringUtils.EMPTY;
 138  
         }
 139  
 
 140  0
         Properties props = new Properties();
 141  0
         props.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, "start");
 142  0
         props.put("id",acalId);
 143  0
         props.put(UifParameters.VIEW_ID, "academicCalendarEditView");
 144  
 
 145  0
         if (StringUtils.isNotBlank(lookupForm.getReturnLocation())) {
 146  0
             props.put(KRADConstants.RETURN_LOCATION_PARAMETER, lookupForm.getReturnLocation());
 147  
         }
 148  
 
 149  0
         return UrlFactory.parameterizeUrl("academicCalendar", props);
 150  
     }
 151  
 
 152  
     protected AcademicCalendarService getAcademicCalendarService() {
 153  0
          if(academicCalendarService == null) {
 154  0
              academicCalendarService = (AcademicCalendarService) GlobalResourceLoader.getService(new QName(AcademicCalendarServiceConstants.NAMESPACE, AcademicCalendarServiceConstants.SERVICE_NAME_LOCAL_PART));
 155  
         }
 156  0
         return this.academicCalendarService;
 157  
     }
 158  
 
 159  
 }