TendersByItemClassification extends GenericOCDSController { @ApiOperation(value = "This should show the number of tenders per tender.items.classification." + "The tender date is taken from tender.tenderPeriod.startDate.") @RequestMapping(value = "/api/tendersByItemClassification", method = { RequestMethod.POST, RequestMethod.GET }, produces = "application/json") public List<Document> tendersByItemClassification( @ModelAttribute @Valid final YearFilterPagingRequest filter) { DBObject project = new BasicDBObject(); project.put(Fields.UNDERSCORE_ID, 0); project.put("tender." + Keys.ITEMS_CLASSIFICATION, 1); project.put(MongoConstants.FieldNames.TENDER_VALUE_AMOUNT, 1); Aggregation agg = newAggregation( match(where(MongoConstants.FieldNames.TENDER_PERIOD_START_DATE).exists(true) .andOperator(getYearDefaultFilterCriteria(filter, MongoConstants.FieldNames.TENDER_PERIOD_START_DATE))), new CustomProjectionOperation(project), unwind("tender.items"), group("$tender." + Keys.ITEMS_CLASSIFICATION).count().as(Keys.TOTAL_TENDERS) .sum(MongoConstants.FieldNames.TENDER_VALUE_AMOUNT).as(Keys.TOTAL_TENDER_AMOUNT), sort(Direction.ASC, Fields.UNDERSCORE_ID)); return releaseAgg(agg); }  @ApiOperation(value = "This should show the number of tenders per tender.items.classification." + "The tender date is taken from tender.tenderPeriod.startDate.") @RequestMapping(value = "/api/tendersByItemClassification", method = { RequestMethod.POST, RequestMethod.GET }, produces = "application/json") List<Document> tendersByItemClassification(
            @ModelAttribute @Valid final YearFilterPagingRequest filter);  }
@Test public void tendersByItemClassification() throws Exception { final List<Document> numberOfTendersByItem = tendersByItemClassification .tendersByItemClassification(new YearFilterPagingRequest()); final Document first = numberOfTendersByItem.get(0); String id = (String) first.get(Fields.UNDERSCORE_ID); String description = (String) first.get(TendersByItemClassification.Keys.DESCRIPTION); int totalTenders = (int) first.get(TendersByItemClassification.Keys.TOTAL_TENDERS); double totalTenderAmount = (double) first.get(TendersByItemClassification.Keys.TOTAL_TENDER_AMOUNT); Assert.assertEquals("09100000", id); Assert.assertEquals("Fuels", description); Assert.assertEquals(1, totalTenders); Assert.assertEquals(9000.0, totalTenderAmount,0); final Document second = numberOfTendersByItem.get(1); id = (String) second.get(Fields.UNDERSCORE_ID); description = (String) second.get(TendersByItemClassification.Keys.DESCRIPTION); totalTenders = (int) second.get(TendersByItemClassification.Keys.TOTAL_TENDERS); totalTenderAmount = (double) second.get(TendersByItemClassification.Keys.TOTAL_TENDER_AMOUNT); Assert.assertEquals("45233130", id); Assert.assertEquals("Construction work for highways", description); Assert.assertEquals(2, totalTenders); Assert.assertEquals(1000000, totalTenderAmount, 0); }