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.keyvalues;
17:
18: import java.util.ArrayList;
19: import java.util.Collection;
20: import java.util.Iterator;
21: import java.util.List;
22:
23: import org.kuali.core.lookup.keyvalues.KeyValuesBase;
24: import org.kuali.core.service.KeyValuesService;
25: import org.kuali.core.web.ui.KeyLabelPair;
26: import org.kuali.kfs.context.SpringContext;
27: import org.kuali.module.cg.bo.Cfda;
28:
29: /**
30: * Allows some information about persisted {@link Cfda} instances to be looked up.
31: */
32: public class CatalogOfFederalDomesticAssistanceMaintenanceTypeIdFinder
33: extends KeyValuesBase {
34:
35: /**
36: * Retrieves the list of possible CFDA Maintenance Type IDs and generates a collection with all the possible values.
37: *
38: * @see org.kuali.keyvalues.KeyValuesFinder#getKeyValues()
39: */
40: public List getKeyValues() {
41:
42: KeyValuesService boService = SpringContext
43: .getBean(KeyValuesService.class);
44: Collection codes = boService.findAll(Cfda.class);
45:
46: List<KeyLabelPair> labels = new ArrayList<KeyLabelPair>();
47: labels.add(new KeyLabelPair("", ""));
48:
49: for (Iterator iter = codes.iterator(); iter.hasNext();) {
50: Cfda cfdaReference = (Cfda) iter.next();
51:
52: if (!isDuplicateValue(labels, cfdaReference
53: .getCfdaMaintenanceTypeId())) {
54: labels.add(new KeyLabelPair(cfdaReference
55: .getCfdaMaintenanceTypeId(), cfdaReference
56: .getCfdaMaintenanceTypeId()));
57: }
58: }
59:
60: return labels;
61: }
62:
63: /**
64: * This method determines if a value already exists in the collection.
65: *
66: * @param collection The collection to be examined.
67: * @param value The value to be added to the collection if it does not already exist within it.
68: * @return True if the value passed in already exists in the collection, false otherwise.
69: */
70: private boolean isDuplicateValue(List<KeyLabelPair> collection,
71: String value) {
72: boolean duplicate = false;
73:
74: for (KeyLabelPair klp : collection) {
75: String klpLabel = klp.getLabel();
76: if (klpLabel != null) {
77: duplicate |= klpLabel.trim().equalsIgnoreCase(
78: value.trim());
79: }
80: }
81:
82: return duplicate;
83: }
84:
85: }
|