use of org.springframework.data.mongodb.core.aggregation.Aggregation in project oc-explorer by devgateway.
the class TopTenController method topTenLargestTenders.
/**
* db.release.aggregate( [ {$match: {MongoConstants.FieldNames.TENDER_VALUE_AMOUNT: {$exists:
* true}}}, {$project:{_id:0,"tender.value":1,
* "tender.tenderPeriod":1,"tender.procuringEntity.name":1}}, {$sort:
* {MongoConstants.FieldNames.TENDER_VALUE_AMOUNT:-1}}, {$limit:10} ] )
*
* @return
*/
@ApiOperation(value = "Returns the top ten largest active tenders." + " The amount is taken from the tender.value.amount field." + " The returned data will contain" + "the following fields: " + "tender.date, tender.value.amount, tender.tenderPeriod, " + "tender.procuringEntity.name")
@RequestMapping(value = "/api/topTenLargestTenders", method = { RequestMethod.POST, RequestMethod.GET }, produces = "application/json")
public List<DBObject> topTenLargestTenders(@ModelAttribute @Valid final YearFilterPagingRequest filter) {
BasicDBObject project = new BasicDBObject();
project.put(Fields.UNDERSCORE_ID, 0);
project.put(MongoConstants.FieldNames.TENDER_VALUE_AMOUNT, 1);
project.put("tender.tenderPeriod", 1);
project.put("tender.procuringEntity.name", 1);
Aggregation agg = newAggregation(match(where(MongoConstants.FieldNames.TENDER_VALUE_AMOUNT).exists(true).andOperator(getYearDefaultFilterCriteria(filter, MongoConstants.FieldNames.TENDER_PERIOD_START_DATE))), new CustomOperation(new BasicDBObject("$project", project)), sort(Direction.DESC, MongoConstants.FieldNames.TENDER_VALUE_AMOUNT), limit(10));
return releaseAgg(agg);
}
use of org.springframework.data.mongodb.core.aggregation.Aggregation in project oc-explorer by devgateway.
the class TopTenController method topTenLargestSuppliers.
@ApiOperation(value = "This endpoint should return the following data for the Top 10 suppliers (by award value)." + "Returns supplier id, total awarded amount of all awarded contracts, count of awarded contracts," + "Ids of the procuring entities from which they have received an award, and their count. " + "All filters ally here, the year filter uses the awards.date field.")
@RequestMapping(value = "/api/topTenSuppliers", method = { RequestMethod.POST, RequestMethod.GET }, produces = "application/json")
public List<DBObject> topTenLargestSuppliers(@ModelAttribute @Valid final YearFilterPagingRequest filter) {
BasicDBObject project = new BasicDBObject();
project.put(Fields.UNDERSCORE_ID, 0);
project.put(MongoConstants.FieldNames.AWARDS_SUPPLIERS_ID, 1);
project.put(MongoConstants.FieldNames.AWARDS_VALUE_AMOUNT, 1);
project.put(MongoConstants.FieldNames.TENDER_PROCURING_ENTITY_ID, 1);
BasicDBObject group = new BasicDBObject();
group.put(Fields.UNDERSCORE_ID, ref(MongoConstants.FieldNames.AWARDS_SUPPLIERS_ID));
group.put(Keys.TOTAL_AWARD_AMOUNT, new BasicDBObject("$sum", ref(MongoConstants.FieldNames.AWARDS_VALUE_AMOUNT)));
group.put(Keys.TOTAL_CONTRACTS, new BasicDBObject("$sum", 1));
group.put(Keys.PROCURING_ENTITY_IDS, new BasicDBObject("$addToSet", ref(MongoConstants.FieldNames.TENDER_PROCURING_ENTITY_ID)));
Aggregation agg = newAggregation(match(where(MongoConstants.FieldNames.AWARDS_VALUE_AMOUNT).exists(true).and(MongoConstants.FieldNames.AWARDS_STATUS).is(Award.Status.active.toString()).andOperator(getDefaultFilterCriteria(filter))), unwind("awards"), match(where(MongoConstants.FieldNames.AWARDS_STATUS).is(Award.Status.active.toString())), unwind("awards.suppliers"), match(getYearFilterCriteria(filter.awardFiltering(), MongoConstants.FieldNames.AWARDS_DATE)), new CustomProjectionOperation(project), new CustomGroupingOperation(group), sort(Direction.DESC, Keys.TOTAL_AWARD_AMOUNT), limit(10), project().and(Fields.UNDERSCORE_ID).as(Keys.SUPPLIER_ID).andInclude(Keys.TOTAL_AWARD_AMOUNT, Keys.TOTAL_CONTRACTS, Keys.PROCURING_ENTITY_IDS).andExclude(Fields.UNDERSCORE_ID).and(Keys.PROCURING_ENTITY_IDS).size().as(Keys.PROCURING_ENTITY_IDS_COUNT));
return releaseAgg(agg);
}
use of org.springframework.data.mongodb.core.aggregation.Aggregation in project oc-explorer by devgateway.
the class TopTenController method topTenLargestAwards.
/**
* db.release.aggregate( [ {$match: {MongoConstants.FieldNames.AWARDS_VALUE_AMOUNT: {$exists:
* true}}}, {$unwind:"$awards"},
* {$project:{_id:0,MongoConstants.FieldNames.AWARDS_DATE:1,
* "awards.suppliers.name":1,"awards.value":1, "planning.budget":1}},
* {$sort: {MongoConstants.FieldNames.AWARDS_VALUE_AMOUNT:-1}}, {$limit:10} ] )
*
* @return
*/
@ApiOperation(value = "Returns the top ten largest active awards." + " The amount is taken from the award.value field. The returned data will contain" + "the following fields: " + "awards.date, awards.suppliers.name, " + "awards.value.amount, awards.suppliers.name, planning.budget (if any)")
@RequestMapping(value = "/api/topTenLargestAwards", method = { RequestMethod.POST, RequestMethod.GET }, produces = "application/json")
public List<DBObject> topTenLargestAwards(@ModelAttribute @Valid final YearFilterPagingRequest filter) {
BasicDBObject project = new BasicDBObject();
project.put(Fields.UNDERSCORE_ID, 0);
project.put(MongoConstants.FieldNames.AWARDS_DATE, 1);
project.put("awards.suppliers.name", 1);
project.put(MongoConstants.FieldNames.AWARDS_VALUE_AMOUNT, 1);
project.put("planning.budget", 1);
Aggregation agg = newAggregation(match(where(MongoConstants.FieldNames.AWARDS_VALUE_AMOUNT).exists(true).and(MongoConstants.FieldNames.AWARDS_STATUS).is(Award.Status.active.toString()).andOperator(getDefaultFilterCriteria(filter))), unwind("awards"), match(getYearFilterCriteria(filter.awardFiltering(), MongoConstants.FieldNames.AWARDS_DATE)), new CustomOperation(new BasicDBObject("$project", project)), sort(Direction.DESC, MongoConstants.FieldNames.AWARDS_VALUE_AMOUNT), limit(10));
return releaseAgg(agg);
}
use of org.springframework.data.mongodb.core.aggregation.Aggregation in project oc-explorer by devgateway.
the class AbstractFlagCrosstabController method flagStats.
protected List<DBObject> flagStats(@ModelAttribute @Valid final YearFilterPagingRequest filter) {
DBObject projectPrepare = getProjectPrepare(filter);
DBObject group = getGroup(filter);
DBObject projectPercentage = getProjectPercentage(filter);
Aggregation agg = newAggregation(match(getYearDefaultFilterCriteria(filter, getYearProperty()).and(getYearProperty()).exists(true).and(getFlagProperty()).is(true)), new CustomProjectionOperation(projectPrepare), new CustomGroupingOperation(group), new CustomProjectionOperation(projectPercentage));
return releaseAgg(agg);
}
use of org.springframework.data.mongodb.core.aggregation.Aggregation in project oc-explorer by devgateway.
the class AbstractFlagStatsController method flagStats.
public List<DBObject> flagStats(@ModelAttribute @Valid final YearFilterPagingRequest filter) {
DBObject projectPrepare = getProjectPrepare(filter);
DBObject group = getGroup(filter);
DBObject projectPercentage = getProjectPercentage(filter);
Aggregation agg = newAggregation(match(getYearDefaultFilterCriteria(filter, getYearProperty()).and(getYearProperty()).exists(true)), new CustomProjectionOperation(projectPrepare), new CustomGroupingOperation(group), new CustomProjectionOperation(projectPercentage), transformYearlyGrouping(filter).andInclude(GenericKeys.TOTAL, GenericKeys.TOTAL_TRUE, GenericKeys.TOTAL_FALSE, GenericKeys.TOTAL_PRECOND_MET, GenericKeys.PERCENT_TRUE_PRECOND_MET, GenericKeys.PERCENT_FALSE_PRECOND_MET, GenericKeys.PERCENT_PRECOND_MET));
return releaseAgg(agg);
}
Aggregations