@Override
 public void deleteClaimedTask(Context c, XmlWorkflowItem wi, ClaimedTask task)
     throws SQLException, AuthorizeException {
   if (task != null) {
     removeUserItemPolicies(c, wi.getItem(), task.getOwner());
     claimedTaskService.delete(c, task);
   }
 }
 /*
  * Claims an action for a given eperson
  */
 @Override
 public void createOwnedTask(
     Context context, XmlWorkflowItem wi, Step step, WorkflowActionConfig action, EPerson e)
     throws SQLException, AuthorizeException {
   ClaimedTask task = claimedTaskService.create(context);
   task.setWorkflowItem(wi);
   task.setStepID(step.getId());
   task.setActionID(action.getId());
   task.setOwner(e);
   task.setWorkflowID(step.getWorkflow().getID());
   claimedTaskService.update(context, task);
   // Make sure this user has a task
   grantUserAllItemPolicies(context, wi.getItem(), e);
 }
  @Override
  public WorkspaceItem sendWorkflowItemBackSubmission(
      Context context, XmlWorkflowItem wi, EPerson e, String provenance, String rejection_message)
      throws SQLException, AuthorizeException, IOException {

    String workflowID = null;
    String currentStepId = null;
    String currentActionConfigId = null;
    ClaimedTask claimedTask = claimedTaskService.findByWorkflowIdAndEPerson(context, wi, e);
    if (claimedTask != null) {
      // Log it
      workflowID = claimedTask.getWorkflowID();
      currentStepId = claimedTask.getStepID();
      currentActionConfigId = claimedTask.getActionID();
    }
    context.turnOffAuthorisationSystem();

    // rejection provenance
    Item myitem = wi.getItem();

    // Get current date
    String now = DCDate.getCurrent().toString();

    // Get user's name + email address
    String usersName = getEPersonName(e);

    // Here's what happened
    String provDescription =
        provenance
            + " Rejected by "
            + usersName
            + ", reason: "
            + rejection_message
            + " on "
            + now
            + " (GMT) ";

    // Add to item as a DC field
    itemService.addMetadata(
        context,
        myitem,
        MetadataSchema.DC_SCHEMA,
        "description",
        "provenance",
        "en",
        provDescription);

    // Clear any workflow schema related metadata
    itemService.clearMetadata(
        context, myitem, WorkflowRequirementsService.WORKFLOW_SCHEMA, Item.ANY, Item.ANY, Item.ANY);

    itemService.update(context, myitem);

    // convert into personal workspace
    WorkspaceItem wsi = returnToWorkspace(context, wi);

    // notify that it's been rejected
    notifyOfReject(context, wi, e, rejection_message);
    log.info(
        LogManager.getHeader(
            context,
            "reject_workflow",
            "workflow_item_id="
                + wi.getID()
                + "item_id="
                + wi.getItem().getID()
                + "collection_id="
                + wi.getCollection().getID()
                + "eperson_id="
                + e.getID()));

    logWorkflowEvent(context, workflowID, currentStepId, currentActionConfigId, wi, e, null, null);

    context.restoreAuthSystemState();
    return wsi;
  }
  protected void logWorkflowEvent(
      Context c,
      String workflowId,
      String previousStepId,
      String previousActionConfigId,
      XmlWorkflowItem wfi,
      EPerson actor,
      Step newStep,
      WorkflowActionConfig newActionConfig)
      throws SQLException {
    try {
      // Fire an event so we can log our action !
      Item item = wfi.getItem();
      Collection myCollection = wfi.getCollection();
      String workflowStepString = null;

      List<EPerson> currentEpersonOwners = new ArrayList<EPerson>();
      List<Group> currentGroupOwners = new ArrayList<Group>();
      // These are only null if our item is sent back to the submission
      if (newStep != null && newActionConfig != null) {
        workflowStepString = workflowId + "." + newStep.getId() + "." + newActionConfig.getId();

        // Retrieve the current owners of the task
        List<ClaimedTask> claimedTasks = claimedTaskService.find(c, wfi, newStep.getId());
        List<PoolTask> pooledTasks = poolTaskService.find(c, wfi);
        for (PoolTask poolTask : pooledTasks) {
          if (poolTask.getEperson() != null) {
            currentEpersonOwners.add(poolTask.getEperson());
          } else {
            currentGroupOwners.add(poolTask.getGroup());
          }
        }
        for (ClaimedTask claimedTask : claimedTasks) {
          currentEpersonOwners.add(claimedTask.getOwner());
        }
      }
      String previousWorkflowStepString = null;
      if (previousStepId != null && previousActionConfigId != null) {
        previousWorkflowStepString =
            workflowId + "." + previousStepId + "." + previousActionConfigId;
      }

      // Fire our usage event !
      UsageWorkflowEvent usageWorkflowEvent =
          new UsageWorkflowEvent(
              c, item, wfi, workflowStepString, previousWorkflowStepString, myCollection, actor);

      usageWorkflowEvent.setEpersonOwners(
          currentEpersonOwners.toArray(new EPerson[currentEpersonOwners.size()]));
      usageWorkflowEvent.setGroupOwners(
          currentGroupOwners.toArray(new Group[currentGroupOwners.size()]));

      DSpaceServicesFactory.getInstance().getEventService().fireEvent(usageWorkflowEvent);
    } catch (Exception e) {
      // Catch all errors we do not want our workflow to crash because the logging threw an
      // exception
      log.error(
          LogManager.getHeader(
              c, "Error while logging workflow event", "Workflow Item: " + wfi.getID()),
          e);
    }
  }