CountPlansTendersAwardsController extends GenericOCDSController { @ApiOperation(value = "Count the tenders and group the results by year. The year is calculated from " + "tender.tenderPeriod.startDate.") @RequestMapping(value = "/api/countTendersByYear", method = { RequestMethod.POST, RequestMethod.GET }, produces = "application/json") public List<DBObject> countTendersByYear(@ModelAttribute @Valid final YearFilterPagingRequest filter) { DBObject project = new BasicDBObject(); addYearlyMonthlyProjection(filter, project, MongoConstants.FieldNames.TENDER_PERIOD_START_DATE_REF); Aggregation agg = Aggregation.newAggregation(match( where(MongoConstants.FieldNames.TENDER_PERIOD_START_DATE).exists(true). andOperator(getYearDefaultFilterCriteria(filter, MongoConstants.FieldNames.TENDER_PERIOD_START_DATE))), new CustomOperation(new BasicDBObject("$project", project)), group(getYearlyMonthlyGroupingFields(filter)).count().as(Keys.COUNT), transformYearlyGrouping(filter).andInclude(Keys.COUNT), getSortByYearMonth(filter), skip(filter.getSkip()), limit(filter.getPageSize())); AggregationResults<DBObject> results = mongoTemplate.aggregate(agg, "release", DBObject.class); List<DBObject> tagCount = results.getMappedResults(); return tagCount; }  @ApiOperation(value = "Count the tenders and group the results by year. The year is calculated from " + "tender.tenderPeriod.startDate.") @RequestMapping(value = "/api/countTendersByYear", method = { RequestMethod.POST, RequestMethod.GET }, produces = "application/json") List<DBObject> countTendersByYear(@ModelAttribute @Valid final YearFilterPagingRequest filter); @ApiOperation(value = "Count the awards and group the results by year. " + "The year is calculated from the awards.date field.") @RequestMapping(value = "/api/countAwardsByYear", method = { RequestMethod.POST, RequestMethod.GET }, produces = "application/json") List<DBObject> countAwardsByYear(@ModelAttribute @Valid final YearFilterPagingRequest filter); @ApiOperation(value = "Count of bid plans, by year. This will count the releases that have the field" + "planning.bidPlanProjectDateApprove populated. " + "The year grouping is taken from planning.bidPlanProjectDateApprove") @RequestMapping(value = "/api/countBidPlansByYear", method = { RequestMethod.POST, RequestMethod.GET }, produces = "application/json") List<DBObject> countBidPlansByYear(@ModelAttribute @Valid final YearFilterPagingRequest filter);  }
@Test public void countTendersByYear() throws Exception { final List<DBObject> countTendersByYear = countPlansTendersAwardsController .countTendersByYear(new YearFilterPagingRequest()); final DBObject first = countTendersByYear.get(0); int year = (int) first.get(CountPlansTendersAwardsController.Keys.YEAR); int count = (int) first.get(CountPlansTendersAwardsController.Keys.COUNT); Assert.assertEquals(2014, year); Assert.assertEquals(1, count); final DBObject second = countTendersByYear.get(1); year = (int) second.get(CountPlansTendersAwardsController.Keys.YEAR); count = (int) second.get(CountPlansTendersAwardsController.Keys.COUNT); Assert.assertEquals(2015, year); Assert.assertEquals(2, count); }