TenderPriceByTypeYearController extends GenericOCDSController { @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 " + MongoConstants.FieldNames.TENDER_VALUE_AMOUNT) @RequestMapping(value = "/api/tenderPriceByProcurementMethod", method = {RequestMethod.POST, RequestMethod.GET}, produces = "application/json") public List<Document> tenderPriceByProcurementMethod( @ModelAttribute @Valid final YearFilterPagingRequest filter) { DBObject project = new BasicDBObject(); project.put("tender." + Keys.PROCUREMENT_METHOD, 1); project.put("tender.value", 1); Aggregation agg = newAggregation( match(where("awards").elemMatch(where("status").is(Award.Status.active.toString())) .and("tender.value") .exists(true) .andOperator(getYearDefaultFilterCriteria( filter, MongoConstants.FieldNames.TENDER_PERIOD_START_DATE ))), new CustomProjectionOperation(project), group("tender." + Keys.PROCUREMENT_METHOD) .sum(ref(MongoConstants.FieldNames.TENDER_VALUE_AMOUNT)).as(Keys.TOTAL_TENDER_AMOUNT), project().and(Fields.UNDERSCORE_ID).as(Keys.PROCUREMENT_METHOD).andInclude(Keys.TOTAL_TENDER_AMOUNT) .andExclude(Fields.UNDERSCORE_ID), sort(Direction.DESC, Keys.TOTAL_TENDER_AMOUNT) ); return releaseAgg(agg); }  @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 " + MongoConstants.FieldNames.TENDER_VALUE_AMOUNT) @RequestMapping(value = "/api/tenderPriceByProcurementMethod", method = {RequestMethod.POST, RequestMethod.GET}, produces = "application/json") List<Document> tenderPriceByProcurementMethod(
            @ModelAttribute @Valid final YearFilterPagingRequest filter);  }
@Test public void tenderPriceByProcurementMethod() throws Exception { final List<Document> tenderPriceByProcurementMethod = tenderPriceByTypeYearController .tenderPriceByProcurementMethod(new YearFilterPagingRequest()); final Document first = tenderPriceByProcurementMethod.get(0); String procurementMethod = (String) first.get(TenderPriceByTypeYearController.Keys.PROCUREMENT_METHOD); Number totalTenderAmount = (Number) first.get(TenderPriceByTypeYearController.Keys.TOTAL_TENDER_AMOUNT); Assert.assertEquals("selective", procurementMethod); Assert.assertEquals(600000.0, totalTenderAmount.doubleValue(), 0); final Document second = tenderPriceByProcurementMethod.get(1); procurementMethod = (String) second.get(TenderPriceByTypeYearController.Keys.PROCUREMENT_METHOD); totalTenderAmount = (Number) second.get(TenderPriceByTypeYearController.Keys.TOTAL_TENDER_AMOUNT); Assert.assertEquals("open", procurementMethod); Assert.assertEquals(9000.0, totalTenderAmount.doubleValue(), 0); }