cancel
Showing results for 
Search instead for 
Did you mean: 

Rest call for delegate task

priyankam
Champ in-the-making
Champ in-the-making

   @RequestMapping(value = "/delegateTask/{taskId}", method = RequestMethod.PUT)
   @ResponseBody
   public StatusDetails delegateTask(
         @PathVariable("taskId") String planItemAggregateId,
         @RequestParam("userId") String userId,
         @RequestParam("comment") String comment) {
      StatusDetails statusDetails = new StatusDetails();
      try {
         cmmnEngineRuntimeService.delegateTask(planItemAggregateId, userId,
               comment);
         String successMessage = "You have Delegated the Task";
         statusDetails.setId(planItemAggregateId);
         statusDetails.setMessage(successMessage);
         statusDetails.setStatus("success");
         return statusDetails;
      } catch (Exception e) {
         String failedMessage = "You have failed to Delegate the Task ";
         statusDetails.setId(null);
         statusDetails.setMessage(failedMessage + e.getMessage());
         statusDetails.setStatus("error");
         return statusDetails;
      }

   }
This my code but i want to know whether i can use @requestparam for put method or I should use reaquestBody and will it correct way of doing it for comment field and userId.
1 REPLY 1

frederikherema1
Star Contributor
Star Contributor
This is more a general REST-question, rather than an Activiti one - but here's my 2 cents:

If you want to follow RESTfull principles, you need to execute a PUT on a resource, with a body containing the updates state of the resource. Since you're doing an 'action' on a resource (not creating one and not really explicit ally updating one) the 100% RESTfull approach won't cut it here.

What we do in Activiti REST is using a POST on the task-resource (see user guide):


POST runtime/tasks/{taskId}
{
  "action" : "delegate",
  "assignee" : "userToDelegateTo"
}

The request-body contains the action to execute and any other parameters you need. The URL remains clean (doesn't include the action) and has a clear indication of what entity instance to perform the action on…