1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krms.impl.util;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.rice.core.api.uif.RemotableAttributeField;
20 import org.kuali.rice.krad.uif.container.Container;
21 import org.kuali.rice.krad.uif.view.View;
22 import org.kuali.rice.krad.web.form.InquiryForm;
23 import org.kuali.rice.krad.web.form.MaintenanceForm;
24 import org.kuali.rice.krms.api.repository.type.KrmsTypeDefinition;
25 import org.kuali.rice.krms.framework.type.ActionTypeService;
26 import org.kuali.rice.krms.framework.type.AgendaTypeService;
27 import org.kuali.rice.krms.framework.type.RuleTypeService;
28 import org.kuali.rice.krms.impl.repository.KrmsRepositoryServiceLocator;
29 import org.kuali.rice.krms.impl.type.ActionTypeServiceBase;
30 import org.kuali.rice.krms.impl.type.AgendaTypeServiceBase;
31 import org.kuali.rice.krms.impl.type.RuleTypeServiceBase;
32 import org.kuali.rice.krms.impl.ui.AgendaEditor;
33
34 import java.util.ArrayList;
35 import java.util.List;
36
37
38
39
40
41
42
43 public class KrmsRetriever {
44
45 private static final long serialVersionUID = 1L;
46
47
48
49
50
51
52 public List<RemotableAttributeField> retrieveRuleActionCustomAttributes(AgendaEditor agendaEditor) {
53 List<RemotableAttributeField> results = new ArrayList<RemotableAttributeField>();
54
55 if (agendaEditor != null && agendaEditor.getAgendaItemLineRuleAction() != null
56 &&!StringUtils.isBlank(agendaEditor.getAgendaItemLineRuleAction().getTypeId())) {
57 ActionTypeService actionTypeService = getActionTypeService(agendaEditor.getAgendaItemLineRuleAction().getTypeId());
58 results.addAll(actionTypeService.getAttributeFields(agendaEditor.getAgendaItemLineRuleAction().getTypeId()));
59 }
60
61 return results;
62 }
63
64
65
66
67
68
69 private AgendaEditor getAgendaEditor(Object model) {
70 MaintenanceForm maintenanceForm = (MaintenanceForm)model;
71 return (AgendaEditor)maintenanceForm.getDocument().getNewMaintainableObject().getDataObject();
72 }
73
74 private ActionTypeService getActionTypeService(String krmsTypeId) {
75
76
77
78
79 KrmsTypeDefinition krmsType = KrmsRepositoryServiceLocator.getKrmsTypeRepositoryService().getTypeById(krmsTypeId);
80
81 ActionTypeService actionTypeService = null;
82
83 if (!StringUtils.isBlank(krmsTypeId)) {
84 String serviceName = krmsType.getServiceName();
85
86 if (!StringUtils.isBlank(serviceName)) {
87 actionTypeService = KrmsRepositoryServiceLocator.getService(serviceName);
88 }
89 }
90 if (actionTypeService == null) {
91 actionTypeService = ActionTypeServiceBase.defaultActionTypeService;
92 }
93
94
95
96 return actionTypeService;
97 }
98
99
100
101
102
103
104 public List<RemotableAttributeField> retrieveAgendaCustomAttributes(AgendaEditor agendaEditor) {
105 List<RemotableAttributeField> results = new ArrayList<RemotableAttributeField>();
106
107 if (agendaEditor != null && agendaEditor.getAgenda() != null
108 && !StringUtils.isBlank(agendaEditor.getAgenda().getTypeId())) {
109
110 String krmsTypeId = agendaEditor.getAgenda().getTypeId();
111
112 AgendaTypeService agendaTypeService = getAgendaTypeService(krmsTypeId);
113 results.addAll(agendaTypeService.getAttributeFields(krmsTypeId));
114 }
115
116 return results;
117 }
118
119 private AgendaTypeService getAgendaTypeService(String krmsTypeId) {
120
121
122
123
124 KrmsTypeDefinition krmsType =
125 KrmsRepositoryServiceLocator.getKrmsTypeRepositoryService().
126 getTypeById(krmsTypeId);
127
128 AgendaTypeService agendaTypeService = null;
129
130 if (!StringUtils.isBlank(krmsTypeId)) {
131 String serviceName = krmsType.getServiceName();
132
133 if (!StringUtils.isBlank(serviceName)) {
134 agendaTypeService = KrmsRepositoryServiceLocator.getService(serviceName);
135 }
136 }
137
138 if (agendaTypeService == null) { agendaTypeService = AgendaTypeServiceBase.defaultAgendaTypeService; }
139
140 return agendaTypeService;
141 }
142
143 public List<RemotableAttributeField> retrieveRuleCustomAttributes(AgendaEditor agendaEditor) {
144 List<RemotableAttributeField> results = new ArrayList<RemotableAttributeField>();
145
146 if (agendaEditor != null && agendaEditor.getAgendaItemLine() != null && agendaEditor.getAgendaItemLine().getRule() != null
147 && !StringUtils.isBlank(agendaEditor.getAgendaItemLine().getRule().getTypeId())) {
148
149 String krmsTypeId = agendaEditor.getAgendaItemLine().getRule().getTypeId();
150
151 RuleTypeService ruleTypeService = getRuleTypeService(krmsTypeId);
152 results.addAll(ruleTypeService.getAttributeFields(krmsTypeId));
153 }
154
155 return results;
156 }
157
158
159 private RuleTypeService getRuleTypeService(String krmsTypeId) {
160 RuleTypeService ruleTypeService = null;
161 String serviceName = getRuleTypeServiceName(krmsTypeId);
162
163 if (!StringUtils.isBlank(serviceName)) {
164 ruleTypeService = KrmsRepositoryServiceLocator.getService(serviceName);
165 }
166 if (ruleTypeService == null) {
167 ruleTypeService = RuleTypeServiceBase.defaultRuleTypeService;
168 }
169 return ruleTypeService;
170 }
171
172 private String getRuleTypeServiceName(String krmsTypeId) {
173 String serviceName = null;
174 KrmsTypeDefinition krmsType =
175 KrmsRepositoryServiceLocator.getKrmsTypeRepositoryService().
176 getTypeById(krmsTypeId);
177
178 if (!StringUtils.isBlank(krmsTypeId)) {
179 serviceName = krmsType.getServiceName();
180 }
181 return serviceName;
182 }
183 }