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