// 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();
  }
Beispiel #2
0
  /**
   * Process the Options to apply to the Item. The options are tab delimited
   *
   * <p>Options: 48217870-MIT.pdf permissions: -r 'MIT Users' description: Full printable version
   * (MIT only) permissions:[r|w]-['group name'] description: 'the description of the file'
   *
   * <p>where: [r|w] (meaning: read|write) ['MIT Users'] (the group name)
   *
   * @param c
   * @param myItem
   * @param options
   * @throws SQLException
   * @throws AuthorizeException
   */
  private void processOptions(Context c, Item myItem, List<String> options)
      throws SQLException, AuthorizeException {
    for (String line : options) {
      System.out.println("\tprocessing " + line);

      boolean permissionsExist = false;
      boolean descriptionExists = false;

      String permissionsMarker = "\tpermissions:";
      int pMarkerIndex = line.indexOf(permissionsMarker);
      int pEndIndex = 0;
      if (pMarkerIndex > 0) {
        pEndIndex = line.indexOf("\t", pMarkerIndex + 1);
        if (pEndIndex == -1) {
          pEndIndex = line.length();
        }
        permissionsExist = true;
      }

      String descriptionMarker = "\tdescription:";
      int dMarkerIndex = line.indexOf(descriptionMarker);
      int dEndIndex = 0;
      if (dMarkerIndex > 0) {
        dEndIndex = line.indexOf("\t", dMarkerIndex + 1);
        if (dEndIndex == -1) {
          dEndIndex = line.length();
        }
        descriptionExists = true;
      }

      int bsEndIndex = line.indexOf("\t");
      String bitstreamName = line.substring(0, bsEndIndex);

      int actionID = -1;
      String groupName = "";
      Group myGroup = null;
      if (permissionsExist) {
        String thisPermission =
            line.substring(pMarkerIndex + permissionsMarker.length(), pEndIndex);

        // get permission type ("read" or "write")
        int pTypeIndex = thisPermission.indexOf('-');

        // get permission group (should be in single quotes)
        int groupIndex = thisPermission.indexOf('\'', pTypeIndex);
        int groupEndIndex = thisPermission.indexOf('\'', groupIndex + 1);

        // if not in single quotes, assume everything after type flag is
        // group name
        if (groupIndex == -1) {
          groupIndex = thisPermission.indexOf(' ', pTypeIndex);
          groupEndIndex = thisPermission.length();
        }

        groupName = thisPermission.substring(groupIndex + 1, groupEndIndex);

        if (thisPermission.toLowerCase().charAt(pTypeIndex + 1) == 'r') {
          actionID = Constants.READ;
        } else if (thisPermission.toLowerCase().charAt(pTypeIndex + 1) == 'w') {
          actionID = Constants.WRITE;
        }

        try {
          myGroup = Group.findByName(c, groupName);
        } catch (SQLException sqle) {
          System.out.println("SQL Exception finding group name: " + groupName);
          // do nothing, will check for null group later
        }
      }

      String thisDescription = "";
      if (descriptionExists) {
        thisDescription =
            line.substring(dMarkerIndex + descriptionMarker.length(), dEndIndex).trim();
      }

      Bitstream bs = null;
      boolean notfound = true;
      if (!isTest) {
        // find bitstream
        Bitstream[] bitstreams = myItem.getNonInternalBitstreams();
        for (int j = 0; j < bitstreams.length && notfound; j++) {
          if (bitstreams[j].getName().equals(bitstreamName)) {
            bs = bitstreams[j];
            notfound = false;
          }
        }
      }

      if (notfound && !isTest) {
        // this should never happen
        System.out.println("\tdefault permissions set for " + bitstreamName);
      } else if (!isTest) {
        if (permissionsExist) {
          if (myGroup == null) {
            System.out.println("\t" + groupName + " not found, permissions set to default");
          } else if (actionID == -1) {
            System.out.println("\tinvalid permissions flag, permissions set to default");
          } else {
            System.out.println("\tSetting special permissions for " + bitstreamName);
            setPermission(c, myGroup, actionID, bs);
          }
        }

        if (descriptionExists) {
          System.out.println("\tSetting description for " + bitstreamName);
          bs.setDescription(thisDescription);
          bs.update();
        }
      }
    }
  }