Пример #1
0
  @Override
  public WorkspaceItem abort(Context c, XmlWorkflowItem wi, EPerson e)
      throws AuthorizeException, SQLException, IOException {
    if (!authorizeService.isAdmin(c)) {
      throw new AuthorizeException("You must be an admin to abort a workflow");
    }

    c.turnOffAuthorisationSystem();
    // Restore permissions for the submitter
    // convert into personal workspace
    WorkspaceItem wsi = returnToWorkspace(c, wi);

    log.info(
        LogManager.getHeader(
            c,
            "abort_workflow",
            "workflow_item_id="
                + wi.getID()
                + "item_id="
                + wsi.getItem().getID()
                + "collection_id="
                + wi.getCollection().getID()
                + "eperson_id="
                + e.getID()));

    c.restoreAuthSystemState();
    return wsi;
  }
Пример #2
0
  protected WorkflowActionConfig processNextStep(
      Context c,
      EPerson user,
      Workflow workflow,
      ActionResult currentOutcome,
      XmlWorkflowItem wfi,
      Step nextStep)
      throws SQLException, IOException, AuthorizeException, WorkflowException,
          WorkflowConfigurationException {
    WorkflowActionConfig nextActionConfig;
    if (nextStep != null) {
      nextActionConfig = nextStep.getUserSelectionMethod();
      nextActionConfig.getProcessingAction().activate(c, wfi);
      //                nextActionConfig.getProcessingAction().generateTasks();

      if (nextActionConfig.requiresUI()) {
        // Since a new step has been started, stop executing actions once one with a user interface
        // is present.
        c.restoreAuthSystemState();
        return nextActionConfig;
      } else {
        ActionResult newOutcome =
            nextActionConfig.getProcessingAction().execute(c, wfi, nextStep, null);
        c.restoreAuthSystemState();
        return processOutcome(c, user, workflow, nextStep, nextActionConfig, newOutcome, wfi, true);
      }
    } else {
      if (currentOutcome.getResult() != ActionResult.OUTCOME_COMPLETE) {
        c.restoreAuthSystemState();
        throw new WorkflowException(
            "No alternate step was found for outcome: " + currentOutcome.getResult());
      }
      archive(c, wfi);
      c.restoreAuthSystemState();
      return null;
    }
  }
Пример #3
0
  @Override
  public XmlWorkflowItem start(Context context, WorkspaceItem wsi)
      throws SQLException, AuthorizeException, IOException, WorkflowException {
    try {
      Item myitem = wsi.getItem();
      Collection collection = wsi.getCollection();
      Workflow wf = xmlWorkflowFactory.getWorkflow(collection);

      XmlWorkflowItem wfi = xmlWorkflowItemService.create(context, myitem, collection);
      wfi.setMultipleFiles(wsi.hasMultipleFiles());
      wfi.setMultipleTitles(wsi.hasMultipleTitles());
      wfi.setPublishedBefore(wsi.isPublishedBefore());
      xmlWorkflowItemService.update(context, wfi);
      removeUserItemPolicies(context, myitem, myitem.getSubmitter());
      grantSubmitterReadPolicies(context, myitem);

      context.turnOffAuthorisationSystem();
      Step firstStep = wf.getFirstStep();
      if (firstStep.isValidStep(context, wfi)) {
        activateFirstStep(context, wf, firstStep, wfi);
      } else {
        // Get our next step, if none is found, archive our item
        firstStep = wf.getNextStep(context, wfi, firstStep, ActionResult.OUTCOME_COMPLETE);
        if (firstStep == null) {
          archive(context, wfi);
        } else {
          activateFirstStep(context, wf, firstStep, wfi);
        }
      }
      // remove the WorkspaceItem
      workspaceItemService.deleteWrapper(context, wsi);
      context.restoreAuthSystemState();
      return wfi;
    } catch (WorkflowConfigurationException e) {
      throw new WorkflowException(e);
    }
  }
