TopTenController extends GenericOCDSController { @ApiOperation(value = "Returns the top ten largest active awards." + " The amount is taken from the award.value field. The returned data will contain" + "the following fields: " + "awards.date, awards.suppliers.name, " + "awards.value.amount, awards.suppliers.name, planning.budget (if any)") @RequestMapping(value = "/api/topTenLargestAwards", method = {RequestMethod.POST, RequestMethod.GET}, produces = "application/json") public List<Document> topTenLargestAwards(@ModelAttribute @Valid final YearFilterPagingRequest filter) { BasicDBObject project = new BasicDBObject(); project.put(Fields.UNDERSCORE_ID, 0); project.put(MongoConstants.FieldNames.AWARDS_DATE, 1); project.put("awards.suppliers.name", 1); project.put(MongoConstants.FieldNames.AWARDS_VALUE_AMOUNT, 1); project.put("planning.budget", 1); Aggregation agg = newAggregation( match(where(MongoConstants.FieldNames.AWARDS_VALUE_AMOUNT).exists(true) .and(MongoConstants.FieldNames.AWARDS_STATUS) .is(Award.Status.active.toString()) .andOperator(getDefaultFilterCriteria(filter))), unwind("awards"), match(getYearFilterCriteria(filter.awardFiltering(), MongoConstants.FieldNames.AWARDS_DATE)), new CustomOperation(new Document("$project", project)), sort(Direction.DESC, MongoConstants.FieldNames.AWARDS_VALUE_AMOUNT), limit(10) ); return releaseAgg(agg); }  @ApiOperation(value = "Returns the top ten largest active awards." + " The amount is taken from the award.value field. The returned data will contain" + "the following fields: " + "awards.date, awards.suppliers.name, " + "awards.value.amount, awards.suppliers.name, planning.budget (if any)") @RequestMapping(value = "/api/topTenLargestAwards", method = {RequestMethod.POST, RequestMethod.GET}, produces = "application/json") List<Document> topTenLargestAwards(@ModelAttribute @Valid final YearFilterPagingRequest filter); @ApiOperation(value = "Returns the top ten largest active tenders." + " The amount is taken from the tender.value.amount field." + " The returned data will contain" + "the following fields: " + "tender.date, tender.value.amount, tender.tenderPeriod, " + "tender.procuringEntity.name") @RequestMapping(value = "/api/topTenLargestTenders", method = {RequestMethod.POST, RequestMethod.GET}, produces = "application/json") List<Document> topTenLargestTenders(@ModelAttribute @Valid final YearFilterPagingRequest filter); @ApiOperation(value = "This endpoint should return the following data for the Top 10 suppliers (by award value)." + "Returns supplier id, total awarded amount of all awarded contracts, count of awarded contracts," + "Ids of the procuring entities from which they have received an award, and their count. " + "All filters ally here, the year filter uses the awards.date field.") @RequestMapping(value = "/api/topTenSuppliers", method = {RequestMethod.POST, RequestMethod.GET}, produces = "application/json") List<Document> topTenLargestSuppliers(@ModelAttribute @Valid final YearFilterPagingRequest filter);  }
@Test public void topTenLargestAwards() throws Exception { final List<Document> topTenLargestAwards = topTenController .topTenLargestAwards(new YearFilterPagingRequest()); Assert.assertEquals(2, topTenLargestAwards.size()); final Document first = topTenLargestAwards.get(0); BasicDBObject awards = (BasicDBObject) first.get("awards"); BasicDBObject value = (BasicDBObject) awards.get("value"); double amount = (double) value.get("amount"); Assert.assertEquals(6000000.0, amount, 0); final Document second = topTenLargestAwards.get(1); awards = (BasicDBObject) second.get("awards"); value = (BasicDBObject) awards.get("value"); amount = (double) value.get("amount"); Assert.assertEquals(40000.0, amount, 0); }