AverageTenderAndAwardPeriodsController extends GenericOCDSController { @ApiOperation(value = "Quality indicator for averageAwardPeriod endpoint, " + "showing the percentage of awards that have start and end dates vs the total tenders in the system") @RequestMapping(value = "/api/qualityAverageAwardPeriod", method = {RequestMethod.POST, RequestMethod.GET}, produces = "application/json") public List<Document> qualityAverageAwardPeriod(@ModelAttribute @Valid final DefaultFilterPagingRequest filter) { DBObject project = new BasicDBObject(); project.put(Fields.UNDERSCORE_ID, 0); project.put( "awardWithStartEndDates", new BasicDBObject( "$cond", Arrays.asList( new BasicDBObject("$and", Arrays.asList( new BasicDBObject( "$gt", Arrays.asList(ref(MongoConstants.FieldNames.AWARDS_DATE), null)), new BasicDBObject( "$gt", Arrays.asList( ref(MongoConstants.FieldNames.TENDER_PERIOD_END_DATE), null ) ) )), 1, 0 ) ) ); DBObject project1 = new BasicDBObject(); project1.put(Keys.TOTAL_AWARD_WITH_START_END_DATES, 1); project1.put(Keys.TOTAL_AWARDS, 1); project1.put( Keys.PERCENTAGE_AWARD_WITH_START_END_DATES, new BasicDBObject("$multiply", Arrays.asList( new BasicDBObject("$divide", Arrays.asList("$totalAwardWithStartEndDates", "$totalAwards")), 100 )) ); Aggregation agg = newAggregation( match(where("awards.0").exists(true).andOperator(getDefaultFilterCriteria(filter))), unwind("awards"), new CustomProjectionOperation(project), group().sum("awardWithStartEndDates") .as(Keys.TOTAL_AWARD_WITH_START_END_DATES).count().as(Keys.TOTAL_AWARDS), new CustomProjectionOperation(project1) ); return releaseAgg(agg); }  @ApiOperation(value = "Calculates the average tender period, per each year. The year is taken from " + "tender.tenderPeriod.startDate and the duration is taken by counting the days" + "between tender.tenderPeriod.endDate and tender.tenderPeriod.startDate") @RequestMapping(value = "/api/averageTenderPeriod", method = {RequestMethod.POST, RequestMethod.GET}, produces = "application/json") List<Document> averageTenderPeriod(@ModelAttribute @Valid final YearFilterPagingRequest filter); @ApiOperation(value = "Quality indicator for averageTenderPeriod endpoint, " + "showing the percentage of tenders that have start and end dates vs the total tenders in the system") @RequestMapping(value = "/api/qualityAverageTenderPeriod", method = {RequestMethod.POST, RequestMethod.GET}, produces = "application/json") List<Document> qualityAverageTenderPeriod(@ModelAttribute @Valid final DefaultFilterPagingRequest filter); @ApiOperation(value = "Calculates the average award period, per each year. The year is taken from " + "awards.date and the duration is taken by counting the days" + "between tender.tenderPeriod.endDate and tender.tenderPeriod.startDate. The award has to be active.") @RequestMapping(value = "/api/averageAwardPeriod", method = {RequestMethod.POST, RequestMethod.GET}, produces = "application/json") List<Document> averageAwardPeriod(@ModelAttribute @Valid final YearFilterPagingRequest filter); @ApiOperation(value = "Quality indicator for averageAwardPeriod endpoint, " + "showing the percentage of awards that have start and end dates vs the total tenders in the system") @RequestMapping(value = "/api/qualityAverageAwardPeriod", method = {RequestMethod.POST, RequestMethod.GET}, produces = "application/json") List<Document> qualityAverageAwardPeriod(@ModelAttribute @Valid final DefaultFilterPagingRequest filter);  }
@Test public void qualityAverageAwardPeriod() throws Exception { final List<Document> qualityAverageAwardPeriod = averageTenderAndAwardPeriodsController .qualityAverageAwardPeriod(new DefaultFilterPagingRequest()); final Document first = qualityAverageAwardPeriod.get(0); int totalAwardWithStartEndDates = (int) first .get(AverageTenderAndAwardPeriodsController.Keys.TOTAL_AWARD_WITH_START_END_DATES); int totalAwards = (int) first .get(AverageTenderAndAwardPeriodsController.Keys.TOTAL_AWARDS); double percentageAwardWithStartEndDates = (double) first .get(AverageTenderAndAwardPeriodsController.Keys.PERCENTAGE_AWARD_WITH_START_END_DATES); Assert.assertEquals(3, totalAwardWithStartEndDates); Assert.assertEquals(3, totalAwards); Assert.assertEquals(100.0, percentageAwardWithStartEndDates, 0); }