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