Search in sources :

Example 1 with CustomSortingOperation

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

the class GenericOCDSController method getSortByYearMonthWhenOtherGroups.

/**
     * Similar to {@link #getSortByYearMonth(YearFilterPagingRequest)} but it can be used
     * if additional grouping elements are present, besides month and year
     *
     * @param filter
     * @return
     */
protected CustomSortingOperation getSortByYearMonthWhenOtherGroups(YearFilterPagingRequest filter, String... otherSort) {
    DBObject sort = new BasicDBObject();
    if (filter.getMonthly()) {
        sort.put("_id.year", 1);
        sort.put("_id.month", 1);
    } else {
        sort.put("_id.year", 1);
    }
    if (otherSort != null) {
        Arrays.asList(otherSort).forEach(s -> sort.put(s, 1));
    }
    return new CustomSortingOperation(sort);
}
Also used : BasicDBObject(com.mongodb.BasicDBObject) CustomSortingOperation(org.devgateway.toolkit.persistence.mongo.aggregate.CustomSortingOperation) DBObject(com.mongodb.DBObject) BasicDBObject(com.mongodb.BasicDBObject)

Example 2 with CustomSortingOperation

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

the class GenericOCDSController method getSortByYearMonth.

protected CustomSortingOperation getSortByYearMonth(YearFilterPagingRequest filter) {
    DBObject sort = new BasicDBObject();
    if (filter.getMonthly()) {
        sort.put("_id.year", 1);
        sort.put("_id.month", 1);
    } else {
        sort.put("year", 1);
    }
    return new CustomSortingOperation(sort);
}
Also used : BasicDBObject(com.mongodb.BasicDBObject) CustomSortingOperation(org.devgateway.toolkit.persistence.mongo.aggregate.CustomSortingOperation) DBObject(com.mongodb.DBObject) BasicDBObject(com.mongodb.BasicDBObject)

Example 3 with CustomSortingOperation

use of org.devgateway.toolkit.persistence.mongo.aggregate.CustomSortingOperation 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;
}
Also used : Aggregation(org.springframework.data.mongodb.core.aggregation.Aggregation) BasicDBObject(com.mongodb.BasicDBObject) CustomUnwindOperation(org.devgateway.toolkit.persistence.mongo.aggregate.CustomUnwindOperation) CustomGroupingOperation(org.devgateway.toolkit.persistence.mongo.aggregate.CustomGroupingOperation) CustomSortingOperation(org.devgateway.toolkit.persistence.mongo.aggregate.CustomSortingOperation) CustomProjectionOperation(org.devgateway.toolkit.persistence.mongo.aggregate.CustomProjectionOperation) Criteria(org.springframework.data.mongodb.core.query.Criteria) 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)3 DBObject (com.mongodb.DBObject)3 CustomSortingOperation (org.devgateway.toolkit.persistence.mongo.aggregate.CustomSortingOperation)3 ApiOperation (io.swagger.annotations.ApiOperation)1 CustomGroupingOperation (org.devgateway.toolkit.persistence.mongo.aggregate.CustomGroupingOperation)1 CustomProjectionOperation (org.devgateway.toolkit.persistence.mongo.aggregate.CustomProjectionOperation)1 CustomUnwindOperation (org.devgateway.toolkit.persistence.mongo.aggregate.CustomUnwindOperation)1 Aggregation (org.springframework.data.mongodb.core.aggregation.Aggregation)1 Criteria (org.springframework.data.mongodb.core.query.Criteria)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1