コード例 #1
0
  /**
   * Use the collection's harvest settings to immediately perform a harvest cycle.
   *
   * @param context The current DSpace context.
   * @param collectionID The collection id.
   * @param request the Cocoon request object
   * @return A process result's object.
   * @throws TransformerException
   * @throws SAXException
   * @throws ParserConfigurationException
   * @throws CrosswalkException
   */
  public static FlowResult processRunCollectionHarvest(
      Context context, int collectionID, Request request)
      throws SQLException, IOException, AuthorizeException, CrosswalkException,
          ParserConfigurationException, SAXException, TransformerException {
    FlowResult result = new FlowResult();
    OAIHarvester harvester;
    List<String> testErrors = new ArrayList<String>();
    Collection collection = Collection.find(context, collectionID);
    HarvestedCollection hc = HarvestedCollection.find(context, collectionID);

    // TODO: is there a cleaner way to do this?
    try {
      if (!HarvestScheduler.hasStatus(HarvestScheduler.HARVESTER_STATUS_STOPPED)) {
        synchronized (HarvestScheduler.lock) {
          HarvestScheduler.setInterrupt(
              HarvestScheduler.HARVESTER_INTERRUPT_INSERT_THREAD, collectionID);
          HarvestScheduler.lock.notify();
        }
      } else {
        harvester = new OAIHarvester(context, collection, hc);
        harvester.runHarvest();
      }
    } catch (Exception e) {
      testErrors.add(e.getMessage());
      result.setErrors(testErrors);
      result.setContinue(false);
      return result;
    }

    result.setContinue(true);

    return result;
  }
コード例 #2
0
  /**
   * Process the collection harvesting options form.
   *
   * @param context The current DSpace context.
   * @param collectionID The collection id.
   * @param request the Cocoon request object
   * @return A process result's object.
   */
  public static FlowResult processSetupCollectionHarvesting(
      Context context, int collectionID, Request request)
      throws SQLException, IOException, AuthorizeException {
    FlowResult result = new FlowResult();
    HarvestedCollection hc = HarvestedCollection.find(context, collectionID);

    String contentSource = request.getParameter("source");

    // First, if this is not a harvested collection (anymore), set the harvest type to 0; possibly
    // also wipe harvest settings
    if (contentSource.equals("source_normal")) {
      if (hc != null) {
        hc.delete();
      }

      result.setContinue(true);
    } else {
      FlowResult subResult = testOAISettings(context, request);

      // create a new harvest instance if all the settings check out
      if (hc == null) {
        hc = HarvestedCollection.create(context, collectionID);
      }

      // if the supplied options all check out, set the harvesting parameters on the collection
      if (subResult.getErrors().isEmpty()) {
        String oaiProvider = request.getParameter("oai_provider");
        boolean oaiAllSets = "all".equals(request.getParameter("oai-set-setting"));
        String oaiSetId;
        if (oaiAllSets) {
          oaiSetId = "all";
        } else {
          oaiSetId = request.getParameter("oai_setid");
        }

        String metadataKey = request.getParameter("metadata_format");
        String harvestType = request.getParameter("harvest_level");

        hc.setHarvestParams(Integer.parseInt(harvestType), oaiProvider, oaiSetId, metadataKey);
        hc.setHarvestStatus(HarvestedCollection.STATUS_READY);
      } else {
        result.setErrors(subResult.getErrors());
        result.setContinue(false);
        return result;
      }

      hc.update();
    }

    // Save everything
    context.commit();

    // No notice...
    // result.setMessage(new Message("default","Harvesting options successfully modified."));
    result.setOutcome(true);
    result.setContinue(true);

    return result;
  }
コード例 #3
0
  /**
   * Purge the collection of all items, then run a fresh harvest cycle.
   *
   * @param context The current DSpace context.
   * @param collectionID The collection id.
   * @param request the Cocoon request object
   * @return A process result's object.
   * @throws TransformerException
   * @throws SAXException
   * @throws ParserConfigurationException
   * @throws CrosswalkException
   * @throws BrowseException
   */
  public static FlowResult processReimportCollection(
      Context context, int collectionID, Request request)
      throws SQLException, IOException, AuthorizeException, CrosswalkException,
          ParserConfigurationException, SAXException, TransformerException, BrowseException {
    Collection collection = Collection.find(context, collectionID);
    HarvestedCollection hc = HarvestedCollection.find(context, collectionID);

    ItemIterator it = collection.getAllItems();
    // IndexBrowse ib = new IndexBrowse(context);
    while (it.hasNext()) {
      Item item = it.next();
      // System.out.println("Deleting: " + item.getHandle());
      // ib.itemRemoved(item);
      collection.removeItem(item);
    }
    hc.setHarvestResult(null, "");
    hc.update();
    collection.update();
    context.commit();

    return processRunCollectionHarvest(context, collectionID, request);
  }