/**
   * This method check to see if the user can create the account maintenance document and set the
   * user session
   *
   * @param String principalId
   * @return boolean
   */
  protected boolean isValidUser(String principalId) {

    PersonService personService = SpringContext.getBean(PersonService.class);
    if (principalId == null) {
      return false;
    }
    Person user = personService.getPerson(principalId);
    if (user == null) {
      return false;
    }
    DocumentAuthorizer documentAuthorizer = new MaintenanceDocumentAuthorizerBase();
    if (documentAuthorizer.canInitiate(
        SpringContext.getBean(MaintenanceDocumentDictionaryService.class)
            .getDocumentTypeName(Account.class),
        user)) {
      // set the user session so that the user name can be displayed in the saved document
      GlobalVariables.setUserSession(new UserSession(user.getPrincipalName()));
      return true;
    }

    LOG.error(
        KcUtils.getErrorMessage(
            KcConstants.AccountCreationService.ERROR_KC_DOCUMENT_INVALID_USER,
            new String[] {principalId}));

    return false;
  }
  /**
   * @see org.kuali.rice.kns.lookup.KualiLookupableHelperServiceImpl#getSearchResults(java.util.Map)
   */
  @Override
  public List<? extends BusinessObject> getSearchResults(Map<String, String> fieldValues) {
    List<TemProfileFromKimPerson> searchResults = new ArrayList<TemProfileFromKimPerson>();

    // final Map<String, String> kimFieldsForLookup = fieldValues;
    final Map<String, String> kimFieldsForLookup = getPersonFieldValues(fieldValues);

    LOG.debug("Looking up people with criteria " + kimFieldsForLookup);
    final List<? extends Person> persons = personService.findPeople(kimFieldsForLookup);

    for (Person personDetail : persons) {
      if (!StringUtils.isBlank(personDetail.getPrincipalId())) {
        searchResults.add(travelerService.convertToTemProfileFromKim(personDetail));
      }
    }

    CollectionIncomplete results =
        new CollectionIncomplete(searchResults, Long.valueOf(searchResults.size()));

    // sort list if default sort column given
    List<String> defaultSortColumns = getDefaultSortColumns();
    if (defaultSortColumns.size() > 0) {
      Collections.sort(results, new BeanPropertyComparator(defaultSortColumns, true));
    }

    return results;
  }
  /**
   * 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;
  }