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: " + "planning.bidNo, 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<DBObject> topTenLargestAwards(@ModelAttribute @Valid final YearFilterPagingRequest filter) { BasicDBObject project = new BasicDBObject(); project.put(Fields.UNDERSCORE_ID, 0); project.put("planning.bidNo", 1); project.put("awards.date", 1); project.put("awards.suppliers.name", 1); project.put("awards.value.amount", 1); project.put("planning.budget", 1); Aggregation agg = newAggregation( match(where("awards.value.amount").exists(true).and("awards.status").is("active") .andOperator(getDefaultFilterCriteria(filter))), unwind("$awards"), match(getYearFilterCriteria(filter, "awards.date")), new CustomOperation(new BasicDBObject("$project", project)), sort(Direction.DESC, "awards.value.amount"), limit(10)); AggregationResults<DBObject> results = mongoTemplate.aggregate(agg, "release", DBObject.class); List<DBObject> tagCount = results.getMappedResults(); return tagCount; }  @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: " + "planning.bidNo, 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<DBObject> 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: " + "planning.bidNo, tender.date, tender.value.amount, tender.tenderPeriod, " + "tender.procuringEntity.name") @RequestMapping(value = "/api/topTenLargestTenders", method = { RequestMethod.POST, RequestMethod.GET }, produces = "application/json") List<DBObject> 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<DBObject> topTenLargestSuppliers(@ModelAttribute @Valid final YearFilterPagingRequest filter);  }
@Test public void topTenLargestAwards() throws Exception { final List<DBObject> topTenLargestAwards = topTenController .topTenLargestAwards(new YearFilterPagingRequest()); Assert.assertEquals(2, topTenLargestAwards.size()); final DBObject 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 DBObject 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); }