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 (!StringUtils.isBlank(agendaEditor.getAgendaItemLineRuleAction().getTypeId())) {
56 ActionTypeService actionTypeService = getActionTypeService(agendaEditor.getAgendaItemLineRuleAction().getTypeId());
57 results.addAll(actionTypeService.getAttributeFields(agendaEditor.getAgendaItemLineRuleAction().getTypeId()));
58 }
59
60 return results;
61 }
62
63
64
65
66
67
68 private AgendaEditor getAgendaEditor(Object model) {
69 MaintenanceForm maintenanceForm = (MaintenanceForm)model;
70 return (AgendaEditor)maintenanceForm.getDocument().getNewMaintainableObject().getDataObject();
71 }
72
73 private ActionTypeService getActionTypeService(String krmsTypeId) {
74
75
76
77
78 KrmsTypeDefinition krmsType = KrmsRepositoryServiceLocator.getKrmsTypeRepositoryService().getTypeById(krmsTypeId);
79
80 ActionTypeService actionTypeService = null;
81
82 if (!StringUtils.isBlank(krmsTypeId)) {
83 String serviceName = krmsType.getServiceName();
84
85 if (!StringUtils.isBlank(serviceName)) {
86 actionTypeService = KrmsRepositoryServiceLocator.getService(serviceName);
87 }
88 }
89 if (actionTypeService == null) {
90 actionTypeService = ActionTypeServiceBase.defaultActionTypeService;
91 }
92
93
94
95 return actionTypeService;
96 }
97
98
99
100
101
102
103 public List<RemotableAttributeField> retrieveAgendaCustomAttributes(AgendaEditor agendaEditor) {
104 List<RemotableAttributeField> results = new ArrayList<RemotableAttributeField>();
105
106 if (agendaEditor.getAgenda() != null && !StringUtils.isBlank(agendaEditor.getAgenda().getTypeId())) {
107
108 String krmsTypeId = agendaEditor.getAgenda().getTypeId();
109
110 AgendaTypeService agendaTypeService = getAgendaTypeService(krmsTypeId);
111 results.addAll(agendaTypeService.getAttributeFields(krmsTypeId));
112 }
113
114 return results;
115 }
116
117 private AgendaTypeService getAgendaTypeService(String krmsTypeId) {
118
119
120
121
122 KrmsTypeDefinition krmsType =
123 KrmsRepositoryServiceLocator.getKrmsTypeRepositoryService().
124 getTypeById(krmsTypeId);
125
126 AgendaTypeService agendaTypeService = null;
127
128 if (!StringUtils.isBlank(krmsTypeId)) {
129 String serviceName = krmsType.getServiceName();
130
131 if (!StringUtils.isBlank(serviceName)) {
132 agendaTypeService = KrmsRepositoryServiceLocator.getService(serviceName);
133 }
134 }
135
136 if (agendaTypeService == null) { agendaTypeService = AgendaTypeServiceBase.defaultAgendaTypeService; }
137
138 return agendaTypeService;
139 }
140
141 public List<RemotableAttributeField> retrieveRuleCustomAttributes(AgendaEditor agendaEditor) {
142 List<RemotableAttributeField> results = new ArrayList<RemotableAttributeField>();
143
144 if (agendaEditor.getAgendaItemLine() != null && agendaEditor.getAgendaItemLine().getRule() != null
145 && !StringUtils.isBlank(agendaEditor.getAgendaItemLine().getRule().getTypeId())) {
146
147 String krmsTypeId = agendaEditor.getAgendaItemLine().getRule().getTypeId();
148
149 RuleTypeService ruleTypeService = getRuleTypeService(krmsTypeId);
150 results.addAll(ruleTypeService.getAttributeFields(krmsTypeId));
151 }
152
153 return results;
154 }
155
156
157 private RuleTypeService getRuleTypeService(String krmsTypeId) {
158 RuleTypeService ruleTypeService = null;
159 String serviceName = getRuleTypeServiceName(krmsTypeId);
160
161 if (!StringUtils.isBlank(serviceName)) {
162 ruleTypeService = KrmsRepositoryServiceLocator.getService(serviceName);
163 }
164 if (ruleTypeService == null) {
165 ruleTypeService = RuleTypeServiceBase.defaultRuleTypeService;
166 }
167 return ruleTypeService;
168 }
169
170 private String getRuleTypeServiceName(String krmsTypeId) {
171 String serviceName = null;
172 KrmsTypeDefinition krmsType =
173 KrmsRepositoryServiceLocator.getKrmsTypeRepositoryService().
174 getTypeById(krmsTypeId);
175
176 if (!StringUtils.isBlank(krmsTypeId)) {
177 serviceName = krmsType.getServiceName();
178 }
179 return serviceName;
180 }
181 }