// Create workflow start provenance message
  private static void recordStart(Context c, Item myitem)
      throws SQLException, IOException, AuthorizeException {
    // Get non-internal format bitstreams
    Bitstream[] bitstreams = myitem.getNonInternalBitstreams();

    // 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 += InstallItem.getBitstreamProvenanceMessage(myitem);

    // Add message to the DC
    myitem.addDC("description", "provenance", "en", provmessage);
    myitem.update();
  }
  /**
   * rejects an item - rejection means undoing a submit - WorkspaceItem is created, and the
   * WorkflowItem is removed, user is emailed rejection_message.
   *
   * @param c Context
   * @param wi WorkflowItem to operate on
   * @param e EPerson doing the operation
   * @param rejection_message message to email to user
   */
  public static WorkspaceItem reject(
      Context c, WorkflowItem wi, EPerson e, String rejection_message)
      throws SQLException, AuthorizeException, IOException {
    // authorize a DSpaceActions.REJECT
    // stop workflow
    deleteTasks(c, wi);

    // 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 =
        "Rejected by " + usersName + ", reason: " + rejection_message + " on " + now + " (GMT) ";

    // Add to item as a DC field
    myitem.addDC("description", "provenance", "en", provDescription);
    myitem.update();

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

    // notify that it's been rejected
    notifyOfReject(c, wi, e, rejection_message);

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

    return wsi;
  }
  // Record approval provenance statement
  private static void recordApproval(Context c, WorkflowItem wi, EPerson e)
      throws SQLException, IOException, AuthorizeException {
    Item item = wi.getItem();

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

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

    // Here's what happened
    String provDescription =
        "Approved for entry into archive by " + usersName + " on " + now + " (GMT) ";

    // add bitstream descriptions (name, size, checksums)
    provDescription += InstallItem.getBitstreamProvenanceMessage(item);

    // Add to item as a DC field
    item.addDC("description", "provenance", "en", provDescription);
    item.update();
  }
Example #4
0
  private void crosswalkPDF(Context context, Item item, InputStream metadata)
      throws CrosswalkException, IOException, SQLException, AuthorizeException {
    COSDocument cos = null;

    try {
      PDFParser parser = new PDFParser(metadata);
      parser.parse();
      cos = parser.getDocument();

      // sanity check: PDFBox breaks on encrypted documents, so give up.
      if (cos.getEncryptionDictionary() != null)
        throw new MetadataValidationException(
            "This packager cannot accept an encrypted PDF document.");

      /* PDF to DC "crosswalk":
       *
       * NOTE: This is not in a crosswalk plugin because (a) it isn't
       * useful anywhere else, and more importantly, (b) the source
       * data is not XML so it doesn't fit the plugin's interface.
       *
       * pattern of crosswalk -- PDF dict entries to DC:
       *   Title -> title.null
       *   Author -> contributor.author
       *   CreationDate -> date.created
       *   ModDate -> date.created
       *   Creator -> description.provenance (application that created orig)
       *   Producer -> description.provenance (convertor to pdf)
       *   Subject -> description.abstract
       *   Keywords -> subject.other
       *    date is java.util.Calendar
       */
      PDDocument pd = new PDDocument(cos);
      PDDocumentInformation docinfo = pd.getDocumentInformation();
      String title = docinfo.getTitle();

      // sanity check: item must have a title.
      if (title == null)
        throw new MetadataValidationException(
            "This PDF file is unacceptable, it does not have a value for \"Title\" in its Info dictionary.");
      log.debug("PDF Info dict title=\"" + title + "\"");
      item.addDC("title", null, "en", title);
      String value;
      Calendar date;
      if ((value = docinfo.getAuthor()) != null) {
        item.addDC("contributor", "author", null, value);
        log.debug("PDF Info dict author=\"" + value + "\"");
      }
      if ((value = docinfo.getCreator()) != null)
        item.addDC(
            "description",
            "provenance",
            "en",
            "Application that created the original document: " + value);
      if ((value = docinfo.getProducer()) != null)
        item.addDC(
            "description", "provenance", "en", "Original document converted to PDF by: " + value);
      if ((value = docinfo.getSubject()) != null)
        item.addDC("description", "abstract", null, value);
      if ((value = docinfo.getKeywords()) != null) item.addDC("subject", "other", null, value);

      // Take either CreationDate or ModDate as "date.created",
      // Too bad there's no place to put "last modified" in the DC.
      Calendar calValue;
      if ((calValue = docinfo.getCreationDate()) == null) calValue = docinfo.getModificationDate();
      if (calValue != null)
        item.addDC("date", "created", null, (new DCDate(calValue.getTime())).toString());
      item.update();
    } finally {
      if (cos != null) cos.close();
    }
  }