View Javadoc
1   /**
2    * Copyright 2005-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.rice.krad.labs.lookup;
17  
18  import org.apache.commons.collections.MapUtils;
19  import org.apache.commons.lang3.StringUtils;
20  import org.kuali.rice.kim.api.identity.IdentityService;
21  import org.kuali.rice.kim.api.services.KimApiServiceLocator;
22  import org.kuali.rice.krad.lookup.LookupForm;
23  import org.kuali.rice.krad.lookup.LookupableImpl;
24  import org.kuali.rice.krad.service.KRADServiceLocator;
25  
26  import java.util.Collection;
27  import java.util.Map;
28  
29  /**
30   * Silly example for demonstrating Spring instantiation of certain services used in KRAD.
31   *
32   * <pre>
33   * {@code <property name="viewHelperService" value="#{#getService('labsTravelAccountLookupable')}"/>}
34   * </pre>
35   *
36   * @author Kuali Rice Team (rice.collab@kuali.org)
37   */
38  public class LabsTravelAccountLookupableImpl extends LookupableImpl {
39  
40      private static final long serialVersionUID = -8463531661189633011L;
41  
42      private transient IdentityService identityService;
43  
44      /**
45       * {@inheritDoc}
46       *
47       * <p>
48       * This lookupable modifies the lookup results so that any search for 'fred' actually searches for 'admin'.
49       * </p>
50       */
51      @Override
52      public Collection<?> performSearch(LookupForm form, Map<String, String> searchCriteria, boolean bounded) {
53          if (StringUtils.equals(MapUtils.getString(searchCriteria, "fiscalOfficer.principalName"), "fred")) {
54              String principalName = getIdentityService().getPrincipal("admin").getPrincipalName();
55              searchCriteria.put("fiscalOfficer.principalName", principalName);
56          }
57  
58          return super.performSearch(form, searchCriteria, bounded);
59      }
60  
61      /**
62       * Returns the {@link IdentityService}.
63       *
64       * @return the {@link IdentityService}
65       */
66      public IdentityService getIdentityService() {
67          return identityService;
68      }
69  
70      /**
71       * Sets the {@link IdentityService}.
72       *
73       * @param identityService  the {@link IdentityService} to set
74       */
75      public void setIdentityService(IdentityService identityService) {
76          this.identityService = identityService;
77      }
78  
79  }