@Override
  protected boolean checkMetadataReferenceExists(
      String depositId, IngestWorkflowState state, String reference) {
    try {
      if (!checkProjectExists(reference)) {
        if (!checkCollectionExists(reference)) {
          if (!checkDataItemExists(reference)) {
            DcsEvent event = state.getEventManager().newEvent(Package.Events.INGEST_FAIL);
            String stackTrace = "";
            for (StackTraceElement st : Thread.currentThread().getStackTrace()) {
              stackTrace += st + "\n";
            }
            event.setDetail(stackTrace);
            event.setOutcome("Package Missing external reference: " + reference);
            List<DcsEntityReference> refs = new ArrayList<DcsEntityReference>();
            DcsEntityReference ref = new DcsEntityReference(reference);
            refs.add(ref);

            event.setTargets(refs);

            state.getEventManager().addEvent(depositId, event);
            return false;
          }
        }
      }

    } catch (Exception e) {
      DcsEvent event = state.getEventManager().newEvent(Package.Events.INGEST_FAIL);
      event.setDetail(e.getStackTrace().toString());
      event.setOutcome(
          "Failed to validate external reference: " + reference + " " + e.getMessage());
      List<DcsEntityReference> refs = new ArrayList<DcsEntityReference>();
      DcsEntityReference ref = new DcsEntityReference(reference);
      refs.add(ref);

      event.setTargets(refs);

      state.getEventManager().addEvent(depositId, event);
      return false;
    }

    return true;
  }
  @Override
  protected boolean checkReferenceExists(
      String depositId, IngestWorkflowState state, String reference, String expectedReferenceType) {
    boolean found = false;

    /*This service only handles references to external objects.
     * So any references that don't start with http should be passed through. These will be checked by the internal
     * reference checker.*/
    if (!reference.startsWith("http:")) {
      return true;
    }

    try {
      if (expectedReferenceType.equalsIgnoreCase("project")) {
        found = checkProjectExists(reference);
      } else if (expectedReferenceType.equalsIgnoreCase("collection")) {
        found = checkCollectionExists(reference);
      } else if (expectedReferenceType.equalsIgnoreCase("dataItem")) {
        found = checkDataItemExists(reference);
      } else if (expectedReferenceType.equalsIgnoreCase("file")) {
        found = checkFileExists(reference);
      } else if (expectedReferenceType.equalsIgnoreCase("collection|project")) {
        if (idService.fromUrl(new URL(reference)).getType() == Types.COLLECTION.getTypeName()) {
          found = checkCollectionExists(reference);
        } else {
          found = checkProjectExists(reference);
        }
      }

      if (!found) {
        DcsEvent event = state.getEventManager().newEvent(Package.Events.INGEST_FAIL);
        String stackTrace = "";
        for (StackTraceElement st : Thread.currentThread().getStackTrace()) {
          stackTrace += st + "\n";
        }
        event.setDetail(stackTrace);
        event.setOutcome("Package Missing external reference: " + reference);
        List<DcsEntityReference> refs = new ArrayList<DcsEntityReference>();
        DcsEntityReference ref = new DcsEntityReference(reference);
        refs.add(ref);

        event.setTargets(refs);

        state.getEventManager().addEvent(depositId, event);
        return false;
      }
    } catch (Exception e) {
      DcsEvent event = state.getEventManager().newEvent(Package.Events.INGEST_FAIL);
      event.setDetail(e.getStackTrace().toString());
      event.setOutcome(
          "Failed to validate external reference: " + reference + " " + e.getMessage());
      List<DcsEntityReference> refs = new ArrayList<DcsEntityReference>();
      DcsEntityReference ref = new DcsEntityReference(reference);
      refs.add(ref);

      event.setTargets(refs);

      state.getEventManager().addEvent(depositId, event);
      return false;
    }

    return found;
  }