Search in sources :

Example 21 with Aggregation

use of org.springframework.data.mongodb.core.aggregation.Aggregation in project ocvn by devgateway.

the class FundingByLocationController method qualityPlannedFundingByLocation.

@ApiOperation("Calculates percentage of releases with planning with at least one specified location," + " that is the array planning.budget.projectLocation has to be initialzied." + "Filters out stub planning, therefore planning.budget.amount has to exist." + "Responds only to the procuring entity id filter: tender.procuringEntity._id")
@RequestMapping(value = "/api/qualityPlannedFundingByLocation", method = { RequestMethod.POST, RequestMethod.GET }, produces = "application/json")
public List<DBObject> qualityPlannedFundingByLocation(@ModelAttribute @Valid final DefaultFilterPagingRequest filter) {
    DBObject project = new BasicDBObject();
    project.putAll(filterProjectMap);
    project.put("planning.budget.projectLocation", 1);
    project.put("planning.budget.amount", 1);
    project.put(Fields.UNDERSCORE_ID, 0);
    DBObject group = new BasicDBObject();
    group.put(Fields.UNDERSCORE_ID, null);
    group.put(Keys.TOTAL_PLANS_WITH_AMOUNTS, new BasicDBObject("$sum", 1));
    group.put(Keys.TOTAL_PLANS_WITH_AMOUNTS_AND_LOCATION, new BasicDBObject("$sum", new BasicDBObject("$cond", Arrays.asList(new BasicDBObject("$gt", Arrays.asList(new BasicDBObject("$size", new BasicDBObject("$ifNull", Arrays.asList("$planning.budget.projectLocation", ArrayUtils.toArray()))), 0)), 1, 0))));
    DBObject project2 = new BasicDBObject();
    project2.put(Fields.UNDERSCORE_ID, 0);
    project2.put(Keys.TOTAL_PLANS_WITH_AMOUNTS, 1);
    project2.put(Keys.TOTAL_PLANS_WITH_AMOUNTS_AND_LOCATION, 1);
    project2.put(Keys.PERCENT_PLANS_WITH_AMOUNTS_AND_LOCATION, new BasicDBObject("$multiply", Arrays.asList(new BasicDBObject("$divide", Arrays.asList("$totalPlansWithAmountsAndLocation", "$totalPlansWithAmounts")), 100)));
    Aggregation agg = newAggregation(new CustomProjectionOperation(project), match(where("planning.budget.amount").exists(true).andOperator(getProcuringEntityIdCriteria(filter))), new CustomGroupingOperation(group), new CustomProjectionOperation(project2));
    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) CustomGroupingOperation(org.devgateway.toolkit.persistence.mongo.aggregate.CustomGroupingOperation) CustomProjectionOperation(org.devgateway.toolkit.persistence.mongo.aggregate.CustomProjectionOperation) DBObject(com.mongodb.DBObject) BasicDBObject(com.mongodb.BasicDBObject) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 22 with Aggregation

use of org.springframework.data.mongodb.core.aggregation.Aggregation 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 23 with Aggregation

use of org.springframework.data.mongodb.core.aggregation.Aggregation in project ocvn by devgateway.

the class TendersAwardsValueIntervals method awardValueInterval.

@ApiOperation(value = "Returns the min and max of awards.value.amount")
@RequestMapping(value = "/api/awardValueInterval", method = { RequestMethod.POST, RequestMethod.GET }, produces = "application/json")
public List<DBObject> awardValueInterval(@ModelAttribute @Valid final YearFilterPagingRequest filter) {
    Aggregation agg = Aggregation.newAggregation(unwind("awards"), match(where("awards.value.amount").exists(true).andOperator(getYearDefaultFilterCriteria(filter, "awards.date"))), project().and("awards.value.amount").as("awards.value.amount"), group().min("awards.value.amount").as("minAwardValue").max("awards.value.amount").as("maxAwardValue"), project().andInclude("minAwardValue", "maxAwardValue").andExclude(Fields.UNDERSCORE_ID));
    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) DBObject(com.mongodb.DBObject) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 24 with Aggregation

