use of org.springframework.data.mongodb.core.query.Criteria in project ocvn by devgateway.
the class GenericOCDSController method getYearFilterCriteria.
protected Criteria getYearFilterCriteria(final YearFilterPagingRequest filter, final String dateProperty) {
Criteria[] yearCriteria = null;
Criteria criteria = new Criteria();
if (filter.getYear() == null) {
yearCriteria = new Criteria[1];
yearCriteria[0] = new Criteria();
} else {
yearCriteria = new Criteria[filter.getYear().size()];
Integer[] yearArray = filter.getYear().toArray(new Integer[0]);
for (int i = 0; i < yearArray.length; i++) {
yearCriteria[i] = where(dateProperty).gte(getStartDate(yearArray[i])).lte(getEndDate(yearArray[i]));
}
criteria = criteria.orOperator(yearCriteria);
if (filter.getMonth() != null && filter.getYear().size() == 1) {
Integer[] monthArray = filter.getMonth().toArray(new Integer[0]);
//we reset the criteria because we use only one year
criteria = new Criteria();
Criteria[] monthCriteria = new Criteria[filter.getMonth().size()];
for (int i = 0; i < monthArray.length; i++) {
monthCriteria[i] = where(dateProperty).gte(getMonthStartDate(yearArray[0], monthArray[i])).lte(getMonthEndDate(yearArray[0], monthArray[i]));
}
criteria = criteria.orOperator(monthCriteria);
}
}
return criteria;
}
use of org.springframework.data.mongodb.core.query.Criteria 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;
}
Aggregations