cancel
Showing results for 
Search instead for 
Did you mean: 

Is claiming a task is mandatory?

pratikbeedkar
Champ in-the-making
Champ in-the-making
Hi,

I have two question -

1. I have a user task (approve/reject) which is assigned to multiple users. My question is, can any one of the assigned user complete the task without claiming it? OR is it mandatory for user to claim the task on his/her name and then only that user can complete the task.

2. Is it posible the to revert the claim? I mean, if one user is claiming the task and later on wants to revoke his/her claim, then is it possible? If yes, how?

Any help is very much appreciated.

Thanks,
Pratik



5 REPLIES 5

martin_grofcik
Confirmed Champ
Confirmed Champ
Hi Pratik.

AFAIK
1. claiming is not mandatory
2. yes, you can set Assignee to null

Regards
Martin

Thanks Martin. Appreciate your quick response..

But, in second question I was talking about real time situation. Let me try to rephrase the scenario - In assignee I have already assigned two users (user1 and user2) and I have invoked the workflow. Now user1 is claiming the task but unable to complete due to some reason and wants to revert his claim, so that user2 can complete it.

In this scenario, is it possible to revert the claimed task in real time? As far as I understand, setting assignee to null can be done in the properties of user task, but that can be done before workflow is invoked I guess?

Thanks,
Pratik

Hi Pratik,

use: org.activiti.engine.TaskService#unclaim
the best examples are following jUnit tests:


  public void testClaimAlreadyClaimedTaskByOtherUser() {
    Task task = taskService.newTask();
    taskService.saveTask(task);
    User user = identityService.newUser("user");
    identityService.saveUser(user);
    User secondUser = identityService.newUser("seconduser");
    identityService.saveUser(secondUser);
   
    // Claim task the first time
    taskService.claim(task.getId(), user.getId());

    try {
      taskService.claim(task.getId(), secondUser.getId());
      fail("ActivitiException expected");
    } catch (ActivitiTaskAlreadyClaimedException ae) {
      assertTextPresent("Task '" + task.getId() + "' is already claimed by someone else.", ae.getMessage());
    }

    taskService.deleteTask(task.getId(), true);
    identityService.deleteUser(user.getId());
    identityService.deleteUser(secondUser.getId());
  }


  public void testClaimAlreadyClaimedTaskBySameUser() {
    Task task = taskService.newTask();
    taskService.saveTask(task);
    User user = identityService.newUser("user");
    identityService.saveUser(user);
   
    // Claim task the first time
    taskService.claim(task.getId(), user.getId());
    task = taskService.createTaskQuery().taskId(task.getId()).singleResult();
   
    // Claim the task again with the same user. No exception should be thrown
    taskService.claim(task.getId(), user.getId());

    taskService.deleteTask(task.getId(), true);
    identityService.deleteUser(user.getId());
  }


  public void testUnClaimTask() {
    Task task = taskService.newTask();
    taskService.saveTask(task);
    User user = identityService.newUser("user");
    identityService.saveUser(user);
   
    // Claim task the first time
    taskService.claim(task.getId(), user.getId());
    task = taskService.createTaskQuery().taskId(task.getId()).singleResult();
    assertEquals(user.getId(), task.getAssignee());
   
    // Unclaim the task
    taskService.unclaim(task.getId());
   
    task = taskService.createTaskQuery().taskId(task.getId()).singleResult();
    assertNull(task.getAssignee());
   
    taskService.deleteTask(task.getId(), true);
    identityService.deleteUser(user.getId());
  }

Regards
Martin

Thanks a lot Martin!!

sumer
Champ in-the-making
Champ in-the-making
Hi,

change your project dependencies.

Regards
Sumer