/**
   * 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
   */
  protected WorkspaceItem returnToWorkspace(Context c, BasicWorkflowItem wfi)
      throws SQLException, IOException, AuthorizeException {
    // 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
    workflowItemService.deleteWrapper(c, wfi);

    return workspaceItem;
  }
Example #2
0
 /**
  * Process the save or remove step. If the user has selected to remove their submission then
  * remove it.
  *
  * @param context The current DSpace content
  * @param id The unique ID of the current workspace/workflow
  * @param request The cocoon request object.
  */
 public static void processSaveOrRemove(Context context, String id, Request request)
     throws SQLException, AuthorizeException, IOException {
   if (request.getParameter("submit_remove") != null) {
     // If they selected to remove the item then delete everything.
     WorkspaceItem workspace = findWorkspace(context, id);
     workspaceItemService.deleteAll(context, workspace);
   }
 }
Example #3
0
  /**
   * Indicate the user has advanced to the given page within a given step. This will only actually
   * do anything when it's a user initially entering a submission. It will increase the "stage
   * reached" and "page reached" columns - it will not "set back" where a user has reached.
   *
   * @param context The current DSpace content
   * @param id The unique ID of the current workflow/workspace
   * @param step the step the user has just reached
   * @param page the page (within the step) the user has just reached
   */
  public static void setPageReached(Context context, String id, int step, int page)
      throws SQLException, AuthorizeException, IOException {
    InProgressSubmission submission = findSubmission(context, id);

    if (submission instanceof WorkspaceItem) {
      WorkspaceItem workspaceItem = (WorkspaceItem) submission;

      if (step > workspaceItem.getStageReached()) {
        workspaceItem.setStageReached(step);
        workspaceItem.setPageReached(1); // reset page to first page in new step
        workspaceItemService.update(context, workspaceItem);
      } else if ((step == workspaceItem.getStageReached())
          && (page > workspaceItem.getPageReached())) {
        workspaceItem.setPageReached(page);
        workspaceItemService.update(context, workspaceItem);
      }
    }
  }
Example #4
0
 // check whether any bundle belongs to any item that passed submission
 // and workflow process
 protected boolean isAnyItemInstalled(Context ctx, List<Bundle> bundles) throws SQLException {
   for (Bundle bundle : bundles) {
     for (Item item : bundle.getItems()) {
       if (workspaceItemService.findByItem(ctx, item) == null
           && workflowItemService.findByItem(ctx, item) == null) {
         return true;
       }
     }
   }
   return false;
 }
Example #5
0
  /**
   * Return the InProgressSubmission, either workspaceItem or workflowItem, depending on the id
   * provided. If the id begins with an S then it is a considered a workspaceItem. If the id begins
   * with a W then it is considered a workflowItem.
   *
   * @param context
   * @param inProgressSubmissionID
   * @return The InprogressSubmission or null if non found
   */
  public static InProgressSubmission findSubmission(Context context, String inProgressSubmissionID)
      throws SQLException, AuthorizeException, IOException {
    char type = inProgressSubmissionID.charAt(0);
    int id = Integer.valueOf(inProgressSubmissionID.substring(1));

    if (type == 'S') {
      return workspaceItemService.find(context, id);
    } else if (type == 'W' || type == 'X') {
      return workflowService.find(context, id);
    }
    return null;
  }
