/** Assigns the lead unit of the proposal to the given principal investigator */
  public void assignLeadUnit(ProposalPerson person, String unitNumber) {
    if (person.containsUnit(unitNumber)) {
      person.getUnit(unitNumber).setLeadUnit(true);
      return;
    }

    ProposalPersonUnit unit = createProposalPersonUnit(unitNumber, person);
    unit.setLeadUnit(true);
    addUnitToPerson(person, unit);
  }
  public void addProposalPerson(
      ProposalPerson proposalPerson, ProposalDevelopmentDocument document) {
    getPersonEditableService().populateContactFields(proposalPerson);
    document.getDevelopmentProposal().addProposalPerson(proposalPerson);

    LOG.info(
        "Added Proposal Person with proposalNumber = "
            + document.getDevelopmentProposal().getProposalNumber()
            + " and proposalPersonNumber = "
            + proposalPerson.getProposalPersonNumber());
    // handle lead unit for investigators respective to coi or pi
    if (proposalPerson.isPrincipalInvestigator()) {
      assignLeadUnit(proposalPerson, document.getDevelopmentProposal().getOwnedByUnitNumber());
    } else {
      // Lead Unit information needs to be removed in case the person used to be a PI
      ProposalPersonUnit unit =
          proposalPerson.getUnit(document.getDevelopmentProposal().getOwnedByUnitNumber());
      if (unit != null) {
        unit.setLeadUnit(false);
      }
    }
    if (proposalPerson.getHomeUnit() != null) {
      proposalPerson.refreshReferenceObject("homeUnitRef");
      String divisionName =
          getProposalPersonService().getProposalPersonDivisionName(proposalPerson);
      proposalPerson.setDivision(divisionName);
    } else {
      proposalPerson.setDivision(ROLODEX_PERSON);
    }
    if (proposalPerson.getProposalPersonRoleId().equals(PRINCIPAL_INVESTIGATOR_ROLE)
        || proposalPerson.getProposalPersonRoleId().equals(CO_INVESTIGATOR_ROLE)) {
      if (isNotBlank(proposalPerson.getHomeUnit())
          && isValidHomeUnit(proposalPerson, proposalPerson.getHomeUnit())) {
        addUnitToPerson(
            proposalPerson, createProposalPersonUnit(proposalPerson.getHomeUnit(), proposalPerson));
      }
    }

    populateProposalPerson(proposalPerson, document);
  }