| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.kuali.rice.kew.removereplace.web; |
| 17 | |
|
| 18 | |
import java.util.ArrayList; |
| 19 | |
import java.util.HashSet; |
| 20 | |
import java.util.List; |
| 21 | |
import java.util.Set; |
| 22 | |
|
| 23 | |
import javax.servlet.http.HttpServletRequest; |
| 24 | |
import javax.servlet.http.HttpServletResponse; |
| 25 | |
|
| 26 | |
import org.apache.commons.lang.StringUtils; |
| 27 | |
import org.apache.struts.action.ActionForm; |
| 28 | |
import org.apache.struts.action.ActionForward; |
| 29 | |
import org.apache.struts.action.ActionMapping; |
| 30 | |
import org.apache.struts.action.ActionMessage; |
| 31 | |
import org.apache.struts.action.ActionMessages; |
| 32 | |
import org.kuali.rice.kew.dto.WorkflowIdDTO; |
| 33 | |
import org.kuali.rice.kew.exception.WorkflowException; |
| 34 | |
import org.kuali.rice.kew.exception.WorkflowRuntimeException; |
| 35 | |
import org.kuali.rice.kew.removereplace.RemoveReplaceDocument; |
| 36 | |
import org.kuali.rice.kew.removereplace.RuleTarget; |
| 37 | |
import org.kuali.rice.kew.removereplace.WorkgroupTarget; |
| 38 | |
import org.kuali.rice.kew.rule.RuleBaseValues; |
| 39 | |
import org.kuali.rice.kew.rule.RuleResponsibility; |
| 40 | |
import org.kuali.rice.kew.service.KEWServiceLocator; |
| 41 | |
import org.kuali.rice.kew.service.WorkflowDocument; |
| 42 | |
import org.kuali.rice.kew.util.CodeTranslator; |
| 43 | |
import org.kuali.rice.kew.util.KEWConstants; |
| 44 | |
import org.kuali.rice.kew.util.Utilities; |
| 45 | |
import org.kuali.rice.kew.web.KewKualiAction; |
| 46 | |
import org.kuali.rice.kew.web.session.UserSession; |
| 47 | |
import org.kuali.rice.kim.bo.Group; |
| 48 | |
import org.kuali.rice.kim.bo.Person; |
| 49 | |
import org.kuali.rice.kim.service.KIMServiceLocator; |
| 50 | |
|
| 51 | |
|
| 52 | |
|
| 53 | |
|
| 54 | |
|
| 55 | |
|
| 56 | |
|
| 57 | |
|
| 58 | 0 | public class RemoveReplaceAction extends KewKualiAction { |
| 59 | |
|
| 60 | 0 | private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(RemoveReplaceAction.class); |
| 61 | |
|
| 62 | |
private static final String INVALID_USER_ID_MSG = "removereplace.invalidUserId"; |
| 63 | |
private static final String USER_ID_NOT_FOUND_MSG = "removereplace.userIdNotFound"; |
| 64 | |
private static final String INVALID_REPLACEMENT_USER_ID_MSG = "removereplace.invalidReplacementUserId"; |
| 65 | |
private static final String REPLACEMENT_USER_ID_NOT_FOUND_MSG = "removereplace.replacementUserIdNotFound"; |
| 66 | |
private static final String REPLACEMENT_USER_ID_REQUIRED_MSG = "removereplace.replacementUserIdRequired"; |
| 67 | |
private static final String INVALID_OPERATION_MSG = "removereplace.invalidOperation"; |
| 68 | |
private static final String FAILED_DOCUMENT_LOAD_MSG = "removereplace.failedDocumentLoad"; |
| 69 | |
|
| 70 | |
@Override |
| 71 | |
public ActionForward execute(ActionMapping mapping, ActionForm form, |
| 72 | |
HttpServletRequest request, HttpServletResponse response) |
| 73 | |
throws Exception { |
| 74 | |
|
| 75 | 0 | initForm(request, form); |
| 76 | 0 | return super.execute(mapping, form, request, response); |
| 77 | |
} |
| 78 | |
|
| 79 | |
@Override |
| 80 | |
public ActionForward start(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, |
| 81 | |
HttpServletResponse response) throws Exception { |
| 82 | 0 | RemoveReplaceForm form = (RemoveReplaceForm) actionForm; |
| 83 | 0 | form.getShowHide().getChild(0).setShow(true); |
| 84 | 0 | form.getShowHide().getChild(1).setShow(true); |
| 85 | 0 | return super.start(mapping, actionForm, request, response); |
| 86 | |
} |
| 87 | |
|
| 88 | |
public ActionMessages initForm(HttpServletRequest request, ActionForm actionForm) throws Exception { |
| 89 | 0 | ActionMessages messages = new ActionMessages(); |
| 90 | 0 | RemoveReplaceForm form = (RemoveReplaceForm)actionForm; |
| 91 | 0 | form.setActionRequestCodes(CodeTranslator.arLabels); |
| 92 | 0 | boolean isCreating = false; |
| 93 | 0 | if (form.getDocId() != null) { |
| 94 | 0 | form.setWorkflowDocument(new WorkflowDocument(getUserSession(request).getPrincipalId(), form.getDocId())); |
| 95 | |
} else { |
| 96 | |
|
| 97 | 0 | isCreating = StringUtils.isEmpty(form.getMethodToCall()) || form.getMethodToCall().equals("start"); |
| 98 | 0 | if (isCreating) { |
| 99 | 0 | form.setWorkflowDocument(createDocument()); |
| 100 | 0 | form.setDocId(form.getWorkflowDocument().getRouteHeaderId()); |
| 101 | 0 | form.establishVisibleActionRequestCds(); |
| 102 | |
} |
| 103 | |
} |
| 104 | 0 | form.establishVisibleActionRequestCds(); |
| 105 | 0 | if (!StringUtils.isEmpty(form.getUserId())) { |
| 106 | 0 | Person user = null; |
| 107 | |
try { |
| 108 | 0 | user = KIMServiceLocator.getPersonService().getPersonByPrincipalName(form.getUserId()); |
| 109 | 0 | } catch (Exception e) { |
| 110 | 0 | LOG.warn("User not found.", e); |
| 111 | 0 | } |
| 112 | 0 | form.setUser(user); |
| 113 | 0 | if (user == null) { |
| 114 | 0 | messages.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(USER_ID_NOT_FOUND_MSG, form.getUserId())); |
| 115 | |
} |
| 116 | |
} |
| 117 | 0 | if (!StringUtils.isEmpty(form.getReplacementUserId())) { |
| 118 | 0 | Person replacementUser = null; |
| 119 | |
try { |
| 120 | 0 | replacementUser = KIMServiceLocator.getPersonService().getPersonByPrincipalName(form.getReplacementUserId()); |
| 121 | 0 | } catch (Exception e) { |
| 122 | 0 | LOG.warn("Replacement user not found.", e); |
| 123 | 0 | } |
| 124 | 0 | form.setReplacementUser(replacementUser); |
| 125 | 0 | if (replacementUser == null) { |
| 126 | 0 | messages.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(REPLACEMENT_USER_ID_NOT_FOUND_MSG, form.getReplacementUserId())); |
| 127 | |
} |
| 128 | |
} |
| 129 | |
|
| 130 | 0 | return messages; |
| 131 | |
} |
| 132 | |
|
| 133 | |
private WorkflowDocument createDocument() throws WorkflowException { |
| 134 | 0 | return new WorkflowDocument(new WorkflowIdDTO(UserSession.getAuthenticatedUser().getPrincipalId()), KEWConstants.REMOVE_REPLACE_DOCUMENT_TYPE); |
| 135 | |
} |
| 136 | |
|
| 137 | |
public ActionForward selectOperation(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) throws Exception { |
| 138 | 0 | ActionMessages messages = new ActionMessages(); |
| 139 | 0 | RemoveReplaceForm form = (RemoveReplaceForm) actionForm; |
| 140 | |
|
| 141 | 0 | if (!form.isRemove() && !form.isReplace()) { |
| 142 | 0 | messages.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(INVALID_OPERATION_MSG)); |
| 143 | |
} |
| 144 | |
|
| 145 | 0 | if (StringUtils.isBlank(form.getUserId())) { |
| 146 | 0 | messages.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(INVALID_USER_ID_MSG)); |
| 147 | |
} |
| 148 | 0 | if (form.isReplace() && StringUtils.isBlank(form.getReplacementUserId())) { |
| 149 | 0 | messages.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(REPLACEMENT_USER_ID_REQUIRED_MSG)); |
| 150 | |
} |
| 151 | 0 | if (!messages.isEmpty()) { |
| 152 | 0 | saveMessages(request, messages); |
| 153 | 0 | return mapping.findForward("basic"); |
| 154 | |
} |
| 155 | 0 | form.setOperationSelected(true); |
| 156 | |
|
| 157 | 0 | form.getRules().clear(); |
| 158 | 0 | form.getWorkgroups().clear(); |
| 159 | 0 | form.getShowHide().getChild(0).setShow(true); |
| 160 | 0 | form.getShowHide().getChild(1).setShow(true); |
| 161 | 0 | return mapping.findForward("basic"); |
| 162 | |
} |
| 163 | |
|
| 164 | |
public ActionForward changeOperation(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) throws Exception { |
| 165 | 0 | RemoveReplaceForm form = (RemoveReplaceForm) actionForm; |
| 166 | 0 | form.setOperationSelected(false); |
| 167 | 0 | return mapping.findForward("basic"); |
| 168 | |
} |
| 169 | |
|
| 170 | |
public ActionForward docHandler(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) throws Exception { |
| 171 | 0 | RemoveReplaceForm form = (RemoveReplaceForm) actionForm; |
| 172 | 0 | if (KEWConstants.INITIATE_COMMAND.equalsIgnoreCase(form.getCommand())) { |
| 173 | 0 | return start(mapping, form, request, response); |
| 174 | |
} |
| 175 | 0 | Long documentId = form.getDocId(); |
| 176 | 0 | RemoveReplaceDocument removeReplaceDocument = KEWServiceLocator.getRemoveReplaceDocumentService().findById(documentId); |
| 177 | 0 | if (removeReplaceDocument == null) { |
| 178 | 0 | ActionMessages messages = new ActionMessages(); |
| 179 | 0 | messages.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(FAILED_DOCUMENT_LOAD_MSG, documentId)); |
| 180 | 0 | saveMessages(request, messages); |
| 181 | 0 | return mapping.findForward("docHandler"); |
| 182 | |
} |
| 183 | 0 | loadFormForReport(form, removeReplaceDocument); |
| 184 | 0 | return mapping.findForward("docHandler"); |
| 185 | |
} |
| 186 | |
|
| 187 | |
protected void loadFormForReport(RemoveReplaceForm form, RemoveReplaceDocument document) { |
| 188 | 0 | form.setDocument(document); |
| 189 | 0 | form.setOperation(document.getOperation()); |
| 190 | 0 | Person user = KIMServiceLocator.getPersonService().getPerson(document.getUserWorkflowId()); |
| 191 | 0 | form.setUserId(user.getPrincipalName()); |
| 192 | 0 | form.setUser(user); |
| 193 | 0 | if (!StringUtils.isBlank(document.getReplacementUserWorkflowId())) { |
| 194 | 0 | Person replacementUser = KIMServiceLocator.getPersonService().getPerson(document.getReplacementUserWorkflowId()); |
| 195 | 0 | form.setReplacementUserId(replacementUser.getPrincipalId()); |
| 196 | 0 | form.setReplacementUser(replacementUser); |
| 197 | |
} |
| 198 | 0 | form.setRules(loadRemoveReplaceRules(form, loadRules(document))); |
| 199 | 0 | form.setWorkgroups(loadRemoveReplaceWorkgroups(form, loadWorkgroups(document))); |
| 200 | 0 | form.setReport(true); |
| 201 | 0 | form.getShowHide().getChild(0).setShow(!form.getRules().isEmpty()); |
| 202 | 0 | form.getShowHide().getChild(1).setShow(!form.getWorkgroups().isEmpty()); |
| 203 | 0 | } |
| 204 | |
|
| 205 | |
protected List<? extends Group> loadWorkgroups(RemoveReplaceDocument document) { |
| 206 | 0 | List<Group> workgroups = new ArrayList<Group>(); |
| 207 | 0 | for (WorkgroupTarget workgroupTarget : document.getWorkgroupTargets()) { |
| 208 | 0 | Group group = KIMServiceLocator.getIdentityManagementService().getGroup(workgroupTarget.getWorkgroupId()); |
| 209 | 0 | if (group == null) { |
| 210 | 0 | throw new WorkflowRuntimeException("Failed to locate group with id " + workgroupTarget.getWorkgroupId()); |
| 211 | |
} |
| 212 | 0 | workgroups.add(group); |
| 213 | 0 | } |
| 214 | 0 | return workgroups; |
| 215 | |
} |
| 216 | |
|
| 217 | |
protected List<RuleBaseValues> loadRules(RemoveReplaceDocument document) { |
| 218 | 0 | List<RuleBaseValues> rules = new ArrayList<RuleBaseValues>(); |
| 219 | 0 | for (RuleTarget ruleTarget : document.getRuleTargets()) { |
| 220 | 0 | RuleBaseValues rule = KEWServiceLocator.getRuleService().findRuleBaseValuesById(ruleTarget.getRuleId()); |
| 221 | 0 | if (rule == null) { |
| 222 | 0 | throw new WorkflowRuntimeException("Failed to locate rule with id " + ruleTarget.getRuleId()); |
| 223 | |
} |
| 224 | 0 | rules.add(rule); |
| 225 | 0 | } |
| 226 | 0 | return rules; |
| 227 | |
} |
| 228 | |
|
| 229 | |
|
| 230 | |
public ActionForward chooseRules(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, |
| 231 | |
HttpServletResponse response) throws Exception { |
| 232 | 0 | RemoveReplaceForm form = (RemoveReplaceForm)actionForm; |
| 233 | |
|
| 234 | 0 | if (form.getUser() == null) { |
| 235 | 0 | throw new RuntimeException("Please enter a valid user id before choosing rules."); |
| 236 | |
} |
| 237 | 0 | List<RuleBaseValues> rules = KEWServiceLocator.getRuleService().findRuleBaseValuesByResponsibilityReviewerTemplateDoc(form.getRuleRuleTemplate(), form.getRuleDocumentTypeName(), form.getUser().getPrincipalId(), KEWConstants.RULE_RESPONSIBILITY_WORKFLOW_ID); |
| 238 | 0 | form.getRules().clear(); |
| 239 | 0 | form.getRules().addAll(loadRemoveReplaceRules(form, rules)); |
| 240 | 0 | return mapping.findForward("basic"); |
| 241 | |
} |
| 242 | |
|
| 243 | |
|
| 244 | |
|
| 245 | |
|
| 246 | |
protected List<RemoveReplaceRule> loadRemoveReplaceRules(RemoveReplaceForm form, List<RuleBaseValues> rules) { |
| 247 | 0 | List<RemoveReplaceRule> removeReplaceRules = new ArrayList<RemoveReplaceRule>(); |
| 248 | 0 | Set<Long> selectedRuleIds = getSelectedRuleIds(form); |
| 249 | 0 | for (RuleBaseValues rule : rules) { |
| 250 | 0 | RemoveReplaceRule removeReplaceRule = new RemoveReplaceRule(); |
| 251 | 0 | removeReplaceRule.setRule(rule); |
| 252 | 0 | removeReplaceRule.setRuleTemplateName(rule.getRuleTemplateName()); |
| 253 | |
|
| 254 | 0 | removeReplaceRule.setSelected(selectedRuleIds.contains(rule.getRuleBaseValuesId())); |
| 255 | 0 | Long documentId = KEWServiceLocator.getRuleService().isLockedForRouting(rule.getRuleBaseValuesId()); |
| 256 | 0 | if (documentId != null) { |
| 257 | 0 | removeReplaceRule.setWarning(removeReplaceRule.getWarning().concat("Rule is locked by document " + documentId + " and cannot be modified.")); |
| 258 | 0 | removeReplaceRule.setDisabled(true); |
| 259 | 0 | removeReplaceRule.setSelected(false); |
| 260 | |
} |
| 261 | 0 | ResponsibilityEvaluation eval = evaluateResponsibility(form, rule); |
| 262 | 0 | if (!eval.foundResponsibility) { |
| 263 | 0 | LOG.warn("Failed to find a valid responsbility on rule " + rule.getRuleBaseValuesId() + " for user " + form.getUserId() + ". This rule will not be added to the list for selection."); |
| 264 | |
} |
| 265 | 0 | for (String warning : eval.warnings) { |
| 266 | 0 | if (!StringUtils.isEmpty(removeReplaceRule.getWarning())) { |
| 267 | 0 | removeReplaceRule.setWarning(removeReplaceRule.getWarning().concat("<br>")); |
| 268 | |
} |
| 269 | 0 | removeReplaceRule.setWarning(removeReplaceRule.getWarning().concat(warning)); |
| 270 | |
} |
| 271 | 0 | removeReplaceRules.add(removeReplaceRule); |
| 272 | 0 | } |
| 273 | 0 | return removeReplaceRules; |
| 274 | |
} |
| 275 | |
|
| 276 | |
private Set<Long> getSelectedRuleIds(RemoveReplaceForm form) { |
| 277 | 0 | Set<Long> selectedRuleIds = new HashSet<Long>(); |
| 278 | 0 | for (RemoveReplaceRule rule : form.getRules()) { |
| 279 | 0 | if (rule.isSelected()) { |
| 280 | 0 | selectedRuleIds.add(rule.getRule().getRuleBaseValuesId()); |
| 281 | |
} |
| 282 | |
} |
| 283 | 0 | return selectedRuleIds; |
| 284 | |
} |
| 285 | |
|
| 286 | |
private ResponsibilityEvaluation evaluateResponsibility(RemoveReplaceForm form, RuleBaseValues rule) { |
| 287 | 0 | ResponsibilityEvaluation eval = new ResponsibilityEvaluation(); |
| 288 | 0 | List<RuleResponsibility> responsibilities = rule.getResponsibilities(); |
| 289 | 0 | for (RuleResponsibility responsibility : responsibilities) { |
| 290 | 0 | if (KEWConstants.RULE_RESPONSIBILITY_WORKFLOW_ID.equals(responsibility.getRuleResponsibilityType()) && |
| 291 | |
responsibility.getRuleResponsibilityName().equals(form.getUser().getPrincipalId())) { |
| 292 | 0 | eval.foundResponsibility = true; |
| 293 | 0 | eval.hasDelegations = responsibility.getDelegationRules().size() > 0; |
| 294 | |
} else { |
| 295 | 0 | eval.hasOtherResponsibility = true; |
| 296 | |
} |
| 297 | |
} |
| 298 | 0 | if (RemoveReplaceDocument.REMOVE_OPERATION.equals(form.getOperation()) && !eval.hasOtherResponsibility) { |
| 299 | 0 | eval.warnings.add("Only one user on the rule, removing them will inactivate the rule."); |
| 300 | |
} |
| 301 | 0 | if (eval.hasDelegations) { |
| 302 | 0 | eval.warnings.add("This rule has delegations which will be inactivated."); |
| 303 | |
} |
| 304 | 0 | return eval; |
| 305 | |
} |
| 306 | |
|
| 307 | |
public ActionForward chooseWorkgroups(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, |
| 308 | |
HttpServletResponse response) throws Exception { |
| 309 | 0 | RemoveReplaceForm form = (RemoveReplaceForm)actionForm; |
| 310 | 0 | if (form.getUser() == null) { |
| 311 | |
|
| 312 | 0 | throw new RuntimeException("Please enter a valid user id before choosing workgroups."); |
| 313 | |
} |
| 314 | 0 | List<? extends Group> groups = KIMServiceLocator.getIdentityManagementService().getGroupsForPrincipal(form.getUser().getPrincipalId()); |
| 315 | 0 | form.getWorkgroups().clear(); |
| 316 | 0 | form.getWorkgroups().addAll(loadRemoveReplaceWorkgroups(form, groups)); |
| 317 | 0 | return mapping.findForward("basic"); |
| 318 | |
} |
| 319 | |
|
| 320 | |
|
| 321 | |
|
| 322 | |
|
| 323 | |
protected List<RemoveReplaceWorkgroup> loadRemoveReplaceWorkgroups(RemoveReplaceForm form, List<? extends Group> groups) { |
| 324 | 0 | List<RemoveReplaceWorkgroup> removeReplaceWorkgroups = new ArrayList<RemoveReplaceWorkgroup>(); |
| 325 | 0 | Set<String> selectedWorkgroupIds = getSelectedWorkgroupIds(form); |
| 326 | 0 | for (Group group : groups) { |
| 327 | 0 | RemoveReplaceWorkgroup removeReplaceWorkgroup = new RemoveReplaceWorkgroup(); |
| 328 | 0 | removeReplaceWorkgroup.setId(group.getGroupId()); |
| 329 | 0 | removeReplaceWorkgroup.setName(group.getGroupName()); |
| 330 | 0 | removeReplaceWorkgroup.setType(group.getKimTypeId()); |
| 331 | 0 | removeReplaceWorkgroup.setWarning(""); |
| 332 | |
|
| 333 | 0 | removeReplaceWorkgroup.setSelected(selectedWorkgroupIds.contains(group.getGroupId())); |
| 334 | 0 | boolean isOnlyMember = true; |
| 335 | 0 | boolean foundMember = false; |
| 336 | 0 | List<String> directMembers = KIMServiceLocator.getIdentityManagementService().getDirectGroupMemberPrincipalIds(group.getGroupId()); |
| 337 | 0 | for (String principalId : directMembers) { |
| 338 | 0 | if (principalId.equals(form.getUser().getPrincipalId())) { |
| 339 | 0 | foundMember = true; |
| 340 | |
} else { |
| 341 | 0 | isOnlyMember = false; |
| 342 | |
} |
| 343 | |
} |
| 344 | 0 | List<String> warnings = new ArrayList<String>(); |
| 345 | |
|
| 346 | |
|
| 347 | |
|
| 348 | |
|
| 349 | |
|
| 350 | |
|
| 351 | |
|
| 352 | |
|
| 353 | |
|
| 354 | |
|
| 355 | |
|
| 356 | 0 | if (RemoveReplaceDocument.REMOVE_OPERATION.equals(form.getOperation()) && isOnlyMember) { |
| 357 | 0 | warnings.add("Only one member on the workgroup, removing them will inactivate the workgroup."); |
| 358 | |
} |
| 359 | 0 | for (String warning : warnings) { |
| 360 | 0 | if (!StringUtils.isEmpty(removeReplaceWorkgroup.getWarning())) { |
| 361 | 0 | removeReplaceWorkgroup.setWarning(removeReplaceWorkgroup.getWarning().concat("<br>")); |
| 362 | |
} |
| 363 | 0 | removeReplaceWorkgroup.setWarning(removeReplaceWorkgroup.getWarning().concat(warning)); |
| 364 | |
} |
| 365 | 0 | if (!foundMember) { |
| 366 | 0 | LOG.warn("Failed to find a valid member on workgroup " + group.getGroupName() + " for user " + form.getUserId() + ". This workgroup will not be added to the list for selection."); |
| 367 | |
} else { |
| 368 | 0 | removeReplaceWorkgroups.add(removeReplaceWorkgroup); |
| 369 | |
} |
| 370 | 0 | } |
| 371 | 0 | return removeReplaceWorkgroups; |
| 372 | |
} |
| 373 | |
|
| 374 | |
private Set<String> getSelectedWorkgroupIds(RemoveReplaceForm form) { |
| 375 | 0 | Set<String> selectedWorkgroupIds = new HashSet<String>(); |
| 376 | 0 | for (RemoveReplaceWorkgroup workgroup : form.getWorkgroups()) { |
| 377 | 0 | if (workgroup.isSelected()) { |
| 378 | 0 | selectedWorkgroupIds.add(workgroup.getId()); |
| 379 | |
} |
| 380 | |
} |
| 381 | 0 | return selectedWorkgroupIds; |
| 382 | |
} |
| 383 | |
|
| 384 | 0 | private class ResponsibilityEvaluation { |
| 385 | 0 | public boolean foundResponsibility = false; |
| 386 | 0 | public boolean hasOtherResponsibility = false; |
| 387 | 0 | public boolean hasDelegations = false; |
| 388 | 0 | public List<String> warnings = new ArrayList<String>(); |
| 389 | |
} |
| 390 | |
|
| 391 | |
public ActionForward blanketApprove(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, |
| 392 | |
HttpServletResponse response) throws Exception { |
| 393 | 0 | RemoveReplaceForm form = (RemoveReplaceForm)actionForm; |
| 394 | 0 | validateSubmission(form); |
| 395 | 0 | RemoveReplaceDocument document = createRemoveReplaceDocument(form); |
| 396 | 0 | KEWServiceLocator.getRemoveReplaceDocumentService().blanketApprove(document, UserSession.getAuthenticatedUser(), form.getAnnotation()); |
| 397 | 0 | loadFormForReport(form, document); |
| 398 | 0 | ActionMessages messages = new ActionMessages(); |
| 399 | 0 | messages.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("general.routing.blanketApproved", "Remove/Replace User Document")); |
| 400 | 0 | saveMessages(request, messages); |
| 401 | 0 | return mapping.findForward("summary"); |
| 402 | |
} |
| 403 | |
|
| 404 | |
public ActionForward route(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, |
| 405 | |
HttpServletResponse response) throws Exception { |
| 406 | 0 | RemoveReplaceForm form = (RemoveReplaceForm)actionForm; |
| 407 | 0 | validateSubmission(form); |
| 408 | 0 | RemoveReplaceDocument document = createRemoveReplaceDocument(form); |
| 409 | 0 | KEWServiceLocator.getRemoveReplaceDocumentService().route(document, UserSession.getAuthenticatedUser(), form.getAnnotation()); |
| 410 | 0 | loadFormForReport(form, document); |
| 411 | 0 | ActionMessages messages = new ActionMessages(); |
| 412 | 0 | messages.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("general.routing.routed", "Remove/Replace User Document")); |
| 413 | 0 | saveMessages(request, messages); |
| 414 | 0 | return mapping.findForward("summary"); |
| 415 | |
} |
| 416 | |
|
| 417 | |
private void validateSubmission(RemoveReplaceForm form) { |
| 418 | 0 | if (form.getUser() == null) { |
| 419 | 0 | throw new RuntimeException("Please select a user."); |
| 420 | |
} |
| 421 | 0 | if (form.getOperation().equals(RemoveReplaceDocument.REPLACE_OPERATION) && form.getReplacementUser() == null) { |
| 422 | 0 | throw new RuntimeException("Please select a replacement user."); |
| 423 | |
} |
| 424 | 0 | } |
| 425 | |
|
| 426 | |
private RemoveReplaceDocument createRemoveReplaceDocument(RemoveReplaceForm form) { |
| 427 | 0 | RemoveReplaceDocument document = new RemoveReplaceDocument(); |
| 428 | 0 | document.setDocumentId(form.getDocId()); |
| 429 | 0 | document.setOperation(form.getOperation()); |
| 430 | 0 | document.setUserWorkflowId(form.getUser().getPrincipalId()); |
| 431 | 0 | if (form.getReplacementUser() != null) { |
| 432 | 0 | document.setReplacementUserWorkflowId(form.getReplacementUser().getPrincipalId()); |
| 433 | |
} |
| 434 | 0 | List<RuleTarget> ruleTargets = new ArrayList<RuleTarget>(); |
| 435 | 0 | for (RemoveReplaceRule rule : form.getRules()) { |
| 436 | 0 | if (rule.isSelected()) { |
| 437 | 0 | RuleTarget target = new RuleTarget(); |
| 438 | 0 | target.setRuleId(rule.getRule().getRuleBaseValuesId()); |
| 439 | 0 | ruleTargets.add(target); |
| 440 | 0 | } |
| 441 | |
} |
| 442 | 0 | List<WorkgroupTarget> workgroupTargets = new ArrayList<WorkgroupTarget>(); |
| 443 | 0 | for (RemoveReplaceWorkgroup workgroup : form.getWorkgroups()) { |
| 444 | 0 | if (workgroup.isSelected()) { |
| 445 | 0 | WorkgroupTarget target = new WorkgroupTarget(); |
| 446 | 0 | target.setWorkgroupId(workgroup.getId()); |
| 447 | 0 | workgroupTargets.add(target); |
| 448 | 0 | } |
| 449 | |
} |
| 450 | 0 | document.setRuleTargets(ruleTargets); |
| 451 | 0 | document.setWorkgroupTargets(workgroupTargets); |
| 452 | 0 | return document; |
| 453 | |
} |
| 454 | |
|
| 455 | |
public ActionForward performLookup(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) throws Exception { |
| 456 | 0 | String lookupService = request.getParameter("lookupableImplServiceName"); |
| 457 | 0 | String conversionFields = request.getParameter("conversionFields"); |
| 458 | 0 | String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath() + mapping.getModuleConfig().getPrefix(); |
| 459 | 0 | StringBuffer lookupUrl = new StringBuffer(basePath); |
| 460 | 0 | lookupUrl.append("/Lookup.do?methodToCall=start&docFormKey=").append(getUserSession(request).addObject(actionForm)).append("&lookupableImplServiceName="); |
| 461 | 0 | lookupUrl.append(lookupService); |
| 462 | 0 | lookupUrl.append("&conversionFields=").append(conversionFields); |
| 463 | 0 | lookupUrl.append("&returnLocation=").append(basePath).append(mapping.getPath()).append(".do"); |
| 464 | 0 | return new ActionForward(lookupUrl.toString(), true); |
| 465 | |
} |
| 466 | |
|
| 467 | |
public ActionForward cancel(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) throws Exception { |
| 468 | 0 | LOG.info("entering cancel() method ..."); |
| 469 | 0 | RemoveReplaceForm form = (RemoveReplaceForm)actionForm; |
| 470 | 0 | form.getWorkflowDocument().cancel(""); |
| 471 | 0 | saveDocumentActionMessage("general.routing.canceled", request); |
| 472 | 0 | LOG.info("forwarding to actionTaken from cancel()"); |
| 473 | 0 | return mapping.findForward("actionTaken"); |
| 474 | |
} |
| 475 | |
|
| 476 | |
public void saveDocumentActionMessage(String messageKey, HttpServletRequest request) { |
| 477 | 0 | saveDocumentActionMessage(messageKey, request, null); |
| 478 | 0 | } |
| 479 | |
|
| 480 | |
public void saveDocumentActionMessage(String messageKey, HttpServletRequest request, String secondMessageParameter) { |
| 481 | 0 | ActionMessages messages = new ActionMessages(); |
| 482 | 0 | if (Utilities.isEmpty(secondMessageParameter)) { |
| 483 | 0 | messages.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(messageKey, "document")); |
| 484 | |
} else { |
| 485 | 0 | messages.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(messageKey, "document", secondMessageParameter)); |
| 486 | |
} |
| 487 | 0 | saveMessages(request, messages); |
| 488 | 0 | } |
| 489 | |
|
| 490 | |
private static UserSession getUserSession(HttpServletRequest request) { |
| 491 | 0 | return UserSession.getAuthenticatedUser(); |
| 492 | |
} |
| 493 | |
|
| 494 | |
|
| 495 | |
|
| 496 | |
} |