1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
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
64 options = getKeyValues();
65 } else {
66
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();
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 }