Coverage Report - org.kuali.rice.kew.rule.bo.RuleBaseValuesLookupableHelperServiceImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
RuleBaseValuesLookupableHelperServiceImpl
0%
0/329
0%
0/226
13
 
 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.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.RuleExtension;
 33  
 import org.kuali.rice.kew.rule.WorkflowAttribute;
 34  
 import org.kuali.rice.kew.rule.service.RuleService;
 35  
 import org.kuali.rice.kew.rule.service.RuleTemplateService;
 36  
 import org.kuali.rice.kew.rule.web.WebRuleUtils;
 37  
 import org.kuali.rice.kew.rule.xmlrouting.GenericXMLRuleAttribute;
 38  
 import org.kuali.rice.kew.service.KEWServiceLocator;
 39  
 import org.kuali.rice.kew.util.KEWConstants;
 40  
 import org.kuali.rice.kim.api.group.Group;
 41  
 import org.kuali.rice.kim.api.group.GroupService;
 42  
 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
 43  
 import org.kuali.rice.kim.bo.Person;
 44  
 import org.kuali.rice.kim.util.KimConstants;
 45  
 import org.kuali.rice.kns.document.authorization.BusinessObjectRestrictions;
 46  
 import org.kuali.rice.kns.lookup.HtmlData;
 47  
 import org.kuali.rice.kns.lookup.KualiLookupableHelperServiceImpl;
 48  
 import org.kuali.rice.kns.lookup.LookupableHelperService;
 49  
 import org.kuali.rice.kns.service.KNSServiceLocator;
 50  
 import org.kuali.rice.kns.web.comparator.CellComparatorHelper;
 51  
 import org.kuali.rice.kns.web.struts.form.LookupForm;
 52  
 import org.kuali.rice.kns.web.ui.Column;
 53  
 import org.kuali.rice.kns.web.ui.Field;
 54  
 import org.kuali.rice.kns.web.ui.ResultRow;
 55  
 import org.kuali.rice.kns.web.ui.Row;
 56  
 import org.kuali.rice.krad.bo.BusinessObject;
 57  
 import org.kuali.rice.krad.bo.PersistableBusinessObject;
 58  
 import org.kuali.rice.krad.exception.ValidationException;
 59  
 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
 60  
 import org.kuali.rice.krad.util.GlobalVariables;
 61  
 import org.kuali.rice.krad.util.KRADConstants;
 62  
 import org.kuali.rice.krad.util.ObjectUtils;
 63  
 
 64  
 import java.sql.Date;
 65  
 import java.util.ArrayList;
 66  
 import java.util.Collection;
 67  
 import java.util.HashMap;
 68  
 import java.util.Iterator;
 69  
 import java.util.List;
 70  
 import java.util.Map;
 71  
 
 72  
 /**
 73  
  * This is a description of what this class does - jjhanso don't forget to fill this in.
 74  
  *
 75  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 76  
  *
 77  
  */
 78  0
 public class RuleBaseValuesLookupableHelperServiceImpl extends KualiLookupableHelperServiceImpl {
 79  0
     private List<Row> rows = new ArrayList<Row>();
 80  
     //private List<Column> columns = establishColumns();
 81  
     //private Long previousRuleTemplateId;
 82  
     private LookupableHelperService ruleDelegationLookupableHelperService;
 83  
     private List<?> delegationPkNames;
 84  
 
 85  
     private static final String RULE_TEMPLATE_PROPERTY_NAME = "ruleTemplate.name";
 86  
     private static final String RULE_ID_PROPERTY_NAME = "ruleBaseValuesId";
 87  
     private static final String RULE_TEMPLATE_ID_PROPERTY_NAME = "ruleTemplateId";
 88  
     private static final String ACTIVE_IND_PROPERTY_NAME = "activeInd";
 89  
     private static final String DELEGATE_RULE_PROPERTY_NAME = "delegateRule";
 90  
     private static final String GROUP_REVIEWER_PROPERTY_NAME = "groupReviewer";
 91  
     private static final String GROUP_REVIEWER_NAME_PROPERTY_NAME = "groupReviewerName";
 92  
     private static final String GROUP_REVIEWER_NAMESPACE_PROPERTY_NAME = "groupReviewerNamespace";
 93  
     private static final String PERSON_REVIEWER_PROPERTY_NAME = "personReviewer";
 94  
     private static final String PERSON_REVIEWER_TYPE_PROPERTY_NAME = "personReviewerType";
 95  
     private static final String DOC_TYP_NAME_PROPERTY_NAME = "documentType.name";
 96  
     private static final String RULE_DESC_PROPERTY_NAME = "description";
 97  
 
 98  
     private static final String BACK_LOCATION = "backLocation";
 99  
     private static final String DOC_FORM_KEY = "docFormKey";
 100  
     private static final String INVALID_WORKGROUP_ERROR = "The Group Reviewer Namespace and Name combination is not valid";
 101  
     private static final String INVALID_PERSON_ERROR = "The Person Reviewer is not valid";
 102  
 
 103  
     @Override
 104  
         public List<Row> getRows() {
 105  0
         List<Row> superRows = super.getRows();
 106  0
         List<Row> returnRows = new ArrayList<Row>();
 107  0
         returnRows.addAll(superRows);
 108  0
         returnRows.addAll(rows);
 109  0
         return returnRows;
 110  
     }
 111  
 
 112  
     @Override
 113  
     public boolean checkForAdditionalFields(Map fieldValues) {
 114  0
         String ruleTemplateNameParam = (String) fieldValues.get(RULE_TEMPLATE_PROPERTY_NAME);
 115  
 
 116  0
         if (ruleTemplateNameParam != null && !ruleTemplateNameParam.equals("")) {
 117  0
             rows = new ArrayList<Row>();
 118  0
             RuleTemplate ruleTemplate = null;
 119  
 
 120  0
             ruleTemplate = getRuleTemplateService().findByRuleTemplateName(ruleTemplateNameParam);
 121  
 
 122  0
             for (Object element : ruleTemplate.getActiveRuleTemplateAttributes()) {
 123  0
                 RuleTemplateAttribute ruleTemplateAttribute = (RuleTemplateAttribute) element;
 124  0
                 if (!ruleTemplateAttribute.isWorkflowAttribute()) {
 125  0
                     continue;
 126  
                 }
 127  0
                 WorkflowAttribute attribute = ruleTemplateAttribute.getWorkflowAttribute();
 128  0
                 RuleAttribute ruleAttribute = ruleTemplateAttribute.getRuleAttribute();
 129  0
                 if (ruleAttribute.getType().equals(KEWConstants.RULE_XML_ATTRIBUTE_TYPE)) {
 130  0
                     ((GenericXMLRuleAttribute) attribute).setRuleAttribute(ruleAttribute);
 131  
                 }
 132  
                 // run through the attributes fields once to populate field values we have to do this
 133  
                 // to allow rows dependent on another row value to populate correctly in the loop below
 134  0
                 List<Row> searchRows = null;
 135  0
                 if (attribute instanceof OddSearchAttribute) {
 136  0
                     searchRows = ((OddSearchAttribute) attribute).getSearchRows();
 137  
                 } else {
 138  0
                     searchRows = attribute.getRuleRows();
 139  
                 }
 140  0
                 for (Row row : searchRows) {
 141  0
                     List<Field> fields = new ArrayList<Field>();
 142  0
                     for (Field field2 : row.getFields()) {
 143  0
                         Field field = field2;
 144  0
                         if (fieldValues.get(field.getPropertyName()) != null) {
 145  0
                             field.setPropertyValue(fieldValues.get(field.getPropertyName()));
 146  
                         }
 147  0
                         fields.add(field);
 148  0
                         fieldValues.put(field.getPropertyName(), field.getPropertyValue());
 149  0
                     }
 150  0
                 }
 151  
 
 152  0
                 if (attribute instanceof OddSearchAttribute) {
 153  0
                     ((OddSearchAttribute) attribute).validateSearchData(fieldValues);
 154  
                 } else {
 155  0
                     attribute.validateRuleData(fieldValues);// populate attribute
 156  
                 }
 157  
 
 158  0
                 if (attribute instanceof OddSearchAttribute) {
 159  0
                     searchRows = ((OddSearchAttribute) attribute).getSearchRows();
 160  
                 } else {
 161  0
                     searchRows = attribute.getRuleRows();
 162  
                 }
 163  0
                 for (Object element2 : searchRows) {
 164  0
                     Row row = (Row) element2;
 165  0
                     List<Field> fields = new ArrayList<Field>();
 166  0
                     for (Field field : row.getFields()) {
 167  0
                         if (fieldValues.get(field.getPropertyName()) != null) {
 168  0
                             field.setPropertyValue(fieldValues.get(field.getPropertyName()));
 169  
                         }
 170  0
                         fields.add(field);
 171  0
                         fieldValues.put(field.getPropertyName(), field.getPropertyValue());
 172  
                     }
 173  0
                     row.setFields(fields);
 174  0
                     rows.add(row);
 175  
 
 176  0
                 }
 177  
 
 178  0
             }
 179  
 
 180  0
             return true;
 181  
         }
 182  0
         rows.clear();
 183  0
         return false;
 184  
     }
 185  
 
 186  
     @Override
 187  
     public List<? extends BusinessObject> getSearchResults(Map<String, String> fieldValues) {
 188  0
         new ArrayList();
 189  
 
 190  0
         String docTypeNameParam = fieldValues.get(DOC_TYP_NAME_PROPERTY_NAME);
 191  0
         String ruleTemplateIdParam = fieldValues.get(RULE_TEMPLATE_ID_PROPERTY_NAME);
 192  0
         String ruleTemplateNameParam = fieldValues.get(RULE_TEMPLATE_PROPERTY_NAME);
 193  0
         String groupIdParam = fieldValues.get(GROUP_REVIEWER_PROPERTY_NAME);
 194  0
         String groupNameParam = fieldValues.get(GROUP_REVIEWER_NAME_PROPERTY_NAME);
 195  0
         String groupNamespaceParam = fieldValues.get(GROUP_REVIEWER_NAMESPACE_PROPERTY_NAME);
 196  0
         String networkIdParam = fieldValues.get(PERSON_REVIEWER_PROPERTY_NAME);
 197  0
         String userDirectiveParam = fieldValues.get(PERSON_REVIEWER_TYPE_PROPERTY_NAME);
 198  0
         String activeParam = fieldValues.get(ACTIVE_IND_PROPERTY_NAME);
 199  0
         String ruleIdParam = fieldValues.get(RULE_ID_PROPERTY_NAME);
 200  0
         String ruleDescription = fieldValues.get(RULE_DESC_PROPERTY_NAME);
 201  0
         String deleteSelection = fieldValues.get(DELEGATE_RULE_PROPERTY_NAME);
 202  
 
 203  0
         String docTypeSearchName = null;
 204  0
         String workflowId = null;
 205  0
         String workgroupId = null;
 206  0
         String ruleTemplateId = null;
 207  0
         Boolean isDelegateRule = null;
 208  0
         Boolean isActive = null;
 209  0
         String ruleId = null;
 210  
       
 211  
         
 212  
         //for KULRICE-3678
 213  0
         if(deleteSelection != null && !"".equals(deleteSelection.trim()))
 214  
         {
 215  0
                 if(deleteSelection.equalsIgnoreCase("Y")) {
 216  0
                                 isDelegateRule = Boolean.TRUE;
 217  
                         } else {
 218  0
                                 isDelegateRule = Boolean.FALSE;
 219  
                         }
 220  
         }
 221  
         
 222  0
         if (ruleIdParam != null && !"".equals(ruleIdParam.trim())) {
 223  
             try {
 224  0
                 ruleId = ruleIdParam.trim();
 225  0
             } catch (NumberFormatException e) {
 226  
                 // FIXME: KULRICE-5201 / KULRICE-5329 : Need to check to see if this makes sense now that ruleId is not a Long anymore
 227  0
                     ruleId = "-1";
 228  0
             }
 229  
         }
 230  
 
 231  0
         if (!activeParam.equals("")) {
 232  0
             if (activeParam.equals("Y")) {
 233  0
                 isActive = Boolean.TRUE;
 234  
             } else {
 235  0
                 isActive = Boolean.FALSE;
 236  
             }
 237  
         }
 238  
 
 239  0
         if (docTypeNameParam != null && !"".equals(docTypeNameParam.trim())) {
 240  0
             docTypeSearchName = docTypeNameParam.replace('*', '%');
 241  0
             docTypeSearchName = "%" + docTypeSearchName.trim() + "%";
 242  
         }
 243  
 
 244  0
         if (!org.apache.commons.lang.StringUtils.isEmpty(networkIdParam)) {
 245  0
                 Person person = KimApiServiceLocator.getPersonService().getPersonByPrincipalName(networkIdParam);
 246  0
                 if (person != null) {
 247  0
                         workflowId = person.getPrincipalId();
 248  
                 }
 249  
         }
 250  
         
 251  0
         if (!org.apache.commons.lang.StringUtils.isEmpty(groupIdParam) || !org.apache.commons.lang.StringUtils.isEmpty(groupNameParam)) {
 252  0
             Group group = null;
 253  0
             if (groupIdParam != null && !"".equals(groupIdParam)) {
 254  0
                 group = getGroupService().getGroup(groupIdParam.trim());
 255  
             } else {
 256  0
                 if (groupNamespaceParam == null) {
 257  0
                     groupNamespaceParam = KimConstants.KIM_GROUP_DEFAULT_NAMESPACE_CODE;
 258  
                 }
 259  0
                 group = getGroupService().getGroupByName(groupNamespaceParam, groupNameParam.trim());
 260  0
                 if (group == null) {
 261  0
                     GlobalVariables.getMessageMap().putError(GROUP_REVIEWER_NAMESPACE_PROPERTY_NAME, RiceKeyConstants.ERROR_CUSTOM, INVALID_WORKGROUP_ERROR);
 262  
                 } else {
 263  0
                     workgroupId = group.getId();
 264  
                 }
 265  
             }
 266  
         }
 267  
 
 268  0
         Map attributes = null;
 269  0
         MyColumns myColumns = new MyColumns();
 270  0
         if (ruleTemplateNameParam != null && !ruleTemplateNameParam.trim().equals("") || ruleTemplateIdParam != null && !"".equals(ruleTemplateIdParam) && !"null".equals(ruleTemplateIdParam)) {
 271  0
             RuleTemplate ruleTemplate = null;
 272  0
             if (ruleTemplateIdParam != null && !"".equals(ruleTemplateIdParam)) {
 273  0
                 ruleTemplateId = ruleTemplateIdParam;
 274  0
                 ruleTemplate = getRuleTemplateService().findByRuleTemplateId(ruleTemplateId);
 275  
             } else {
 276  0
                 ruleTemplate = getRuleTemplateService().findByRuleTemplateName(ruleTemplateNameParam.trim());
 277  0
                 ruleTemplateId = ruleTemplate.getRuleTemplateId();
 278  
             }
 279  
 
 280  0
             attributes = new HashMap();
 281  0
             for (Iterator iter = ruleTemplate.getActiveRuleTemplateAttributes().iterator(); iter.hasNext();) {
 282  0
                 RuleTemplateAttribute ruleTemplateAttribute = (RuleTemplateAttribute) iter.next();
 283  0
                 if (!ruleTemplateAttribute.isWorkflowAttribute()) {
 284  0
                     continue;
 285  
                 }
 286  0
                 WorkflowAttribute attribute = (WorkflowAttribute)GlobalResourceLoader.getObject(new ObjectDefinition(ruleTemplateAttribute.getRuleAttribute().getClassName(), ruleTemplateAttribute.getRuleAttribute().getApplicationId()));//SpringServiceLocator.getExtensionService().getWorkflowAttribute(ruleTemplateAttribute.getRuleAttribute().getClassName());
 287  0
                 RuleAttribute ruleAttribute = ruleTemplateAttribute.getRuleAttribute();
 288  0
                 if (ruleAttribute.getType().equals(KEWConstants.RULE_XML_ATTRIBUTE_TYPE)) {
 289  0
                     ((GenericXMLRuleAttribute) attribute).setRuleAttribute(ruleAttribute);
 290  
                 }
 291  0
                 attribute.setRequired(false);
 292  0
                 List<Row> searchRows = null;
 293  0
                 String curExtId = "0";//debugging for EN-1682
 294  0
                 if (attribute instanceof OddSearchAttribute) {
 295  0
                     for (WorkflowServiceErrorImpl wsei : (List<WorkflowServiceErrorImpl>)((OddSearchAttribute)attribute).validateSearchData(fieldValues)) {
 296  0
                         GlobalVariables.getMessageMap().putError(wsei.getMessage(), RiceKeyConstants.ERROR_CUSTOM, wsei.getArg1());
 297  
                     }                   
 298  
                     try {
 299  0
                                                 List<RuleExtension> curExts = ruleTemplateAttribute.getRuleExtensions();
 300  0
                                 for (Object element : curExts) {
 301  0
                                         RuleExtension curExt = (RuleExtension) iter.next();
 302  0
                                         curExtId = curExt.getRuleExtensionId();
 303  0
                                         RuleBaseValues curRule = curExt.getRuleBaseValues();
 304  0
                                                         attribute.validateRuleData(WebRuleUtils.getFieldMapForRuleTemplateAttribute(curRule, ruleTemplateAttribute));
 305  0
                     }
 306  0
                                         } catch (Exception e) {                                                
 307  0
                                                 LOG.warn("Exception caught attempting to validate attribute data for extension id:" + curExtId + ". Reason: " + e.getCause());
 308  0
                                         }
 309  
                     
 310  0
                     searchRows = ((OddSearchAttribute) attribute).getSearchRows();
 311  
                 } else {
 312  0
                     for (WorkflowServiceErrorImpl wsei : (List<WorkflowServiceErrorImpl>)attribute.validateRuleData(fieldValues)) {
 313  0
                         GlobalVariables.getMessageMap().putError(wsei.getMessage(), RiceKeyConstants.ERROR_CUSTOM, wsei.getArg1());
 314  
                     }
 315  
                    
 316  
                                         try {
 317  0
                                                 List<RuleExtension> curExts = ruleTemplateAttribute.getRuleExtensions();
 318  0
                                 for (Object element : curExts) {
 319  0
                                         RuleExtension curExt = (RuleExtension) iter.next();
 320  0
                                         curExtId = curExt.getRuleExtensionId();
 321  0
                                         RuleBaseValues curRule = curExt.getRuleBaseValues();
 322  0
                                                         attribute.validateRuleData(WebRuleUtils.getFieldMapForRuleTemplateAttribute(curRule, ruleTemplateAttribute));
 323  0
                                 }
 324  0
                                         } catch (Exception e) {                                                
 325  0
                                                 LOG.warn("Exception caught attempting to validate attribute data for extension id:" + curExtId + ". Reason: " + e.getCause());
 326  0
                                         }
 327  
                  
 328  0
                     searchRows = attribute.getRuleRows();
 329  
                 }
 330  0
                 for (Row row : searchRows) {
 331  0
                     for (Field field : row.getFields()) {
 332  0
                         if (fieldValues.get(field.getPropertyName()) != null) {
 333  0
                             String attributeParam = fieldValues.get(field.getPropertyName());
 334  0
                             if (!attributeParam.equals("")) {
 335  0
                                 if (ruleAttribute.getType().equals(KEWConstants.RULE_XML_ATTRIBUTE_TYPE)) {
 336  0
                                     attributes.put(field.getPropertyName(), attributeParam.trim());
 337  
                                 } else {
 338  0
                                     attributes.put(field.getPropertyName(), attributeParam.trim());
 339  
                                 }
 340  
                             }
 341  
                         }
 342  0
                         if (field.getFieldType().equals(Field.TEXT) || field.getFieldType().equals(Field.DROPDOWN) || field.getFieldType().equals(Field.DROPDOWN_REFRESH) || field.getFieldType().equals(Field.RADIO)) {
 343  0
                             if (ruleAttribute.getType().equals(KEWConstants.RULE_XML_ATTRIBUTE_TYPE)) {
 344  0
                                 myColumns.getColumns().add(new ConcreteKeyValue(field.getPropertyName(), ruleTemplateAttribute.getRuleTemplateAttributeId()+""));
 345  
                             } else {
 346  0
                                 myColumns.getColumns().add(new ConcreteKeyValue(field.getPropertyName(), ruleTemplateAttribute.getRuleTemplateAttributeId()+""));
 347  
                             }
 348  
                         }
 349  
                     }
 350  
                 }
 351  0
             }
 352  
         }
 353  
 
 354  0
         if (!org.apache.commons.lang.StringUtils.isEmpty(ruleDescription)) {
 355  0
             ruleDescription = ruleDescription.replace('*', '%');
 356  0
             ruleDescription = "%" + ruleDescription.trim() + "%";
 357  
         }
 358  
        
 359  0
         if (!GlobalVariables.getMessageMap().hasNoErrors()) {
 360  0
             throw new ValidationException("errors in search criteria");
 361  
         }
 362  
        
 363  
 
 364  0
         Iterator rules = getRuleService().search(docTypeSearchName, ruleId, ruleTemplateId, ruleDescription, workgroupId, workflowId, isDelegateRule, isActive, attributes, userDirectiveParam).iterator();
 365  0
         List displayList = new ArrayList();
 366  
 
 367  0
         while (rules.hasNext()) {
 368  0
             RuleBaseValues record = (RuleBaseValues) rules.next();
 369  
 
 370  0
             if (org.apache.commons.lang.StringUtils.isEmpty(record.getDescription())) {
 371  
                     
 372  0
                 record.setDescription("");
 373  
             }
 374  
 
 375  0
             if (ruleTemplateNameParam != null && !ruleTemplateNameParam.trim().equals("") || ruleTemplateIdParam != null && !"".equals(ruleTemplateIdParam) && !"null".equals(ruleTemplateIdParam)) {
 376  0
                 MyColumns myNewColumns = new MyColumns();
 377  0
                 for (KeyValue pair : myColumns.getColumns()) {
 378  
                     final KeyValue newPair;
 379  0
                     if (record.getRuleExtensionValue(pair.getValue(), pair.getKey().toString()) != null) {
 380  0
                             newPair = new ConcreteKeyValue(pair.getKey(), record.getRuleExtensionValue(pair.getValue(), pair.getKey().toString()).getValue());
 381  
                     } else {
 382  0
                             newPair = new ConcreteKeyValue(pair.getKey(), "");
 383  
                     }
 384  0
                     myNewColumns.getColumns().add(newPair);
 385  0
                     record.getFieldValues().put(newPair.getKey(), newPair.getValue());
 386  0
                 }
 387  0
                 record.setMyColumns(myNewColumns);
 388  
             }
 389  
 
 390  0
             StringBuffer returnUrl = new StringBuffer("<a href=\"");
 391  0
             returnUrl.append(fieldValues.get(BACK_LOCATION)).append("?methodToCall=refresh&docFormKey=").append(fieldValues.get(DOC_FORM_KEY)).append("&");
 392  
 
 393  0
             returnUrl.append(RULE_ID_PROPERTY_NAME);
 394  0
             returnUrl.append("=").append(record.getRuleBaseValuesId()).append("\">return value</a>");
 395  0
             record.setReturnUrl(returnUrl.toString());
 396  
 
 397  0
             String destinationUrl = "<a href=\"Rule.do?methodToCall=report&currentRuleId=" + record.getRuleBaseValuesId() + "\">report</a>";
 398  
 
 399  0
             record.setDestinationUrl(destinationUrl);
 400  
 
 401  0
             displayList.add(record);
 402  0
         }
 403  0
         return displayList;
 404  
 
 405  
     }
 406  
 
 407  
 
 408  
 
 409  
     private GroupService getGroupService() {
 410  0
        return KimApiServiceLocator.getGroupService();
 411  
     }
 412  
 
 413  
     private RuleTemplateService getRuleTemplateService() {
 414  0
         return (RuleTemplateService) KEWServiceLocator.getService(KEWServiceLocator.RULE_TEMPLATE_SERVICE);
 415  
     }
 416  
     private RuleService getRuleService() {
 417  0
         return (RuleService) KEWServiceLocator.getService(KEWServiceLocator.RULE_SERVICE);
 418  
     }
 419  
 
 420  
     @Override
 421  
     public void validateSearchParameters(Map fieldValues) {
 422  0
         super.validateSearchParameters(fieldValues);
 423  
 
 424  
         // make sure that if we have either groupName or Namespace, that both are filled in
 425  0
         String groupName = (String)fieldValues.get(GROUP_REVIEWER_NAME_PROPERTY_NAME);
 426  0
         String groupNamespace = (String)fieldValues.get(GROUP_REVIEWER_NAMESPACE_PROPERTY_NAME);
 427  0
         String principalName = (String)fieldValues.get(PERSON_REVIEWER_PROPERTY_NAME);
 428  
 
 429  0
         if (org.apache.commons.lang.StringUtils.isEmpty(groupName) && !org.apache.commons.lang.StringUtils.isEmpty(groupNamespace)) {
 430  0
             String attributeLabel = getDataDictionaryService().getAttributeLabel(getBusinessObjectClass(), GROUP_REVIEWER_NAME_PROPERTY_NAME);
 431  0
             GlobalVariables.getMessageMap().putError(GROUP_REVIEWER_NAME_PROPERTY_NAME, RiceKeyConstants.ERROR_REQUIRED, attributeLabel);
 432  
         }
 433  
 
 434  0
         if  (!org.apache.commons.lang.StringUtils.isEmpty(groupName) && org.apache.commons.lang.StringUtils.isEmpty(groupNamespace)) {
 435  0
             String attributeLabel = getDataDictionaryService().getAttributeLabel(getBusinessObjectClass(), GROUP_REVIEWER_NAMESPACE_PROPERTY_NAME);
 436  0
             GlobalVariables.getMessageMap().putError(GROUP_REVIEWER_NAMESPACE_PROPERTY_NAME, RiceKeyConstants.ERROR_REQUIRED, attributeLabel);
 437  
         }
 438  
 
 439  0
         if  (!org.apache.commons.lang.StringUtils.isEmpty(groupName) && !org.apache.commons.lang.StringUtils.isEmpty(groupNamespace)) {
 440  0
             Group group = KimApiServiceLocator.getGroupService().getGroupByName(groupNamespace, groupName);
 441  0
             if (group == null) {
 442  0
                 GlobalVariables.getMessageMap().putError(GROUP_REVIEWER_NAME_PROPERTY_NAME, RiceKeyConstants.ERROR_CUSTOM, INVALID_WORKGROUP_ERROR);
 443  
             }
 444  
         }
 445  
 
 446  0
         if  (!org.apache.commons.lang.StringUtils.isEmpty(principalName)) {
 447  0
             Person person = KimApiServiceLocator.getPersonService().getPersonByPrincipalName(principalName);
 448  0
             if (person == null) {
 449  0
                 GlobalVariables.getMessageMap().putError(PERSON_REVIEWER_PROPERTY_NAME, RiceKeyConstants.ERROR_CUSTOM, INVALID_PERSON_ERROR);
 450  
             }
 451  
         }
 452  0
         if (!GlobalVariables.getMessageMap().hasNoErrors()) {
 453  0
             throw new ValidationException("errors in search criteria");
 454  
         }
 455  0
     }
 456  
 
 457  
     @Override
 458  
     public Collection performLookup(LookupForm lookupForm,
 459  
             Collection resultTable, boolean bounded) {
 460  
         // TODO jjhanso - THIS METHOD NEEDS JAVADOCS
 461  
         //return super.performLookup(lookupForm, resultTable, bounded);
 462  0
         setBackLocation((String) lookupForm.getFieldsForLookup().get(KRADConstants.BACK_LOCATION));
 463  0
         setDocFormKey((String) lookupForm.getFieldsForLookup().get(KRADConstants.DOC_FORM_KEY));
 464  
         Collection displayList;
 465  
 
 466  
         // call search method to get results
 467  0
         if (bounded) {
 468  0
             displayList = getSearchResults(lookupForm.getFieldsForLookup());
 469  
         }
 470  
         else {
 471  0
             displayList = getSearchResultsUnbounded(lookupForm.getFieldsForLookup());
 472  
         }
 473  
 
 474  0
         HashMap<String,Class> propertyTypes = new HashMap<String, Class>();
 475  
 
 476  0
         boolean hasReturnableRow = false;
 477  
 
 478  0
         List returnKeys = getReturnKeys();
 479  0
         List pkNames = getBusinessObjectMetaDataService().listPrimaryKeyFieldNames(getBusinessObjectClass());
 480  0
         Person user = GlobalVariables.getUserSession().getPerson();
 481  
         
 482  
         // iterate through result list and wrap rows with return url and action urls
 483  0
         for (Iterator iter = displayList.iterator(); iter.hasNext();) {
 484  0
             BusinessObject element = (BusinessObject) iter.next();
 485  0
             if(element instanceof PersistableBusinessObject){
 486  0
                 lookupForm.setLookupObjectId(((PersistableBusinessObject)element).getObjectId());
 487  
             }
 488  
 
 489  0
             BusinessObjectRestrictions businessObjectRestrictions = getBusinessObjectAuthorizationService().getLookupResultRestrictions(element, user);
 490  
 
 491  0
             HtmlData returnUrl = getReturnUrl(element, lookupForm, returnKeys, businessObjectRestrictions);
 492  
 
 493  0
             String actionUrls = getActionUrls(element, pkNames, businessObjectRestrictions);
 494  
             //Fix for JIRA - KFSMI-2417
 495  0
             if("".equals(actionUrls)){
 496  0
                 actionUrls = ACTION_URLS_EMPTY;
 497  
             }
 498  
 
 499  
             // Determine whether or not this rule is a delegate rule.
 500  0
             boolean isRuleDelegation = (element instanceof RuleBaseValues && ((RuleBaseValues) element).getDelegateRule().booleanValue());
 501  
             
 502  0
             List<Column> columns = getColumns();
 503  0
             for (Object element2 : columns) {
 504  
 
 505  0
                 Column col = (Column) element2;
 506  0
                 Formatter formatter = col.getFormatter();
 507  
 
 508  
                 // pick off result column from result list, do formatting
 509  0
                 String propValue = KRADConstants.EMPTY_STRING;
 510  0
                 Object prop = null;
 511  0
                 boolean skipPropTypeCheck = false;
 512  
                 //try to get value elsewhere
 513  0
                 if (element instanceof RuleBaseValues) {
 514  0
                     prop = ((RuleBaseValues)element).getFieldValues().get(col.getPropertyName());
 515  0
                     skipPropTypeCheck = true;
 516  
                 }
 517  0
                 if (prop == null) {
 518  0
                     prop = ObjectUtils.getPropertyValue(element, col.getPropertyName());
 519  
                 }
 520  
 
 521  
                 // set comparator and formatter based on property type
 522  0
                 Class propClass = propertyTypes.get(col.getPropertyName());
 523  0
                 if ( propClass == null && !skipPropTypeCheck) {
 524  
                     try {
 525  0
                         propClass = ObjectUtils.getPropertyType( element, col.getPropertyName(), getPersistenceStructureService() );
 526  0
                         propertyTypes.put( col.getPropertyName(), propClass );
 527  0
                     } catch (Exception e) {
 528  0
                         throw new RuntimeException("Cannot access PropertyType for property " + "'" + col.getPropertyName() + "' " + " on an instance of '" + element.getClass().getName() + "'.", e);
 529  0
                     }
 530  
                 }
 531  
 
 532  
                 // formatters
 533  0
                 if (prop != null) {
 534  
                     // for Booleans, always use BooleanFormatter
 535  0
                     if (prop instanceof Boolean) {
 536  0
                         formatter = new BooleanFormatter();
 537  
                     }
 538  
 
 539  
                     // for Dates, always use DateFormatter
 540  0
                     if (prop instanceof Date) {
 541  0
                         formatter = new DateFormatter();
 542  
                     }
 543  
 
 544  
                     // for collection, use the list formatter if a formatter hasn't been defined yet
 545  0
                     if (prop instanceof Collection && formatter == null) {
 546  0
                     formatter = new CollectionFormatter();
 547  
                     }
 548  
 
 549  0
                     if (formatter != null) {
 550  0
                         propValue = (String) formatter.format(prop);
 551  
                     }
 552  
                     else {
 553  0
                         propValue = prop.toString();
 554  
                     }
 555  
                 }
 556  
 
 557  
                 // comparator
 558  0
                 col.setComparator(CellComparatorHelper.getAppropriateComparatorForPropertyClass(propClass));
 559  0
                 col.setValueComparator(CellComparatorHelper.getAppropriateValueComparatorForPropertyClass(propClass));
 560  
 
 561  0
                 propValue = maskValueIfNecessary(element.getClass(), col.getPropertyName(), propValue, businessObjectRestrictions);
 562  
 
 563  0
                 col.setPropertyValue(propValue);
 564  
 
 565  0
                 if (StringUtils.isNotBlank(propValue)) {
 566  0
                         if (RULE_ID_PROPERTY_NAME.equals(col.getPropertyName()) && isRuleDelegation) {
 567  
                                 // If the row represents a delegate rule, make the ID column's inquiry link lead to the corresponding delegate rule instead.
 568  0
                                    List<?> delegationList = KEWServiceLocator.getRuleDelegationService().findByDelegateRuleId(
 569  
                                                    ((RuleBaseValues) element).getRuleBaseValuesId());
 570  0
                                 if (ObjectUtils.isNotNull(delegationList) && !delegationList.isEmpty()) {
 571  0
                                         BusinessObject ruleDelegation = (BusinessObject) delegationList.get(0);
 572  0
                                         col.setColumnAnchor(getInquiryUrl(ruleDelegation, "ruleDelegationId"));
 573  0
                                 } else {
 574  0
                                         col.setColumnAnchor(getInquiryUrl(element, col.getPropertyName()));
 575  
                                 }
 576  0
                         }else {
 577  0
                                 col.setColumnAnchor(getInquiryUrl(element, col.getPropertyName()));
 578  
                         }
 579  
 
 580  
                 }
 581  0
             }
 582  
 
 583  0
             ResultRow row = new ResultRow(columns, returnUrl.constructCompleteHtmlTag(), actionUrls);
 584  0
             row.setRowId(returnUrl.getName());
 585  0
             row.setReturnUrlHtmlData(returnUrl);
 586  
             // because of concerns of the BO being cached in session on the ResultRow,
 587  
             // let's only attach it when needed (currently in the case of export)
 588  0
             if (getBusinessObjectDictionaryService().isExportable(getBusinessObjectClass())) {
 589  0
                 row.setBusinessObject(element);
 590  
             }
 591  0
             if(element instanceof PersistableBusinessObject){
 592  0
                 row.setObjectId((((PersistableBusinessObject)element).getObjectId()));
 593  
             }
 594  
 
 595  
 
 596  0
             boolean rowReturnable = isResultReturnable(element);
 597  0
             row.setRowReturnable(rowReturnable);
 598  0
             if (rowReturnable) {
 599  0
                 hasReturnableRow = true;
 600  
             }
 601  0
             resultTable.add(row);
 602  0
         }
 603  
 
 604  0
         lookupForm.setHasReturnableRow(hasReturnableRow);
 605  
 
 606  0
         return displayList;
 607  
     }
 608  
 
 609  
     @Override
 610  
     public List<Column> getColumns() {
 611  0
         List<Column> columns = super.getColumns();
 612  0
         for (Row row : rows) {
 613  0
             for (Field field : row.getFields()) {
 614  0
                 Column newColumn = new Column();
 615  0
                 newColumn.setColumnTitle(field.getFieldLabel());
 616  0
                 newColumn.setMaxLength(field.getMaxLength());
 617  0
                 newColumn.setPropertyName(field.getPropertyName());
 618  0
                 columns.add(newColumn);
 619  0
             }
 620  
         }
 621  0
         return columns;
 622  
     }
 623  
 
 624  
     @Override
 625  
     public List<HtmlData> getCustomActionUrls(BusinessObject businessObject,
 626  
             List pkNames) {
 627  0
         RuleBaseValues ruleBaseValues = (RuleBaseValues)businessObject;
 628  0
         List<HtmlData> htmlDataList = new ArrayList<HtmlData>();
 629  0
         if (StringUtils.isNotBlank(ruleBaseValues.getRuleTemplateName()) && StringUtils.isNotBlank(getMaintenanceDocumentTypeName())) {
 630  0
                 if (ruleBaseValues.getDelegateRule().booleanValue()) {
 631  
                         // If the rule is a delegate rule, have the edit/copy links open the rule delegation maintenance document screen instead.
 632  0
                         List<?> delegationList = KEWServiceLocator.getRuleDelegationService().findByDelegateRuleId(ruleBaseValues.getRuleBaseValuesId());
 633  0
                         if (ObjectUtils.isNotNull(delegationList) && !delegationList.isEmpty()) {
 634  0
                                 BusinessObject ruleDelegation = (BusinessObject) delegationList.get(0);
 635  
                                     // Retrieve the rule delegation lookupable helper service and the primary key names, if they have not been obtained yet.
 636  0
                         if (ruleDelegationLookupableHelperService == null) {
 637  0
                                         ruleDelegationLookupableHelperService = KNSServiceLocator.getLookupable(
 638  
                                 KRADServiceLocatorWeb.getBusinessObjectDictionaryService()
 639  
                                         .getLookupableID(ruleDelegation.getClass())).getLookupableHelperService();
 640  0
                                         if (ruleDelegationLookupableHelperService.getBusinessObjectClass() == null) {
 641  0
                                                 ruleDelegationLookupableHelperService.setBusinessObjectClass(ruleDelegation.getClass());
 642  
                                         }
 643  0
                                         delegationPkNames = getBusinessObjectMetaDataService().listPrimaryKeyFieldNames(ruleDelegation.getClass());
 644  
                                 }
 645  
                         // Allow the rule delegation's lookupable helper service to handle the custom action URL generation instead.
 646  0
                                 htmlDataList = ruleDelegationLookupableHelperService.getCustomActionUrls(ruleDelegation, delegationPkNames);
 647  
                         }
 648  0
                 } else {
 649  
                         // Otherwise, have the links open the regular routing rule maintenance document screen.
 650  0
                         if (allowsMaintenanceEditAction(businessObject)) {
 651  0
                                 htmlDataList.add(getUrlData(businessObject, KRADConstants.MAINTENANCE_EDIT_METHOD_TO_CALL, pkNames));
 652  
                         }
 653  0
                         if (allowsMaintenanceNewOrCopyAction()) {
 654  0
                         htmlDataList.add(getUrlData(businessObject, KRADConstants.MAINTENANCE_COPY_METHOD_TO_CALL, pkNames));
 655  
                     }
 656  
                 }
 657  
         }
 658  
         
 659  0
         return htmlDataList;
 660  
     }
 661  
 
 662  
 
 663  
 
 664  
 }