View Javadoc

1   /**
2    * Copyright 2004-2014 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.apache.commons.lang.StringUtils;
23  import org.joda.time.LocalDate;
24  import org.kuali.kpme.core.bo.HrBusinessObject;
25  import org.kuali.kpme.pm.flag.Flag;
26  import org.kuali.kpme.pm.positionflag.PositionFlag;
27  import org.kuali.kpme.pm.service.base.PmServiceLocator;
28  import org.kuali.rice.core.api.util.ConcreteKeyValue;
29  import org.kuali.rice.core.api.util.KeyValue;
30  import org.kuali.rice.krad.uif.control.UifKeyValuesFinderBase;
31  import org.kuali.rice.krad.uif.view.ViewModel;
32  import org.kuali.rice.krad.web.form.MaintenanceDocumentForm;
33  
34  public class FlagNameKeyValueFinder extends UifKeyValuesFinderBase {
35  	private static final long serialVersionUID = 1L;
36  
37  	@Override
38  	public List<KeyValue> getKeyValues(ViewModel model) {
39  		MaintenanceDocumentForm docForm = (MaintenanceDocumentForm) model;
40  		List<KeyValue> options = new ArrayList<KeyValue>();
41  		HrBusinessObject anHrObject = (HrBusinessObject) docForm.getDocument().getNewMaintainableObject().getDataObject();
42  		LocalDate aDate = anHrObject.getEffectiveLocalDate() != null ? anHrObject.getEffectiveLocalDate() : null;
43  
44  		Flag aFlagObj = (Flag) docForm.getNewCollectionLines().get("document.newMaintainableObject.dataObject.flagList");
45  		String category = null;
46  		if(aFlagObj != null && StringUtils.isNotEmpty(aFlagObj.getCategory())) {
47  			category = aFlagObj.getCategory();
48  		}
49  		List<PositionFlag> flagList = PmServiceLocator.getPositionFlagService().getAllActivePositionFlagsWithCategory(category, aDate);
50  		if(CollectionUtils.isNotEmpty(flagList)) {
51  			for(PositionFlag aFlag : flagList) {
52  				options.add(new ConcreteKeyValue((String) aFlag.getPositionFlagName(), (String) aFlag.getPositionFlagName()));
53  			}
54  		}
55          return options;
56  	}
57  
58  }