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.joda.time.LocalDate;
23 import org.kuali.kpme.core.bo.HrBusinessObject;
24 import org.kuali.kpme.pm.api.positionflag.PositionFlagContract;
25 import org.kuali.kpme.pm.classification.ClassificationBo;
26 import org.kuali.kpme.pm.classification.flag.ClassificationFlagBo;
27 import org.kuali.kpme.pm.position.PositionBo;
28 import org.kuali.kpme.pm.position.PstnFlagBo;
29 import org.kuali.kpme.pm.service.base.PmServiceLocator;
30 import org.kuali.rice.core.api.util.ConcreteKeyValue;
31 import org.kuali.rice.core.api.util.KeyValue;
32 import org.kuali.rice.krad.uif.control.UifKeyValuesFinderBase;
33 import org.kuali.rice.krad.uif.field.InputField;
34 import org.kuali.rice.krad.uif.view.ViewModel;
35 import org.kuali.rice.krad.web.form.MaintenanceDocumentForm;
36
37 public class FlagCategoryKeyValueFinder extends UifKeyValuesFinderBase {
38
39 private static final long serialVersionUID = 1L;
40
41 @Override
42 public List<KeyValue> getKeyValues() {
43 List<KeyValue> keyValues = new ArrayList<KeyValue>();
44 List<String> categories = PmServiceLocator.getPositionFlagService().getAllActiveFlagCategories();
45 keyValues.add(new ConcreteKeyValue("", "Select category to see flags"));
46 if(CollectionUtils.isNotEmpty(categories)) {
47 for(String aCategory : categories) {
48 keyValues.add(new ConcreteKeyValue(aCategory, aCategory));
49 }
50 }
51 return keyValues;
52 }
53
54 @Override
55 public List<KeyValue> getKeyValues(ViewModel model) {
56 List<KeyValue> options = new ArrayList<KeyValue>();
57 MaintenanceDocumentForm docForm = (MaintenanceDocumentForm) model;
58 HrBusinessObject anHrObject = (HrBusinessObject) docForm.getDocument().getNewMaintainableObject().getDataObject();
59 if(anHrObject.getEffectiveDate() != null) {
60 List<? extends PositionFlagContract> flagList = PmServiceLocator.getPositionFlagService().getAllActivePositionFlags(null, null, anHrObject.getEffectiveLocalDate());
61 options.add(new ConcreteKeyValue("", "Select category to see flags"));
62 if(CollectionUtils.isNotEmpty(flagList)) {
63 for(PositionFlagContract aFlag : flagList) {
64 if (!options.contains(new ConcreteKeyValue((String) aFlag.getCategory(), (String) aFlag.getCategory()))) {
65 options.add(new ConcreteKeyValue((String) aFlag.getCategory(), (String) aFlag.getCategory()));
66 }
67 }
68 }
69 } else {
70 options = this.getKeyValues();
71 }
72
73 return options;
74 }
75
76
77 @Override
78 public List<KeyValue> getKeyValues(ViewModel model, InputField field){
79
80 MaintenanceDocumentForm docForm = (MaintenanceDocumentForm) model;
81 HrBusinessObject anHrObject = (HrBusinessObject) docForm.getDocument().getNewMaintainableObject().getDataObject();
82 LocalDate aDate = anHrObject.getEffectiveLocalDate() != null ? anHrObject.getEffectiveLocalDate() : null;
83 List<KeyValue> options = new ArrayList<KeyValue>();
84
85
86 if (field.getId().contains("add")) {
87
88
89 if(aDate != null) {
90 List<? extends PositionFlagContract> availableFlagList = PmServiceLocator.getPositionFlagService().getAllActivePositionFlags(null, null, anHrObject.getEffectiveLocalDate());
91 options.add(new ConcreteKeyValue("", "Select category to see flags"));
92 if (CollectionUtils.isNotEmpty(availableFlagList)) {
93 for(PositionFlagContract aFlag : availableFlagList) {
94 if (!options.contains(new ConcreteKeyValue((String) aFlag.getCategory(), (String) aFlag.getCategory()))) {
95 options.add(new ConcreteKeyValue((String) aFlag.getCategory(), (String) aFlag.getCategory()));
96 }
97 }
98 }
99 } else{
100 List<String> categories = PmServiceLocator.getPositionFlagService().getAllActiveFlagCategories();
101 options.add(new ConcreteKeyValue("", "Select category to see flags"));
102 if(CollectionUtils.isNotEmpty(categories)) {
103 for(String aCategory : categories) {
104 options.add(new ConcreteKeyValue(aCategory, aCategory));
105 }
106 }
107 }
108
109
110 if (anHrObject instanceof ClassificationBo) {
111 ClassificationBo aClass = (ClassificationBo)anHrObject;
112 List<ClassificationFlagBo> existingFlagList = aClass.getFlagList();
113 if (CollectionUtils.isNotEmpty(existingFlagList)) {
114 for (ClassificationFlagBo aFlag : existingFlagList) {
115 KeyValue aFlagKeyVale = new ConcreteKeyValue((String)aFlag.getCategory(), (String)aFlag.getCategory());
116 if (options.contains(aFlagKeyVale)) {
117 options.remove(aFlagKeyVale);
118 }
119 }
120 }
121
122 } else {
123 PositionBo aClass = (PositionBo)anHrObject;
124 List<PstnFlagBo> existingFlagList = aClass.getFlagList();
125 if (CollectionUtils.isNotEmpty(existingFlagList)) {
126 for (PstnFlagBo aFlag : existingFlagList) {
127 KeyValue aFlagKeyVale = new ConcreteKeyValue((String)aFlag.getCategory(), (String)aFlag.getCategory());
128 if (options.contains(aFlagKeyVale)) {
129 options.remove(aFlagKeyVale);
130 }
131 }
132 }
133 }
134
135 } else {
136 options = this.getKeyValues(model);
137 }
138
139 return options;
140 }
141
142 }