@Override public void addUnitToPerson(ProposalPerson person, ProposalPersonUnit unit) { if (unit == null) { throw new IllegalArgumentException("Cannot add null units to a ProposalPerson instance"); } if (!person.containsUnit(unit.getUnitNumber())) { unit.setProposalPerson(person); person.addUnit(unit); unit.refreshReferenceObject("unit"); } }
@Override public List<ProposalCreditSplitListDto> createCreditSplitListItems( List<ProposalPerson> investigators) { List<ProposalCreditSplitListDto> creditSplitListItems = new ArrayList<ProposalCreditSplitListDto>(); Map<String, ProposalPersonCreditSplit> totalInvestigatorSplits = new HashMap<String, ProposalPersonCreditSplit>(); for (ProposalPerson investigator : investigators) { ProposalCreditSplitListDto investigatorLine = new ProposalCreditSplitListDto(); investigatorLine.setDescription(investigator.getFullName()); investigatorLine.setLineType("investigator"); investigatorLine.getCreditSplits().addAll(investigator.getCreditSplits()); creditSplitListItems.add(investigatorLine); for (ProposalPersonCreditSplit invesitgatorCreditSplit : investigator.getCreditSplits()) { if (totalInvestigatorSplits.containsKey(invesitgatorCreditSplit.getInvCreditTypeCode())) { ProposalPersonCreditSplit creditSplit = totalInvestigatorSplits.get(invesitgatorCreditSplit.getInvCreditTypeCode()); creditSplit.setCredit(creditSplit.getCredit().add(invesitgatorCreditSplit.getCredit())); } else { ProposalPersonCreditSplit creditSplit = new ProposalPersonCreditSplit(); creditSplit.setCredit(invesitgatorCreditSplit.getCredit()); totalInvestigatorSplits.put(invesitgatorCreditSplit.getInvCreditTypeCode(), creditSplit); } } Map<String, ProposalUnitCreditSplit> totalUnitSplits = new HashMap<String, ProposalUnitCreditSplit>(); for (ProposalPersonUnit unit : investigator.getUnits()) { ProposalCreditSplitListDto unitLine = new ProposalCreditSplitListDto(); unitLine.setDescription(unit.getUnitNumber() + " - " + unit.getUnit().getUnitName()); unitLine.getCreditSplits().addAll(unit.getCreditSplits()); unitLine.setLineType("unit"); creditSplitListItems.add(unitLine); for (ProposalUnitCreditSplit unitCreditSplit : unit.getCreditSplits()) { if (totalUnitSplits.containsKey(unitCreditSplit.getInvCreditTypeCode())) { ProposalUnitCreditSplit creditSplit = totalUnitSplits.get(unitCreditSplit.getInvCreditTypeCode()); creditSplit.setCredit(creditSplit.getCredit().add(unitCreditSplit.getCredit())); } else { ProposalUnitCreditSplit creditSplit = new ProposalUnitCreditSplit(); creditSplit.setCredit(unitCreditSplit.getCredit()); totalUnitSplits.put(unitCreditSplit.getInvCreditTypeCode(), creditSplit); } } } ProposalCreditSplitListDto unitTotalLine = new ProposalCreditSplitListDto(); unitTotalLine.setDescription("Unit Total:"); unitTotalLine.setLineType("unit-total"); for (Map.Entry<String, ProposalUnitCreditSplit> entry : totalUnitSplits.entrySet()) { unitTotalLine.getCreditSplits().add(0, entry.getValue()); } creditSplitListItems.add(unitTotalLine); } ProposalCreditSplitListDto investigatorTotalLine = new ProposalCreditSplitListDto(); investigatorTotalLine.setDescription("Investigator Total:"); investigatorTotalLine.setLineType("investigator-total"); for (Map.Entry<String, ProposalPersonCreditSplit> entry : totalInvestigatorSplits.entrySet()) { investigatorTotalLine.getCreditSplits().add(0, entry.getValue()); } creditSplitListItems.add(investigatorTotalLine); return creditSplitListItems; }