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