use of org.springframework.data.mongodb.core.aggregation.Aggregation in project oc-explorer by devgateway.
the class AverageNumberOfTenderersController method averageNumberOfTenderers.
@ApiOperation(value = "Calculate average number of tenderers. The endpoint can be filtered" + "by year read from tender.tenderPeriod.startDate. " + "The number of tenderers are read from tender.numberOfTenderers")
@RequestMapping(value = "/api/averageNumberOfTenderers", method = { RequestMethod.POST, RequestMethod.GET }, produces = "application/json")
public List<DBObject> averageNumberOfTenderers(@ModelAttribute @Valid final YearFilterPagingRequest filter) {
DBObject project = new BasicDBObject();
addYearlyMonthlyProjection(filter, project, ref(MongoConstants.FieldNames.TENDER_PERIOD_START_DATE));
project.put(MongoConstants.FieldNames.TENDER_NO_TENDERERS, 1);
Aggregation agg = newAggregation(match(where(MongoConstants.FieldNames.TENDER_NO_TENDERERS).gt(0).and(MongoConstants.FieldNames.TENDER_PERIOD_START_DATE).exists(true).andOperator(getYearDefaultFilterCriteria(filter, MongoConstants.FieldNames.TENDER_PERIOD_START_DATE))), new CustomProjectionOperation(project), group().avg(MongoConstants.FieldNames.TENDER_NO_TENDERERS).as(Keys.AVERAGE_NO_OF_TENDERERS));
return releaseAgg(agg);
}
use of org.springframework.data.mongodb.core.aggregation.Aggregation in project oc-explorer by devgateway.
the class AverageTenderAndAwardPeriodsController method averageTenderPeriod.
@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")
public List<DBObject> averageTenderPeriod(@ModelAttribute @Valid final YearFilterPagingRequest filter) {
DBObject tenderLengthDays = new BasicDBObject("$divide", Arrays.asList(new BasicDBObject("$subtract", Arrays.asList(ref(MongoConstants.FieldNames.TENDER_PERIOD_END_DATE), ref(MongoConstants.FieldNames.TENDER_PERIOD_START_DATE))), DAY_MS));
DBObject project = new BasicDBObject();
project.put(Fields.UNDERSCORE_ID, 0);
addYearlyMonthlyProjection(filter, project, ref(MongoConstants.FieldNames.TENDER_PERIOD_START_DATE));
project.put("tenderLengthDays", tenderLengthDays);
Aggregation agg = newAggregation(match(where(MongoConstants.FieldNames.TENDER_PERIOD_START_DATE).exists(true).and(MongoConstants.FieldNames.TENDER_PERIOD_END_DATE).exists(true).andOperator(getYearDefaultFilterCriteria(filter, MongoConstants.FieldNames.TENDER_PERIOD_START_DATE))), new CustomProjectionOperation(project), getYearlyMonthlyGroupingOperation(filter).avg("$tenderLengthDays").as(Keys.AVERAGE_TENDER_DAYS), transformYearlyGrouping(filter).andInclude(Keys.AVERAGE_TENDER_DAYS), getSortByYearMonth(filter), skip(filter.getSkip()), limit(filter.getPageSize()));
return releaseAgg(agg);
}
use of org.springframework.data.mongodb.core.aggregation.Aggregation in project oc-explorer by devgateway.
the class AwardsWonLostController method procuringEntitiesAwardsCount.
@ApiOperation(value = "Number of awards grouped by procuring entities. All filters apply. " + "procuringEntityId filter is mandatory.")
@RequestMapping(value = "/api/procuringEntitiesAwardsCount", method = { RequestMethod.POST, RequestMethod.GET }, produces = "application/json")
public List<DBObject> procuringEntitiesAwardsCount(@ModelAttribute @Valid final YearFilterPagingRequest filter) {
Assert.notEmpty(filter.getProcuringEntityId(), "procuringEntityId must not be empty!");
Aggregation agg = newAggregation(match(getYearDefaultFilterCriteria(filter, TENDER_PERIOD_START_DATE)), unwind("awards"), match(where(MongoConstants.FieldNames.AWARDS_STATUS).is(Award.Status.active.toString())), group(TENDER_PROCURING_ENTITY_ID).count().as("awardCount"));
return releaseAgg(agg);
}
use of org.springframework.data.mongodb.core.aggregation.Aggregation in project oc-explorer by devgateway.
the class AwardsWonLostController method procuringEntitiesTendersCount.
@ApiOperation(value = "Number of tenders grouped by procuring entities. All filters apply. " + "procuringEntityId filter is mandatory.")
@RequestMapping(value = "/api/procuringEntitiesTendersCount", method = { RequestMethod.POST, RequestMethod.GET }, produces = "application/json")
public List<DBObject> procuringEntitiesTendersCount(@ModelAttribute @Valid final YearFilterPagingRequest filter) {
Assert.notEmpty(filter.getProcuringEntityId(), "procuringEntityId must not be empty!");
Aggregation agg = newAggregation(match(getYearDefaultFilterCriteria(filter, TENDER_PERIOD_START_DATE)), group(TENDER_PROCURING_ENTITY_ID).count().as("tenderCount"));
return releaseAgg(agg);
}
use of org.springframework.data.mongodb.core.aggregation.Aggregation in project oc-explorer by devgateway.
the class AwardsWonLostController method procurementsByProcurementMethod.
@ApiOperation(value = "Number of procurements by procurement method for a list of procuring entities")
@RequestMapping(value = "/api/procurementsByProcurementMethod", method = { RequestMethod.POST, RequestMethod.GET }, produces = "application/json")
public List<DBObject> procurementsByProcurementMethod(@ModelAttribute @Valid final YearFilterPagingRequest filter) {
Assert.notEmpty(filter.getProcuringEntityId(), "procuringEntityId must not be empty!");
Aggregation agg = newAggregation(match(where(MongoConstants.FieldNames.TENDER_PROC_METHOD).exists(true).andOperator(getYearDefaultFilterCriteria(filter, TENDER_PERIOD_START_DATE))), group(Fields.from(Fields.field("procuringEntityId", MongoConstants.FieldNames.TENDER_PROCURING_ENTITY_ID), Fields.field("procuringEntityName", MongoConstants.FieldNames.TENDER_PROCURING_ENTITY_NAME), Fields.field("tenderStatus", MongoConstants.FieldNames.TENDER_PROC_METHOD))).count().as("count"));
return releaseAgg(agg);
}
Aggregations