/**
   * Consume an Install event. If the item is being installed and it is not embargoed then we want
   * to set the item's policies. See {@link DuoPolicyManager} for details
   *
   * @param context
   * @param event
   * @throws Exception
   */
  public void consume(Context context, Event event) throws Exception {
    Item item = (Item) event.getSubject(context);

    // check to see if the item has a StudentWeb grade of "fail"
    if (this.isFail(context, item)) {
      // if so, withdraw the item
      item.withdraw();
      return;
    }

    // we mustn't set the policies if the item is embargoed; these will have already
    // been removed, and should stay that way
    if (this.isEmbargoed(context, item)) {
      return;
    }

    DuoPolicyManager dpm = new DuoPolicyManager();
    dpm.setDefaultPolicies(context, item);
  }
Example #2
0
  /**
   * Consume a content event -- just build the sets of objects to add (new) to the index, update,
   * and delete.
   *
   * @param ctx DSpace context
   * @param event Content event
   */
  public void consume(Context ctx, Event event) throws Exception {

    if (objectsToUpdate == null) {
      objectsToUpdate = new HashSet<DSpaceObject>();
      handlesToDelete = new HashSet<String>();
    }

    int st = event.getSubjectType();
    if (!(st == Constants.ITEM
        || st == Constants.BUNDLE
        || st == Constants.COLLECTION
        || st == Constants.COMMUNITY)) {
      log.warn(
          "SearchConsumer should not have been given this kind of Subject in an event, skipping: "
              + event.toString());
      return;
    }

    DSpaceObject subject = event.getSubject(ctx);

    DSpaceObject object = event.getObject(ctx);

    // If event subject is a Bundle and event was Add or Remove,
    // transform the event to be a Modify on the owning Item.
    // It could be a new bitstream in the TEXT bundle which
    // would change the index.
    int et = event.getEventType();
    if (st == Constants.BUNDLE) {
      if ((et == Event.ADD || et == Event.REMOVE)
          && subject != null
          && "TEXT".equals(((Bundle) subject).getName())) {
        st = Constants.ITEM;
        et = Event.MODIFY;
        subject = ((Bundle) subject).getItems()[0];
        if (log.isDebugEnabled()) {
          log.debug("Transforming Bundle event into MODIFY of Item " + subject.getHandle());
        }
      } else {
        return;
      }
    }

    switch (et) {
      case Event.CREATE:
      case Event.MODIFY:
      case Event.MODIFY_METADATA:
        if (subject == null) {
          log.warn(
              event.getEventTypeAsString()
                  + " event, could not get object for "
                  + event.getSubjectTypeAsString()
                  + " id="
                  + String.valueOf(event.getSubjectID())
                  + ", perhaps it has been deleted.");
        } else {
          log.debug("consume() adding event to update queue: " + event.toString());
          objectsToUpdate.add(subject);
        }
        break;

      case Event.REMOVE:
      case Event.ADD:
        if (object == null) {
          log.warn(
              event.getEventTypeAsString()
                  + " event, could not get object for "
                  + event.getObjectTypeAsString()
                  + " id="
                  + String.valueOf(event.getObjectID())
                  + ", perhaps it has been deleted.");
        } else {
          log.debug("consume() adding event to update queue: " + event.toString());
          objectsToUpdate.add(object);
        }
        break;

      case Event.DELETE:
        String detail = event.getDetail();
        if (detail == null) {
          log.warn("got null detail on DELETE event, skipping it.");
        } else {
          log.debug("consume() adding event to delete queue: " + event.toString());
          handlesToDelete.add(detail);
        }
        break;
      default:
        log.warn(
            "SearchConsumer should not have been given a event of type="
                + event.getEventTypeAsString()
                + " on subject="
                + event.getSubjectTypeAsString());
        break;
    }
  }