TenderPercentagesController extends GenericOCDSController { @ApiOperation("Returns the percent of tenders with active awards, " + "with tender.submissionMethod='electronicSubmission'." + "The endpoint also returns the total tenderds with active awards and the count of tenders with " + "tender.submissionMethod='electronicSubmission") @RequestMapping(value = "/api/percentTendersUsingEBid", method = {RequestMethod.POST, RequestMethod.GET}, produces = "application/json") public List<Document> percentTendersUsingEBid(@ModelAttribute @Valid final YearFilterPagingRequest filter) { DBObject project1 = new BasicDBObject(); addYearlyMonthlyProjection(filter, project1, ref(MongoConstants.FieldNames.TENDER_PERIOD_START_DATE)); project1.put(Fields.UNDERSCORE_ID, "$tender._id"); project1.put("electronicSubmission", new BasicDBObject("$cond", Arrays.asList(new BasicDBObject( "$eq", Arrays.asList( "$tender.submissionMethod", Tender.SubmissionMethod.electronicSubmission.toString() ) ), 1, 0 ))); DBObject group1 = new BasicDBObject(); group1.put( Fields.UNDERSCORE_ID, org.springframework.data .mongodb.core.aggregation.Fields.UNDERSCORE_ID_REF); addYearlyMonthlyGroupingOperationFirst(filter, group1); group1.put("electronicSubmission", new BasicDBObject("$max", "$electronicSubmission")); DBObject group2 = new BasicDBObject(); addYearlyMonthlyReferenceToGroup(filter, group2); group2.put(Keys.TOTAL_TENDERS, new BasicDBObject("$sum", 1)); group2.put(Keys.TOTAL_TENDERS_USING_EBID, new BasicDBObject("$sum", "$electronicSubmission")); DBObject project2 = new BasicDBObject(); project2.put(Keys.TOTAL_TENDERS, 1); project2.put(Keys.TOTAL_TENDERS_USING_EBID, 1); project2.put(Keys.PERCENTAGE_TENDERS_USING_EBID, new BasicDBObject("$multiply", Arrays .asList(new BasicDBObject("$divide", Arrays.asList("$totalTendersUsingEbid", "$totalTenders")), 100))); Aggregation agg = newAggregation( match(where(MongoConstants.FieldNames.TENDER_PERIOD_START_DATE).exists(true) .and("tender.submissionMethod.0").exists(true). and(MongoConstants.FieldNames.AWARDS_STATUS).is(Award.Status.active.toString()) .andOperator(getYearDefaultFilterCriteria( filter, MongoConstants.FieldNames.TENDER_PERIOD_START_DATE ))), unwind("$tender.submissionMethod"), new CustomProjectionOperation(project1), new CustomGroupingOperation(group1), new CustomGroupingOperation(group2), new CustomProjectionOperation(project2), transformYearlyGrouping(filter).andInclude(Keys.TOTAL_TENDERS, Keys.TOTAL_TENDERS_USING_EBID, Keys.PERCENTAGE_TENDERS_USING_EBID ), getSortByYearMonth(filter), skip(filter.getSkip()), limit(filter.getPageSize()) ); return releaseAgg(agg); }  @ApiOperation("Returns the percent of tenders that were cancelled, grouped by year." + " The year is taken from tender.tenderPeriod.startDate. The response also contains the" + " total number of tenders and total number of cancelled tenders for each year.") @RequestMapping(value = "/api/percentTendersCancelled", method = {RequestMethod.POST, RequestMethod.GET}, produces = "application/json") List<Document> percentTendersCancelled(@ModelAttribute @Valid final YearFilterPagingRequest filter); @ApiOperation("Percentage of tenders with >1 tenderer/bidder): " + "Count of tenders with numberOfTenderers >1 divided by total count of tenders." + "This endpoint uses tender.tenderPeriod.startDate to calculate the tender year.") @RequestMapping(value = "/api/percentTendersWithTwoOrMoreTenderers", method = {RequestMethod.POST, RequestMethod.GET}, produces = "application/json") List<Document> percentTendersWithTwoOrMoreTenderers(@ModelAttribute
                                                               @Valid final YearFilterPagingRequest filter); @ApiOperation("Percent of awarded tenders with >1 tenderer/bidder" + "Count of tenders with numberOfTenderers >1 divided by total count of tenders with numberOfTenderers >0" + "This endpoint uses tender.tenderPeriod.startDate to calculate the tender year.") @RequestMapping(value = "/api/percentTendersAwardedWithTwoOrMoreTenderers", method = {RequestMethod.POST, RequestMethod.GET}, produces = "application/json") List<Document> percentTendersAwarded(@ModelAttribute @Valid final YearFilterPagingRequest filter); @ApiOperation("Returns the percent of tenders with active awards, " + "with tender.submissionMethod='electronicSubmission'." + "The endpoint also returns the total tenderds with active awards and the count of tenders with " + "tender.submissionMethod='electronicSubmission") @RequestMapping(value = "/api/percentTendersUsingEBid", method = {RequestMethod.POST, RequestMethod.GET}, produces = "application/json") List<Document> percentTendersUsingEBid(@ModelAttribute @Valid final YearFilterPagingRequest filter); @ApiOperation("Percentage of tenders that are associated in releases that " + "have the planning.budget.amount non empty," + "meaning there really is a planning entity correlated with the tender entity." + "This endpoint uses tender.tenderPeriod.startDate to calculate the tender year.") @RequestMapping(value = "/api/percentTendersWithLinkedProcurementPlan", method = {RequestMethod.POST, RequestMethod.GET}, produces = "application/json") List<Document> percentTendersWithLinkedProcurementPlan(@ModelAttribute
                                                                  @Valid final YearFilterPagingRequest filter);  }
@Test public void percentTendersUsingEBid() throws Exception { final List<Document> percentTendersUsingEBid = tenderPercentagesController .percentTendersUsingEBid(new YearFilterPagingRequest()); final Document first = percentTendersUsingEBid.get(0); int year = (int) first.get(TenderPercentagesController.Keys.YEAR); int totalTenders = (int) first .get(TenderPercentagesController.Keys.TOTAL_TENDERS); int totalTendersUsingEbid = (int) first.get(TenderPercentagesController.Keys.TOTAL_TENDERS_USING_EBID); double percentageTendersUsingEbid = (double) first .get(TenderPercentagesController.Keys.PERCENTAGE_TENDERS_USING_EBID); Assert.assertEquals(2014, year); Assert.assertEquals(1, totalTenders); Assert.assertEquals(1, totalTendersUsingEbid); Assert.assertEquals(100.0, percentageTendersUsingEbid, 0); final Document second = percentTendersUsingEBid.get(1); year = (int) second.get(TenderPercentagesController.Keys.YEAR); totalTenders = (int) second .get(TenderPercentagesController.Keys.TOTAL_TENDERS); totalTendersUsingEbid = (int) second.get(TenderPercentagesController.Keys.TOTAL_TENDERS_USING_EBID); percentageTendersUsingEbid = (double) second .get(TenderPercentagesController.Keys.PERCENTAGE_TENDERS_USING_EBID); Assert.assertEquals(2015, year); Assert.assertEquals(1, totalTenders); Assert.assertEquals(1, totalTendersUsingEbid); Assert.assertEquals(100.0, percentageTendersUsingEbid, 0); }