コード例 #1
0
  /**
   * Commit the contained item to the main archive. The item is associated with the relevant
   * collection, added to the search index, and any other tasks such as assigning dates are
   * performed.
   *
   * @return the fully archived item.
   */
  @Override
  public Item archive(Context context, BasicWorkflowItem workflowItem)
      throws SQLException, IOException, AuthorizeException {
    // FIXME: Check auth
    Item item = workflowItem.getItem();
    Collection collection = workflowItem.getCollection();

    log.info(
        LogManager.getHeader(
            context,
            "archive_item",
            "workflow_item_id="
                + workflowItem.getID()
                + "item_id="
                + item.getID()
                + "collection_id="
                + collection.getID()));

    installItemService.installItem(context, workflowItem);

    // Log the event
    log.info(
        LogManager.getHeader(
            context,
            "install_item",
            "workflow_id=" + workflowItem.getID() + ", item_id=" + item.getID() + "handle=FIXME"));

    return item;
  }
コード例 #2
0
  // Create workflow start provenance message
  protected void recordStart(Context context, Item myitem)
      throws SQLException, IOException, AuthorizeException {
    // get date
    DCDate now = DCDate.getCurrent();

    // Create provenance description
    String provmessage;

    if (myitem.getSubmitter() != null) {
      provmessage =
          "Submitted by "
              + myitem.getSubmitter().getFullName()
              + " ("
              + myitem.getSubmitter().getEmail()
              + ") on "
              + now.toString()
              + "\n";
    } else
    // null submitter
    {
      provmessage = "Submitted by unknown (probably automated) on" + now.toString() + "\n";
    }

    // add sizes and checksums of bitstreams
    provmessage += installItemService.getBitstreamProvenanceMessage(context, myitem);

    // Add message to the DC
    itemService.addMetadata(
        context, myitem, MetadataSchema.DC_SCHEMA, "description", "provenance", "en", provmessage);
    itemService.update(context, myitem);
  }
コード例 #3
0
  @Override
  public String getItemTitle(BasicWorkflowItem wi) throws SQLException {
    Item myitem = wi.getItem();
    String title = myitem.getName();

    // only return the first element, or "Untitled"
    if (StringUtils.isNotBlank(title)) {
      return title;
    } else {
      return I18nUtil.getMessage("org.dspace.workflow.WorkflowManager.untitled ");
    }
  }
コード例 #4
0
 protected void removeUserItemPolicies(Context context, Item item, EPerson e)
     throws SQLException, AuthorizeException {
   if (e != null) {
     // Also remove any lingering authorizations from this user
     authorizeService.removeEPersonPolicies(context, item, e);
     // Remove the bundle rights
     List<Bundle> bundles = item.getBundles();
     for (Bundle bundle : bundles) {
       authorizeService.removeEPersonPolicies(context, bundle, e);
       List<Bitstream> bitstreams = bundle.getBitstreams();
       for (Bitstream bitstream : bitstreams) {
         authorizeService.removeEPersonPolicies(context, bitstream, e);
       }
     }
     // Ensure that the submitter always retains his resource policies
     if (e.getID().equals(item.getSubmitter().getID())) {
       grantSubmitterReadPolicies(context, item);
     }
   }
 }
コード例 #5
0
  /**
   * Commit the contained item to the main archive. The item is associated with the relevant
   * collection, added to the search index, and any other tasks such as assigning dates are
   * performed.
   *
   * @param context The relevant DSpace Context.
   * @param wfi workflow item
   * @return the fully archived item.
   * @throws IOException A general class of exceptions produced by failed or interrupted I/O
   *     operations.
   * @throws SQLException An exception that provides information on a database access error or other
   *     errors.
   * @throws AuthorizeException Exception indicating the current user of the context does not have
   *     permission to perform a particular action.
   */
  @Override
  public Item archive(Context context, XmlWorkflowItem wfi)
      throws SQLException, IOException, AuthorizeException {
    // FIXME: Check auth
    Item item = wfi.getItem();
    Collection collection = wfi.getCollection();

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

    log.info(
        LogManager.getHeader(
            context,
            "archive_item",
            "workflow_item_id="
                + wfi.getID()
                + "item_id="
                + item.getID()
                + "collection_id="
                + collection.getID()));

    installItemService.installItem(context, wfi);

    // Notify
    notifyOfArchive(context, item, collection);

    // Clear any remaining workflow metadata
    itemService.clearMetadata(
        context, item, WorkflowRequirementsService.WORKFLOW_SCHEMA, Item.ANY, Item.ANY, Item.ANY);
    itemService.update(context, item);

    // Log the event
    log.info(
        LogManager.getHeader(
            context,
            "install_item",
            "workflow_item_id=" + wfi.getID() + ", item_id=" + item.getID() + "handle=FIXME"));

    return item;
  }
コード例 #6
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;
  }
