| 1 | |
package org.kuali.student.enrollment.class2.acal.service; |
| 2 | |
|
| 3 | |
import org.apache.commons.lang.StringUtils; |
| 4 | |
import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader; |
| 5 | |
import org.kuali.rice.krad.lookup.LookupableImpl; |
| 6 | |
import org.kuali.rice.krad.web.form.LookupForm; |
| 7 | |
import org.kuali.rice.krad.uif.UifConstants; |
| 8 | |
import org.kuali.rice.krad.uif.UifParameters; |
| 9 | |
import org.kuali.rice.krad.util.KRADUtils; |
| 10 | |
import org.kuali.rice.krad.util.UrlFactory; |
| 11 | |
import org.kuali.rice.krad.util.KRADConstants; |
| 12 | |
|
| 13 | |
import org.kuali.student.enrollment.acal.dto.TermInfo; |
| 14 | |
import org.kuali.student.enrollment.acal.service.AcademicCalendarService; |
| 15 | |
import org.kuali.student.enrollment.class2.acal.dto.TermWrapper; |
| 16 | |
import org.kuali.student.r2.common.dto.ContextInfo; |
| 17 | |
import org.kuali.student.r2.common.exceptions.*; |
| 18 | |
|
| 19 | |
import javax.xml.namespace.QName; |
| 20 | |
import java.util.ArrayList; |
| 21 | |
import java.util.List; |
| 22 | |
import java.util.Map; |
| 23 | |
import java.util.Properties; |
| 24 | |
|
| 25 | |
|
| 26 | |
|
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | 0 | public class TermLookupableImpl extends LookupableImpl { |
| 31 | |
public final static String TERM_KEY = "key"; |
| 32 | |
private transient AcademicCalendarService academicCalendarService; |
| 33 | |
|
| 34 | |
|
| 35 | |
@Override |
| 36 | |
protected List<?> getSearchResults(LookupForm lookupForm, Map<String, String> fieldValues, boolean unbounded) { |
| 37 | 0 | TermInfo termInfo = null; |
| 38 | 0 | List<TermInfo> termInfoList = new ArrayList<TermInfo>(); |
| 39 | |
|
| 40 | 0 | String termKey = fieldValues.get(TERM_KEY); |
| 41 | 0 | ContextInfo context = new ContextInfo(); |
| 42 | |
try{ |
| 43 | 0 | termInfo = getAcademicCalendarService().getTerm(termKey, context); |
| 44 | 0 | termInfoList.add(termInfo); |
| 45 | 0 | return termInfoList; |
| 46 | 0 | }catch (DoesNotExistException dnee){ |
| 47 | 0 | System.out.println("call getAcademicCalendarService().getKeyDatesForTerm(termKey, context), and get DoesNotExistException: "+dnee.toString()); |
| 48 | 0 | }catch (InvalidParameterException ipe){ |
| 49 | 0 | System.out.println("call getAcademicCalendarService().getKeyDatesForTerm(termKey, context), and get InvalidParameterException: "+ipe.toString()); |
| 50 | 0 | }catch (MissingParameterException mpe){ |
| 51 | 0 | System.out.println("call getAcademicCalendarService().getKeyDatesForTerm(termKey, context), and get MissingParameterException: "+mpe.toString()); |
| 52 | 0 | }catch (OperationFailedException ofe){ |
| 53 | 0 | System.out.println("call getAcademicCalendarService().getKeyDatesForTerm(termKey, context), and get OperationFailedException: "+ofe.toString()); |
| 54 | 0 | }catch (PermissionDeniedException pde){ |
| 55 | 0 | System.out.println("call getAcademicCalendarService().getKeyDatesForTerm(termKey, context), and get PermissionDeniedException: "+pde.toString()); |
| 56 | 0 | } |
| 57 | 0 | return null; |
| 58 | |
|
| 59 | |
} |
| 60 | |
|
| 61 | |
@Override |
| 62 | |
protected String getActionUrlHref(LookupForm lookupForm, Object dataObject, String methodToCall, List<String> pkNames) { |
| 63 | |
|
| 64 | 0 | Properties props = new Properties(); |
| 65 | 0 | props.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, methodToCall); |
| 66 | |
|
| 67 | 0 | Map<String, String> primaryKeyValues = KRADUtils.getPropertyKeyValuesFromDataObject(pkNames, dataObject); |
| 68 | 0 | for (String primaryKey : primaryKeyValues.keySet()) { |
| 69 | 0 | String primaryKeyValue = primaryKeyValues.get(primaryKey); |
| 70 | 0 | props.put(primaryKey, primaryKeyValue); |
| 71 | 0 | props.put(KRADConstants.OVERRIDE_KEYS, primaryKey); |
| 72 | 0 | } |
| 73 | |
|
| 74 | 0 | if (StringUtils.isNotBlank(lookupForm.getReturnLocation())) { |
| 75 | 0 | props.put(KRADConstants.RETURN_LOCATION_PARAMETER, lookupForm.getReturnLocation()); |
| 76 | |
} |
| 77 | |
|
| 78 | 0 | props.put(UifParameters.DATA_OBJECT_CLASS_NAME, TermWrapper.class.getName()); |
| 79 | 0 | props.put(UifParameters.VIEW_TYPE_NAME, UifConstants.ViewType.MAINTENANCE); |
| 80 | |
|
| 81 | 0 | return UrlFactory.parameterizeUrl(KRADConstants.Maintenance.REQUEST_MAPPING_MAINTENANCE, props); |
| 82 | |
|
| 83 | |
} |
| 84 | |
|
| 85 | |
protected AcademicCalendarService getAcademicCalendarService() { |
| 86 | 0 | if(academicCalendarService == null) { |
| 87 | 0 | academicCalendarService = (AcademicCalendarService) GlobalResourceLoader.getService(new QName("http://student.kuali.org/wsdl/acal", "AcademicCalendarService")); |
| 88 | |
} |
| 89 | 0 | return academicCalendarService; |
| 90 | |
} |
| 91 | |
|
| 92 | |
|
| 93 | |
|
| 94 | |
|
| 95 | |
} |