View Javadoc

1   /*
2    * Copyright 2007-2009 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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   * This is a description of what this class does - jjhanso don't forget to fill this in.
65   *
66   * @author Kuali Rice Team (rice.collab@kuali.org)
67   *
68   */
69  public class RuleDelegationLookupableHelperServiceImpl extends KualiLookupableHelperServiceImpl {
70      private List<Row> rows = new ArrayList<Row>();
71      //private List<Column> columns = establishColumns();
72      //private Long previousRuleTemplateId;
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          List<Row> superRows = super.getRows();
100         List<Row> returnRows = new ArrayList<Row>();
101         returnRows.addAll(superRows);
102         returnRows.addAll(rows);
103         return returnRows;
104     }
105 
106     @Override
107     public boolean checkForAdditionalFields(Map fieldValues) {
108         String ruleTemplateNameParam = (String) fieldValues.get(RULE_TEMPLATE_PROPERTY_NAME);
109 
110         if (ruleTemplateNameParam != null && !ruleTemplateNameParam.equals("")) {
111             rows = new ArrayList<Row>();
112             RuleTemplate ruleTemplate = null;
113 
114             ruleTemplate = getRuleTemplateService().findByRuleTemplateName(ruleTemplateNameParam);
115 
116             int i = 0;
117             for (Iterator iter = ruleTemplate.getActiveRuleTemplateAttributes().iterator(); iter.hasNext();) {
118                 RuleTemplateAttribute ruleTemplateAttribute = (RuleTemplateAttribute) iter.next();
119                 if (!ruleTemplateAttribute.isWorkflowAttribute()) {
120                     continue;
121                 }
122                 WorkflowAttribute attribute = ruleTemplateAttribute.getWorkflowAttribute();
123                 RuleAttribute ruleAttribute = ruleTemplateAttribute.getRuleAttribute();
124                 if (ruleAttribute.getType().equals(KEWConstants.RULE_XML_ATTRIBUTE_TYPE)) {
125                     ((GenericXMLRuleAttribute) attribute).setRuleAttribute(ruleAttribute);
126                 }
127                 // run through the attributes fields once to populate field values we have to do this
128                 // to allow rows dependent on another row value to populate correctly in the loop below
129                 List<Row> searchRows = null;
130                 if (attribute instanceof OddSearchAttribute) {
131                     searchRows = ((OddSearchAttribute) attribute).getSearchRows();
132                 } else {
133                     searchRows = attribute.getRuleRows();
134                 }
135                 for (Iterator<Row> iterator = searchRows.iterator(); iterator.hasNext();) {
136                     Row row = iterator.next();
137                     List<Field> fields = new ArrayList<Field>();
138                     for (Iterator<Field> iterator2 = row.getFields().iterator(); iterator2.hasNext();) {
139                         Field field = (Field) iterator2.next();
140                         if (fieldValues.get(field.getPropertyName()) != null) {
141                             field.setPropertyValue(fieldValues.get(field.getPropertyName()));
142                         }
143                         fields.add(field);
144                         fieldValues.put(field.getPropertyName(), field.getPropertyValue());
145                     }
146                 }
147 
148                 if (attribute instanceof OddSearchAttribute) {
149                     ((OddSearchAttribute) attribute).validateSearchData(fieldValues);
150                 } else {
151                     attribute.validateRuleData(fieldValues);// populate attribute
152                 }
153 
154                 if (attribute instanceof OddSearchAttribute) {
155                     searchRows = ((OddSearchAttribute) attribute).getSearchRows();
156                 } else {
157                     searchRows = attribute.getRuleRows();
158                 }
159                 for (Iterator iterator = searchRows.iterator(); iterator.hasNext();) {
160                     Row row = (Row) iterator.next();
161                     List<Field> fields = new ArrayList<Field>();
162                     for (Iterator<Field> iterator2 = row.getFields().iterator(); iterator2.hasNext();) {
163                         Field field = iterator2.next();
164                         if (fieldValues.get(field.getPropertyName()) != null) {
165                             field.setPropertyValue(fieldValues.get(field.getPropertyName()));
166                         }
167                         fields.add(field);
168                         fieldValues.put(field.getPropertyName(), field.getPropertyValue());
169                     }
170                     row.setFields(fields);
171                     rows.add(row);
172 
173                 }
174 
175             }
176 
177             return true;
178         }
179         rows.clear();
180         return false;
181     }
182 
183     @Override
184     public List<? extends BusinessObject> getSearchResults(Map<String, String> fieldValues) {
185         List errors = new ArrayList();
186 
187         String parentRuleBaseValueId = (String) fieldValues.get(PARENT_RULE_ID_PROPERTY_NAME);
188         String parentResponsibilityId = (String) fieldValues.get(PARENT_RESPONSIBILITY_ID_PROPERTY_NAME);
189         String docTypeNameParam = (String) fieldValues.get(DOC_TYP_NAME_PROPERTY_NAME);
190         String ruleTemplateIdParam = null;//(String) fieldValues.get(RULE_TEMPLATE_ID_PROPERTY_NAME);
191         String ruleTemplateNameParam = (String) fieldValues.get(RULE_TEMPLATE_PROPERTY_NAME);
192         String groupIdParam = (String) fieldValues.get(GROUP_REVIEWER_PROPERTY_NAME);
193         String groupNameParam = (String) fieldValues.get(GROUP_REVIEWER_NAME_PROPERTY_NAME);
194         String groupNamespaceParam = (String) fieldValues.get(GROUP_REVIEWER_NAMESPACE_PROPERTY_NAME);
195         String networkIdParam = (String) fieldValues.get(PERSON_REVIEWER_PROPERTY_NAME);
196         String userDirectiveParam = (String) fieldValues.get(PERSON_REVIEWER_TYPE_PROPERTY_NAME);
197         String activeParam = (String) fieldValues.get(ACTIVE_IND_PROPERTY_NAME);
198         String delegationParam = (String) fieldValues.get(DELEGATION_PROPERTY_NAME);
199         String ruleIdParam = (String) fieldValues.get(RULE_ID_PROPERTY_NAME);
200         String delegationWizard = (String) fieldValues.get(KEWConstants.DELEGATION_WIZARD);
201         String ruleDescription = (String) fieldValues.get(RULE_DESC_PROPERTY_NAME);
202 
203         String docTypeSearchName = null;
204         String workflowId = null;
205         String workgroupId = null;
206         Long ruleTemplateId = null;
207         Boolean isDelegateRule = null;
208         Boolean isActive = null;
209         Long ruleId = null;
210 
211         if (ruleIdParam != null && !"".equals(ruleIdParam.trim())) {
212             try {
213                 ruleId = new Long(ruleIdParam.trim());
214             } catch (NumberFormatException e) {
215                 ruleId = new Long(-1);
216             }
217         }
218 
219         if (!activeParam.equals("")) {
220             if (activeParam.equals("Y")) {
221                 isActive = Boolean.TRUE;
222             } else {
223                 isActive = Boolean.FALSE;
224             }
225         }
226 
227         if (docTypeNameParam != null && !"".equals(docTypeNameParam.trim())) {
228             docTypeSearchName = docTypeNameParam.replace('*', '%');
229             docTypeSearchName = "%" + docTypeSearchName.trim() + "%";
230         }
231 
232         if (!Utilities.isEmpty(groupIdParam) || !Utilities.isEmpty(groupNameParam)) {
233             Group group = null;
234             if (groupIdParam != null && !"".equals(groupIdParam)) {
235                 group = getIdentityManagementService().getGroup(groupIdParam.trim());
236             } else {
237                 if (groupNamespaceParam == null) {
238                     groupNamespaceParam = KimConstants.KIM_GROUP_DEFAULT_NAMESPACE_CODE;
239                 }
240                 group = getIdentityManagementService().getGroupByName(groupNamespaceParam, groupNameParam.trim());
241                 if (group == null) {
242                     String attributeLabel = getDataDictionaryService().getAttributeLabel(getBusinessObjectClass(), GROUP_REVIEWER_NAME_PROPERTY_NAME) + ":" + getDataDictionaryService().getAttributeLabel(getBusinessObjectClass(), GROUP_REVIEWER_NAMESPACE_PROPERTY_NAME);
243                     GlobalVariables.getMessageMap().putError(GROUP_REVIEWER_NAMESPACE_PROPERTY_NAME, RiceKeyConstants.ERROR_CUSTOM, INVALID_WORKGROUP_ERROR);
244                 } else {
245                     workgroupId = group.getGroupId();
246                 }
247             }
248         }
249 
250         Map attributes = null;
251         MyColumns myColumns = new MyColumns();
252         if (ruleTemplateNameParam != null && !ruleTemplateNameParam.trim().equals("") || ruleTemplateIdParam != null && !"".equals(ruleTemplateIdParam) && !"null".equals(ruleTemplateIdParam)) {
253             RuleTemplate ruleTemplate = null;
254             if (ruleTemplateIdParam != null && !"".equals(ruleTemplateIdParam)) {
255                 ruleTemplateId = new Long(ruleTemplateIdParam);
256                 ruleTemplate = getRuleTemplateService().findByRuleTemplateId(ruleTemplateId);
257             } else {
258                 ruleTemplate = getRuleTemplateService().findByRuleTemplateName(ruleTemplateNameParam.trim());
259                 ruleTemplateId = new Long(ruleTemplate.getRuleTemplateId().longValue());
260             }
261 
262             if(ruleTemplate == null){
263                 rows.clear();
264                 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                 return new ArrayList<RuleDelegation>();
266             }
267 
268             attributes = new HashMap();
269             for (Iterator iter = ruleTemplate.getActiveRuleTemplateAttributes().iterator(); iter.hasNext();) {
270                 RuleTemplateAttribute ruleTemplateAttribute = (RuleTemplateAttribute) iter.next();
271                 if (!ruleTemplateAttribute.isWorkflowAttribute()) {
272                     continue;
273                 }
274                 WorkflowAttribute attribute = (WorkflowAttribute)GlobalResourceLoader.getObject(new ObjectDefinition(ruleTemplateAttribute.getRuleAttribute().getClassName(), ruleTemplateAttribute.getRuleAttribute().getServiceNamespace()));//SpringServiceLocator.getExtensionService().getWorkflowAttribute(ruleTemplateAttribute.getRuleAttribute().getClassName());
275                 RuleAttribute ruleAttribute = ruleTemplateAttribute.getRuleAttribute();
276                 if (ruleAttribute.getType().equals(KEWConstants.RULE_XML_ATTRIBUTE_TYPE)) {
277                     ((GenericXMLRuleAttribute) attribute).setRuleAttribute(ruleAttribute);
278                 }
279                 attribute.setRequired(false);
280                 List<Row> searchRows = null;
281                 if (attribute instanceof OddSearchAttribute) {
282                     for (WorkflowServiceErrorImpl wsei : (List<WorkflowServiceErrorImpl>)((OddSearchAttribute)attribute).validateSearchData(fieldValues)) {
283                         GlobalVariables.getMessageMap().putError(wsei.getMessage(), RiceKeyConstants.ERROR_CUSTOM, wsei.getArg1());
284                     }
285                     searchRows = ((OddSearchAttribute) attribute).getSearchRows();
286                 } else {
287                     for (WorkflowServiceErrorImpl wsei : (List<WorkflowServiceErrorImpl>)attribute.validateRuleData(fieldValues)) {
288                         GlobalVariables.getMessageMap().putError(wsei.getMessage(), RiceKeyConstants.ERROR_CUSTOM, wsei.getArg1());
289                     }
290                     searchRows = attribute.getRuleRows();
291                 }
292                 for (Row row : searchRows) {
293                     for (Field field : row.getFields()) {
294                         if (fieldValues.get(field.getPropertyName()) != null) {
295                             String attributeParam = (String) fieldValues.get(field.getPropertyName());
296                             if (!attributeParam.equals("")) {
297                                 if (ruleAttribute.getType().equals(KEWConstants.RULE_XML_ATTRIBUTE_TYPE)) {
298                                     attributes.put(field.getPropertyName(), attributeParam.trim());
299                                 } else {
300                                     attributes.put(field.getPropertyName(), attributeParam.trim());
301                                 }
302                             }
303                         }
304                         if (field.getFieldType().equals(Field.TEXT) || field.getFieldType().equals(Field.DROPDOWN) || field.getFieldType().equals(Field.DROPDOWN_REFRESH) || field.getFieldType().equals(Field.RADIO)) {
305                             if (ruleAttribute.getType().equals(KEWConstants.RULE_XML_ATTRIBUTE_TYPE)) {
306                                 myColumns.getColumns().add(new KeyLabelPair(field.getPropertyName(), ruleTemplateAttribute.getRuleTemplateAttributeId()+""));
307                             } else {
308                                 myColumns.getColumns().add(new KeyLabelPair(field.getPropertyName(), ruleTemplateAttribute.getRuleTemplateAttributeId()+""));
309                             }
310                         }
311                     }
312                 }
313             }
314         }
315 
316         if (!Utilities.isEmpty(ruleDescription)) {
317             ruleDescription = ruleDescription.replace('*', '%');
318             ruleDescription = "%" + ruleDescription.trim() + "%";
319         }
320 
321         if (!errors.isEmpty()) {
322             throw new ValidationException("errors in search criteria");
323         }
324 
325         if(!Utilities.isEmpty(networkIdParam)){
326         workflowId = networkIdParam;
327         workflowId = KIMServiceLocator.getIdentityService().getPrincipalByPrincipalName(networkIdParam).getPrincipalId();
328         }
329 
330         Iterator<RuleDelegation> rules = getRuleDelegationService().search(parentRuleBaseValueId, parentResponsibilityId, docTypeSearchName, ruleId, ruleTemplateId, ruleDescription, workgroupId, workflowId, delegationParam, isActive, attributes, userDirectiveParam).iterator();
331         List<RuleDelegation> displayList = new ArrayList<RuleDelegation>();
332 
333         while (rules.hasNext()) {
334             RuleDelegation ruleDelegation = (RuleDelegation) rules.next();
335             RuleBaseValues record = ruleDelegation.getDelegationRuleBaseValues();
336 
337             if (Utilities.isEmpty(record.getDescription())) {
338                 record.setDescription(KEWConstants.HTML_NON_BREAKING_SPACE);
339             }
340 
341             if (ruleTemplateNameParam != null && !ruleTemplateNameParam.trim().equals("") || ruleTemplateIdParam != null && !"".equals(ruleTemplateIdParam) && !"null".equals(ruleTemplateIdParam)) {
342                 MyColumns myNewColumns = new MyColumns();
343                 for (Iterator iter = myColumns.getColumns().iterator(); iter.hasNext();) {
344                     KeyLabelPair pair = (KeyLabelPair) iter.next();
345                     KeyLabelPair newPair = new KeyLabelPair();
346                     newPair.setKey(pair.getKey());
347                     if (record.getRuleExtensionValue(new Long(pair.getLabel()), pair.getKey().toString()) != null) {
348                         newPair.setLabel(record.getRuleExtensionValue(new Long(pair.getLabel()), pair.getKey().toString()).getValue());
349                     } else {
350                         newPair.setLabel(KEWConstants.HTML_NON_BREAKING_SPACE);
351                     }
352                     myNewColumns.getColumns().add(newPair);
353                     record.getFieldValues().put((String)newPair.key, newPair.label);
354                 }
355                 record.setMyColumns(myNewColumns);
356             }
357 
358             StringBuffer returnUrl = new StringBuffer("<a href=\"");
359             returnUrl.append(fieldValues.get(BACK_LOCATION)).append("?methodToCall=refresh&docFormKey=").append(fieldValues.get(DOC_FORM_KEY)).append("&");
360 
361             returnUrl.append(RULE_ID_PROPERTY_NAME);
362             returnUrl.append("=").append(record.getRuleBaseValuesId()).append("\">return value</a>");
363             record.setReturnUrl(returnUrl.toString());
364 
365             String destinationUrl = "<a href=\"Rule.do?methodToCall=report&currentRuleId=" + record.getRuleBaseValuesId() + "\">report</a>";
366 
367             record.setDestinationUrl(destinationUrl);
368 
369             displayList.add(ruleDelegation);
370         }
371         return displayList;
372 
373     }
374 
375 
376 
377     private IdentityManagementService getIdentityManagementService() {
378        return (IdentityManagementService) KIMServiceLocator.getService(KIMServiceLocator.KIM_IDENTITY_MANAGEMENT_SERVICE);
379     }
380 
381     private RuleTemplateService getRuleTemplateService() {
382         return (RuleTemplateService) KEWServiceLocator.getService(KEWServiceLocator.RULE_TEMPLATE_SERVICE);
383     }
384     private RuleDelegationService getRuleDelegationService() {
385         return (RuleDelegationService) KEWServiceLocator.getService(KEWServiceLocator.RULE_DELEGATION_SERVICE);
386     }
387 
388     @Override
389     public void validateSearchParameters(Map fieldValues) {
390         super.validateSearchParameters(fieldValues);
391 
392         // make sure that if we have either groupName or Namespace, that both are filled in
393         String groupName = (String)fieldValues.get(GROUP_REVIEWER_NAME_PROPERTY_NAME);
394         String groupNamespace = (String)fieldValues.get(GROUP_REVIEWER_NAMESPACE_PROPERTY_NAME);
395         String personId = (String)fieldValues.get(PERSON_REVIEWER_PROPERTY_NAME);
396 
397         if (Utilities.isEmpty(groupName) && !Utilities.isEmpty(groupNamespace)) {
398             String attributeLabel = getDataDictionaryService().getAttributeLabel(getBusinessObjectClass(), GROUP_REVIEWER_NAME_PROPERTY_NAME);
399             GlobalVariables.getMessageMap().putError(GROUP_REVIEWER_NAME_PROPERTY_NAME, RiceKeyConstants.ERROR_REQUIRED, attributeLabel);
400         }
401 
402         if  (!Utilities.isEmpty(groupName) && Utilities.isEmpty(groupNamespace)) {
403             String attributeLabel = getDataDictionaryService().getAttributeLabel(getBusinessObjectClass(), GROUP_REVIEWER_NAMESPACE_PROPERTY_NAME);
404             GlobalVariables.getMessageMap().putError(GROUP_REVIEWER_NAMESPACE_PROPERTY_NAME, RiceKeyConstants.ERROR_REQUIRED, attributeLabel);
405         }
406 
407         if  (!Utilities.isEmpty(groupName) && !Utilities.isEmpty(groupNamespace)) {
408             Group group = KIMServiceLocator.getIdentityManagementService().getGroupByName(groupNamespace, groupName);
409             if (group == null) {
410                 String attributeLabel =  getDataDictionaryService().getAttributeLabel(getBusinessObjectClass(), GROUP_REVIEWER_NAMESPACE_PROPERTY_NAME) + ":" + getDataDictionaryService().getAttributeLabel(getBusinessObjectClass(), GROUP_REVIEWER_NAME_PROPERTY_NAME);
411                 GlobalVariables.getMessageMap().putError(GROUP_REVIEWER_NAME_PROPERTY_NAME, RiceKeyConstants.ERROR_CUSTOM, INVALID_WORKGROUP_ERROR);
412             }
413         }
414 
415         if  (!Utilities.isEmpty(personId)) {
416             //Person person = KIMServiceLocator.getPersonService().getPerson(personId);
417             Person person = KIMServiceLocator.getPersonService().getPersonByPrincipalName(personId);/** IU fix EN-1552 */
418             if (person == null) {
419                 String attributeLabel = getDataDictionaryService().getAttributeLabel(getBusinessObjectClass(), PERSON_REVIEWER_PROPERTY_NAME) + ":" + getDataDictionaryService().getAttributeLabel(getBusinessObjectClass(), PERSON_REVIEWER_PROPERTY_NAME);
420                 GlobalVariables.getMessageMap().putError(PERSON_REVIEWER_PROPERTY_NAME, RiceKeyConstants.ERROR_CUSTOM, INVALID_PERSON_ERROR);
421             }
422         }
423         if (!GlobalVariables.getMessageMap().isEmpty()) {
424             throw new ValidationException("errors in search criteria");
425         }
426     }
427 
428     @Override
429     public Collection performLookup(LookupForm lookupForm,
430             Collection resultTable, boolean bounded) {
431         // TODO jjhanso - THIS METHOD NEEDS JAVADOCS
432         //return super.performLookup(lookupForm, resultTable, bounded);
433         setBackLocation((String) lookupForm.getFieldsForLookup().get(KNSConstants.BACK_LOCATION));
434         setDocFormKey((String) lookupForm.getFieldsForLookup().get(KNSConstants.DOC_FORM_KEY));
435         Collection displayList;
436 
437         // call search method to get results
438         if (bounded) {
439             displayList = getSearchResults(lookupForm.getFieldsForLookup());
440         }
441         else {
442             displayList = getSearchResultsUnbounded(lookupForm.getFieldsForLookup());
443         }
444 
445         HashMap<String,Class> propertyTypes = new HashMap<String, Class>();
446 
447         boolean hasReturnableRow = false;
448 
449         List returnKeys = getReturnKeys();
450         List pkNames = getBusinessObjectMetaDataService().listPrimaryKeyFieldNames(getBusinessObjectClass());
451         Person user = GlobalVariables.getUserSession().getPerson();
452 
453         // iterate through result list and wrap rows with return url and action urls
454         for (Iterator iter = displayList.iterator(); iter.hasNext();) {
455             BusinessObject element = (BusinessObject) iter.next();
456             if(element instanceof PersistableBusinessObject){
457                 lookupForm.setLookupObjectId(((PersistableBusinessObject)element).getObjectId());
458             }
459 
460             BusinessObjectRestrictions businessObjectRestrictions = getBusinessObjectAuthorizationService().getLookupResultRestrictions(element, user);
461 
462             HtmlData returnUrl = getReturnUrl(element, lookupForm, returnKeys, businessObjectRestrictions);
463 
464             String actionUrls = getActionUrls(element, pkNames, businessObjectRestrictions);
465             //Fix for JIRA - KFSMI-2417
466             if("".equals(actionUrls)){
467                 actionUrls = ACTION_URLS_EMPTY;
468             }
469 
470             List<Column> columns = getColumns();
471             for (Iterator iterator = columns.iterator(); iterator.hasNext();) {
472 
473                 Column col = (Column) iterator.next();
474                 String curPropName = col.getPropertyName();
475                 Formatter formatter = col.getFormatter();
476 
477                 // pick off result column from result list, do formatting
478                 String propValue = KNSConstants.EMPTY_STRING;
479                 Object prop = null;
480                 boolean skipPropTypeCheck = false;
481                 //try to get value elsewhere
482                 if (element instanceof RuleDelegation) {
483                     prop = ((RuleDelegation)element).getDelegationRuleBaseValues().getFieldValues().get(curPropName);
484                     skipPropTypeCheck = true;
485                 }
486                 if (prop == null) {
487                     prop = ObjectUtils.getPropertyValue(element, curPropName);
488                 }
489 
490                 // set comparator and formatter based on property type
491                 Class propClass = propertyTypes.get(curPropName);
492                 if ( propClass == null && !skipPropTypeCheck) {
493                     try {
494                         propClass = ObjectUtils.getPropertyType( element, curPropName, getPersistenceStructureService() );
495                         propertyTypes.put( curPropName, propClass );
496                     } catch (Exception e) {
497                         throw new RuntimeException("Cannot access PropertyType for property " + "'" + curPropName + "' " + " on an instance of '" + element.getClass().getName() + "'.", e);
498                     }
499                 }
500 
501                 // formatters
502                 if (prop != null) {
503                     // for Booleans, always use BooleanFormatter
504                     if (prop instanceof Boolean) {
505                         formatter = new BooleanFormatter();
506                     }
507 
508                     // for Dates, always use DateFormatter
509                     if (prop instanceof Date) {
510                         formatter = new DateFormatter();
511                     }
512 
513                     // for collection, use the list formatter if a formatter hasn't been defined yet
514                     if (prop instanceof Collection && formatter == null) {
515                     formatter = new CollectionFormatter();
516                     }
517 
518                     if (formatter != null) {
519                         propValue = (String) formatter.format(prop);
520                     }
521                     else {
522                         propValue = prop.toString();
523                     }
524                 }
525 
526                 // comparator
527                 col.setComparator(CellComparatorHelper.getAppropriateComparatorForPropertyClass(propClass));
528                 col.setValueComparator(CellComparatorHelper.getAppropriateValueComparatorForPropertyClass(propClass));
529 
530                 propValue = maskValueIfNecessary(element.getClass(), curPropName, propValue, businessObjectRestrictions);
531 
532                 col.setPropertyValue(propValue);
533 
534                 if (StringUtils.isNotBlank(propValue)) {
535                     col.setColumnAnchor(getInquiryUrl(element, curPropName));
536 
537                 }
538             }
539 
540             ResultRow row = new ResultRow(columns, returnUrl.constructCompleteHtmlTag(), actionUrls);
541             row.setRowId(returnUrl.getName());
542             row.setReturnUrlHtmlData(returnUrl);
543             // because of concerns of the BO being cached in session on the ResultRow,
544             // let's only attach it when needed (currently in the case of export)
545             if (getBusinessObjectDictionaryService().isExportable(getBusinessObjectClass())) {
546                 row.setBusinessObject(element);
547             }
548             if(element instanceof PersistableBusinessObject){
549                 row.setObjectId((((PersistableBusinessObject)element).getObjectId()));
550             }
551 
552 
553             boolean rowReturnable = isResultReturnable(element);
554             row.setRowReturnable(rowReturnable);
555             if (rowReturnable) {
556                 hasReturnableRow = true;
557             }
558             resultTable.add(row);
559         }
560 
561         lookupForm.setHasReturnableRow(hasReturnableRow);
562 
563         return displayList;
564     }
565 
566     @Override
567     public List<Column> getColumns() {
568         List<Column> columns = super.getColumns();
569         for (Row row : rows) {
570             for (Field field : row.getFields()) {
571                 Column newColumn = new Column();
572                 newColumn.setColumnTitle(field.getFieldLabel());
573                 newColumn.setMaxLength(field.getMaxLength());
574                 newColumn.setPropertyName(field.getPropertyName());
575                 columns.add(newColumn);
576             }
577         }
578         return columns;
579     }
580 
581     @Override
582     public List<HtmlData> getCustomActionUrls(BusinessObject businessObject,
583             List pkNames) {
584         RuleDelegation ruleDelegation = (RuleDelegation)businessObject;
585         List<HtmlData> htmlDataList = new ArrayList<HtmlData>();
586         if (StringUtils.isNotBlank(ruleDelegation.getDelegationRuleBaseValues().getRuleTemplateName()) && StringUtils.isNotBlank(getMaintenanceDocumentTypeName())) {
587         	if (allowsMaintenanceEditAction(businessObject)) {
588         		htmlDataList.add(getUrlData(businessObject, KNSConstants.MAINTENANCE_EDIT_METHOD_TO_CALL, pkNames));
589         	}
590             if (allowsMaintenanceNewOrCopyAction()) {
591                 htmlDataList.add(getUrlData(businessObject, KNSConstants.MAINTENANCE_COPY_METHOD_TO_CALL, pkNames));
592             }
593         }
594             
595         return htmlDataList;
596     }
597 
598 
599 
600 }