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