Search in sources :

Example 1 with CustomOperation

use of org.devgateway.toolkit.persistence.mongo.aggregate.CustomOperation in project ocvn by devgateway.

the class TopTenController method topTenLargestTenders.

/**
     * db.release.aggregate( [ {$match: {"tender.value.amount": {$exists:
     * true}}}, {$project:{_id:0,"planning.bidNo":1,"tender.value":1,
     * "tender.tenderPeriod":1,"tender.procuringEntity.name":1}}, {$sort:
     * {"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: " + "planning.bidNo, 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("planning.bidNo", 1);
    project.put("tender.value.amount", 1);
    project.put("tender.tenderPeriod", 1);
    project.put("tender.procuringEntity.name", 1);
    Aggregation agg = newAggregation(match(where("tender.value.amount").exists(true).andOperator(getYearDefaultFilterCriteria(filter, MongoConstants.FieldNames.TENDER_PERIOD_START_DATE))), new CustomOperation(new BasicDBObject("$project", project)), sort(Direction.DESC, "tender.value.amount"), limit(10));
    AggregationResults<DBObject> results = mongoTemplate.aggregate(agg, "release", DBObject.class);
    List<DBObject> tagCount = results.getMappedResults();
    return tagCount;
}
Also used : Aggregation.newAggregation(org.springframework.data.mongodb.core.aggregation.Aggregation.newAggregation) Aggregation(org.springframework.data.mongodb.core.aggregation.Aggregation) BasicDBObject(com.mongodb.BasicDBObject) CustomOperation(org.devgateway.toolkit.persistence.mongo.aggregate.CustomOperation) DBObject(com.mongodb.DBObject) BasicDBObject(com.mongodb.BasicDBObject) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with CustomOperation

use of org.devgateway.toolkit.persistence.mongo.aggregate.CustomOperation in project ocvn by devgateway.

the class TopTenController method topTenLargestAwards.

/**
     * db.release.aggregate( [ {$match: {"awards.value.amount": {$exists:
     * true}}}, {$unwind:"$awards"},
     * {$project:{_id:0,"planning.bidNo":1,"awards.date":1,
     * "awards.suppliers.name":1,"awards.value":1, "planning.budget":1}},
     * {$sort: {"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: " + "planning.bidNo, 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("planning.bidNo", 1);
    project.put("awards.date", 1);
    project.put("awards.suppliers.name", 1);
    project.put("awards.value.amount", 1);
    project.put("planning.budget", 1);
    Aggregation agg = newAggregation(match(where("awards.value.amount").exists(true).and("awards.status").is("active").andOperator(getDefaultFilterCriteria(filter))), unwind("$awards"), match(getYearFilterCriteria(filter, "awards.date")), new CustomOperation(new BasicDBObject("$project", project)), sort(Direction.DESC, "awards.value.amount"), limit(10));
    AggregationResults<DBObject> results = mongoTemplate.aggregate(agg, "release", DBObject.class);
    List<DBObject> tagCount = results.getMappedResults();
    return tagCount;
}
Also used : Aggregation.newAggregation(org.springframework.data.mongodb.core.aggregation.Aggregation.newAggregation) Aggregation(org.springframework.data.mongodb.core.aggregation.Aggregation) BasicDBObject(com.mongodb.BasicDBObject) CustomOperation(org.devgateway.toolkit.persistence.mongo.aggregate.CustomOperation) DBObject(com.mongodb.DBObject) BasicDBObject(com.mongodb.BasicDBObject) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with CustomOperation

use of org.devgateway.toolkit.persistence.mongo.aggregate.CustomOperation in project ocvn by devgateway.

the class CountPlansTendersAwardsController method countAwardsByYear.

/**
     * db.release.aggregate( [ {$match : { "awards.0": { $exists: true } }},
     * {$project: {awards:1}}, {$unwind: "$awards"}, {$match: {"awards.date":
     * {$exists:true}}}, {$project: { year: {$year : "$awards.date"} } },
     * {$group: {_id: "$year", count: { $sum:1}}}, {$sort: { _id:1}} ])
     *
     * @return
     */
