@Override
 public void execute() throws SBonitaException {
   final SActivityInstance activityInstance =
       activityInstanceService.getActivityInstance(userTaskId);
   if (userId == 0 && SFlowNodeType.MANUAL_TASK.equals(activityInstance.getType())) {
     throw new SUnreleasableTaskException(
         "The activity with id "
             + activityInstance.getId()
             + " can't be assigned because it is a manual sub task");
   }
   activityInstanceService.assignHumanTask(userTaskId, userId);
   if (userId > 0) {
     activityInstanceService.deleteHiddenTasksForActivity(activityInstance.getId());
     final SUser user = identityService.getUser(userId);
     if (commentService.isCommentEnabled(SystemCommentType.STATE_CHANGE)) {
       commentService.addSystemComment(
           activityInstance.getRootContainerId(),
           "The task \""
               + activityInstance.getDisplayName()
               + "\" is now assigned to "
               + user.getUserName());
     }
   }
 }
 private void deleteProcessInstanceElements(final SProcessInstance processInstance)
     throws SBonitaException {
   SProcessDefinition processDefinition = null;
   try {
     processDefinition =
         processDefinitionService.getProcessDefinition(processInstance.getProcessDefinitionId());
   } catch (final SProcessDefinitionNotFoundException e) {
     // delete anyway
   }
   try {
     tokenService.deleteTokens(processInstance.getId());
   } catch (final SObjectReadException e) {
     throw new SProcessInstanceModificationException(e);
   } catch (final SObjectModificationException e) {
     throw new SProcessInstanceModificationException(e);
   }
   deleteFlowNodeInstances(processInstance.getId(), processDefinition);
   deleteDataInstancesIfNecessary(processInstance, processDefinition);
   processDocumentService.deleteDocumentsFromProcessInstance(processInstance.getId());
   deleteConnectorInstancesIfNecessary(processInstance, processDefinition);
   commentService.deleteComments(processInstance.getId());
 }
 @Override
 public void deleteArchivedProcessInstanceElements(
     final long processInstanceId, final long processDefinitionId)
     throws SProcessInstanceModificationException {
   final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
   try {
     final ClassLoader localClassLoader =
         classLoaderService.getLocalClassLoader("process", processDefinitionId);
     Thread.currentThread().setContextClassLoader(localClassLoader);
     deleteArchivedFlowNodeInstances(processInstanceId);
     dataInstanceService.deleteLocalArchivedDataInstances(
         processInstanceId, DataInstanceContainer.PROCESS_INSTANCE.toString());
     processDocumentService.deleteArchivedDocuments(processInstanceId);
     connectorInstanceService.deleteArchivedConnectorInstances(
         processInstanceId, SConnectorInstance.PROCESS_TYPE);
     transitionService.deleteArchivedTransitionsOfProcessInstance(processInstanceId);
     commentService.deleteArchivedComments(processInstanceId);
     deleteArchivedChidrenProcessInstanceElements(processInstanceId, processDefinitionId);
   } catch (final SBonitaException e) {
     throw new SProcessInstanceModificationException(e);
   } finally {
     Thread.currentThread().setContextClassLoader(contextClassLoader);
   }
 }