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.position;
17  
18  import java.util.ArrayList;
19  import java.util.List;
20  
21  import org.apache.commons.lang.StringUtils;
22  import org.kuali.kpme.core.bo.HrBusinessObject;
23  import org.kuali.kpme.pm.PMConstants;
24  import org.kuali.kpme.pm.api.pstnqlfrtype.PstnQlfrTypeContract;
25  import org.kuali.kpme.pm.service.base.PmServiceLocator;
26  import org.kuali.rice.core.api.util.ConcreteKeyValue;
27  import org.kuali.rice.core.api.util.KeyValue;
28  import org.kuali.rice.krad.uif.control.UifKeyValuesFinderBase;
29  import org.kuali.rice.krad.uif.field.InputField;
30  import org.kuali.rice.krad.uif.view.ViewModel;
31  import org.kuali.rice.krad.web.form.MaintenanceDocumentForm;
32  
33  public class PositionQualifierValueKeyValueFinder  extends UifKeyValuesFinderBase {
34  
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  
42  		PositionQualificationBo aQualification = (PositionQualificationBo) docForm.getNewCollectionLines().get("document.newMaintainableObject.dataObject.qualificationList");
43  		if(aQualification != null) {
44  			String aTypeId = aQualification.getQualificationType();
45  			PstnQlfrTypeContract aTypeObj = PmServiceLocator.getPstnQlfrTypeService().getPstnQlfrTypeById(aTypeId);
46  			if(aTypeObj != null) {
47  				if(aTypeObj.getTypeValue().equals(PMConstants.PSTN_QLFR_SELECT)){
48  					String[] aCol = aTypeObj.getSelectValues().split(",");
49  					for(String aString : aCol){
50  						aString = StringUtils.strip(aString);
51  						options.add(new ConcreteKeyValue(aString, aString));
52  					}
53  				} else{
54  					return new ArrayList<KeyValue>();
55  				}
56  			}
57  		}
58          return options;
59  	}
60  	
61  	// KPME-2958
62  	@Override
63      public List<KeyValue> getKeyValues(ViewModel model, InputField field){
64  		 
65  		MaintenanceDocumentForm docForm = (MaintenanceDocumentForm) model;
66  		HrBusinessObject anHrObject = (HrBusinessObject) docForm.getDocument().getNewMaintainableObject().getDataObject();
67  		List<KeyValue> options = new ArrayList<KeyValue>();
68  		
69  		if (field.getId().contains("add")) {
70  			// For "add" line, just delegate to getKeyValues(model) method as it is working correctly
71  			options = getKeyValues(model);	
72  		} else {
73  			// Strip index off field id
74  			String fieldId = field.getId();
75  			int line_index = fieldId.indexOf("line");
76  			int index = Integer.parseInt(fieldId.substring(line_index+4));
77  			
78  			PositionBo aPosition = (PositionBo)anHrObject;
79  			List<PositionQualificationBo> qualificationList = aPosition.getQualificationList(); // holds "added" lines
80  			PositionQualificationBo posQualification = (PositionQualificationBo)qualificationList.get(index);
81  			String aTypeId = posQualification.getQualificationType();
82  			
83  			PstnQlfrTypeContract aTypeObj = PmServiceLocator.getPstnQlfrTypeService().getPstnQlfrTypeById(aTypeId);;
84  			if(aTypeObj != null) {
85  				if(aTypeObj.getTypeValue().equals(PMConstants.PSTN_QLFR_SELECT)){
86  					String[] aCol = aTypeObj.getSelectValues().split(",");
87  					for(String aString : aCol){
88  						aString = StringUtils.strip(aString);
89  						options.add(new ConcreteKeyValue(aString, aString));
90  					}
91  				} else{
92  					return new ArrayList<KeyValue>();
93  				}
94  			}
95  		} 
96  
97  		return options;
98  		
99  	}
100 
101 }