Пример #4
0
  @Override
  public void alertUsersOnTaskActivation(
      Context c, XmlWorkflowItem wfi, String emailTemplate, List<EPerson> epa, String... arguments)
      throws IOException, SQLException, MessagingException {
    if (noEMail.containsKey(wfi.getItem().getID())) {
      // suppress email, and delete key
      noEMail.remove(wfi.getItem().getID());
    } else {
      Email mail = Email.getEmail(I18nUtil.getEmailFilename(c.getCurrentLocale(), emailTemplate));
      for (String argument : arguments) {
        mail.addArgument(argument);
      }
      for (EPerson anEpa : epa) {
        mail.addRecipient(anEpa.getEmail());
      }

      mail.send();
    }
  }
Пример #5
0
  /**
   * Return the workflow item to the workspace of the submitter. The workflow item is removed, and a
   * workspace item created.
   *
   * @param c Context
   * @param wfi WorkflowItem to be 'dismantled'
   * @return the workspace item
   * @throws java.io.IOException ...
   * @throws java.sql.SQLException ...
   * @throws org.dspace.authorize.AuthorizeException ...
   */
  protected WorkspaceItem returnToWorkspace(Context c, XmlWorkflowItem wfi)
      throws SQLException, IOException, AuthorizeException {
    // authorize a DSpaceActions.REJECT
    // stop workflow
    deleteAllTasks(c, wfi);

    c.turnOffAuthorisationSystem();
    // Also clear all info for this step
    workflowRequirementsService.clearInProgressUsers(c, wfi);

    // Remove (if any) the workflowItemroles for this item
    workflowItemRoleService.deleteForWorkflowItem(c, wfi);

    Item myitem = wfi.getItem();
    // Restore permissions for the submitter
    grantUserAllItemPolicies(c, myitem, myitem.getSubmitter());

    // FIXME: How should this interact with the workflow system?
    // FIXME: Remove license
    // FIXME: Provenance statement?
    // Create the new workspace item row
    WorkspaceItem workspaceItem = workspaceItemService.create(c, wfi);
    workspaceItem.setMultipleFiles(wfi.hasMultipleFiles());
    workspaceItem.setMultipleTitles(wfi.hasMultipleTitles());
    workspaceItem.setPublishedBefore(wfi.isPublishedBefore());
    workspaceItemService.update(c, workspaceItem);

    // myitem.update();
    log.info(
        LogManager.getHeader(
            c,
            "return_to_workspace",
            "workflow_item_id=" + wfi.getID() + "workspace_item_id=" + workspaceItem.getID()));

    // Now remove the workflow object manually from the database
    xmlWorkflowItemService.deleteWrapper(c, wfi);
    return workspaceItem;
  }
  // returns true if archived
  protected boolean doState(
      Context context, BasicWorkflowItem workflowItem, int newstate, EPerson newowner)
      throws SQLException, IOException, AuthorizeException {
    Collection mycollection = workflowItem.getCollection();
    Group mygroup = null;
    boolean archived = false;

    // Gather our old data for launching the workflow event
    int oldState = workflowItem.getState();

    workflowItem.setState(newstate);

    switch (newstate) {
      case WFSTATE_STEP1POOL:

        // any reviewers?
        // if so, add them to the tasklist
        workflowItem.setOwner(null);

        // get reviewers (group 1 )
        mygroup = collectionService.getWorkflowGroup(mycollection, 1);

        if ((mygroup != null) && !(groupService.isEmpty(mygroup))) {
          // get a list of all epeople in group (or any subgroups)
          List<EPerson> epa = groupService.allMembers(context, mygroup);

          // there were reviewers, change the state
          //  and add them to the list
          createTasks(context, workflowItem, epa);
          workflowItemService.update(context, workflowItem);

          // email notification
          notifyGroupOfTask(context, workflowItem, mygroup, epa);
        } else {
          // no reviewers, skip ahead
          workflowItem.setState(WFSTATE_STEP1);
          archived = advance(context, workflowItem, null, true, false);
        }

        break;

      case WFSTATE_STEP1:

        // remove reviewers from tasklist
        // assign owner
        taskListItemService.deleteByWorkflowItem(context, workflowItem);
        workflowItem.setOwner(newowner);

        break;

      case WFSTATE_STEP2POOL:

        // clear owner
        // any approvers?
        // if so, add them to tasklist
        // if not, skip to next state
        workflowItem.setOwner(null);

        // get approvers (group 2)
        mygroup = collectionService.getWorkflowGroup(mycollection, 2);

        if ((mygroup != null) && !(groupService.isEmpty(mygroup))) {
          // get a list of all epeople in group (or any subgroups)
          List<EPerson> epa = groupService.allMembers(context, mygroup);

          // there were approvers, change the state
          //  timestamp, and add them to the list
          createTasks(context, workflowItem, epa);

          // email notification
          notifyGroupOfTask(context, workflowItem, mygroup, epa);
        } else {
          // no reviewers, skip ahead
          workflowItem.setState(WFSTATE_STEP2);
          archived = advance(context, workflowItem, null, true, false);
        }

        break;

      case WFSTATE_STEP2:

        // remove admins from tasklist
        // assign owner
        taskListItemService.deleteByWorkflowItem(context, workflowItem);
        workflowItem.setOwner(newowner);

        break;

      case WFSTATE_STEP3POOL:

        // any editors?
        // if so, add them to tasklist
        workflowItem.setOwner(null);
        mygroup = collectionService.getWorkflowGroup(mycollection, 3);

        if ((mygroup != null) && !(groupService.isEmpty(mygroup))) {
          // get a list of all epeople in group (or any subgroups)
          List<EPerson> epa = groupService.allMembers(context, mygroup);

          // there were editors, change the state
          //  timestamp, and add them to the list
          createTasks(context, workflowItem, epa);

          // email notification
          notifyGroupOfTask(context, workflowItem, mygroup, epa);
        } else {
          // no editors, skip ahead
          workflowItem.setState(WFSTATE_STEP3);
          archived = advance(context, workflowItem, null, true, false);
        }

        break;

      case WFSTATE_STEP3:

        // remove editors from tasklist
        // assign owner
        taskListItemService.deleteByWorkflowItem(context, workflowItem);
        workflowItem.setOwner(newowner);

        break;

      case WFSTATE_ARCHIVE:

        // put in archive in one transaction
        // remove workflow tasks
        taskListItemService.deleteByWorkflowItem(context, workflowItem);

        mycollection = workflowItem.getCollection();

        Item myitem = archive(context, workflowItem);

        // now email notification
        notifyOfArchive(context, myitem, mycollection);
        archived = true;

        break;
    }

    logWorkflowEvent(
        context,
        workflowItem.getItem(),
        workflowItem,
        context.getCurrentUser(),
        newstate,
        newowner,
        mycollection,
        oldState,
        mygroup);

    if (!archived) {
      workflowItemService.update(context, workflowItem);
    }

    return archived;
  }
