|
4 | 4 | package com.topcoder.direct.services.view.dto.contest; |
5 | 5 |
|
6 | 6 | import com.topcoder.direct.services.view.dto.cost.CostDTO; |
| 7 | +import com.topcoder.management.project.Prize; |
7 | 8 |
|
8 | 9 | import java.io.Serializable; |
| 10 | +import java.util.ArrayList; |
| 11 | +import java.util.Collections; |
| 12 | +import java.util.Comparator; |
| 13 | +import java.util.HashMap; |
9 | 14 | import java.util.List; |
| 15 | +import java.util.Map; |
10 | 16 |
|
11 | 17 | /** |
12 | 18 | * <p>A DTO providing the complete details on a contest receipt.</p> |
|
35 | 41 | * </ul> |
36 | 42 | * </p> |
37 | 43 | * |
| 44 | + * <p> |
| 45 | + * Version 1.5 ([Direct] - challenge receipt page update) |
| 46 | + * <ul> |
| 47 | + * <li>Added {@link #getWinnerEntries()}</li> |
| 48 | + * <li>Added {@link #getCheckpointWinnerEntries()}</li> |
| 49 | + * <li>Added {@link #getNonWinnerEntries()}</li> |
| 50 | + * </ul> |
| 51 | + * </p> |
| 52 | + * |
38 | 53 | * @author flexme, GreatKevin, Veve |
39 | | - * @version 1.4 |
| 54 | + * @version 1.5 |
40 | 55 | */ |
41 | 56 | public class ContestReceiptDTO implements Serializable { |
42 | 57 | /** |
@@ -500,6 +515,133 @@ public void setEntries(List<ContestReceiptEntry> entries) { |
500 | 515 | this.entries = entries; |
501 | 516 | } |
502 | 517 |
|
| 518 | + /** |
| 519 | + * Gets the winner entries. |
| 520 | + * |
| 521 | + * @return the list of winner entries. |
| 522 | + * @since 1.5 |
| 523 | + */ |
| 524 | + public List<ContestReceiptEntry> getWinnerEntries() { |
| 525 | + List<ContestReceiptEntry> winnerEntries = new ArrayList<ContestReceiptEntry>(); |
| 526 | + |
| 527 | + for (ContestReceiptEntry e : this.getEntries()) { |
| 528 | + |
| 529 | + if (e.getPaymentType().equalsIgnoreCase("winner")) { |
| 530 | + winnerEntries.add(e); |
| 531 | + } |
| 532 | + } |
| 533 | + |
| 534 | + Collections.sort(winnerEntries, new Comparator<ContestReceiptEntry>() { |
| 535 | + public int compare(ContestReceiptEntry o1, ContestReceiptEntry o2) { |
| 536 | + return Double.compare(o2.getPaymentAmount(), o1.getPaymentAmount()); |
| 537 | + } |
| 538 | + }); |
| 539 | + |
| 540 | + // get the main winner prizes |
| 541 | + List<Prize> prizes = getEstimation().getMainPrizes(); |
| 542 | + |
| 543 | + int prizeRank = 1; |
| 544 | + |
| 545 | + int maxPrizePlace = -1; |
| 546 | + |
| 547 | + for (ContestReceiptEntry e : winnerEntries) { |
| 548 | + for (Prize p : prizes) { |
| 549 | + |
| 550 | + if (p.getPlace() > maxPrizePlace) { |
| 551 | + maxPrizePlace = p.getPlace(); |
| 552 | + } |
| 553 | + |
| 554 | + if (p.getPlace() == prizeRank ) { |
| 555 | + e.setEstimatedAmount(p.getPrizeAmount()); |
| 556 | + } |
| 557 | + } |
| 558 | + prizeRank++; |
| 559 | + } |
| 560 | + |
| 561 | + if (maxPrizePlace > winnerEntries.size()) { |
| 562 | + for (int k = winnerEntries.size(); k < maxPrizePlace; ++k) { |
| 563 | + ContestReceiptEntry extraEntry = new ContestReceiptEntry(); |
| 564 | + extraEntry.setPaymentType("Winner"); |
| 565 | + extraEntry.setEstimatedAmount(prizes.get(k).getPrizeAmount()); |
| 566 | + winnerEntries.add(extraEntry); |
| 567 | + } |
| 568 | + } |
| 569 | + |
| 570 | + return winnerEntries; |
| 571 | + } |
| 572 | + |
| 573 | + /** |
| 574 | + * Gets the checkpoint winner entries. |
| 575 | + * |
| 576 | + * @return the checkpoint winner entries. |
| 577 | + * @since 1.5 |
| 578 | + */ |
| 579 | + public List<ContestReceiptEntry> getCheckpointWinnerEntries() { |
| 580 | + List<ContestReceiptEntry> checkpointWinnerEntries = new ArrayList<ContestReceiptEntry>(); |
| 581 | + |
| 582 | + // get the checkpoint prize |
| 583 | + Prize checkpointPrize = this.getEstimation().getCheckpointPrize(); |
| 584 | + |
| 585 | + if (checkpointPrize == null) { |
| 586 | + return checkpointWinnerEntries; |
| 587 | + } |
| 588 | + |
| 589 | + for (ContestReceiptEntry e : this.getEntries()) { |
| 590 | + if(e.getPaymentType().equalsIgnoreCase("checkpoint winner")) { |
| 591 | + checkpointWinnerEntries.add(e); |
| 592 | + } |
| 593 | + } |
| 594 | + |
| 595 | + Collections.sort(checkpointWinnerEntries, new Comparator<ContestReceiptEntry>() { |
| 596 | + public int compare(ContestReceiptEntry o1, ContestReceiptEntry o2) { |
| 597 | + return Double.compare(o2.getPaymentAmount(), o1.getPaymentAmount()); |
| 598 | + } |
| 599 | + }); |
| 600 | + |
| 601 | + for (ContestReceiptEntry e : checkpointWinnerEntries) { |
| 602 | + e.setEstimatedAmount(checkpointPrize.getPrizeAmount()); |
| 603 | + } |
| 604 | + |
| 605 | + if (checkpointPrize.getNumberOfSubmissions() > checkpointWinnerEntries.size()) { |
| 606 | + for (int k = checkpointWinnerEntries.size(); k < checkpointPrize.getNumberOfSubmissions(); ++k) { |
| 607 | + ContestReceiptEntry extraEntry = new ContestReceiptEntry(); |
| 608 | + extraEntry.setPaymentType("Checkpoint Winner"); |
| 609 | + extraEntry.setEstimatedAmount(checkpointPrize.getPrizeAmount()); |
| 610 | + checkpointWinnerEntries.add(extraEntry); |
| 611 | + } |
| 612 | + } |
| 613 | + |
| 614 | + return checkpointWinnerEntries; |
| 615 | + } |
| 616 | + |
| 617 | + /** |
| 618 | + * Gets the nonWinner (checkpoint winner) entries. |
| 619 | + * |
| 620 | + * @return the list of nonWinner (checkpint winner) entries. |
| 621 | + * @since 1.5 |
| 622 | + */ |
| 623 | + public Map<String, ContestReceiptEntry> getNonWinnerEntries() { |
| 624 | + // map which is used to aggregate the payment amount of the same payment type |
| 625 | + Map<String, ContestReceiptEntry> entriesMap = new HashMap<String, ContestReceiptEntry>(); |
| 626 | + |
| 627 | + for (ContestReceiptEntry e : this.getEntries()) { |
| 628 | + if (!(e.getPaymentType().equalsIgnoreCase("winner") |
| 629 | + || e.getPaymentType().equalsIgnoreCase("checkpoint winner"))) { |
| 630 | + if (entriesMap.containsKey(e.getPaymentType())) { |
| 631 | + // exists, sum up the payment amount |
| 632 | + ContestReceiptEntry existingEntry = entriesMap.get(e.getPaymentType()); |
| 633 | + existingEntry.setPaymentAmount(existingEntry.getPaymentAmount() + e.getPaymentAmount()); |
| 634 | + } else { |
| 635 | + // no exist, put into map |
| 636 | + entriesMap.put(e.getPaymentType(), new ContestReceiptEntry(e)); |
| 637 | + } |
| 638 | + } |
| 639 | + } |
| 640 | + |
| 641 | + return entriesMap; |
| 642 | + } |
| 643 | + |
| 644 | + |
503 | 645 | /** |
504 | 646 | * Gets the estimation cost. |
505 | 647 | * |
|
0 commit comments