View Javadoc
1   /*
2    * Copyright 2007 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.ole.module.cg.businessobject.lookup;
17  
18  import java.util.Collections;
19  import java.util.List;
20  import java.util.Map;
21  
22  import org.apache.commons.lang.StringUtils;
23  import org.kuali.ole.sys.context.SpringContext;
24  import org.kuali.rice.kim.api.identity.Person;
25  import org.kuali.rice.kim.api.identity.PersonService;
26  import org.kuali.rice.kns.lookup.KualiLookupableHelperServiceImpl;
27  import org.kuali.rice.krad.bo.BusinessObject;
28  
29  /**
30   * Allows custom handling of Proposals within the lookup framework.
31   */
32  public class ProposalLookupableHelperServiceImpl extends KualiLookupableHelperServiceImpl {
33  
34      private static final String LOOKUP_USER_ID_FIELD = "lookupPerson.principalName";
35      private static final String LOOKUP_UNIVERSAL_USER_ID_FIELD = "proposalProjectDirectors.principalId";
36  
37      private PersonService personService;
38  
39      /**
40       * @see org.kuali.rice.kns.lookup.KualiLookupableHelperServiceImpl#getSearchResultsHelper(java.util.Map, boolean)
41       */
42      @Override
43      protected List<? extends BusinessObject> getSearchResultsHelper(Map<String, String> fieldValues, boolean unbounded) {
44          // perform the lookup on the project director object first
45          if (!StringUtils.isBlank(fieldValues.get(LOOKUP_USER_ID_FIELD))) {
46              Person person = getPersonService().getPersonByPrincipalName(fieldValues.get(LOOKUP_USER_ID_FIELD));
47  
48              // if no project directors match, we can return an empty list right now
49              if (person == null) {
50                  return Collections.EMPTY_LIST;
51              }
52              
53              // place the universal ID into the fieldValues map and remove the dummy attribute
54              fieldValues.put(LOOKUP_UNIVERSAL_USER_ID_FIELD, person.getPrincipalId());
55              fieldValues.remove(LOOKUP_USER_ID_FIELD);
56          }
57  
58          return super.getSearchResultsHelper(fieldValues, unbounded);
59      }
60  
61      /**
62       * @return Returns the personService.
63       */
64      protected PersonService getPersonService() {
65          if(personService==null)
66              personService = SpringContext.getBean(PersonService.class);
67          return personService;
68      }
69  
70  }