001 /*
002 * Copyright 2011 The Kuali Foundation.
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.kfs.module.cg.businessobject.lookup;
017
018 import java.util.ArrayList;
019 import java.util.Collections;
020 import java.util.List;
021 import java.util.Map;
022
023 import org.apache.commons.lang.StringUtils;
024 import org.kuali.kfs.sys.context.SpringContext;
025 import org.kuali.rice.kim.bo.Person;
026 import org.kuali.rice.kim.service.PersonService;
027 import org.kuali.rice.kns.bo.BusinessObject;
028 import org.kuali.rice.kns.lookup.HtmlData;
029 import org.kuali.rice.kns.lookup.KualiLookupableHelperServiceImpl;
030 import org.kuali.rice.kns.util.KNSConstants;
031
032 /**
033 * Allows custom handling of Awards within the lookup framework.
034 */
035 public class AwardLookupableHelperServiceImpl extends KualiLookupableHelperServiceImpl {
036
037 private static final String LOOKUP_USER_ID_FIELD = "lookupPerson.principalName";
038 private static final String LOOKUP_UNIVERSAL_USER_ID_FIELD = "awardProjectDirectors.principalId";
039
040 private PersonService<Person> personService;
041
042 /**
043 * @see org.kuali.rice.kns.lookup.KualiLookupableHelperServiceImpl#getSearchResultsHelper(java.util.Map, boolean)
044 */
045 @Override
046 protected List<? extends BusinessObject> getSearchResultsHelper(Map<String, String> fieldValues, boolean unbounded) {
047 // perform the lookup on the project director object first
048 if (!StringUtils.isBlank(fieldValues.get(LOOKUP_USER_ID_FIELD))) {
049 Person person = getPersonService().getPersonByPrincipalName(fieldValues.get(LOOKUP_USER_ID_FIELD));
050
051 // if no project directors match, we can return an empty list right now
052 if (person == null) {
053 return Collections.EMPTY_LIST;
054 }
055
056 // place the universal ID into the fieldValues map and remove the dummy attribute
057 fieldValues.put(LOOKUP_UNIVERSAL_USER_ID_FIELD, person.getPrincipalId());
058 fieldValues.remove(LOOKUP_USER_ID_FIELD);
059 }
060
061 return super.getSearchResultsHelper(fieldValues, unbounded);
062 }
063
064 /**
065 * @see org.kuali.rice.kns.lookup.AbstractLookupableHelperServiceImpl#getCustomActionUrls(org.kuali.rice.kns.bo.BusinessObject, List pkNames)
066 */
067 @Override
068 public List<HtmlData> getCustomActionUrls(BusinessObject businessObject, List pkNames) {
069 List<HtmlData> anchorHtmlDataList = new ArrayList<HtmlData>();
070 anchorHtmlDataList.add(getUrlData(businessObject, KNSConstants.MAINTENANCE_EDIT_METHOD_TO_CALL, pkNames));
071 return anchorHtmlDataList;
072 }
073
074 /**
075 * @return Returns the personService.
076 */
077 protected PersonService<Person> getPersonService() {
078 if(personService==null)
079 personService = SpringContext.getBean(PersonService.class);
080 return personService;
081 }
082
083 }