use of org.springframework.data.mongodb.core.aggregation.Aggregation in project oc-explorer by devgateway.
the class AwardsWonLostController method buyersProcuringEntities.
@ApiOperation(value = "List of buyers with releases for the given procuring entities." + "procuringEntityId is mandatory")
@RequestMapping(value = "/api/buyersForProcuringEntities", method = { RequestMethod.POST, RequestMethod.GET }, produces = "application/json")
public List<DBObject> buyersProcuringEntities(@ModelAttribute @Valid final YearFilterPagingRequest filter) {
Assert.notEmpty(filter.getProcuringEntityId(), "procuringEntityId must not be empty!");
Aggregation agg = newAggregation(match(where(MongoConstants.FieldNames.BUYER_ID).exists(true).andOperator(getYearDefaultFilterCriteria(filter, TENDER_PERIOD_START_DATE))), group(Fields.from(Fields.field("buyerId", MongoConstants.FieldNames.BUYER_ID), Fields.field("buyerName", MongoConstants.FieldNames.BUYER_NAME), Fields.field("procuringEntityId", MongoConstants.FieldNames.TENDER_PROCURING_ENTITY_ID))));
return releaseAgg(agg);
}
use of org.springframework.data.mongodb.core.aggregation.Aggregation in project oc-explorer by devgateway.
the class AwardsWonLostController method procurementsWonLostPerProcuringEntity.
@ApiOperation(value = "Counts the number of wins per supplierId per procuringEntityId, plus shows the flags" + " and the awarded total. You must provide supplierId parameter. Any other filter can be used as well.")
@RequestMapping(value = "/api/supplierWinsPerProcuringEntity", method = { RequestMethod.POST, RequestMethod.GET }, produces = "application/json")
public List<DBObject> procurementsWonLostPerProcuringEntity(@ModelAttribute @Valid final YearFilterPagingRequest filter) {
Assert.notEmpty(filter.getSupplierId(), "supplierId must not be empty!");
Aggregation agg = newAggregation(match(where(AWARDS_STATUS).is(Award.Status.active.toString()).andOperator(getYearDefaultFilterCriteria(filter, TENDER_PERIOD_START_DATE)).and(MongoConstants.FieldNames.TENDER_PROCURING_ENTITY_ID).exists(true).and(MongoConstants.FieldNames.TENDER_PROCURING_ENTITY_NAME).exists(true)), unwind("awards"), unwind("awards.suppliers"), match(where(AWARDS_STATUS).is(Award.Status.active.toString()).andOperator(getYearDefaultFilterCriteria(filter.awardFiltering(), TENDER_PERIOD_START_DATE))), group(Fields.from(field("supplierId", MongoConstants.FieldNames.AWARDS_SUPPLIERS_ID), field("procuringEntityName", MongoConstants.FieldNames.TENDER_PROCURING_ENTITY_NAME), field("procuringEntityId", MongoConstants.FieldNames.TENDER_PROCURING_ENTITY_ID))).count().as("count").sum(MongoConstants.FieldNames.AWARDS_VALUE_AMOUNT).as("totalAmountAwarded").sum(FLAGS_TOTAL_FLAGGED).as("countFlags"), sort(Sort.Direction.DESC, "count"));
return releaseAgg(agg);
}
use of org.springframework.data.mongodb.core.aggregation.Aggregation in project oc-explorer 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, ref(MongoConstants.FieldNames.TENDER_PERIOD_START_DATE));
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));
return releaseAgg(agg);
}
use of org.springframework.data.mongodb.core.aggregation.Aggregation in project oc-explorer by devgateway.
the class CorruptionRiskDashboardIndicatorsStatsController method totalProjectsByIndicatorTypeByYear.
private List<DBObject> totalProjectsByIndicatorTypeByYear(String statsProperty, final YearFilterPagingRequest filter) {
DBObject project1 = new BasicDBObject();
addYearlyMonthlyProjection(filter, project1, ref(MongoConstants.FieldNames.TENDER_PERIOD_START_DATE));
project1.put("stats", "$flags." + statsProperty);
project1.put(Fields.UNDERSCORE_ID, 0);
Aggregation agg = newAggregation(match(where(MongoConstants.FieldNames.TENDER_PERIOD_START_DATE).exists(true).and("flags." + statsProperty + ".0").exists(true).andOperator(getYearDefaultFilterCriteria(filter, MongoConstants.FieldNames.TENDER_PERIOD_START_DATE))), unwind("flags." + statsProperty), new CustomProjectionOperation(project1), group(getYearlyMonthlyGroupingFields(filter, "stats.type")).sum("stats.count").as(statsProperty.equals(ELIGIBLE_STATS) ? Keys.ELIGIBLE_COUNT : Keys.FLAGGED_COUNT).count().as(statsProperty.equals(ELIGIBLE_STATS) ? Keys.ELIGIBLE_PROJECT_COUNT : Keys.FLAGGED_PROJECT_COUNT), getSortByYearMonthWhenOtherGroups(filter, "_id.type"));
return releaseAgg(agg);
}
use of org.springframework.data.mongodb.core.aggregation.Aggregation in project oc-explorer by devgateway.
the class CostEffectivenessVisualsController method costEffectivenessAwardAmount.
@ApiOperation(value = "Cost effectiveness of Awards: Displays the total amount of active awards grouped by year." + "The tender entity, for each award, has to have amount value. The year is calculated from " + MongoConstants.FieldNames.TENDER_PERIOD_START_DATE)
@RequestMapping(value = "/api/costEffectivenessAwardAmount", method = { RequestMethod.POST, RequestMethod.GET }, produces = "application/json")
public List<DBObject> costEffectivenessAwardAmount(@ModelAttribute @Valid final YearFilterPagingRequest filter) {
DBObject project = new BasicDBObject();
addYearlyMonthlyProjection(filter, project, ref(MongoConstants.FieldNames.TENDER_PERIOD_START_DATE));
project.put(MongoConstants.FieldNames.AWARDS_VALUE_AMOUNT, 1);
project.put("totalAwardsWithTender", new BasicDBObject("$cond", Arrays.asList(new BasicDBObject("$gt", Arrays.asList(ref(MongoConstants.FieldNames.TENDER_PERIOD_START_DATE), null)), 1, 0)));
project.put("awardsWithTenderValue", new BasicDBObject("$cond", Arrays.asList(new BasicDBObject("$gt", Arrays.asList(ref(MongoConstants.FieldNames.TENDER_PERIOD_START_DATE), null)), "$awards.value.amount", 0)));
Aggregation agg = Aggregation.newAggregation(match(where("awards").elemMatch(where("status").is(Award.Status.active.toString())).and(MongoConstants.FieldNames.AWARDS_DATE).exists(true).and(MongoConstants.FieldNames.TENDER_PERIOD_START_DATE).exists(true)), getMatchDefaultFilterOperation(filter), unwind("awards"), match(where(MongoConstants.FieldNames.AWARDS_STATUS).is(Award.Status.active.toString()).and("awards.value").exists(true).andOperator(getYearDefaultFilterCriteria(filter, MongoConstants.FieldNames.TENDER_PERIOD_START_DATE))), new CustomProjectionOperation(project), getYearlyMonthlyGroupingOperation(filter).sum("awardsWithTenderValue").as(Keys.TOTAL_AWARD_AMOUNT).count().as(Keys.TOTAL_AWARDS).sum("totalAwardsWithTender").as(Keys.TOTAL_AWARDS_WITH_TENDER), project(Fields.UNDERSCORE_ID, Keys.TOTAL_AWARD_AMOUNT, Keys.TOTAL_AWARDS, Keys.TOTAL_AWARDS_WITH_TENDER).and(Keys.TOTAL_AWARDS_WITH_TENDER).divide(Keys.TOTAL_AWARDS).as(Keys.FRACTION_AWARDS_WITH_TENDER), project(Fields.UNDERSCORE_ID, Keys.TOTAL_AWARD_AMOUNT, Keys.TOTAL_AWARDS, Keys.TOTAL_AWARDS_WITH_TENDER, Keys.FRACTION_AWARDS_WITH_TENDER).and(Keys.FRACTION_AWARDS_WITH_TENDER).multiply(100).as(Keys.PERCENTAGE_AWARDS_WITH_TENDER), transformYearlyGrouping(filter).andInclude(Keys.TOTAL_AWARD_AMOUNT, Keys.TOTAL_AWARDS, Keys.TOTAL_AWARDS_WITH_TENDER, Keys.PERCENTAGE_AWARDS_WITH_TENDER), getSortByYearMonth(filter), skip(filter.getSkip()), limit(filter.getPageSize()));
return releaseAgg(agg);
}
Aggregations