use of org.devgateway.toolkit.persistence.mongo.aggregate.CustomOperation in project ocvn by devgateway.
the class CountPlansTendersAwardsController method countTendersByYear.
/**
* db.release.aggregate( [ {$match : { MongoConstants.FieldNames.TENDER_PERIOD_START_DATE: {
* $exists: true } }}, {$project: { year: {$year :
* MongoConstants.FieldNames.TENDER_PERIOD_START_DATE_REF} } }, {$group: {_id: "$year", count: {
* $sum:1}}}, {$sort: { _id:1}} ])
*
* @return
*/
@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;
}
use of org.devgateway.toolkit.persistence.mongo.aggregate.CustomOperation in project ocvn by devgateway.
the class AverageTenderAndAwardPeriodsController method averageAwardPeriod.
@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")
public List<DBObject> averageAwardPeriod(@ModelAttribute @Valid final YearFilterPagingRequest filter) {
DBObject awardLengthDays = new BasicDBObject("$divide", Arrays.asList(new BasicDBObject("$subtract", Arrays.asList("$awards.date", MongoConstants.FieldNames.TENDER_PERIOD_END_DATE_REF)), MongoConstants.DAY_MS));
DBObject project = new BasicDBObject();
project.put(Fields.UNDERSCORE_ID, 0);
addYearlyMonthlyProjection(filter, project, "$awards.date");
project.put("awardLengthDays", awardLengthDays);
project.put("awards.date", 1);
project.put("awards.status", 1);
project.put(MongoConstants.FieldNames.TENDER_PERIOD_END_DATE, 1);
Aggregation agg = newAggregation(// unwind
match(where(MongoConstants.FieldNames.TENDER_PERIOD_END_DATE).exists(true).and("awards.date").exists(true).and("awards.status").is("active")), unwind("$awards"), // we need to filter the awards again after unwind
match(where("awards.date").exists(true).and("awards.status").is("active").andOperator(getYearDefaultFilterCriteria(filter, "awards.date"))), new CustomOperation(new BasicDBObject("$project", project)), group(getYearlyMonthlyGroupingFields(filter)).avg("$awardLengthDays").as(Keys.AVERAGE_AWARD_DAYS), transformYearlyGrouping(filter).andInclude(Keys.AVERAGE_AWARD_DAYS), getSortByYearMonth(filter), skip(filter.getSkip()), limit(filter.getPageSize()));
AggregationResults<DBObject> results = mongoTemplate.aggregate(agg, "release", DBObject.class);
List<DBObject> list = results.getMappedResults();
return list;
}
use of org.devgateway.toolkit.persistence.mongo.aggregate.CustomOperation in project ocvn by devgateway.
the class ProcurementMethodSearchController method procurementMethods.
@ApiOperation(value = "Display the available procurement methods. " + "These are taken from tender.procurementMethod")
@RequestMapping(value = "/api/ocds/procurementMethod/all", method = { RequestMethod.POST, RequestMethod.GET }, produces = "application/json")
public List<DBObject> procurementMethods() {
DBObject project = new BasicDBObject("tender.procurementMethod", 1);
Aggregation agg = newAggregation(new CustomOperation(new BasicDBObject("$project", project)), group("$tender.procurementMethod"));
AggregationResults<DBObject> results = mongoTemplate.aggregate(agg, "release", DBObject.class);
List<DBObject> mappedResults = results.getMappedResults();
return mappedResults;
}
use of org.devgateway.toolkit.persistence.mongo.aggregate.CustomOperation in project ocvn by devgateway.
the class TotalCancelledTendersByYearController method totalCancelledTendersByYear.
@ApiOperation(value = "Total Cancelled tenders by year. The tender amount is read from tender.value." + "The tender status has to be 'cancelled'. The year is retrieved from tender.tenderPeriod.startDate.")
@RequestMapping(value = "/api/totalCancelledTendersByYear", method = { RequestMethod.POST, RequestMethod.GET }, produces = "application/json")
public List<DBObject> totalCancelledTendersByYear(@ModelAttribute @Valid final YearFilterPagingRequest filter) {
DBObject project = new BasicDBObject();
addYearlyMonthlyProjection(filter, project, MongoConstants.FieldNames.TENDER_PERIOD_START_DATE_REF);
project.put("tender.value.amount", 1);
Aggregation agg = newAggregation(match(where("tender.status").is("cancelled").and(MongoConstants.FieldNames.TENDER_PERIOD_START_DATE).exists(true).andOperator(getYearDefaultFilterCriteria(filter, MongoConstants.FieldNames.TENDER_PERIOD_START_DATE))), new CustomOperation(new BasicDBObject("$project", project)), getYearlyMonthlyGroupingOperation(filter).sum("$tender.value.amount").as(Keys.TOTAL_CANCELLED_TENDERS_AMOUNT), transformYearlyGrouping(filter).andInclude(Keys.TOTAL_CANCELLED_TENDERS_AMOUNT), getSortByYearMonth(filter));
AggregationResults<DBObject> results = mongoTemplate.aggregate(agg, "release", DBObject.class);
List<DBObject> list = results.getMappedResults();
return list;
}
Aggregations