TenderPriceByTypeYearController extends GenericOCDSController { @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") public List<DBObject> tenderPriceByAllBidSelectionMethods(@ModelAttribute @Valid final YearFilterPagingRequest filter) { List<DBObject> tenderPriceByBidSelectionMethod = tenderPriceByBidSelectionMethod(filter); Collection<DBObject> ret = new TreeSet<>((DBObject o1, DBObject o2) -> o1.get(Keys.PROCUREMENT_METHOD_DETAILS) .toString().compareTo(o2.get(Keys.PROCUREMENT_METHOD_DETAILS).toString())); for (DBObject o : tenderPriceByBidSelectionMethod) { if (o.containsField(Keys.PROCUREMENT_METHOD_DETAILS) && o.get(Keys.PROCUREMENT_METHOD_DETAILS) != null) { ret.add(o); } else { o.put(Keys.PROCUREMENT_METHOD_DETAILS, UNSPECIFIED); ret.add(o); } } Set<Object> bidSelectionMethods = bidSelectionMethodSearchController.bidSelectionMethods().stream() .filter(e -> e.get(Fields.UNDERSCORE_ID) != null).map(e -> e.get(Fields.UNDERSCORE_ID)) .collect(Collectors.toCollection(LinkedHashSet::new)); bidSelectionMethods.add(UNSPECIFIED); bidSelectionMethods .removeAll(ret.stream().map(e -> e.get(Keys.PROCUREMENT_METHOD_DETAILS)).collect(Collectors.toSet())); bidSelectionMethods.forEach(e -> { DBObject obj = new BasicDBObject(Keys.PROCUREMENT_METHOD_DETAILS, e.toString()); obj.put(Keys.TOTAL_TENDER_AMOUNT, BigDecimal.ZERO); ret.add(obj); }); return new ArrayList<>(ret); }  @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 tenderPriceByAllBidSelectionMethods() throws Exception { final List<DBObject> tenderPriceByAllBidSelectionMethods = tenderPriceByTypeYearController .tenderPriceByAllBidSelectionMethods(new YearFilterPagingRequest()); final DBObject first = tenderPriceByAllBidSelectionMethods.get(1); Number totalTenderAmount = (Number) first.get(TenderPriceByTypeYearController.Keys.TOTAL_TENDER_AMOUNT); String procurementMethodDetails = (String) first .get(TenderPriceByTypeYearController.Keys.PROCUREMENT_METHOD_DETAILS); Assert.assertEquals("Competitive offers", procurementMethodDetails); Assert.assertEquals(9000.0, totalTenderAmount.doubleValue(), 0); final DBObject second = tenderPriceByAllBidSelectionMethods.get(0); totalTenderAmount = (Number) second.get(TenderPriceByTypeYearController.Keys.TOTAL_TENDER_AMOUNT); procurementMethodDetails = (String) second.get(TenderPriceByTypeYearController.Keys.PROCUREMENT_METHOD_DETAILS); Assert.assertEquals("Chưa xác định", procurementMethodDetails); Assert.assertEquals(600000.0, totalTenderAmount.doubleValue(), 0); }