Exemplo n.º 1
0
  /**
   * Send a collection backup file and respective children to cloud to be preserved.
   *
   * @param context context DSpace
   * @param ref ID of the collection
   * @param establishConnection true if pretend establish connection to cloud
   * @return true if file correctly sent to cloud, or false if not
   */
  public Boolean sendCollectionAndChilds(
      Context context, Integer ref, Boolean establishConnection) {
    // if first, make connection and get collection and item files preserved in cloud
    if (establishConnection == true) {
      this.makeConnection();
      this.filesInCloud.putAll(this.newCloudConnection.getInfoFilesIn(Constants.COLLECTION));
      this.filesInCloud.putAll(this.newCloudConnection.getInfoFilesIn(Constants.ITEM));
    }

    // send to cloud atual collection
    sendCollection(context, ref, false);

    Collection obj;
    ItemIterator items;

    // get the items presents in the collection
    try {
      obj = Collection.find(context, ref);
      items = obj.getAllItems();
    } catch (Exception ex) {
      Logger.getLogger(ActualContentManagement.class.getName()).log(Level.SEVERE, null, ex);
      // it means it is the first father in the order, so close connection
      if (establishConnection == true) this.closeConnection();
      return false;
    }

    // send to cloud, one by one, each item
    try {
      if (items.hasNext()) {
        Item newObj = items.next();
        sendItem(context, newObj.getID(), false);
      }
    } catch (Exception ex) {
      Logger.getLogger(ActualContentManagement.class.getName()).log(Level.SEVERE, null, ex);
      // it means it is the first father in the order, so close connection
      if (establishConnection == true) this.closeConnection();
      return false;
    }

    // it means it is the first father in the order
    if (establishConnection == true) this.closeConnection();

    return true;
  }
Exemplo n.º 2
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);
  }