/**
   * Uses a <code>{@link Unit}</code> obtained from the <code>{@link Unit}</code> lookup to create a
   * <code>{@link ProposalPersonUnit}</code> instance.
   *
   * @param unitId
   * @return ProposalPersonUnit
   */
  public ProposalPersonUnit createProposalPersonUnit(String unitId, ProposalPerson person) {
    ProposalPersonUnit retval = new ProposalPersonUnit();
    Map valueMap = new HashMap();
    valueMap.put("unitNumber", unitId);
    Collection<Unit> units = getBusinessObjectService().findMatching(Unit.class, valueMap);

    for (Unit found : units) {
      retval.setUnitNumber(found.getUnitNumber());
      retval.setUnit(found);
    }

    for (InvestigatorCreditType creditType : getInvestigatorCreditTypes()) {
      ProposalUnitCreditSplit creditSplit = new ProposalUnitCreditSplit();
      creditSplit.setProposalPersonUnit(retval);
      creditSplit.setInvCreditTypeCode(creditType.getCode());
      creditSplit.setCredit(new ScaleTwoDecimal(0));
      retval.getCreditSplits().add(creditSplit);
    }

    return retval;
  }
 /**
  * It populates the Active credit type in the proposalpersoncreditsplit and unitcreditsplit
  *
  * @param document
  * @return true or false
  */
 public void populateActiveCredittypesPerson(ProposalDevelopmentDocument document) {
   Collection<InvestigatorCreditType> invcrdttype = getInvestigatorCreditTypes();
   for (ProposalPerson person : document.getDevelopmentProposal().getInvestigators()) {
     for (InvestigatorCreditType invcredtype : invcrdttype) {
       boolean creditTypeFound = false;
       for (ProposalPersonCreditSplit proposalpersoncrdt : person.getCreditSplits()) {
         if ((invcredtype.getCode().equals(proposalpersoncrdt.getInvCreditTypeCode()))) {
           creditTypeFound = true;
           break;
         }
       }
       if (!creditTypeFound) {
         ProposalPersonCreditSplit creditSplit = new ProposalPersonCreditSplit();
         creditSplit.setProposalPerson(person);
         creditSplit.setInvCreditTypeCode(invcredtype.getCode());
         creditSplit.setCredit(new ScaleTwoDecimal(0));
         person.getCreditSplits().add(creditSplit);
       }
     }
     for (ProposalPersonUnit unitsplit : person.getUnits()) {
       for (InvestigatorCreditType invcrdtype : invcrdttype) {
         boolean creditTypeFound = false;
         for (ProposalUnitCreditSplit unitcreditsplit : unitsplit.getCreditSplits()) {
           if ((invcrdtype.getCode().equals(unitcreditsplit.getInvCreditTypeCode()))) {
             creditTypeFound = true;
             break;
           }
         }
         if (!creditTypeFound) {
           ProposalUnitCreditSplit creditSplit = new ProposalUnitCreditSplit();
           creditSplit.setProposalPersonUnit(unitsplit);
           creditSplit.setInvCreditTypeCode(invcrdtype.getCode());
           creditSplit.setCredit(new ScaleTwoDecimal(0));
           unitsplit.getCreditSplits().add(creditSplit);
         }
       }
     }
   }
 }