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.kuali.kpme.core.bo.HrBusinessObject;
23  import org.kuali.kpme.pm.api.positionresponsibilityoption.PositionResponsibilityOptionContract;
24  import org.kuali.kpme.pm.position.PositionBo;
25  import org.kuali.kpme.pm.positionresponsibility.PositionResponsibilityBo;
26  import org.kuali.kpme.pm.service.base.PmServiceLocator;
27  import org.kuali.rice.core.api.util.ConcreteKeyValue;
28  import org.kuali.rice.core.api.util.KeyValue;
29  import org.kuali.rice.krad.uif.control.UifKeyValuesFinderBase;
30  import org.kuali.rice.krad.uif.field.InputField;
31  import org.kuali.rice.krad.uif.view.ViewModel;
32  import org.kuali.rice.krad.web.form.MaintenanceDocumentForm;
33  
34  public class PstnRspOptionKeyValueFinder extends UifKeyValuesFinderBase {
35  
36  	/**
37  	 * 
38  	 */
39  	private static final long serialVersionUID = -6768131853656090086L;
40  
41  	@Override
42  	public List<KeyValue> getKeyValues() {
43  		List<KeyValue> keyValues = new ArrayList<KeyValue>();
44  		List<? extends PositionResponsibilityOptionContract> typeList = PmServiceLocator.getPositionResponsibilityOptionService().getAllActivePstnRspOptions();
45  		keyValues.add(new ConcreteKeyValue("", ""));
46  		if(CollectionUtils.isNotEmpty(typeList)) {
47  			for(PositionResponsibilityOptionContract aType : typeList) {
48  				keyValues.add(new ConcreteKeyValue((String) aType.getPrOptionId(), (String) aType.getPrOptionName()));
49  			}
50  		}         
51  		return keyValues;
52  	}
53  	
54  	// KPME-2360
55  	@Override
56      public List<KeyValue> getKeyValues(ViewModel model, InputField field){
57  		 
58  		MaintenanceDocumentForm docForm = (MaintenanceDocumentForm) model;
59  		HrBusinessObject anHrObject = (HrBusinessObject) docForm.getDocument().getNewMaintainableObject().getDataObject();
60  		List<KeyValue> options = new ArrayList<KeyValue>();
61  		
62  		if (field.getId().contains("add")) {
63  			// For "add" line, just delegate to getKeyValues() method as it is working correctly
64  			options = getKeyValues();	
65  		} else {
66  			// Strip index off field id
67  			String fieldId = field.getId();
68  			int line_index = fieldId.indexOf("line");
69  			int index = Integer.parseInt(fieldId.substring(line_index+4));
70  
71  			PositionBo aClass = (PositionBo)anHrObject;
72  			List<PositionResponsibilityBo> posRresponsibilityList = aClass.getPositionResponsibilityList(); // holds "added" lines
73  			PositionResponsibilityBo posResponsibility = (PositionResponsibilityBo)posRresponsibilityList.get(index);
74  			
75  			List<? extends PositionResponsibilityOptionContract> typeList = PmServiceLocator.getPositionResponsibilityOptionService().getAllActivePstnRspOptions();
76  			options.add(new ConcreteKeyValue("", ""));
77  			if(CollectionUtils.isNotEmpty(typeList)) {
78  				for(PositionResponsibilityOptionContract aType : typeList) {
79  					options.add(new ConcreteKeyValue((String) aType.getPrOptionId(), (String) aType.getPrOptionName()));
80  				}
81  			}      
82  		} 
83  
84  		return options;
85  		
86  	}
87  
88  }