TopTenController extends GenericOCDSController { @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") public List<Document> topTenLargestSuppliers(@ModelAttribute @Valid final YearFilterPagingRequest filter) { BasicDBObject project = new BasicDBObject(); project.put(Fields.UNDERSCORE_ID, 0); project.put(MongoConstants.FieldNames.AWARDS_SUPPLIERS_ID, 1); project.put(MongoConstants.FieldNames.AWARDS_VALUE_AMOUNT, 1); project.put(MongoConstants.FieldNames.TENDER_PROCURING_ENTITY_ID, 1); BasicDBObject group = new BasicDBObject(); group.put(Fields.UNDERSCORE_ID, ref(MongoConstants.FieldNames.AWARDS_SUPPLIERS_ID)); group.put( Keys.TOTAL_AWARD_AMOUNT, new BasicDBObject("$sum", ref(MongoConstants.FieldNames.AWARDS_VALUE_AMOUNT))); group.put(Keys.TOTAL_CONTRACTS, new BasicDBObject("$sum", 1)); group.put( Keys.PROCURING_ENTITY_IDS, new BasicDBObject("$addToSet", ref(MongoConstants.FieldNames.TENDER_PROCURING_ENTITY_ID)) ); 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(where(MongoConstants.FieldNames.AWARDS_STATUS).is(Award.Status.active.toString())), unwind("awards.suppliers"), match(getYearFilterCriteria(filter.awardFiltering(), MongoConstants.FieldNames.AWARDS_DATE)), new CustomProjectionOperation(project), new CustomGroupingOperation(group), sort(Direction.DESC, Keys.TOTAL_AWARD_AMOUNT), limit(10), project().and(Fields.UNDERSCORE_ID). as(Keys.SUPPLIER_ID). andInclude(Keys.TOTAL_AWARD_AMOUNT, Keys.TOTAL_CONTRACTS, Keys.PROCURING_ENTITY_IDS) .andExclude(Fields.UNDERSCORE_ID) .and(Keys.PROCURING_ENTITY_IDS).size().as(Keys.PROCURING_ENTITY_IDS_COUNT) ); 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 topTenLargestSuppliers() throws Exception { final List<Document> topTenLargestSuppliers = topTenController .topTenLargestSuppliers(new YearFilterPagingRequest()); final Document first = topTenLargestSuppliers.get(0); Assert.assertEquals(6000000d, first.get(TopTenController.Keys.TOTAL_AWARD_AMOUNT)); Assert.assertEquals(1, first.get(TopTenController.Keys.TOTAL_CONTRACTS)); Assert.assertEquals("E09000005", ((Collection) first.get(TopTenController.Keys.PROCURING_ENTITY_IDS)).iterator().next()); Assert.assertEquals("GB-COH-1234567845", first.get(TopTenController.Keys.SUPPLIER_ID)); Assert.assertEquals(1, first.get(TopTenController.Keys.PROCURING_ENTITY_IDS_COUNT)); Assert.assertEquals(2, topTenLargestSuppliers.size()); }