01: /*
02: * Copyright 2007 The Kuali Foundation.
03: *
04: * Licensed under the Educational Community License, Version 1.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.opensource.org/licenses/ecl1.php
09: *
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.module.cg.lookup;
17:
18: import java.util.Collection;
19: import java.util.Collections;
20: import java.util.HashMap;
21: import java.util.List;
22: import java.util.Map;
23:
24: import org.apache.commons.lang.StringUtils;
25: import org.kuali.core.bo.BusinessObject;
26: import org.kuali.core.lookup.KualiLookupableHelperServiceImpl;
27: import org.kuali.module.cg.bo.ProjectDirector;
28:
29: /**
30: * Allows custom handling of Proposals within the lookup framework.
31: */
32: public class ProposalLookupableHelperServiceImpl extends
33: KualiLookupableHelperServiceImpl {
34:
35: private static final String LOOKUP_USER_ID_FIELD = "lookupUniversalUser.personUserIdentifier";
36: private static final String LOOKUP_UNIVERSAL_USER_ID_FIELD = "proposalProjectDirectors.projectDirector.personUniversalIdentifier";
37: private static final String PROJECT_DIRECTOR_USER_ID_LOOKUP_FIELD = "universalUser.personUserIdentifier";
38:
39: /**
40: * @see org.kuali.core.lookup.KualiLookupableHelperServiceImpl#getSearchResultsHelper(java.util.Map, boolean)
41: */
42: @Override
43: protected List<? extends BusinessObject> getSearchResultsHelper(
44: Map<String, String> fieldValues, boolean unbounded) {
45: // perform the lookup on the project director object first
46: if (!StringUtils.isBlank(fieldValues.get(LOOKUP_USER_ID_FIELD))) {
47: HashMap<String, String> newParam = new HashMap<String, String>(
48: 1);
49: newParam.put(PROJECT_DIRECTOR_USER_ID_LOOKUP_FIELD,
50: fieldValues.get(LOOKUP_USER_ID_FIELD));
51: Collection<ProjectDirector> pds = getLookupService()
52: .findCollectionBySearchUnbounded(
53: ProjectDirector.class, newParam);
54: // if no project directors match, we can return an empty list right now
55: if (pds.isEmpty()) {
56: return Collections.EMPTY_LIST;
57: }
58: // place the universal ID into the fieldValues map and remove the dummy attribute
59: fieldValues.put(LOOKUP_UNIVERSAL_USER_ID_FIELD, pds
60: .iterator().next().getPersonUniversalIdentifier());
61: fieldValues.remove(LOOKUP_USER_ID_FIELD);
62: }
63:
64: return super.getSearchResultsHelper(fieldValues, unbounded);
65: }
66:
67: }
|