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