View Javadoc
1   /**
2    * Copyright 2004-2014 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.kpme.pm.positionappointment.web;
17  
18  import java.util.ArrayList;
19  import java.util.HashMap;
20  import java.util.List;
21  import java.util.Map;
22  
23  import org.apache.commons.lang.StringUtils;
24  import org.kuali.kpme.core.api.groupkey.HrGroupKey;
25  import org.kuali.kpme.core.lookup.KPMELookupableImpl;
26  import org.kuali.kpme.core.service.HrServiceLocator;
27  import org.kuali.kpme.core.util.TKUtils;
28  import org.kuali.kpme.pm.api.positionappointment.PositionAppointment;
29  import org.kuali.kpme.pm.api.positionappointment.PositionAppointmentContract;
30  import org.kuali.kpme.pm.positionappointment.PositionAppointmentBo;
31  import org.kuali.kpme.pm.positionappointment.authorization.PositionAppointmentAuthorizer;
32  import org.kuali.kpme.pm.service.base.PmServiceLocator;
33  import org.kuali.rice.core.api.mo.ModelObjectUtils;
34  import org.kuali.rice.kim.api.identity.Person;
35  import org.kuali.rice.krad.util.GlobalVariables;
36  import org.kuali.rice.krad.web.form.LookupForm;
37  
38  public class PositionAppointmentLookupableImpl extends KPMELookupableImpl {
39  
40  	private static final long serialVersionUID = 4826886027602440306L;
41  
42  	private static final ModelObjectUtils.Transformer<PositionAppointment, PositionAppointmentBo> toPositionAppointmentBo =
43  			new ModelObjectUtils.Transformer<PositionAppointment, PositionAppointmentBo>() {
44  		public PositionAppointmentBo transform(PositionAppointment input) {
45  			return PositionAppointmentBo.from(input);
46  		};
47  	};
48  
49      protected List<PositionAppointmentBo> filterLookupPositionAppointments(List<PositionAppointmentBo> rawResults, Person user)
50      {
51          List<PositionAppointmentBo> returnList = new ArrayList<PositionAppointmentBo>();
52          for (PositionAppointmentBo positionAppointmentObj : rawResults)
53          {
54              if (((PositionAppointmentAuthorizer)(getDocumentDictionaryService().getDocumentAuthorizer(this.getMaintenanceDocumentTypeName()))).canView((Object) positionAppointmentObj, user))
55              {
56                  returnList.add(positionAppointmentObj);
57              }
58          }
59          return returnList;
60      }
61  
62  	@Override
63  	public List<?> getSearchResults(LookupForm form, Map<String, String> searchCriteria, boolean bounded) {
64  
65  		//return super.getSearchResults(form, searchCriteria, bounded);
66  /*
67  		String description = searchCriteria.get("description");
68  		String fromEffdt = TKUtils.getFromDateString(searchCriteria.get("effectiveDate"));
69  		String toEffdt = TKUtils.getToDateString(searchCriteria.get("effectiveDate"));
70  		String active = searchCriteria.get("active");
71  		String showHist = searchCriteria.get("history");
72  		String positionAppointment = searchCriteria.get("positionAppointment");
73  		String institution = searchCriteria.get("institution");
74  		String location = searchCriteria.get("location");
75  		String groupKeyCode = searchCriteria.get("groupKeyCode");
76  
77  		List<PositionAppointmentBo> posApptContrasts = ModelObjectUtils.transform(PmServiceLocator.getPositionAppointmentService().getPositionAppointmentList
78  				(positionAppointment, description, groupKeyCode, TKUtils.formatDateString(fromEffdt), TKUtils.formatDateString(toEffdt), active, showHist), toPositionAppointmentBo);
79  */
80  
81          List<PositionAppointmentBo> posApptContrasts = (List<PositionAppointmentBo>)super.getSearchResults(form, searchCriteria, bounded);
82  
83          List<PositionAppointmentBo> filteredResults = filterLookupPositionAppointments(posApptContrasts, GlobalVariables.getUserSession().getPerson());
84  		// TODO: Filter the result by institution and location here
85  
86  		return filteredResults;
87  	}
88  
89  }