@Override public void addClaimedUser(Context context, XmlWorkflowItem wfi, Step step, EPerson user) throws SQLException, AuthorizeException, IOException { // Make sure we delete the pooled task for our current user if the task is not a group pooltask PoolTask task = poolTaskService.findByWorkflowIdAndEPerson(context, wfi, user); if (task != null && task.getEperson() != null) { xmlWorkflowService.deletePooledTask(context, wfi, task); } InProgressUser ipu = inProgressUserService.create(context); ipu.setWorkflowItem(wfi); ipu.setUser(user); ipu.setFinished(false); inProgressUserService.update(context, ipu); int totalUsers = inProgressUserService.getNumberOfInProgressUsers(context, wfi) + inProgressUserService.getNumberOfFinishedUsers(context, wfi); if (totalUsers == step.getRequiredUsers()) { // If enough users have claimed/finished this step then remove the tasks xmlWorkflowService.deleteAllPooledTasks(context, wfi); } xmlWorkflowItemService.update(context, wfi); }
@Override public void removeClaimedUser(Context context, XmlWorkflowItem wfi, EPerson user, String stepID) throws SQLException, IOException, WorkflowConfigurationException, AuthorizeException { // Check if we had reached our max number @ this moment int totalUsers = inProgressUserService.getNumberOfInProgressUsers(context, wfi) + inProgressUserService.getNumberOfFinishedUsers(context, wfi); // Then remove the current user from the inProgressUsers inProgressUserService.delete( context, inProgressUserService.findByWorkflowItemAndEPerson(context, wfi, user)); Workflow workflow = workflowFactory.getWorkflow(wfi.getCollection()); Step step = workflow.getStep(stepID); // WorkflowManager.deleteOwnedTask(c, user, wfi, step, step.getActionConfig()); // We had reached our total user, so recreate tasks for the user who don't have one if (totalUsers == step.getRequiredUsers()) { // Create a list of the users we are to ignore List<InProgressUser> toIgnore = inProgressUserService.findByWorkflowItem(context, wfi); // Remove the users to ignore RoleMembers roleMembers = step.getRole().getMembers(context, wfi); // Create a list out all the users we are to pool a task for for (InProgressUser ipu : toIgnore) { roleMembers.removeEperson(ipu.getUser()); } step.getUserSelectionMethod() .getProcessingAction() .regenerateTasks(context, wfi, roleMembers); } else { // If the user previously had a personal PoolTask, this must be regenerated. Therefore we call // the regeneration method // with only one EPerson RoleMembers role = step.getRole().getMembers(context, wfi); List<EPerson> epersons = role.getEPersons(); for (EPerson eperson : epersons) { if (eperson.getID().equals(user.getID())) { RoleMembers memberToRegenerateTasksFor = new RoleMembers(); memberToRegenerateTasksFor.addEPerson(user); step.getUserSelectionMethod() .getProcessingAction() .regenerateTasks(context, wfi, memberToRegenerateTasksFor); break; } } } // Update our item itemService.update(context, wfi.getItem()); }