View Javadoc

1   /**
2    * Copyright 2005-2012 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.kew.lookup.valuefinder;
17  
18  import org.apache.commons.lang.StringUtils;
19  import org.kuali.rice.core.api.util.ConcreteKeyValue;
20  import org.kuali.rice.core.api.util.KeyValue;
21  import org.kuali.rice.kew.service.KEWServiceLocator;
22  import org.kuali.rice.krad.keyvalues.KeyValuesBase;
23  import org.kuali.rice.krad.util.GlobalVariables;
24  
25  import java.util.ArrayList;
26  import java.util.List;
27  
28  /**
29   * This is a description of what this class does - chris don't forget to fill this in. 
30   * 
31   * @author Kuali Rice Team (rice.collab@kuali.org)
32   *
33   */
34  public class SavedSearchValuesFinder extends KeyValuesBase {
35  
36  	/**
37  	 * @see org.kuali.rice.krad.keyvalues.KeyValuesFinder#getKeyValues()
38  	 */
39  	@Override
40  	public List<KeyValue> getKeyValues() {
41  		List<KeyValue> savedSearchValues = new ArrayList<KeyValue>();
42  		savedSearchValues.add(new ConcreteKeyValue("", "Searches"));
43  		savedSearchValues.add(new ConcreteKeyValue("*ignore*", "-----"));
44  		savedSearchValues.add(new ConcreteKeyValue("*ignore*", "-Named Searches"));
45  		List<KeyValue> namedSearches = KEWServiceLocator.getDocumentSearchService().getNamedSearches(GlobalVariables.getUserSession().getPrincipalId());
46  		for (KeyValue keyValue : namedSearches) {
47  			String label = StringUtils.abbreviate(keyValue.getValue(), 75);
48  			KeyValue keyLabel = new ConcreteKeyValue(keyValue.getKey(),label);
49  			savedSearchValues.add(keyLabel);
50  		}
51  		savedSearchValues.add(new ConcreteKeyValue("*ignore*", "-----"));
52  		savedSearchValues.add(new ConcreteKeyValue("*ignore*", "-Recent Searches"));
53  		List<KeyValue> mostRecentSearches = KEWServiceLocator.getDocumentSearchService().getMostRecentSearches(GlobalVariables.getUserSession().getPrincipalId());
54  		for (KeyValue keyValue : mostRecentSearches) {
55  			String label = StringUtils.abbreviate(keyValue.getValue(), 75);
56  			KeyValue keyLabel = new ConcreteKeyValue(keyValue.getKey(),label);
57  			savedSearchValues.add(keyLabel);
58  		}
59  		return savedSearchValues;
60  	}
61  
62  }