@Override
 public List<ProtocolOnlineReviewDocumentBase> getProtocolReviewDocumentsForCurrentSubmission(
     ProtocolBase protocol) {
   List<ProtocolOnlineReviewDocumentBase> onlineReviewDocuments =
       new ArrayList<ProtocolOnlineReviewDocumentBase>();
   ProtocolSubmissionBase submission = protocol.getProtocolSubmission();
   List<ProtocolOnlineReviewBase> reviews =
       findProtocolOnlineReviews(protocol.getProtocolId(), submission.getSubmissionId());
   for (ProtocolOnlineReviewBase review : reviews) {
     if (review.isActive()) {
       review.refresh();
       try {
         onlineReviewDocuments.add(
             (ProtocolOnlineReviewDocumentBase)
                 (documentService.getByDocumentHeaderId(
                     review.getProtocolOnlineReviewDocument().getDocumentNumber())));
       } catch (WorkflowException e) {
         throw new RuntimeException(
             String.format(
                 "Could not load ProtocolOnlineReviewBase docuemnt %s due to WorkflowException: %s",
                 review.getProtocolOnlineReviewDocument().getDocumentNumber(), e.getMessage()),
             e);
       }
     }
   }
   return onlineReviewDocuments;
 }
 /*
  * 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 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);
   }
 }
  private void performGenericAction(
      Protocol protocol, ProtocolGenericActionBean actionBean, String protocolActionType)
      throws Exception {
    ProtocolAction protocolAction =
        (ProtocolAction) createProtocolActionAndAttach(protocol, actionBean, protocolActionType);

    if (protocol.getNotifyIrbSubmissionId() == null) {
      getProtocolActionService().updateProtocolStatus(protocolAction, protocol);
    } else {
      for (ProtocolSubmissionBase submission : protocol.getProtocolSubmissions()) {
        if (submission.getSubmissionId().equals(protocol.getNotifyIrbSubmissionId())) {
          submission.setSubmissionStatusCode(ProtocolSubmissionStatus.IRB_ACKNOWLEDGEMENT);
        }
      }
    }

    protocol.refreshReferenceObject("protocolStatus");
    protocol.refreshReferenceObject("protocolSubmission");
    getDocumentService().saveDocument(protocol.getProtocolDocument());
  }
  @Override
  public ProtocolOnlineReviewDocumentBase getProtocolOnlineReviewDocument(
      String personId, boolean nonEmployeeFlag, ProtocolSubmissionBase protocolSubmission) {
    ProtocolOnlineReviewDocumentBase protocolOnlineReviewDocument = null;

    if (protocolSubmission != null) {
      for (ProtocolOnlineReviewBase protocolOnlineReview :
          protocolSubmission.getProtocolOnlineReviews()) {
        if (protocolOnlineReview
                .getProtocolReviewer()
                .isPersonIdProtocolReviewer(personId, nonEmployeeFlag)
            && protocolOnlineReview.isActive()) {
          try {
            protocolOnlineReviewDocument =
                (ProtocolOnlineReviewDocumentBase)
                    getDocumentService()
                        .getByDocumentHeaderId(
                            protocolOnlineReview
                                .getProtocolOnlineReviewDocument()
                                .getDocumentNumber());
          } catch (WorkflowException e) {
            if (LOG.isDebugEnabled()) {
              String errorMessage =
                  String.format(
                      "WorkflowException encountered while looking up document number %s for ProtocolOnlineReviewDocumentBase associated with (submissionId=%s,personId=%s,nonEmployeeFlag=%s",
                      protocolOnlineReview.getProtocolOnlineReviewDocument().getDocumentNumber(),
                      protocolSubmission.getSubmissionId(),
                      personId,
                      nonEmployeeFlag);

              LOG.error(errorMessage, e);
              throw new RuntimeException(errorMessage, e);
            }
          }
        }
      }
    }

    return protocolOnlineReviewDocument;
  }
  @Override
  public ProtocolReviewer createProtocolReviewer(
      String principalId,
      boolean nonEmployeeFlag,
      String reviewerTypeCode,
      ProtocolSubmissionBase protocolSubmission) {
    ProtocolReviewer reviewer = createNewProtocolReviewerInstanceHook();
    reviewer.setProtocolIdFk(protocolSubmission.getProtocolId());
    reviewer.setSubmissionIdFk(protocolSubmission.getSubmissionId());
    reviewer.setProtocolNumber(protocolSubmission.getProtocolNumber());
    reviewer.setSequenceNumber(protocolSubmission.getSequenceNumber());
    reviewer.setSubmissionNumber(protocolSubmission.getSubmissionNumber());
    if (!nonEmployeeFlag) {
      reviewer.setPersonId(principalId);
    } else {
      reviewer.setRolodexId(Integer.parseInt(principalId));
    }
    reviewer.setNonEmployeeFlag(nonEmployeeFlag);
    reviewer.setReviewerTypeCode(reviewerTypeCode);

    businessObjectService.save(reviewer);

    return reviewer;
  }