Example #6
0
  /**
   * Set a specific step and page as reached. It will also "set back" where a user has reached.
   *
   * @param context The current DSpace content
   * @param id The unique ID of the current workflow/workspace
   * @param step the step to set as reached, can be also a previous reached step
   * @param page the page (within the step) to set as reached, can be also a previous reached page
   */
  public static void setBackPageReached(Context context, String id, int step, int page)
      throws SQLException, AuthorizeException, IOException {
    InProgressSubmission submission = findSubmission(context, id);

    if (submission instanceof WorkspaceItem) {
      WorkspaceItem workspaceItem = (WorkspaceItem) submission;

      workspaceItem.setStageReached(step);
      workspaceItem.setPageReached(page > 0 ? page : 1);
      workspaceItemService.update(context, workspaceItem);
    }
  }
  /**
   * 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;
  }
  @Override
  public BasicWorkflowItem start(Context context, WorkspaceItem wsi)
      throws SQLException, AuthorizeException, IOException {
    // FIXME Check auth
    Item myitem = wsi.getItem();
    Collection collection = wsi.getCollection();

    log.info(
        LogManager.getHeader(
            context,
            "start_workflow",
            "workspace_item_id="
                + wsi.getID()
                + "item_id="
                + myitem.getID()
                + "collection_id="
                + collection.getID()));

    // record the start of the workflow w/provenance message
    recordStart(context, myitem);

    // create the WorkflowItem
    BasicWorkflowItem wfi = workflowItemService.create(context, myitem, collection);
    wfi.setMultipleFiles(wsi.hasMultipleFiles());
    wfi.setMultipleTitles(wsi.hasMultipleTitles());
    wfi.setPublishedBefore(wsi.isPublishedBefore());

    // remove the WorkspaceItem
    workspaceItemService.deleteWrapper(context, wsi);

    // now get the workflow started
    wfi.setState(WFSTATE_SUBMIT);
    advance(context, wfi, null);

    // Return the workflow item
    return wfi;
  }
  @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);
    }
  }
Example #10
0
  /**
   * Check to see if the given user can perform the given action on the given object. Always returns
   * true if the ignore authorization flat is set in the current context.
   *
   * @param c current context. User is irrelevant; "ignore authorization" flag is relevant
   * @param o object action is being attempted on
   * @param action ID of action being attempted, from <code>org.dspace.core.Constants</code>
   * @param e user attempting action
   * @param useInheritance flag to say if ADMIN action on the current object or parent object can be
   *     used
   * @return <code>true</code> if user is authorized to perform the given action, <code>false</code>
   *     otherwise
   * @throws SQLException if database error
   */
  protected boolean authorize(
      Context c, DSpaceObject o, int action, EPerson e, boolean useInheritance)
      throws SQLException {
    // return FALSE if there is no DSpaceObject
    if (o == null) {
      return false;
    }

    // is authorization disabled for this context?
    if (c.ignoreAuthorization()) {
      return true;
    }

    // is eperson set? if not, userToCheck = null (anonymous)
    EPerson userToCheck = null;
    if (e != null) {
      userToCheck = e;

      // perform isAdmin check to see
      // if user is an Admin on this object
      DSpaceObject adminObject =
          useInheritance
              ? serviceFactory.getDSpaceObjectService(o).getAdminObject(c, o, action)
              : null;

      if (isAdmin(c, adminObject)) {
        return true;
      }
    }

    // In case the dso is an bundle or bitstream we must ignore custom
    // policies if it does not belong to at least one installed item (see
    // DS-2614).
    // In case the dso is an item and a corresponding workspace or workflow
    // item exist, we have to ignore custom policies (see DS-2614).
    boolean ignoreCustomPolicies = false;
    if (o instanceof Bitstream) {
      Bitstream b = (Bitstream) o;

      // Ensure that this is not a collection or community logo
      DSpaceObject parent = bitstreamService.getParentObject(c, b);
      if (!(parent instanceof Collection) && !(parent instanceof Community)) {
        ignoreCustomPolicies = !isAnyItemInstalled(c, b.getBundles());
      }
    }
    if (o instanceof Bundle) {
      ignoreCustomPolicies = !isAnyItemInstalled(c, Arrays.asList(((Bundle) o)));
    }
    if (o instanceof Item) {
      if (workspaceItemService.findByItem(c, (Item) o) != null
          || workflowItemService.findByItem(c, (Item) o) != null) {
        ignoreCustomPolicies = true;
      }
    }

    for (ResourcePolicy rp : getPoliciesActionFilter(c, o, action)) {

      if (ignoreCustomPolicies && ResourcePolicy.TYPE_CUSTOM.equals(rp.getRpType())) {
        continue;
      }

      // check policies for date validity
      if (resourcePolicyService.isDateValid(rp)) {
        if (rp.getEPerson() != null && rp.getEPerson().equals(userToCheck)) {
          return true; // match
        }

        if ((rp.getGroup() != null) && (groupService.isMember(c, rp.getGroup()))) {
          // group was set, and eperson is a member
          // of that group
          return true;
        }
      }
    }

    // default authorization is denial
    return false;
  }