use of org.springframework.data.mongodb.core.aggregation.Aggregation in project ocvn by devgateway.
the class FundingByLocationController method qualityFundingByTenderDeliveryLocation.
@ApiOperation("Calculates percentage of releases with tender with at least one specified delivery location," + " that is the array tender.items.deliveryLocation has to have items." + "Filters out stub tenders, therefore tender.tenderPeriod.startDate has to exist.")
@RequestMapping(value = "/api/qualityFundingByTenderDeliveryLocation", method = { RequestMethod.POST, RequestMethod.GET }, produces = "application/json")
public List<DBObject> qualityFundingByTenderDeliveryLocation(@ModelAttribute @Valid final YearFilterPagingRequest filter) {
DBObject project = new BasicDBObject();
project.putAll(filterProjectMap);
project.put(Fields.UNDERSCORE_ID, "$tender._id");
project.put("tenderItemsDeliveryLocation", new BasicDBObject("$cond", Arrays.asList(new BasicDBObject("$gt", Arrays.asList("$tender.items.deliveryLocation", 0)), 1, 0)));
DBObject project1 = new BasicDBObject();
project1.put(Fields.UNDERSCORE_ID, 0);
project1.put(Keys.TOTAL_TENDERS_WITH_START_DATE, 1);
project1.put(Keys.TOTAL_TENDERS_WITH_START_DATE_AND_LOCATION, 1);
project1.put(Keys.PERCENT_TENDERS_WITH_START_DATE_AND_LOCATION, new BasicDBObject("$multiply", Arrays.asList(new BasicDBObject("$divide", Arrays.asList("$totalTendersWithStartDateAndLocation", "$totalTendersWithStartDate")), 100)));
Aggregation agg = newAggregation(match(where(MongoConstants.FieldNames.TENDER_PERIOD_START_DATE).exists(true).andOperator(getYearDefaultFilterCriteria(filter, MongoConstants.FieldNames.TENDER_PERIOD_START_DATE))), unwind("$tender.items"), new CustomProjectionOperation(project), group(Fields.UNDERSCORE_ID_REF).max("tenderItemsDeliveryLocation").as("hasTenderItemsDeliverLocation"), group().count().as("totalTendersWithStartDate").sum("hasTenderItemsDeliverLocation").as(Keys.TOTAL_TENDERS_WITH_START_DATE_AND_LOCATION), new CustomProjectionOperation(project1));
AggregationResults<DBObject> results = mongoTemplate.aggregate(agg, "release", DBObject.class);
List<DBObject> tagCount = results.getMappedResults();
return tagCount;
}
use of org.springframework.data.mongodb.core.aggregation.Aggregation in project ocvn by devgateway.
the class FundingByLocationController method plannedFundingByLocation.
@ApiOperation(value = "Planned funding by location by year. Returns the total amount of planning.budget" + " available per planning.budget.projectLocation, grouped by year. " + "This will return full location information, including geocoding data." + "Responds only to the procuring entity id filter: tender.procuringEntity._id")
@RequestMapping(value = "/api/plannedFundingByLocation", method = { RequestMethod.POST, RequestMethod.GET }, produces = "application/json")
public List<DBObject> plannedFundingByLocation(@ModelAttribute @Valid final YearFilterPagingRequest filter) {
DBObject vars = new BasicDBObject();
vars.put("numberOfLocations", new BasicDBObject("$size", "$planning.budget.projectLocation"));
vars.put("planningBudget", "$planning.budget.amount.amount");
DBObject in = new BasicDBObject("$divide", Arrays.asList("$$planningBudget", "$$numberOfLocations"));
DBObject let = new BasicDBObject();
let.put("vars", vars);
let.put("in", in);
DBObject dividedTotal = new BasicDBObject("$let", let);
DBObject project = new BasicDBObject();
project.put("planning.budget.projectLocation", 1);
project.put("cntprj", new BasicDBObject("$literal", 1));
project.put("planning.budget.amount.amount", 1);
project.put("dividedTotal", dividedTotal);
addYearlyMonthlyProjection(filter, project, "$planning.bidPlanProjectDateApprove");
Aggregation agg = newAggregation(match(where("planning").exists(true).and("planning.budget.projectLocation.0").exists(true).andOperator(getProcuringEntityIdCriteria(filter), getYearFilterCriteria(filter, "planning.bidPlanProjectDateApprove"))), new CustomProjectionOperation(project), unwind("$planning.budget.projectLocation"), match(where("planning.budget.projectLocation.geometry.coordinates.0").exists(true)), project(getYearlyMonthlyGroupingFields(filter)).and("dividedTotal").as("dividedTotal").and("cntprj").as("cntprj").and("planning.budget.projectLocation").as("projectLocation"), group(getYearlyMonthlyGroupingFields(filter, Keys.PLANNING_BUDGET_PROJECTLOCATION)).sum("dividedTotal").as(Keys.TOTAL_PLANNED_AMOUNT).sum("cntprj").as(Keys.RECORDS_COUNT), getSortByYearMonth(filter));
AggregationResults<DBObject> results = mongoTemplate.aggregate(agg, "release", DBObject.class);
List<DBObject> tagCount = results.getMappedResults();
return tagCount;
}
use of org.springframework.data.mongodb.core.aggregation.Aggregation in project ocvn by devgateway.
the class FundingByLocationController method fundingByTenderDeliveryLocation.
@ApiOperation(value = "Total estimated funding (tender.value) grouped by " + "tender.items.deliveryLocation and also grouped by year." + " The endpoint also returns the count of tenders for each location. " + "It responds to all filters. The year is calculated based on tender.tenderPeriod.startDate")
@RequestMapping(value = "/api/fundingByTenderDeliveryLocation", method = { RequestMethod.POST, RequestMethod.GET }, produces = "application/json")
public List<DBObject> fundingByTenderDeliveryLocation(@ModelAttribute @Valid final YearFilterPagingRequest filter) {
DBObject project = new BasicDBObject();
project.put("tender.items.deliveryLocation", 1);
project.put("tender.value.amount", 1);
addYearlyMonthlyProjection(filter, project, MongoConstants.FieldNames.TENDER_PERIOD_START_DATE_REF);
Aggregation agg = newAggregation(match(where("tender").exists(true).and(MongoConstants.FieldNames.TENDER_PERIOD_START_DATE).exists(true).andOperator(getYearDefaultFilterCriteria(filter, MongoConstants.FieldNames.TENDER_PERIOD_START_DATE))), new CustomProjectionOperation(project), unwind("$tender.items"), unwind("$tender.items.deliveryLocation"), project(getYearlyMonthlyGroupingFields(filter)).and("tender.value.amount").as("tenderAmount").and("tender.items.deliveryLocation").as("deliveryLocation"), match(where("deliveryLocation.geometry.coordinates.0").exists(true)), group(getYearlyMonthlyGroupingFields(filter, Keys.ITEMS_DELIVERY_LOCATION)).sum("tenderAmount").as(Keys.TOTAL_TENDERS_AMOUNT).count().as(Keys.TENDERS_COUNT), getSortByYearMonth(filter));
AggregationResults<DBObject> results = mongoTemplate.aggregate(agg, "release", DBObject.class);
List<DBObject> tagCount = results.getMappedResults();
return tagCount;
}
use of org.springframework.data.mongodb.core.aggregation.Aggregation in project ocvn by devgateway.
the class LocationInfowindowController method awardsByLocation.
@ApiOperation(value = "Displays the awards, filtered by location. See the location filter " + "for the options to filter by")
@RequestMapping(value = "/api/awardsByLocation", method = { RequestMethod.POST, RequestMethod.GET }, produces = "application/json")
@JsonView(Views.Public.class)
public List<DBObject> awardsByLocation(@ModelAttribute @Valid final YearFilterPagingRequest filter) {
Aggregation agg = newAggregation(match(where("awards.0").exists(true).orOperator(where("tender.items.deliveryLocation._id").exists(true), where("planning.budget.projectLocation._id").exists(true)).andOperator(getYearDefaultFilterCriteria(filter, "awards.date"))), project("awards").andExclude(Fields.UNDERSCORE_ID), unwind("awards"), 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.springframework.data.mongodb.core.aggregation.Aggregation in project ocvn by devgateway.
the class LocationInfowindowController method tendersByLocation.
@ApiOperation(value = "Displays the tenders filtered by location. See the location filter " + "for the options to filter by")
@RequestMapping(value = "/api/tendersByLocation", method = { RequestMethod.POST, RequestMethod.GET }, produces = "application/json")
@JsonView(Views.Public.class)
public List<DBObject> tendersByLocation(@ModelAttribute @Valid final YearFilterPagingRequest filter) {
Aggregation agg = newAggregation(match(where("tender").exists(true).orOperator(where("tender.items.deliveryLocation._id").exists(true), where("planning.budget.projectLocation._id").exists(true)).andOperator(getYearDefaultFilterCriteria(filter, MongoConstants.FieldNames.TENDER_PERIOD_START_DATE))), project("tender").andExclude(Fields.UNDERSCORE_ID), skip(filter.getSkip()), limit(filter.getPageSize()));
AggregationResults<DBObject> results = mongoTemplate.aggregate(agg, "release", DBObject.class);
List<DBObject> tagCount = results.getMappedResults();
return tagCount;
}
Aggregations