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