Пример #7
0
  @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;
  }
Пример #8
0
  @Override
  public WorkflowActionConfig processOutcome(
      Context c,
      EPerson user,
      Workflow workflow,
      Step currentStep,
      WorkflowActionConfig currentActionConfig,
      ActionResult currentOutcome,
      XmlWorkflowItem wfi,
      boolean enteredNewStep)
      throws IOException, AuthorizeException, SQLException, WorkflowException {
    if (currentOutcome.getType() == ActionResult.TYPE.TYPE_PAGE
        || currentOutcome.getType() == ActionResult.TYPE.TYPE_ERROR) {
      // Our outcome is a page or an error, so return our current action
      c.restoreAuthSystemState();
      return currentActionConfig;
    } else if (currentOutcome.getType() == ActionResult.TYPE.TYPE_CANCEL
        || currentOutcome.getType() == ActionResult.TYPE.TYPE_SUBMISSION_PAGE) {
      // We either pressed the cancel button or got an order to return to the submission page, so
      // don't return an action
      // By not returning an action we ensure ourselfs that we go back to the submission page
      c.restoreAuthSystemState();
      return null;
    } else if (currentOutcome.getType() == ActionResult.TYPE.TYPE_OUTCOME) {
      Step nextStep = null;
      WorkflowActionConfig nextActionConfig = null;
      try {
        // We have completed our action search & retrieve the next action
        if (currentOutcome.getResult() == ActionResult.OUTCOME_COMPLETE) {
          nextActionConfig = currentStep.getNextAction(currentActionConfig);
        }

        if (nextActionConfig != null) {
          // We remain in the current step since an action is found
          nextStep = currentStep;
          nextActionConfig.getProcessingAction().activate(c, wfi);
          if (nextActionConfig.requiresUI() && !enteredNewStep) {
            createOwnedTask(c, wfi, currentStep, nextActionConfig, user);
            return nextActionConfig;
          } else if (nextActionConfig.requiresUI() && enteredNewStep) {
            // We have entered a new step and have encountered a UI, return null since the current
            // user doesn't have anything to do with this
            c.restoreAuthSystemState();
            return null;
          } else {
            ActionResult newOutcome =
                nextActionConfig.getProcessingAction().execute(c, wfi, currentStep, null);
            return processOutcome(
                c, user, workflow, currentStep, nextActionConfig, newOutcome, wfi, enteredNewStep);
          }
        } else if (enteredNewStep) {
          // If the user finished his/her step, we keep processing until there is a UI step action
          // or no step at all
          nextStep = workflow.getNextStep(c, wfi, currentStep, currentOutcome.getResult());
          c.turnOffAuthorisationSystem();
          nextActionConfig = processNextStep(c, user, workflow, currentOutcome, wfi, nextStep);
          // If we require a user interface return null so that the user is redirected to the
          // "submissions page"
          if (nextActionConfig == null || nextActionConfig.requiresUI()) {
            return null;
          } else {
            return nextActionConfig;
          }
        } else {
          ClaimedTask task = claimedTaskService.findByWorkflowIdAndEPerson(c, wfi, user);

          // Check if we have a task for this action (might not be the case with automatic steps)
          // First add it to our list of finished users, since no more actions remain
          workflowRequirementsService.addFinishedUser(c, wfi, user);
          c.turnOffAuthorisationSystem();
          // Check if our requirements have been met
          if ((currentStep.isFinished(c, wfi)
                  && currentOutcome.getResult() == ActionResult.OUTCOME_COMPLETE)
              || currentOutcome.getResult() != ActionResult.OUTCOME_COMPLETE) {
            // Delete all the table rows containing the users who performed this task
            workflowRequirementsService.clearInProgressUsers(c, wfi);
            // Remove all the tasks
            deleteAllTasks(c, wfi);

            nextStep = workflow.getNextStep(c, wfi, currentStep, currentOutcome.getResult());

            nextActionConfig = processNextStep(c, user, workflow, currentOutcome, wfi, nextStep);
            // If we require a user interface return null so that the user is redirected to the
            // "submissions page"
            if (nextActionConfig == null || nextActionConfig.requiresUI()) {
              return null;
            } else {
              return nextActionConfig;
            }
          } else {
            // We are done with our actions so go to the submissions page but remove action
            // ClaimedAction first
            deleteClaimedTask(c, wfi, task);
            c.restoreAuthSystemState();
            nextStep = currentStep;
            nextActionConfig = currentActionConfig;
            return null;
          }
        }
      } catch (Exception e) {
        log.error("error while processing workflow outcome", e);
        e.printStackTrace();
      } finally {
        if ((nextStep != null && currentStep != null && nextActionConfig != null)
            || (wfi.getItem().isArchived() && currentStep != null)) {
          logWorkflowEvent(
              c,
              currentStep.getWorkflow().getID(),
              currentStep.getId(),
              currentActionConfig.getId(),
              wfi,
              user,
              nextStep,
              nextActionConfig);
        }
      }
    }

    log.error(LogManager.getHeader(c, "Invalid step outcome", "Workflow item id: " + wfi.getID()));
    throw new WorkflowException("Invalid step outcome");
  }