use of org.springframework.data.mongodb.core.aggregation.Aggregation in project ocvn by devgateway.
the class TenderPercentagesController method percentTendersAwarded.
@ApiOperation("Percent of awarded tenders with >1 tenderer/bidder" + "Count of tenders with numberOfTenderers >1 divided by total count of tenders with numberOfTenderers >0" + "This endpoint uses tender.tenderPeriod.startDate to calculate the tender year.")
@RequestMapping(value = "/api/percentTendersAwardedWithTwoOrMoreTenderers", method = { RequestMethod.POST, RequestMethod.GET }, produces = "application/json")
public List<DBObject> percentTendersAwarded(@ModelAttribute @Valid final YearFilterPagingRequest filter) {
DBObject project1 = new BasicDBObject();
addYearlyMonthlyProjection(filter, project1, MongoConstants.FieldNames.TENDER_PERIOD_START_DATE_REF);
project1.put("tender.numberOfTenderers", 1);
DBObject group = new BasicDBObject();
addYearlyMonthlyReferenceToGroup(filter, group);
group.put(Keys.TOTAL_TENDERS_WITH_ONE_OR_MORE_TENDERERS, new BasicDBObject("$sum", new BasicDBObject("$cond", Arrays.asList(new BasicDBObject("$gt", Arrays.asList("$tender.numberOfTenderers", 0)), 1, 0))));
group.put(Keys.TOTAL_TENDERS_WITH_TWO_OR_MORE_TENDERERS, new BasicDBObject("$sum", new BasicDBObject("$cond", Arrays.asList(new BasicDBObject("$gt", Arrays.asList("$tender.numberOfTenderers", 1)), 1, 0))));
DBObject project2 = new BasicDBObject();
project2.put(Keys.TOTAL_TENDERS_WITH_ONE_OR_MORE_TENDERERS, 1);
project2.put(Keys.TOTAL_TENDERS_WITH_TWO_OR_MORE_TENDERERS, 1);
project2.put(Keys.PERCENT_TENDERS, new BasicDBObject("$multiply", Arrays.asList(new BasicDBObject("$divide", Arrays.asList("$totalTendersWithTwoOrMoreTenderers", "$totalTendersWithOneOrMoreTenderers")), 100)));
Aggregation agg = newAggregation(match(where(MongoConstants.FieldNames.TENDER_PERIOD_START_DATE).exists(true).and("tender.numberOfTenderers").gt(0).andOperator(getYearDefaultFilterCriteria(filter, MongoConstants.FieldNames.TENDER_PERIOD_START_DATE))), new CustomProjectionOperation(project1), new CustomGroupingOperation(group), new CustomProjectionOperation(project2), transformYearlyGrouping(filter).andInclude(Keys.TOTAL_TENDERS_WITH_ONE_OR_MORE_TENDERERS, Keys.TOTAL_TENDERS_WITH_TWO_OR_MORE_TENDERERS, Keys.PERCENT_TENDERS), 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.springframework.data.mongodb.core.aggregation.Aggregation in project ocvn by devgateway.
the class TenderPercentagesController method percentTendersWithLinkedProcurementPlan.
@ApiOperation("Percentage of tenders that are associated in releases that " + "have the planning.budget.amount non empty," + "meaning there really is a planning entity correlated with the tender entity." + "This endpoint uses tender.tenderPeriod.startDate to calculate the tender year.")
@RequestMapping(value = "/api/percentTendersWithLinkedProcurementPlan", method = { RequestMethod.POST, RequestMethod.GET }, produces = "application/json")
public List<DBObject> percentTendersWithLinkedProcurementPlan(@ModelAttribute @Valid final YearFilterPagingRequest filter) {
DBObject project1 = new BasicDBObject();
addYearlyMonthlyProjection(filter, project1, "$tender.tenderPeriod.startDate");
project1.put("tender._id", 1);
project1.put("planning.budget.amount", 1);
DBObject group = new BasicDBObject();
addYearlyMonthlyReferenceToGroup(filter, group);
group.put(Keys.TOTAL_TENDERS, new BasicDBObject("$sum", 1));
group.put(Keys.TOTAL_TENDERS_WITH_LINKED_PROCUREMENT_PLAN, new BasicDBObject("$sum", new BasicDBObject("$cond", Arrays.asList(new BasicDBObject("$gt", Arrays.asList("$planning.budget.amount", null)), 1, 0))));
DBObject project2 = new BasicDBObject();
project2.put(Keys.YEAR, 1);
project2.put("month", 1);
project2.put(Keys.TOTAL_TENDERS, 1);
project2.put(Keys.TOTAL_TENDERS_WITH_LINKED_PROCUREMENT_PLAN, 1);
project2.put(Keys.PERCENT_TENDERS, new BasicDBObject("$multiply", Arrays.asList(new BasicDBObject("$divide", Arrays.asList("$" + Keys.TOTAL_TENDERS_WITH_LINKED_PROCUREMENT_PLAN, "$" + Keys.TOTAL_TENDERS)), 100)));
Aggregation agg = newAggregation(match(where("tender.tenderPeriod.startDate").exists(true).andOperator(getYearDefaultFilterCriteria(filter, "tender.tenderPeriod.startDate"))), new CustomProjectionOperation(project1), new CustomGroupingOperation(group), transformYearlyGrouping(filter).andInclude(Keys.TOTAL_TENDERS, Keys.TOTAL_TENDERS_WITH_LINKED_PROCUREMENT_PLAN, Keys.PERCENT_TENDERS), new CustomProjectionOperation(project2), 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.springframework.data.mongodb.core.aggregation.Aggregation in project ocvn by devgateway.
the class TenderPriceByTypeYearController method tenderPriceByProcurementMethod.
@ApiOperation(value = "Returns the tender price by OCDS type (procurementMethod), by year. " + "The OCDS type is read from tender.procurementMethod. The tender price is read from " + "tender.value.amount")
@RequestMapping(value = "/api/tenderPriceByProcurementMethod", method = { RequestMethod.POST, RequestMethod.GET }, produces = "application/json")
public List<DBObject> tenderPriceByProcurementMethod(@ModelAttribute @Valid final YearFilterPagingRequest filter) {
DBObject project = new BasicDBObject();
project.put("tender." + Keys.PROCUREMENT_METHOD, 1);
project.put("tender.value", 1);
Aggregation agg = newAggregation(match(where("awards").elemMatch(where("status").is("active")).and("tender.value").exists(true).andOperator(getYearDefaultFilterCriteria(filter, MongoConstants.FieldNames.TENDER_PERIOD_START_DATE))), new CustomProjectionOperation(project), group("tender." + Keys.PROCUREMENT_METHOD).sum("$tender.value.amount").as(Keys.TOTAL_TENDER_AMOUNT), project().and(Fields.UNDERSCORE_ID).as(Keys.PROCUREMENT_METHOD).andInclude(Keys.TOTAL_TENDER_AMOUNT).andExclude(Fields.UNDERSCORE_ID), sort(Direction.DESC, Keys.TOTAL_TENDER_AMOUNT));
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 TendersAwardsYears method tendersAwardsYears.
@ApiOperation(value = "Computes all available years from awards.date, tender.tenderPeriod.startDate" + "and planning.bidPlanProjectDateApprove")
@RequestMapping(value = "/api/tendersAwardsYears", method = { RequestMethod.POST, RequestMethod.GET }, produces = "application/json")
public List<DBObject> tendersAwardsYears() {
BasicDBObject project1 = new BasicDBObject();
project1.put("tenderYear", new BasicDBObject("$cond", Arrays.asList(new BasicDBObject("$gt", Arrays.asList(MongoConstants.FieldNames.TENDER_PERIOD_START_DATE_REF, null)), new BasicDBObject("$year", MongoConstants.FieldNames.TENDER_PERIOD_START_DATE_REF), null)));
project1.put("bidPlanYear", new BasicDBObject("$cond", Arrays.asList(new BasicDBObject("$gt", Arrays.asList("$planning.bidPlanProjectDateApprove", null)), new BasicDBObject("$year", "$planning.bidPlanProjectDateApprove"), null)));
project1.put("awardYear", new BasicDBObject("$cond", Arrays.asList(new BasicDBObject("$gt", Arrays.asList("$awards.date", null)), new BasicDBObject("$year", "$awards.date"), null)));
project1.put(Fields.UNDERSCORE_ID, 0);
BasicDBObject project2 = new BasicDBObject();
project2.put("year", Arrays.asList("$tenderYear", "$awardYear", "$bidPlanYear"));
Aggregation agg = Aggregation.newAggregation(project().and(MongoConstants.FieldNames.TENDER_PERIOD_START_DATE).as(MongoConstants.FieldNames.TENDER_PERIOD_START_DATE).and("awards.date").as("awards.date").and("planning.bidPlanProjectDateApprove").as("planning.bidPlanProjectDateApprove"), match(new Criteria().orOperator(where(MongoConstants.FieldNames.TENDER_PERIOD_START_DATE).exists(true), where("awards.date").exists(true), where("planning.bidPlanProjectDateApprove").exists(true))), new CustomUnwindOperation("$awards", true), new CustomProjectionOperation(project1), new CustomProjectionOperation(project2), new CustomUnwindOperation("$year"), match(where("year").ne(null)), new CustomGroupingOperation(new BasicDBObject(Fields.UNDERSCORE_ID, "$year")), new CustomSortingOperation(new BasicDBObject(Fields.UNDERSCORE_ID, 1)));
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 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;
}
Aggregations