View Javadoc

1   /**
2    * Copyright 2004-2013 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.kpme.pm.util;
17  
18  import java.util.ArrayList;
19  import java.util.List;
20  
21  import org.apache.commons.collections.CollectionUtils;
22  import org.kuali.kpme.core.bo.HrBusinessObject;
23  import org.kuali.kpme.pm.positionflag.PositionFlag;
24  import org.kuali.kpme.pm.service.base.PmServiceLocator;
25  import org.kuali.rice.core.api.util.ConcreteKeyValue;
26  import org.kuali.rice.core.api.util.KeyValue;
27  import org.kuali.rice.krad.uif.control.UifKeyValuesFinderBase;
28  import org.kuali.rice.krad.uif.view.ViewModel;
29  import org.kuali.rice.krad.web.form.MaintenanceDocumentForm;
30  
31  public class FlagCategoryKeyValueFinder extends UifKeyValuesFinderBase {
32  	
33  	private static final long serialVersionUID = 1L;
34  	
35  	@Override
36  	public List<KeyValue> getKeyValues() {		
37  		List<KeyValue> keyValues = new ArrayList<KeyValue>();
38  		List<String> categories = PmServiceLocator.getPositionFlagService().getAllActiveFlagCategories();
39  		keyValues.add(new ConcreteKeyValue("", "Select category to see flags"));
40  		if(CollectionUtils.isNotEmpty(categories)) {
41  			for(String aCategory : categories) {
42  				keyValues.add(new ConcreteKeyValue(aCategory, aCategory));
43  			}
44  		}         
45  		return keyValues;
46  	}
47  	
48  	@Override
49  	public List<KeyValue> getKeyValues(ViewModel model) {
50  		List<KeyValue> options = new ArrayList<KeyValue>();
51  		MaintenanceDocumentForm docForm = (MaintenanceDocumentForm) model; 
52  		HrBusinessObject anHrObject = (HrBusinessObject) docForm.getDocument().getNewMaintainableObject().getDataObject();
53  		if(anHrObject.getEffectiveDate() != null) {
54  			List<PositionFlag> flagList = PmServiceLocator.getPositionFlagService().getAllActivePositionFlags(null, null, anHrObject.getEffectiveLocalDate());
55  			options.add(new ConcreteKeyValue("", "Select category to see flags"));
56  			if(CollectionUtils.isNotEmpty(flagList)) {
57  				for(PositionFlag aFlag : flagList) {
58  					options.add(new ConcreteKeyValue((String) aFlag.getCategory(), (String) aFlag.getCategory()));
59  				}
60  			}         
61  		} else {
62  			options = this.getKeyValues();
63  		}
64  		
65          return options;
66      }
67  
68  }