@Override
 public void moveOnlineReviews(
     ProtocolSubmissionBase submission, ProtocolSubmissionBase newSubmission) {
   newSubmission.setProtocolOnlineReviews(new ArrayList<ProtocolOnlineReviewBase>());
   for (ProtocolOnlineReviewBase review : submission.getProtocolOnlineReviews()) {
     review.setProtocol(newSubmission.getProtocol());
     review.setProtocolId(newSubmission.getProtocol().getProtocolId());
     review.setSubmissionIdFk(newSubmission.getSubmissionId());
     if (CollectionUtils.isNotEmpty(review.getCommitteeScheduleMinutes())) {
       for (CommitteeScheduleMinuteBase comment : review.getCommitteeScheduleMinutes()) {
         comment.setProtocolIdFk(review.getProtocolId());
         comment.setScheduleIdFk(newSubmission.getScheduleIdFk());
       }
     }
     newSubmission.getProtocolOnlineReviews().add(review);
   }
 }
 /*
  * create the view link url for protocolsubmission
  */
 protected AnchorHtmlData getViewLink(ProtocolSubmissionBase protocolSubmission) {
   AnchorHtmlData viewHtmlData =
       super.getViewLink(protocolSubmission.getProtocol().getProtocolDocument());
   String submissionIdParam = "&submissionId=" + protocolSubmission.getSubmissionId();
   String href = viewHtmlData.getHref();
   href = href.replace(DOC_TYPE_NAME_PARAM, submissionIdParam + DOC_TYPE_NAME_PARAM);
   viewHtmlData.setHref(href);
   return viewHtmlData;
 }
  public ProtocolOnlineReviewDocumentBase createProtocolOnlineReviewDocument(
      ProtocolSubmissionBase protocolSubmission,
      ProtocolReviewer protocolReviewer,
      String documentDescription,
      String documentExplanation,
      String documentOrganizationDocumentNumber,
      Date dateRequested,
      Date dateDue,
      String principalId)
      throws WorkflowException {

    IacucProtocolOnlineReviewDocument protocolReviewDocument;

    Person person = personService.getPerson(principalId);
    WorkflowDocument workflowDocument =
        workflowDocumentService.createWorkflowDocument(
            IACUC_PROTOCOL_ONLINE_REVIEW_DOCUMENT_TYPE, person);

    DocumentHeader docHeader = new DocumentHeader();
    docHeader.setWorkflowDocument(workflowDocument);
    docHeader.setDocumentNumber(workflowDocument.getDocumentId().toString());
    protocolReviewDocument = new IacucProtocolOnlineReviewDocument();
    protocolReviewDocument.setDocumentNumber(docHeader.getDocumentNumber());
    protocolReviewDocument.setDocumentHeader(docHeader);

    protocolReviewDocument.getProtocolOnlineReview().setProtocol(protocolSubmission.getProtocol());

    protocolReviewDocument
        .getProtocolOnlineReview()
        .setProtocolId(protocolSubmission.getProtocolId());

    protocolReviewDocument.getProtocolOnlineReview().setProtocolSubmission(protocolSubmission);
    protocolReviewDocument
        .getProtocolOnlineReview()
        .setSubmissionIdFk(protocolSubmission.getSubmissionId());
    protocolReviewDocument
        .getProtocolOnlineReview()
        .setProtocolOnlineReviewStatusCode(IacucProtocolOnlineReviewStatus.SAVED_STATUS_CD);
    protocolReviewDocument
        .getProtocolOnlineReview()
        .setDateRequested(
            dateRequested == null ? new Date((new java.util.Date()).getTime()) : dateRequested);
    protocolReviewDocument.getProtocolOnlineReview().setDateDue(dateDue);

    protocolReviewDocument
        .getProtocolOnlineReview()
        .setProtocolReviewerId(protocolReviewer.getProtocolReviewerId());
    protocolReviewDocument.getProtocolOnlineReview().setProtocolReviewer(protocolReviewer);

    docHeader.setDocumentDescription(documentDescription);
    docHeader.setOrganizationDocumentNumber(documentOrganizationDocumentNumber);
    docHeader.setExplanation(documentExplanation);

    documentService.saveDocument(protocolReviewDocument);
    return protocolReviewDocument;
  }
  /**
   * Creates a new ProtocolReviewDocument.
   *
   * <p>Handles creating the workflow document, and the underlying ProtocolReview BO linking the
   * protocol, submission, and reviewer.
   *
   * @param protocolSubmission The protocol submission
   * @param protocolReviewerBean The bean that holds
   * @param documentDescription the description for the created document
   * @param documentExplanation the explanation for the created document
   * @param documentOrganizationNumber the organizationNumber for the created document
   * @param principalId The principalId to use when creating the workflow document. Usually this
   *     should be the principal of the user creating the review.
   * @return
   * @throws WorkflowException
   */
  protected ProtocolOnlineReviewDocumentBase createProtocolOnlineReviewDocument(
      ProtocolSubmissionBase protocolSubmission,
      ProtocolReviewer protocolReviewer,
      String documentDescription,
      String documentExplanation,
      String documentOrganizationDocumentNumber,
      Date dateRequested,
      Date dateDue,
      String principalId)
      throws WorkflowException {

    ProtocolOnlineReviewDocumentBase protocolReviewDocument;

    Person person = personService.getPerson(principalId);
    WorkflowDocument workflowDocument =
        workflowDocumentService.createWorkflowDocument(getProtocolOLRDocumentTypeHook(), person);

    DocumentHeader docHeader = new DocumentHeader();
    docHeader.setWorkflowDocument(workflowDocument);
    docHeader.setDocumentNumber(workflowDocument.getDocumentId().toString());
    protocolReviewDocument = getNewProtocolOnlineReviewDocumentInstanceHook();
    protocolReviewDocument.setDocumentNumber(docHeader.getDocumentNumber());
    protocolReviewDocument.setDocumentHeader(docHeader);

    protocolReviewDocument.getProtocolOnlineReview().setProtocol(protocolSubmission.getProtocol());

    protocolReviewDocument
        .getProtocolOnlineReview()
        .setProtocolId(protocolSubmission.getProtocolId());

    protocolReviewDocument.getProtocolOnlineReview().setProtocolSubmission(protocolSubmission);
    protocolReviewDocument
        .getProtocolOnlineReview()
        .setSubmissionIdFk(protocolSubmission.getSubmissionId());
    protocolReviewDocument
        .getProtocolOnlineReview()
        .setProtocolOnlineReviewStatusCode(getProtocolOLRSavedStatusCodeHook());
    protocolReviewDocument
        .getProtocolOnlineReview()
        .setDateRequested(
            dateRequested == null ? new Date((new java.util.Date()).getTime()) : dateRequested);
    protocolReviewDocument.getProtocolOnlineReview().setDateDue(dateDue);

    protocolReviewDocument
        .getProtocolOnlineReview()
        .setProtocolReviewerId(protocolReviewer.getProtocolReviewerId());
    protocolReviewDocument.getProtocolOnlineReview().setProtocolReviewer(protocolReviewer);

    docHeader.setDocumentDescription(documentDescription);
    docHeader.setOrganizationDocumentNumber(documentOrganizationDocumentNumber);
    docHeader.setExplanation(documentExplanation);

    documentService.saveDocument(protocolReviewDocument);
    return protocolReviewDocument;
  }
  @Override
  public void removeOnlineReviewDocument(
      String personId,
      boolean nonEmployeeFlag,
      ProtocolSubmissionBase submission,
      String annotation) {
    ProtocolOnlineReviewDocumentBase protocolOnlineReviewDocument =
        this.getProtocolOnlineReviewDocument(personId, nonEmployeeFlag, submission);

    ProtocolOnlineReviewBase submissionsProtocolOnlineReview = null;
    for (ProtocolOnlineReviewBase rev : submission.getProtocolOnlineReviews()) {
      if (rev.getProtocolOnlineReviewId()
          .equals(
              protocolOnlineReviewDocument.getProtocolOnlineReview().getProtocolOnlineReviewId())) {
        submissionsProtocolOnlineReview = rev;
        break;
      }
    }

    if (submissionsProtocolOnlineReview == null) {
      throw new IllegalStateException(
          "Could not match OnlineReview document being removed to a protocolOnlineReview in the submission.");
    }

    if (LOG.isDebugEnabled()) {
      LOG.debug(
          String.format(
              "Processing request to remove online review for (personId=%s,nonEmployeeFlag=%s) from (protocol=%s,submission=%s)",
              personId,
              nonEmployeeFlag,
              submission.getProtocol().getProtocolNumber(),
              submission.getSubmissionNumber()));
    }

    if (protocolOnlineReviewDocument != null) {
      if (LOG.isDebugEnabled()) {
        LOG.debug(
            String.format(
                "Found protocolOnlineReviewDocument %s, removing it.",
                protocolOnlineReviewDocument.getDocumentNumber()));
      }
      cancelOnlineReviewDocument(protocolOnlineReviewDocument, submission, annotation);
      submissionsProtocolOnlineReview.setProtocolOnlineReviewStatusCode(
          getProtocolOLRRemovedCancelledStatusCodeHook());

      List<CommitteeScheduleMinuteBase> reviewComments =
          protocolOnlineReviewDocument.getProtocolOnlineReview().getCommitteeScheduleMinutes();
      List<CommitteeScheduleMinuteBase> deletedReviewComments =
          new ArrayList<CommitteeScheduleMinuteBase>();
      getReviewerCommentsService().deleteAllReviewComments(reviewComments, deletedReviewComments);
      getReviewerCommentsService().saveReviewComments(reviewComments, deletedReviewComments);

      getBusinessObjectService().save(submissionsProtocolOnlineReview);

    } else {
      LOG.warn(
          String.format(
              "ProtocolBase Online Review document could not be found for (personId=%s,nonEmployeeFlag=%s) from (protocol=%s,submission=%s)",
              personId,
              nonEmployeeFlag,
              submission.getProtocol().getProtocolNumber(),
              submission.getSubmissionNumber()));
    }
  }