1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kew.rule.bo; |
17 | |
|
18 | |
import org.apache.commons.lang.StringUtils; |
19 | |
import org.kuali.rice.core.api.reflect.ObjectDefinition; |
20 | |
import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader; |
21 | |
import org.kuali.rice.core.util.ConcreteKeyValue; |
22 | |
import org.kuali.rice.core.util.KeyValue; |
23 | |
import org.kuali.rice.core.util.RiceKeyConstants; |
24 | |
import org.kuali.rice.core.web.format.BooleanFormatter; |
25 | |
import org.kuali.rice.core.web.format.CollectionFormatter; |
26 | |
import org.kuali.rice.core.web.format.DateFormatter; |
27 | |
import org.kuali.rice.core.web.format.Formatter; |
28 | |
import org.kuali.rice.kew.exception.WorkflowServiceErrorImpl; |
29 | |
import org.kuali.rice.kew.lookupable.MyColumns; |
30 | |
import org.kuali.rice.kew.rule.OddSearchAttribute; |
31 | |
import org.kuali.rice.kew.rule.RuleBaseValues; |
32 | |
import org.kuali.rice.kew.rule.RuleDelegation; |
33 | |
import org.kuali.rice.kew.rule.WorkflowAttribute; |
34 | |
import org.kuali.rice.kew.rule.service.RuleDelegationService; |
35 | |
import org.kuali.rice.kew.rule.service.RuleTemplateService; |
36 | |
import org.kuali.rice.kew.rule.xmlrouting.GenericXMLRuleAttribute; |
37 | |
import org.kuali.rice.kew.service.KEWServiceLocator; |
38 | |
import org.kuali.rice.kew.util.KEWConstants; |
39 | |
import org.kuali.rice.kim.api.group.Group; |
40 | |
import org.kuali.rice.kim.api.group.GroupService; |
41 | |
import org.kuali.rice.kim.api.services.KimApiServiceLocator; |
42 | |
import org.kuali.rice.kim.bo.Person; |
43 | |
import org.kuali.rice.kim.util.KimConstants; |
44 | |
import org.kuali.rice.kns.document.authorization.BusinessObjectRestrictions; |
45 | |
import org.kuali.rice.kns.lookup.HtmlData; |
46 | |
import org.kuali.rice.kns.lookup.KualiLookupableHelperServiceImpl; |
47 | |
import org.kuali.rice.kns.web.comparator.CellComparatorHelper; |
48 | |
import org.kuali.rice.kns.web.struts.form.LookupForm; |
49 | |
import org.kuali.rice.kns.web.ui.Column; |
50 | |
import org.kuali.rice.kns.web.ui.Field; |
51 | |
import org.kuali.rice.kns.web.ui.ResultRow; |
52 | |
import org.kuali.rice.kns.web.ui.Row; |
53 | |
import org.kuali.rice.krad.bo.BusinessObject; |
54 | |
import org.kuali.rice.krad.bo.PersistableBusinessObject; |
55 | |
import org.kuali.rice.krad.exception.ValidationException; |
56 | |
import org.kuali.rice.krad.util.GlobalVariables; |
57 | |
import org.kuali.rice.krad.util.KRADConstants; |
58 | |
import org.kuali.rice.krad.util.ObjectUtils; |
59 | |
|
60 | |
import java.sql.Date; |
61 | |
import java.util.ArrayList; |
62 | |
import java.util.Collection; |
63 | |
import java.util.HashMap; |
64 | |
import java.util.Iterator; |
65 | |
import java.util.List; |
66 | |
import java.util.Map; |
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | 0 | public class RuleDelegationLookupableHelperServiceImpl extends KualiLookupableHelperServiceImpl { |
75 | 0 | private List<Row> rows = new ArrayList<Row>(); |
76 | |
|
77 | |
|
78 | |
private static final String PARENT_RESPONSIBILITY_ID_PROPERTY_NAME = "responsibilityId"; |
79 | |
private static final String PARENT_RULE_ID_PROPERTY_NAME = "ruleResponsibility.ruleBaseValues.ruleBaseValuesId"; |
80 | |
private static final String RULE_TEMPLATE_PROPERTY_NAME = "delegationRuleBaseValues.ruleTemplate.name"; |
81 | |
private static final String RULE_ID_PROPERTY_NAME = "delegationRuleBaseValues.ruleBaseValuesId"; |
82 | |
private static final String ACTIVE_IND_PROPERTY_NAME = "delegationRuleBaseValues.activeInd"; |
83 | |
private static final String DELEGATION_PROPERTY_NAME = "delegationType"; |
84 | |
private static final String GROUP_REVIEWER_PROPERTY_NAME = "delegationRuleBaseValues.groupReviewer"; |
85 | |
private static final String GROUP_REVIEWER_NAME_PROPERTY_NAME = "delegationRuleBaseValues.groupReviewerName"; |
86 | |
private static final String GROUP_REVIEWER_NAMESPACE_PROPERTY_NAME = "delegationRuleBaseValues.groupReviewerNamespace"; |
87 | |
private static final String PERSON_REVIEWER_PROPERTY_NAME = "delegationRuleBaseValues.personReviewer"; |
88 | |
private static final String PERSON_REVIEWER_TYPE_PROPERTY_NAME = "delegationRuleBaseValues.personReviewerType"; |
89 | |
private static final String DOC_TYP_NAME_PROPERTY_NAME = "delegationRuleBaseValues.documentType.name"; |
90 | |
private static final String RULE_DESC_PROPERTY_NAME = "delegationRuleBaseValues.description"; |
91 | |
|
92 | |
private static final String BACK_LOCATION = "backLocation"; |
93 | |
private static final String DOC_FORM_KEY = "docFormKey"; |
94 | |
private static final String INVALID_WORKGROUP_ERROR = "The Group Reviewer Namespace and Name combination is not valid"; |
95 | |
private static final String INVALID_PERSON_ERROR = "The Person Reviewer is not valid"; |
96 | |
|
97 | |
@Override |
98 | |
public List<Row> getRows() { |
99 | 0 | List<Row> superRows = super.getRows(); |
100 | 0 | List<Row> returnRows = new ArrayList<Row>(); |
101 | 0 | returnRows.addAll(superRows); |
102 | 0 | returnRows.addAll(rows); |
103 | 0 | return returnRows; |
104 | |
} |
105 | |
|
106 | |
@Override |
107 | |
public boolean checkForAdditionalFields(Map fieldValues) { |
108 | 0 | String ruleTemplateNameParam = (String) fieldValues.get(RULE_TEMPLATE_PROPERTY_NAME); |
109 | |
|
110 | 0 | if (ruleTemplateNameParam != null && !ruleTemplateNameParam.equals("")) { |
111 | 0 | rows = new ArrayList<Row>(); |
112 | 0 | RuleTemplate ruleTemplate = null; |
113 | |
|
114 | 0 | ruleTemplate = getRuleTemplateService().findByRuleTemplateName(ruleTemplateNameParam); |
115 | |
|
116 | 0 | for (Object element : ruleTemplate.getActiveRuleTemplateAttributes()) { |
117 | 0 | RuleTemplateAttribute ruleTemplateAttribute = (RuleTemplateAttribute) element; |
118 | 0 | if (!ruleTemplateAttribute.isWorkflowAttribute()) { |
119 | 0 | continue; |
120 | |
} |
121 | 0 | WorkflowAttribute attribute = ruleTemplateAttribute.getWorkflowAttribute(); |
122 | 0 | RuleAttribute ruleAttribute = ruleTemplateAttribute.getRuleAttribute(); |
123 | 0 | if (ruleAttribute.getType().equals(KEWConstants.RULE_XML_ATTRIBUTE_TYPE)) { |
124 | 0 | ((GenericXMLRuleAttribute) attribute).setRuleAttribute(ruleAttribute); |
125 | |
} |
126 | |
|
127 | |
|
128 | 0 | List<Row> searchRows = null; |
129 | 0 | if (attribute instanceof OddSearchAttribute) { |
130 | 0 | searchRows = ((OddSearchAttribute) attribute).getSearchRows(); |
131 | |
} else { |
132 | 0 | searchRows = attribute.getRuleRows(); |
133 | |
} |
134 | 0 | for (Row row : searchRows) { |
135 | 0 | List<Field> fields = new ArrayList<Field>(); |
136 | 0 | for (Field field2 : row.getFields()) { |
137 | 0 | Field field = field2; |
138 | 0 | if (fieldValues.get(field.getPropertyName()) != null) { |
139 | 0 | field.setPropertyValue(fieldValues.get(field.getPropertyName())); |
140 | |
} |
141 | 0 | fields.add(field); |
142 | 0 | fieldValues.put(field.getPropertyName(), field.getPropertyValue()); |
143 | 0 | } |
144 | 0 | } |
145 | |
|
146 | 0 | if (attribute instanceof OddSearchAttribute) { |
147 | 0 | ((OddSearchAttribute) attribute).validateSearchData(fieldValues); |
148 | |
} else { |
149 | 0 | attribute.validateRuleData(fieldValues); |
150 | |
} |
151 | |
|
152 | 0 | if (attribute instanceof OddSearchAttribute) { |
153 | 0 | searchRows = ((OddSearchAttribute) attribute).getSearchRows(); |
154 | |
} else { |
155 | 0 | searchRows = attribute.getRuleRows(); |
156 | |
} |
157 | 0 | for (Object element2 : searchRows) { |
158 | 0 | Row row = (Row) element2; |
159 | 0 | List<Field> fields = new ArrayList<Field>(); |
160 | 0 | for (Field field : row.getFields()) { |
161 | 0 | if (fieldValues.get(field.getPropertyName()) != null) { |
162 | 0 | field.setPropertyValue(fieldValues.get(field.getPropertyName())); |
163 | |
} |
164 | 0 | fields.add(field); |
165 | 0 | fieldValues.put(field.getPropertyName(), field.getPropertyValue()); |
166 | |
} |
167 | 0 | row.setFields(fields); |
168 | 0 | rows.add(row); |
169 | |
|
170 | 0 | } |
171 | |
|
172 | 0 | } |
173 | |
|
174 | 0 | return true; |
175 | |
} |
176 | 0 | rows.clear(); |
177 | 0 | return false; |
178 | |
} |
179 | |
|
180 | |
@Override |
181 | |
public List<? extends BusinessObject> getSearchResults(Map<String, String> fieldValues) { |
182 | 0 | List errors = new ArrayList(); |
183 | |
|
184 | 0 | String parentRuleBaseValueId = fieldValues.get(PARENT_RULE_ID_PROPERTY_NAME); |
185 | 0 | String parentResponsibilityId = fieldValues.get(PARENT_RESPONSIBILITY_ID_PROPERTY_NAME); |
186 | 0 | String docTypeNameParam = fieldValues.get(DOC_TYP_NAME_PROPERTY_NAME); |
187 | 0 | String ruleTemplateIdParam = null; |
188 | 0 | String ruleTemplateNameParam = fieldValues.get(RULE_TEMPLATE_PROPERTY_NAME); |
189 | 0 | String groupIdParam = fieldValues.get(GROUP_REVIEWER_PROPERTY_NAME); |
190 | 0 | String groupNameParam = fieldValues.get(GROUP_REVIEWER_NAME_PROPERTY_NAME); |
191 | 0 | String groupNamespaceParam = fieldValues.get(GROUP_REVIEWER_NAMESPACE_PROPERTY_NAME); |
192 | 0 | String networkIdParam = fieldValues.get(PERSON_REVIEWER_PROPERTY_NAME); |
193 | 0 | String userDirectiveParam = fieldValues.get(PERSON_REVIEWER_TYPE_PROPERTY_NAME); |
194 | 0 | String activeParam = fieldValues.get(ACTIVE_IND_PROPERTY_NAME); |
195 | 0 | String delegationParam = fieldValues.get(DELEGATION_PROPERTY_NAME); |
196 | 0 | String ruleIdParam = fieldValues.get(RULE_ID_PROPERTY_NAME); |
197 | 0 | fieldValues.get(KEWConstants.DELEGATION_WIZARD); |
198 | 0 | String ruleDescription = fieldValues.get(RULE_DESC_PROPERTY_NAME); |
199 | |
|
200 | 0 | String docTypeSearchName = null; |
201 | 0 | String workflowId = null; |
202 | 0 | String workgroupId = null; |
203 | 0 | String ruleTemplateId = null; |
204 | 0 | Boolean isActive = null; |
205 | 0 | String ruleId = null; |
206 | |
|
207 | 0 | if (ruleIdParam != null && !"".equals(ruleIdParam.trim())) { |
208 | |
try { |
209 | 0 | ruleId = ruleIdParam.trim(); |
210 | 0 | } catch (NumberFormatException e) { |
211 | |
|
212 | 0 | ruleId = "-1"; |
213 | 0 | } |
214 | |
} |
215 | |
|
216 | 0 | if (!activeParam.equals("")) { |
217 | 0 | if (activeParam.equals("Y")) { |
218 | 0 | isActive = Boolean.TRUE; |
219 | |
} else { |
220 | 0 | isActive = Boolean.FALSE; |
221 | |
} |
222 | |
} |
223 | |
|
224 | 0 | if (docTypeNameParam != null && !"".equals(docTypeNameParam.trim())) { |
225 | 0 | docTypeSearchName = docTypeNameParam.replace('*', '%'); |
226 | 0 | docTypeSearchName = "%" + docTypeSearchName.trim() + "%"; |
227 | |
} |
228 | |
|
229 | 0 | if (!org.apache.commons.lang.StringUtils.isEmpty(groupIdParam) || !org.apache.commons.lang.StringUtils.isEmpty(groupNameParam)) { |
230 | 0 | Group group = null; |
231 | 0 | if (groupIdParam != null && !"".equals(groupIdParam)) { |
232 | 0 | group = getGroupService().getGroup(groupIdParam.trim()); |
233 | |
} else { |
234 | 0 | if (groupNamespaceParam == null) { |
235 | 0 | groupNamespaceParam = KimConstants.KIM_GROUP_DEFAULT_NAMESPACE_CODE; |
236 | |
} |
237 | 0 | group = getGroupService().getGroupByName(groupNamespaceParam, groupNameParam.trim()); |
238 | 0 | if (group == null) { |
239 | 0 | GlobalVariables.getMessageMap().putError(GROUP_REVIEWER_NAMESPACE_PROPERTY_NAME, RiceKeyConstants.ERROR_CUSTOM, INVALID_WORKGROUP_ERROR); |
240 | |
} else { |
241 | 0 | workgroupId = group.getId(); |
242 | |
} |
243 | |
} |
244 | |
} |
245 | |
|
246 | 0 | Map attributes = null; |
247 | 0 | MyColumns myColumns = new MyColumns(); |
248 | 0 | if (ruleTemplateNameParam != null && !ruleTemplateNameParam.trim().equals("") || ruleTemplateIdParam != null && !"".equals(ruleTemplateIdParam) && !"null".equals(ruleTemplateIdParam)) { |
249 | 0 | RuleTemplate ruleTemplate = null; |
250 | 0 | if (ruleTemplateIdParam != null && !"".equals(ruleTemplateIdParam)) { |
251 | 0 | ruleTemplateId = ruleTemplateIdParam; |
252 | 0 | ruleTemplate = getRuleTemplateService().findByRuleTemplateId(ruleTemplateId); |
253 | |
} else { |
254 | 0 | ruleTemplate = getRuleTemplateService().findByRuleTemplateName(ruleTemplateNameParam.trim()); |
255 | 0 | ruleTemplateId = ruleTemplate.getRuleTemplateId(); |
256 | |
} |
257 | |
|
258 | 0 | if(ruleTemplate == null){ |
259 | 0 | rows.clear(); |
260 | 0 | LOG.info("Returning empty result set for Delegation Rule Lookup because a RuleTemplate Name or ID was provided, but no valid RuleTemplates were retrieved by the service."); |
261 | 0 | return new ArrayList<RuleDelegation>(); |
262 | |
} |
263 | |
|
264 | 0 | attributes = new HashMap(); |
265 | 0 | for (Object element : ruleTemplate.getActiveRuleTemplateAttributes()) { |
266 | 0 | RuleTemplateAttribute ruleTemplateAttribute = (RuleTemplateAttribute) element; |
267 | 0 | if (!ruleTemplateAttribute.isWorkflowAttribute()) { |
268 | 0 | continue; |
269 | |
} |
270 | 0 | WorkflowAttribute attribute = (WorkflowAttribute)GlobalResourceLoader.getObject(new ObjectDefinition(ruleTemplateAttribute.getRuleAttribute().getClassName(), ruleTemplateAttribute.getRuleAttribute().getApplicationId())); |
271 | 0 | RuleAttribute ruleAttribute = ruleTemplateAttribute.getRuleAttribute(); |
272 | 0 | if (ruleAttribute.getType().equals(KEWConstants.RULE_XML_ATTRIBUTE_TYPE)) { |
273 | 0 | ((GenericXMLRuleAttribute) attribute).setRuleAttribute(ruleAttribute); |
274 | |
} |
275 | 0 | attribute.setRequired(false); |
276 | 0 | List<Row> searchRows = null; |
277 | 0 | if (attribute instanceof OddSearchAttribute) { |
278 | 0 | for (WorkflowServiceErrorImpl wsei : (List<WorkflowServiceErrorImpl>)((OddSearchAttribute)attribute).validateSearchData(fieldValues)) { |
279 | 0 | GlobalVariables.getMessageMap().putError(wsei.getMessage(), RiceKeyConstants.ERROR_CUSTOM, wsei.getArg1()); |
280 | |
} |
281 | 0 | searchRows = ((OddSearchAttribute) attribute).getSearchRows(); |
282 | |
} else { |
283 | 0 | for (WorkflowServiceErrorImpl wsei : (List<WorkflowServiceErrorImpl>)attribute.validateRuleData(fieldValues)) { |
284 | 0 | GlobalVariables.getMessageMap().putError(wsei.getMessage(), RiceKeyConstants.ERROR_CUSTOM, wsei.getArg1()); |
285 | |
} |
286 | 0 | searchRows = attribute.getRuleRows(); |
287 | |
} |
288 | 0 | for (Row row : searchRows) { |
289 | 0 | for (Field field : row.getFields()) { |
290 | 0 | if (fieldValues.get(field.getPropertyName()) != null) { |
291 | 0 | String attributeParam = fieldValues.get(field.getPropertyName()); |
292 | 0 | if (!attributeParam.equals("")) { |
293 | 0 | if (ruleAttribute.getType().equals(KEWConstants.RULE_XML_ATTRIBUTE_TYPE)) { |
294 | 0 | attributes.put(field.getPropertyName(), attributeParam.trim()); |
295 | |
} else { |
296 | 0 | attributes.put(field.getPropertyName(), attributeParam.trim()); |
297 | |
} |
298 | |
} |
299 | |
} |
300 | 0 | if (field.getFieldType().equals(Field.TEXT) || field.getFieldType().equals(Field.DROPDOWN) || field.getFieldType().equals(Field.DROPDOWN_REFRESH) || field.getFieldType().equals(Field.RADIO)) { |
301 | 0 | if (ruleAttribute.getType().equals(KEWConstants.RULE_XML_ATTRIBUTE_TYPE)) { |
302 | 0 | myColumns.getColumns().add(new ConcreteKeyValue(field.getPropertyName(), ruleTemplateAttribute.getRuleTemplateAttributeId()+"")); |
303 | |
} else { |
304 | 0 | myColumns.getColumns().add(new ConcreteKeyValue(field.getPropertyName(), ruleTemplateAttribute.getRuleTemplateAttributeId()+"")); |
305 | |
} |
306 | |
} |
307 | |
} |
308 | |
} |
309 | 0 | } |
310 | |
} |
311 | |
|
312 | 0 | if (!org.apache.commons.lang.StringUtils.isEmpty(ruleDescription)) { |
313 | 0 | ruleDescription = ruleDescription.replace('*', '%'); |
314 | 0 | ruleDescription = "%" + ruleDescription.trim() + "%"; |
315 | |
} |
316 | |
|
317 | 0 | if (!errors.isEmpty()) { |
318 | 0 | throw new ValidationException("errors in search criteria"); |
319 | |
} |
320 | |
|
321 | 0 | if(!org.apache.commons.lang.StringUtils.isEmpty(networkIdParam)){ |
322 | 0 | workflowId = networkIdParam; |
323 | 0 | workflowId = KimApiServiceLocator.getIdentityService().getPrincipalByPrincipalName(networkIdParam).getPrincipalId(); |
324 | |
} |
325 | |
|
326 | 0 | Iterator<RuleDelegation> rules = getRuleDelegationService().search(parentRuleBaseValueId, parentResponsibilityId, docTypeSearchName, ruleId, ruleTemplateId, ruleDescription, workgroupId, workflowId, delegationParam, isActive, attributes, userDirectiveParam).iterator(); |
327 | 0 | List<RuleDelegation> displayList = new ArrayList<RuleDelegation>(); |
328 | |
|
329 | 0 | while (rules.hasNext()) { |
330 | 0 | RuleDelegation ruleDelegation = rules.next(); |
331 | 0 | RuleBaseValues record = ruleDelegation.getDelegationRuleBaseValues(); |
332 | |
|
333 | 0 | if (org.apache.commons.lang.StringUtils.isEmpty(record.getDescription())) { |
334 | 0 | record.setDescription(KEWConstants.HTML_NON_BREAKING_SPACE); |
335 | |
} |
336 | |
|
337 | 0 | if (ruleTemplateNameParam != null && !ruleTemplateNameParam.trim().equals("") || ruleTemplateIdParam != null && !"".equals(ruleTemplateIdParam) && !"null".equals(ruleTemplateIdParam)) { |
338 | 0 | MyColumns myNewColumns = new MyColumns(); |
339 | 0 | for (Object element : myColumns.getColumns()) { |
340 | 0 | KeyValue pair = (KeyValue) element; |
341 | |
final KeyValue newPair; |
342 | 0 | if (record.getRuleExtensionValue(pair.getKey(), pair.getKey().toString()) != null) { |
343 | 0 | newPair = new ConcreteKeyValue(pair.getKey(), record.getRuleExtensionValue(pair.getValue(), pair.getKey().toString()).getValue()); |
344 | |
} else { |
345 | 0 | newPair = new ConcreteKeyValue(pair.getKey(), KEWConstants.HTML_NON_BREAKING_SPACE); |
346 | |
} |
347 | 0 | myNewColumns.getColumns().add(newPair); |
348 | 0 | record.getFieldValues().put(newPair.getKey(), newPair.getValue()); |
349 | 0 | } |
350 | 0 | record.setMyColumns(myNewColumns); |
351 | |
} |
352 | |
|
353 | 0 | StringBuffer returnUrl = new StringBuffer("<a href=\""); |
354 | 0 | returnUrl.append(fieldValues.get(BACK_LOCATION)).append("?methodToCall=refresh&docFormKey=").append(fieldValues.get(DOC_FORM_KEY)).append("&"); |
355 | |
|
356 | 0 | returnUrl.append(RULE_ID_PROPERTY_NAME); |
357 | 0 | returnUrl.append("=").append(record.getRuleBaseValuesId()).append("\">return value</a>"); |
358 | 0 | record.setReturnUrl(returnUrl.toString()); |
359 | |
|
360 | 0 | String destinationUrl = "<a href=\"Rule.do?methodToCall=report¤tRuleId=" + record.getRuleBaseValuesId() + "\">report</a>"; |
361 | |
|
362 | 0 | record.setDestinationUrl(destinationUrl); |
363 | |
|
364 | 0 | displayList.add(ruleDelegation); |
365 | 0 | } |
366 | 0 | return displayList; |
367 | |
|
368 | |
} |
369 | |
|
370 | |
|
371 | |
|
372 | |
private GroupService getGroupService() { |
373 | 0 | return KimApiServiceLocator.getGroupService(); |
374 | |
} |
375 | |
|
376 | |
private RuleTemplateService getRuleTemplateService() { |
377 | 0 | return (RuleTemplateService) KEWServiceLocator.getService(KEWServiceLocator.RULE_TEMPLATE_SERVICE); |
378 | |
} |
379 | |
private RuleDelegationService getRuleDelegationService() { |
380 | 0 | return (RuleDelegationService) KEWServiceLocator.getService(KEWServiceLocator.RULE_DELEGATION_SERVICE); |
381 | |
} |
382 | |
|
383 | |
@Override |
384 | |
public void validateSearchParameters(Map fieldValues) { |
385 | 0 | super.validateSearchParameters(fieldValues); |
386 | |
|
387 | |
|
388 | 0 | String groupName = (String)fieldValues.get(GROUP_REVIEWER_NAME_PROPERTY_NAME); |
389 | 0 | String groupNamespace = (String)fieldValues.get(GROUP_REVIEWER_NAMESPACE_PROPERTY_NAME); |
390 | 0 | String personId = (String)fieldValues.get(PERSON_REVIEWER_PROPERTY_NAME); |
391 | |
|
392 | 0 | if (org.apache.commons.lang.StringUtils.isEmpty(groupName) && !org.apache.commons.lang.StringUtils.isEmpty(groupNamespace)) { |
393 | 0 | String attributeLabel = getDataDictionaryService().getAttributeLabel(getBusinessObjectClass(), GROUP_REVIEWER_NAME_PROPERTY_NAME); |
394 | 0 | GlobalVariables.getMessageMap().putError(GROUP_REVIEWER_NAME_PROPERTY_NAME, RiceKeyConstants.ERROR_REQUIRED, attributeLabel); |
395 | |
} |
396 | |
|
397 | 0 | if (!org.apache.commons.lang.StringUtils.isEmpty(groupName) && org.apache.commons.lang.StringUtils.isEmpty(groupNamespace)) { |
398 | 0 | String attributeLabel = getDataDictionaryService().getAttributeLabel(getBusinessObjectClass(), GROUP_REVIEWER_NAMESPACE_PROPERTY_NAME); |
399 | 0 | GlobalVariables.getMessageMap().putError(GROUP_REVIEWER_NAMESPACE_PROPERTY_NAME, RiceKeyConstants.ERROR_REQUIRED, attributeLabel); |
400 | |
} |
401 | |
|
402 | 0 | if (!org.apache.commons.lang.StringUtils.isEmpty(groupName) && !org.apache.commons.lang.StringUtils.isEmpty(groupNamespace)) { |
403 | 0 | Group group = getGroupService().getGroupByName(groupNamespace, groupName); |
404 | 0 | if (group == null) { |
405 | 0 | GlobalVariables.getMessageMap().putError(GROUP_REVIEWER_NAME_PROPERTY_NAME, RiceKeyConstants.ERROR_CUSTOM, INVALID_WORKGROUP_ERROR); |
406 | |
} |
407 | |
} |
408 | |
|
409 | 0 | if (!org.apache.commons.lang.StringUtils.isEmpty(personId)) { |
410 | |
|
411 | 0 | Person person = KimApiServiceLocator.getPersonService().getPersonByPrincipalName(personId); |
412 | 0 | if (person == null) { |
413 | 0 | GlobalVariables.getMessageMap().putError(PERSON_REVIEWER_PROPERTY_NAME, RiceKeyConstants.ERROR_CUSTOM, INVALID_PERSON_ERROR); |
414 | |
} |
415 | |
} |
416 | 0 | if (!GlobalVariables.getMessageMap().hasNoErrors()) { |
417 | 0 | throw new ValidationException("errors in search criteria"); |
418 | |
} |
419 | 0 | } |
420 | |
|
421 | |
@Override |
422 | |
public Collection performLookup(LookupForm lookupForm, |
423 | |
Collection resultTable, boolean bounded) { |
424 | |
|
425 | |
|
426 | 0 | setBackLocation((String) lookupForm.getFieldsForLookup().get(KRADConstants.BACK_LOCATION)); |
427 | 0 | setDocFormKey((String) lookupForm.getFieldsForLookup().get(KRADConstants.DOC_FORM_KEY)); |
428 | |
Collection displayList; |
429 | |
|
430 | |
|
431 | 0 | if (bounded) { |
432 | 0 | displayList = getSearchResults(lookupForm.getFieldsForLookup()); |
433 | |
} |
434 | |
else { |
435 | 0 | displayList = getSearchResultsUnbounded(lookupForm.getFieldsForLookup()); |
436 | |
} |
437 | |
|
438 | 0 | HashMap<String,Class> propertyTypes = new HashMap<String, Class>(); |
439 | |
|
440 | 0 | boolean hasReturnableRow = false; |
441 | |
|
442 | 0 | List returnKeys = getReturnKeys(); |
443 | 0 | List pkNames = getBusinessObjectMetaDataService().listPrimaryKeyFieldNames(getBusinessObjectClass()); |
444 | 0 | Person user = GlobalVariables.getUserSession().getPerson(); |
445 | |
|
446 | |
|
447 | 0 | for (Iterator iter = displayList.iterator(); iter.hasNext();) { |
448 | 0 | BusinessObject element = (BusinessObject) iter.next(); |
449 | 0 | if(element instanceof PersistableBusinessObject){ |
450 | 0 | lookupForm.setLookupObjectId(((PersistableBusinessObject)element).getObjectId()); |
451 | |
} |
452 | |
|
453 | 0 | BusinessObjectRestrictions businessObjectRestrictions = getBusinessObjectAuthorizationService().getLookupResultRestrictions(element, user); |
454 | |
|
455 | 0 | HtmlData returnUrl = getReturnUrl(element, lookupForm, returnKeys, businessObjectRestrictions); |
456 | |
|
457 | 0 | String actionUrls = getActionUrls(element, pkNames, businessObjectRestrictions); |
458 | |
|
459 | 0 | if("".equals(actionUrls)){ |
460 | 0 | actionUrls = ACTION_URLS_EMPTY; |
461 | |
} |
462 | |
|
463 | 0 | List<Column> columns = getColumns(); |
464 | 0 | for (Object element2 : columns) { |
465 | |
|
466 | 0 | Column col = (Column) element2; |
467 | 0 | String curPropName = col.getPropertyName(); |
468 | 0 | Formatter formatter = col.getFormatter(); |
469 | |
|
470 | |
|
471 | 0 | String propValue = KRADConstants.EMPTY_STRING; |
472 | 0 | Object prop = null; |
473 | 0 | boolean skipPropTypeCheck = false; |
474 | |
|
475 | 0 | if (element instanceof RuleDelegation) { |
476 | 0 | prop = ((RuleDelegation)element).getDelegationRuleBaseValues().getFieldValues().get(curPropName); |
477 | 0 | skipPropTypeCheck = true; |
478 | |
} |
479 | 0 | if (prop == null) { |
480 | 0 | prop = ObjectUtils.getPropertyValue(element, curPropName); |
481 | |
} |
482 | |
|
483 | |
|
484 | 0 | Class propClass = propertyTypes.get(curPropName); |
485 | 0 | if ( propClass == null && !skipPropTypeCheck) { |
486 | |
try { |
487 | 0 | propClass = ObjectUtils.getPropertyType( element, curPropName, getPersistenceStructureService() ); |
488 | 0 | propertyTypes.put( curPropName, propClass ); |
489 | 0 | } catch (Exception e) { |
490 | 0 | throw new RuntimeException("Cannot access PropertyType for property " + "'" + curPropName + "' " + " on an instance of '" + element.getClass().getName() + "'.", e); |
491 | 0 | } |
492 | |
} |
493 | |
|
494 | |
|
495 | 0 | if (prop != null) { |
496 | |
|
497 | 0 | if (prop instanceof Boolean) { |
498 | 0 | formatter = new BooleanFormatter(); |
499 | |
} |
500 | |
|
501 | |
|
502 | 0 | if (prop instanceof Date) { |
503 | 0 | formatter = new DateFormatter(); |
504 | |
} |
505 | |
|
506 | |
|
507 | 0 | if (prop instanceof Collection && formatter == null) { |
508 | 0 | formatter = new CollectionFormatter(); |
509 | |
} |
510 | |
|
511 | 0 | if (formatter != null) { |
512 | 0 | propValue = (String) formatter.format(prop); |
513 | |
} |
514 | |
else { |
515 | 0 | propValue = prop.toString(); |
516 | |
} |
517 | |
} |
518 | |
|
519 | |
|
520 | 0 | col.setComparator(CellComparatorHelper.getAppropriateComparatorForPropertyClass(propClass)); |
521 | 0 | col.setValueComparator(CellComparatorHelper.getAppropriateValueComparatorForPropertyClass(propClass)); |
522 | |
|
523 | 0 | propValue = maskValueIfNecessary(element.getClass(), curPropName, propValue, businessObjectRestrictions); |
524 | |
|
525 | 0 | col.setPropertyValue(propValue); |
526 | |
|
527 | 0 | if (StringUtils.isNotBlank(propValue)) { |
528 | 0 | col.setColumnAnchor(getInquiryUrl(element, curPropName)); |
529 | |
|
530 | |
} |
531 | 0 | } |
532 | |
|
533 | 0 | ResultRow row = new ResultRow(columns, returnUrl.constructCompleteHtmlTag(), actionUrls); |
534 | 0 | row.setRowId(returnUrl.getName()); |
535 | 0 | row.setReturnUrlHtmlData(returnUrl); |
536 | |
|
537 | |
|
538 | 0 | if (getBusinessObjectDictionaryService().isExportable(getBusinessObjectClass())) { |
539 | 0 | row.setBusinessObject(element); |
540 | |
} |
541 | 0 | if(element instanceof PersistableBusinessObject){ |
542 | 0 | row.setObjectId((((PersistableBusinessObject)element).getObjectId())); |
543 | |
} |
544 | |
|
545 | |
|
546 | 0 | boolean rowReturnable = isResultReturnable(element); |
547 | 0 | row.setRowReturnable(rowReturnable); |
548 | 0 | if (rowReturnable) { |
549 | 0 | hasReturnableRow = true; |
550 | |
} |
551 | 0 | resultTable.add(row); |
552 | 0 | } |
553 | |
|
554 | 0 | lookupForm.setHasReturnableRow(hasReturnableRow); |
555 | |
|
556 | 0 | return displayList; |
557 | |
} |
558 | |
|
559 | |
@Override |
560 | |
public List<Column> getColumns() { |
561 | 0 | List<Column> columns = super.getColumns(); |
562 | 0 | for (Row row : rows) { |
563 | 0 | for (Field field : row.getFields()) { |
564 | 0 | Column newColumn = new Column(); |
565 | 0 | newColumn.setColumnTitle(field.getFieldLabel()); |
566 | 0 | newColumn.setMaxLength(field.getMaxLength()); |
567 | 0 | newColumn.setPropertyName(field.getPropertyName()); |
568 | 0 | columns.add(newColumn); |
569 | 0 | } |
570 | |
} |
571 | 0 | return columns; |
572 | |
} |
573 | |
|
574 | |
@Override |
575 | |
public List<HtmlData> getCustomActionUrls(BusinessObject businessObject, |
576 | |
List pkNames) { |
577 | 0 | RuleDelegation ruleDelegation = (RuleDelegation)businessObject; |
578 | 0 | List<HtmlData> htmlDataList = new ArrayList<HtmlData>(); |
579 | 0 | if (StringUtils.isNotBlank(ruleDelegation.getDelegationRuleBaseValues().getRuleTemplateName()) && StringUtils.isNotBlank(getMaintenanceDocumentTypeName())) { |
580 | 0 | if (allowsMaintenanceEditAction(businessObject)) { |
581 | 0 | htmlDataList.add(getUrlData(businessObject, KRADConstants.MAINTENANCE_EDIT_METHOD_TO_CALL, pkNames)); |
582 | |
} |
583 | 0 | if (allowsMaintenanceNewOrCopyAction()) { |
584 | 0 | htmlDataList.add(getUrlData(businessObject, KRADConstants.MAINTENANCE_COPY_METHOD_TO_CALL, pkNames)); |
585 | |
} |
586 | |
} |
587 | |
|
588 | 0 | return htmlDataList; |
589 | |
} |
590 | |
|
591 | |
|
592 | |
|
593 | |
} |