FrequentTenderersController extends GenericOCDSController { @ApiOperation(value = "Counts the tenders/awards where the given supplier id is among the winners. " + "This assumes there is only one active award, which always seems to be the case, per tender. ") @RequestMapping(value = "/api/activeAwardsCount", method = {RequestMethod.POST, RequestMethod.GET}, produces = "application/json") public List<Document> activeAwardsCount(@ModelAttribute @Valid final YearFilterPagingRequest filter) { Aggregation agg = newAggregation( match(where(MongoConstants.FieldNames.AWARDS_STATUS).is(Award.Status.active.toString()) .andOperator(getYearDefaultFilterCriteria( filter, MongoConstants.FieldNames.TENDER_PERIOD_START_DATE ))), unwind("awards"), match(where(MongoConstants.FieldNames.AWARDS_STATUS).is(Award.Status.active.toString()) .andOperator(getYearDefaultFilterCriteria( filter.awardFiltering(), MongoConstants.FieldNames.TENDER_PERIOD_START_DATE ))), unwind("awards.suppliers"), group(MongoConstants.FieldNames.AWARDS_SUPPLIERS_ID).count().as("cnt"), project("cnt").and(Fields.UNDERSCORE_ID).as("supplierId") .andExclude(Fields.UNDERSCORE_ID) ); return releaseAgg(agg); }  @ApiOperation(value = "Detect frequent pairs of tenderers that apply together to bids." + "We are only showing pairs if they applied to more than one bid together." + "We are sorting the results after the number of occurences, descending." + "You can use all the filters that are available along with pagination options.") @RequestMapping(value = "/api/frequentTenderers", method = {RequestMethod.POST, RequestMethod.GET}, produces = "application/json") List<Document> frequentTenderers(@ModelAttribute @Valid final YearFilterPagingRequest filter); @ApiOperation(value = "Counts the tenders/awards where the given supplier id is among the winners. " + "This assumes there is only one active award, which always seems to be the case, per tender. ") @RequestMapping(value = "/api/activeAwardsCount", method = {RequestMethod.POST, RequestMethod.GET}, produces = "application/json") List<Document> activeAwardsCount(@ModelAttribute @Valid final YearFilterPagingRequest filter);  }
@Test public void activeAwardsCountTest() throws Exception { final List<Document> frequentTenderers = frequentTenderersController .activeAwardsCount(new YearFilterPagingRequest()); Assert.assertEquals(2, frequentTenderers.size()); Assert.assertEquals(1, frequentTenderers.get(0).get("cnt")); Assert.assertEquals(1, frequentTenderers.get(1).get("cnt")); }