コード例 #7
0
 protected void addGroupPolicyToItem(Context context, Item item, int type, Group group)
     throws AuthorizeException, SQLException {
   if (group != null) {
     authorizeService.addPolicy(context, item, type, group);
     List<Bundle> bundles = item.getBundles();
     for (Bundle bundle : bundles) {
       authorizeService.addPolicy(context, bundle, type, group);
       List<Bitstream> bits = bundle.getBitstreams();
       for (Bitstream bit : bits) {
         authorizeService.addPolicy(context, bit, type, group);
       }
     }
   }
 }
コード例 #8
0
  @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;
  }
コード例 #9
0
  /**
   * notify the submitter that the item is archived
   *
   * @param context The relevant DSpace Context.
   * @param item which item was archived
   * @param coll collection name to display in template
   * @throws SQLException An exception that provides information on a database access error or other
   *     errors.
   * @throws IOException A general class of exceptions produced by failed or interrupted I/O
   *     operations.
   */
  protected void notifyOfArchive(Context context, Item item, Collection coll)
      throws SQLException, IOException {
    try {
      // Get submitter
      EPerson ep = item.getSubmitter();
      // Get the Locale
      Locale supportedLocale = I18nUtil.getEPersonLocale(ep);
      Email email = Email.getEmail(I18nUtil.getEmailFilename(supportedLocale, "submit_archive"));

      // Get the item handle to email to user
      String handle = handleService.findHandle(context, item);

      // Get title
      List<MetadataValue> titles =
          itemService.getMetadata(item, MetadataSchema.DC_SCHEMA, "title", null, Item.ANY);
      String title = "";
      try {
        title = I18nUtil.getMessage("org.dspace.workflow.WorkflowManager.untitled");
      } catch (MissingResourceException e) {
        title = "Untitled";
      }
      if (titles.size() > 0) {
        title = titles.iterator().next().getValue();
      }

      email.addRecipient(ep.getEmail());
      email.addArgument(title);
      email.addArgument(coll.getName());
      email.addArgument(handleService.getCanonicalForm(handle));

      email.send();
    } catch (MessagingException e) {
      log.warn(
          LogManager.getHeader(
              context, "notifyOfArchive", "cannot email user" + " item_id=" + item.getID()));
    }
  }
コード例 #10
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);
    }
  }
コード例 #11
0
  /** notify the submitter that the item is archived */
  protected void notifyOfArchive(Context context, Item item, Collection coll)
      throws SQLException, IOException {
    try {
      // Get submitter
      EPerson ep = item.getSubmitter();
      // Get the Locale
      Locale supportedLocale = I18nUtil.getEPersonLocale(ep);
      Email email = Email.getEmail(I18nUtil.getEmailFilename(supportedLocale, "submit_archive"));

      // Get the item handle to email to user
      String handle = handleService.findHandle(context, item);

      // Get title
      String title = item.getName();
      if (StringUtils.isBlank(title)) {
        try {
          title = I18nUtil.getMessage("org.dspace.workflow.WorkflowManager.untitled");
        } catch (MissingResourceException e) {
          title = "Untitled";
        }
      }

      email.addRecipient(ep.getEmail());
      email.addArgument(title);
      email.addArgument(coll.getName());
      email.addArgument(handleService.getCanonicalForm(handle));

      email.send();
    } catch (MessagingException e) {
      log.warn(
          LogManager.getHeader(
              context,
              "notifyOfArchive",
              "cannot email user; item_id=" + item.getID() + ":  " + e.getMessage()));
    }
  }
コード例 #12
0
 protected void removeGroupItemPolicies(Context context, Item item, Group e)
     throws SQLException, AuthorizeException {
   if (e != null) {
     // Also remove any lingering authorizations from this user
     authorizeService.removeGroupPolicies(context, item, e);
     // Remove the bundle rights
     List<Bundle> bundles = item.getBundles();
     for (Bundle bundle : bundles) {
       authorizeService.removeGroupPolicies(context, bundle, e);
       List<Bitstream> bitstreams = bundle.getBitstreams();
       for (Bitstream bitstream : bitstreams) {
         authorizeService.removeGroupPolicies(context, bitstream, e);
       }
     }
   }
 }
コード例 #13
0
 protected void grantSubmitterReadPolicies(Context context, Item item)
     throws SQLException, AuthorizeException {
   // A list of policies the user has for this item
   List<Integer> userHasPolicies = new ArrayList<Integer>();
   List<ResourcePolicy> itempols = authorizeService.getPolicies(context, item);
   EPerson submitter = item.getSubmitter();
   for (ResourcePolicy resourcePolicy : itempols) {
     if (submitter.equals(resourcePolicy.getEPerson())) {
       // The user has already got this policy so add it to the list
       userHasPolicies.add(resourcePolicy.getAction());
     }
   }
   // Make sure we don't add duplicate policies
   if (!userHasPolicies.contains(Constants.READ))
     addPolicyToItem(context, item, Constants.READ, submitter);
 }