use of org.springframework.data.mongodb.core.aggregation.Aggregation in project ocvn by devgateway.

the class TendersAwardsValueIntervals method tenderValueInterval.

@ApiOperation(value = "Returns the min and max of tender.value.amount")
@RequestMapping(value = "/api/tenderValueInterval", method = { RequestMethod.POST, RequestMethod.GET }, produces = "application/json")
public List<DBObject> tenderValueInterval(@ModelAttribute @Valid final YearFilterPagingRequest filter) {
    Aggregation agg = Aggregation.newAggregation(match(where("tender.value.amount").exists(true).andOperator(getYearDefaultFilterCriteria(filter, MongoConstants.FieldNames.TENDER_PERIOD_START_DATE))), project().and("tender.value.amount").as("tender.value.amount"), group().min("tender.value.amount").as("minTenderValue").max("tender.value.amount").as("maxTenderValue"), project().andInclude("minTenderValue", "maxTenderValue").andExclude(Fields.UNDERSCORE_ID));
    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) DBObject(com.mongodb.DBObject) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 25 with Aggregation

use of org.springframework.data.mongodb.core.aggregation.Aggregation in project ocvn by devgateway.

the class CorruptionRiskDashboardIndicatorsStatsController method totalProjectsByYear.

@ApiOperation(value = "Count total projects by year/month.")
@RequestMapping(value = "/api/totalProjectsByYear", method = { RequestMethod.POST, RequestMethod.GET }, produces = "application/json")
public List<DBObject> totalProjectsByYear(final YearFilterPagingRequest filter) {
    DBObject project1 = new BasicDBObject();
    addYearlyMonthlyProjection(filter, project1, MongoConstants.FieldNames.TENDER_PERIOD_START_DATE_REF);
    project1.put(Fields.UNDERSCORE_ID, 0);
    Aggregation agg = newAggregation(match(where(MongoConstants.FieldNames.TENDER_PERIOD_START_DATE).exists(true).andOperator(getYearDefaultFilterCriteria(filter, MongoConstants.FieldNames.TENDER_PERIOD_START_DATE))), new CustomProjectionOperation(project1), group(getYearlyMonthlyGroupingFields(filter)).count().as(Keys.PROJECT_COUNT), transformYearlyGrouping(filter).andInclude(Keys.PROJECT_COUNT), getSortByYearMonth(filter));
    AggregationResults<DBObject> results = mongoTemplate.aggregate(agg, "release", DBObject.class);
    List<DBObject> list = results.getMappedResults();
    return list;
}
Also used : Aggregation.newAggregation(org.springframework.data.mongodb.core.aggregation.Aggregation.newAggregation) Aggregation(org.springframework.data.mongodb.core.aggregation.Aggregation) BasicDBObject(com.mongodb.BasicDBObject) CustomProjectionOperation(org.devgateway.toolkit.persistence.mongo.aggregate.CustomProjectionOperation) DBObject(com.mongodb.DBObject) BasicDBObject(com.mongodb.BasicDBObject) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

DBObject (com.mongodb.DBObject)51 Aggregation (org.springframework.data.mongodb.core.aggregation.Aggregation)51 ApiOperation (io.swagger.annotations.ApiOperation)44 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)44 BasicDBObject (com.mongodb.BasicDBObject)41 Aggregation.newAggregation (org.springframework.data.mongodb.core.aggregation.Aggregation.newAggregation)40 CustomProjectionOperation (org.devgateway.toolkit.persistence.mongo.aggregate.CustomProjectionOperation)30 CustomGroupingOperation (org.devgateway.toolkit.persistence.mongo.aggregate.CustomGroupingOperation)12 CustomOperation (org.devgateway.toolkit.persistence.mongo.aggregate.CustomOperation)9 JsonView (com.fasterxml.jackson.annotation.JsonView)4 CustomUnwindOperation (org.devgateway.toolkit.persistence.mongo.aggregate.CustomUnwindOperation)2 Date (java.util.Date)1 CustomSortingOperation (org.devgateway.toolkit.persistence.mongo.aggregate.CustomSortingOperation)1 Criteria (org.springframework.data.mongodb.core.query.Criteria)1