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