TenderPriceByTypeYearController extends GenericOCDSController { @ApiOperation(value = "Returns the tender price by Vietnam type (procurementMethodDetails), by year. " + "The OCDS type is read from tender.procurementMethodDetails. The tender price is read from " + "tender.value.amount") @RequestMapping(value = "/api/tenderPriceByBidSelectionMethod", method = { RequestMethod.POST, RequestMethod.GET }, produces = "application/json") public List<DBObject> tenderPriceByBidSelectionMethod(@ModelAttribute @Valid final YearFilterPagingRequest filter) { DBObject project = new BasicDBObject(); project.put("tender." + Keys.PROCUREMENT_METHOD_DETAILS, 1); project.put("tender.value", 1); Aggregation agg = newAggregation( match(where("awards").elemMatch(where("status").is("active")).and("tender.value").exists(true) .andOperator(getYearFilterCriteria(filter, "tender.tenderPeriod.startDate"))), getMatchDefaultFilterOperation(filter), new CustomProjectionOperation(project), group("tender." + Keys.PROCUREMENT_METHOD_DETAILS).sum("$tender.value.amount") .as(Keys.TOTAL_TENDER_AMOUNT), project().and(Fields.UNDERSCORE_ID).as(Keys.PROCUREMENT_METHOD_DETAILS) .andInclude(Keys.TOTAL_TENDER_AMOUNT).andExclude(Fields.UNDERSCORE_ID), sort(Direction.DESC, Keys.TOTAL_TENDER_AMOUNT)); AggregationResults<DBObject> results = mongoTemplate.aggregate(agg, "release", DBObject.class); List<DBObject> tagCount = results.getMappedResults(); return tagCount; }  @ApiOperation(value = "Returns the tender price by OCDS type (procurementMethod), by year. " + "The OCDS type is read from tender.procurementMethod. The tender price is read from " + "tender.value.amount") @RequestMapping(value = "/api/tenderPriceByProcurementMethod", method = { RequestMethod.POST, RequestMethod.GET }, produces = "application/json") List<DBObject> tenderPriceByProcurementMethod(@ModelAttribute @Valid final YearFilterPagingRequest filter); @ApiOperation(value = "Returns the tender price by Vietnam type (procurementMethodDetails), by year. " + "The OCDS type is read from tender.procurementMethodDetails. The tender price is read from " + "tender.value.amount") @RequestMapping(value = "/api/tenderPriceByBidSelectionMethod", method = { RequestMethod.POST, RequestMethod.GET }, produces = "application/json") List<DBObject> tenderPriceByBidSelectionMethod(@ModelAttribute @Valid final YearFilterPagingRequest filter); @ApiOperation(value = "Same as /api/tenderPriceByBidSelectionMethod, but it always returns " + "all bidSelectionMethods (it adds the missing bid selection methods with zero totals") @RequestMapping(value = "/api/tenderPriceByAllBidSelectionMethods", method = { RequestMethod.POST, RequestMethod.GET }, produces = "application/json") List<DBObject> tenderPriceByAllBidSelectionMethods(@ModelAttribute @Valid final YearFilterPagingRequest filter);  }
@Test public void tenderPriceByBidSelectionMethod() throws Exception { final List<DBObject> tenderPriceByBidSelectionMethod = tenderPriceByTypeYearController .tenderPriceByBidSelectionMethod(new YearFilterPagingRequest()); final DBObject first = tenderPriceByBidSelectionMethod.get(0); Number totalTenderAmount = (Number) first.get(TenderPriceByTypeYearController.Keys.TOTAL_TENDER_AMOUNT); String procurementMethodDetails = (String) first .get(TenderPriceByTypeYearController.Keys.PROCUREMENT_METHOD_DETAILS); Assert.assertNull(procurementMethodDetails); Assert.assertEquals(600000.0, totalTenderAmount.doubleValue(), 0); final DBObject second = tenderPriceByBidSelectionMethod.get(1); totalTenderAmount = (Number) second.get(TenderPriceByTypeYearController.Keys.TOTAL_TENDER_AMOUNT); procurementMethodDetails = (String) second.get(TenderPriceByTypeYearController.Keys.PROCUREMENT_METHOD_DETAILS); Assert.assertEquals("Competitive offers", procurementMethodDetails); Assert.assertEquals(9000.0, totalTenderAmount.doubleValue(), 0); }