@ApiOperation(value = "Count the awards and group the results by year. " + "The year is calculated from the awards.date field.")
@RequestMapping(value = "/api/countAwardsByYear", method = { RequestMethod.POST, RequestMethod.GET }, produces = "application/json")
public List<DBObject> countAwardsByYear(@ModelAttribute @Valid final YearFilterPagingRequest filter) {
    DBObject project0 = new BasicDBObject();
    project0.put("awards", 1);
    DBObject project = new BasicDBObject();
    addYearlyMonthlyProjection(filter, project, "$awards.date");
    Aggregation agg = Aggregation.newAggregation(match(where("awards.0").exists(true).andOperator(getDefaultFilterCriteria(filter))), new CustomOperation(new BasicDBObject("$project", project0)), unwind("$awards"), match(where("awards.date").exists(true).andOperator(getYearFilterCriteria(filter, "awards.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;
}
Also used : Aggregation(org.springframework.data.mongodb.core.aggregation.Aggregation) BasicDBObject(com.mongodb.BasicDBObject) CustomOperation(org.devgateway.toolkit.persistence.mongo.aggregate.CustomOperation) BasicDBObject(com.mongodb.BasicDBObject) DBObject(com.mongodb.DBObject) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with CustomOperation

use of org.devgateway.toolkit.persistence.mongo.aggregate.CustomOperation in project ocvn by devgateway.

the class BidSelectionMethodSearchController method bidSelectionMethods.

/**
     * db.release.aggregate([ {$project : {"tender.procurementMethodDetails":1}
     * }, {$group: {_id: "$tender.procurementMethodDetails" }} ])
     *
     * @return
     */
@ApiOperation(value = "Display the available bid selection methods. " + "These are taken from tender.procurementMethodDetails")
@RequestMapping(value = "/api/ocds/bidSelectionMethod/all", method = { RequestMethod.POST, RequestMethod.GET }, produces = "application/json")
public List<DBObject> bidSelectionMethods() {
    DBObject project = new BasicDBObject("tender.procurementMethodDetails", 1);
    Aggregation agg = newAggregation(new CustomOperation(new BasicDBObject("$project", project)), group("$tender.procurementMethodDetails"), sort(Direction.ASC, Fields.UNDERSCORE_ID));
    AggregationResults<DBObject> results = mongoTemplate.aggregate(agg, "release", DBObject.class);
    List<DBObject> mappedResults = results.getMappedResults();
    return mappedResults;
}
Also used : Aggregation.newAggregation(org.springframework.data.mongodb.core.aggregation.Aggregation.newAggregation) Aggregation(org.springframework.data.mongodb.core.aggregation.Aggregation) BasicDBObject(com.mongodb.BasicDBObject) CustomOperation(org.devgateway.toolkit.persistence.mongo.aggregate.CustomOperation) BasicDBObject(com.mongodb.BasicDBObject) DBObject(com.mongodb.DBObject) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with CustomOperation

use of org.devgateway.toolkit.persistence.mongo.aggregate.CustomOperation in project ocvn by devgateway.

the class CountPlansTendersAwardsController method countBidPlansByYear.

/**
     * db.release.aggregate( [ {$match : { "planning.bidPlanProjectDateApprove":
     * { $exists: true } }}, {$project: { planning:1, year: {$year :
     * "$planning.bidPlanProjectDateApprove"} } }, {$group: {_id: "$year",
     * count: { $sum:1}}}, {$sort: { _id:1}} ])
     *
     * @return
     */
@ApiOperation(value = "Count of bid plans, by year. This will count the releases that have the field" + "planning.bidPlanProjectDateApprove populated. " + "The year grouping is taken from planning.bidPlanProjectDateApprove")
@RequestMapping(value = "/api/countBidPlansByYear", method = { RequestMethod.POST, RequestMethod.GET }, produces = "application/json")
public List<DBObject> countBidPlansByYear(@ModelAttribute @Valid final YearFilterPagingRequest filter) {
    DBObject project = new BasicDBObject();
    addYearlyMonthlyProjection(filter, project, "$planning.bidPlanProjectDateApprove");
    Aggregation agg = Aggregation.newAggregation(match(where("planning.bidPlanProjectDateApprove").exists(true).andOperator(getYearDefaultFilterCriteria(filter, "planning.bidPlanProjectDateApprove"))), new CustomOperation(new BasicDBObject("$project", project)), getYearlyMonthlyGroupingOperation(filter).count().as("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;
}
Also used : Aggregation(org.springframework.data.mongodb.core.aggregation.Aggregation) BasicDBObject(com.mongodb.BasicDBObject) CustomOperation(org.devgateway.toolkit.persistence.mongo.aggregate.CustomOperation) BasicDBObject(com.mongodb.BasicDBObject) DBObject(com.mongodb.DBObject) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

BasicDBObject (com.mongodb.BasicDBObject)9 DBObject (com.mongodb.DBObject)9 ApiOperation (io.swagger.annotations.ApiOperation)9 CustomOperation (org.devgateway.toolkit.persistence.mongo.aggregate.CustomOperation)9 Aggregation (org.springframework.data.mongodb.core.aggregation.Aggregation)9 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)9 Aggregation.newAggregation (org.springframework.data.mongodb.core.aggregation.Aggregation.newAggregation)6