1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krms.impl.ui;
17
18
19 import org.apache.commons.lang.StringUtils;
20 import org.kuali.rice.core.api.util.ConcreteKeyValue;
21 import org.kuali.rice.core.api.util.KeyValue;
22 import org.kuali.rice.krad.service.KRADServiceLocator;
23 import org.kuali.rice.krad.uif.control.UifKeyValuesFinderBase;
24 import org.kuali.rice.krad.uif.view.ViewModel;
25 import org.kuali.rice.krad.web.form.MaintenanceForm;
26 import org.kuali.rice.krms.impl.repository.CategoryBo;
27 import org.kuali.rice.krms.impl.repository.ContextValidTermBo;
28 import org.kuali.rice.krms.impl.repository.PropositionBo;
29 import org.kuali.rice.krms.impl.repository.TermBo;
30
31 import java.util.ArrayList;
32 import java.util.Collection;
33 import java.util.Collections;
34 import java.util.HashMap;
35 import java.util.Map;
36 import java.util.List;
37
38
39
40
41
42
43 public class ValidTermsValuesFinder extends UifKeyValuesFinderBase {
44
45 @Override
46 public List<KeyValue> getKeyValues(ViewModel model) {
47 List<KeyValue> keyValues = new ArrayList<KeyValue>();
48
49 MaintenanceForm maintenanceForm = (MaintenanceForm) model;
50 AgendaEditor agendaEditor = ((AgendaEditor) maintenanceForm.getDocument().getNewMaintainableObject().getDataObject());
51 String contextId = agendaEditor.getAgenda().getContextId();
52
53 String selectedPropId = agendaEditor.getSelectedPropositionId();
54
55 PropositionBo rootProposition = agendaEditor.getAgendaItemLine().getRule().getProposition();
56 PropositionBo editModeProposition = findPropositionUnderEdit(rootProposition);
57 String selectedCategoryId = (editModeProposition != null) ? editModeProposition.getCategoryId() : null;
58
59
60
61 Collection<ContextValidTermBo> contextValidTerms = null;
62 contextValidTerms = KRADServiceLocator.getBusinessObjectService()
63 .findMatching(ContextValidTermBo.class, Collections.singletonMap("contextId", contextId));
64
65 List<String> termSpecIds = new ArrayList();
66 for (ContextValidTermBo validTerm : contextValidTerms) {
67 termSpecIds.add(validTerm.getTermSpecificationId());
68 }
69
70 if (termSpecIds.size() > 0) {
71 Collection<TermBo> terms = null;
72 Map<String,Object> criteria = new HashMap<String,Object>();
73 criteria.put("specificationId", termSpecIds);
74 terms = KRADServiceLocator.getBusinessObjectService().findMatchingOrderBy(TermBo.class, criteria, "description", true);
75
76
77 for (TermBo term : terms) {
78 String selectName = term.getDescription();
79
80 if (StringUtils.isBlank(selectName) || "null".equals(selectName)) {
81 selectName = term.getSpecification().getName();
82 }
83
84 if (!StringUtils.isBlank(selectedCategoryId)) {
85
86 if (term.getSpecification().getCategories() != null) {
87 for (CategoryBo category : term.getSpecification().getCategories()) {
88 if (selectedCategoryId.equals(category.getId())) {
89 keyValues.add(new ConcreteKeyValue(term.getId(), selectName));
90 break;
91 }
92 }
93 }
94 } else {
95 keyValues.add(new ConcreteKeyValue(term.getId(), selectName));
96 }
97 }
98 }
99
100 return keyValues;
101 }
102
103
104
105
106 private PropositionBo findPropositionUnderEdit(PropositionBo currentProposition) {
107 PropositionBo result = null;
108 if (currentProposition.getEditMode()) {
109 result = currentProposition;
110 } else {
111 if (currentProposition.getCompoundComponents() != null) {
112 for (PropositionBo child : currentProposition.getCompoundComponents()) {
113 result = findPropositionUnderEdit(child);
114 if (result != null) break;
115 }
116 }
117 }
118 return result;
119 }
120
121 }