List of usage examples for org.springframework.data.mongodb.core.aggregation Fields UNDERSCORE_ID
String UNDERSCORE_ID
To view the source code for org.springframework.data.mongodb.core.aggregation Fields UNDERSCORE_ID.
Click Source Link
From source file:org.devgateway.ocds.web.rest.controller.selector.LocationSearchController.java
@RequestMapping(value = "/api/ocds/location/all", method = { RequestMethod.POST, RequestMethod.GET }, produces = "application/json") public List<VNLocation> locationsAll() { return locationRepository.findAll(new Sort(Direction.ASC, Fields.UNDERSCORE_ID)); }
From source file:org.devgateway.ocds.web.rest.controller.selector.BidSelectionMethodSearchController.java
/** * db.release.aggregate([ {$project : {"tender.procurementMethodDetails":1} * }, {$group: {_id: "$tender.procurementMethodDetails" }} ]) * * @return/*w w w . j ava2 s . com*/ */ @ApiOperation(value = "Display the available bid selection methods. " + "These are taken from tender.procurementMethodDetails") @RequestMapping(value = "/api/ocds/bidSelectionMethod/all", method = { RequestMethod.POST, RequestMethod.GET }, produces = "application/json") public List<DBObject> bidSelectionMethods() { DBObject project = new BasicDBObject("tender.procurementMethodDetails", 1); Aggregation agg = newAggregation(new CustomOperation(new BasicDBObject("$project", project)), group("$tender.procurementMethodDetails"), sort(Direction.ASC, Fields.UNDERSCORE_ID)); AggregationResults<DBObject> results = mongoTemplate.aggregate(agg, "release", DBObject.class); List<DBObject> mappedResults = results.getMappedResults(); return mappedResults; }
From source file:it.f2informatica.mongodb.repositories.impl.ConsultantRepositoryImpl.java
@Override public Experience findExperience(String consultantId, String experienceId) { Aggregation aggregation = newAggregation(match(where("id").is(consultantId)), group("experiences"), unwind(previousOperation()), match(where(previousOperation() + "." + Fields.UNDERSCORE_ID).is(experienceId))); AggregationResults<Experience> aggregationResults = mongoTemplate.aggregate(aggregation, Consultant.class, Experience.class); return aggregationResults.getUniqueMappedResult(); }
From source file:org.devgateway.ocds.web.rest.controller.NumberOfTendersByItemClassification.java
@ApiOperation(value = "This should show the number of tenders per tender.items.classification." + "The tender date is taken from tender.tenderPeriod.startDate.") @RequestMapping(value = "/api/numberOfTendersByItemClassification", method = { RequestMethod.POST, RequestMethod.GET }, produces = "application/json") public List<DBObject> numberOfTendersByItemClassification( @ModelAttribute @Valid final YearFilterPagingRequest filter) { DBObject project = new BasicDBObject(); project.put(Fields.UNDERSCORE_ID, 0); project.put("tender." + Keys.ITEMS_CLASSIFICATION, 1); Aggregation agg = newAggregation(//from ww w . jav a2s . co m match(where("tender.tenderPeriod.startDate").exists(true) .andOperator(getYearDefaultFilterCriteria(filter, "tender.tenderPeriod.startDate"))), new CustomProjectionOperation(project), unwind("tender.items"), group("$tender." + Keys.ITEMS_CLASSIFICATION).count().as(Keys.TOTAL_TENDERS), sort(Direction.ASC, Fields.UNDERSCORE_ID)); AggregationResults<DBObject> results = mongoTemplate.aggregate(agg, "release", DBObject.class); List<DBObject> list = results.getMappedResults(); return list; }
From source file:org.devgateway.ocds.web.rest.controller.TendersByItemClassification.java
@ApiOperation(value = "This should show the number of tenders per tender.items.classification." + "The tender date is taken from tender.tenderPeriod.startDate.") @RequestMapping(value = "/api/tendersByItemClassification", method = { RequestMethod.POST, RequestMethod.GET }, produces = "application/json") public List<DBObject> tendersByItemClassification(@ModelAttribute @Valid final YearFilterPagingRequest filter) { DBObject project = new BasicDBObject(); project.put(Fields.UNDERSCORE_ID, 0); project.put("tender." + Keys.ITEMS_CLASSIFICATION, 1); project.put(MongoConstants.FieldNames.TENDER_VALUE_AMOUNT, 1); Aggregation agg = newAggregation(/*from ww w.j a va 2 s. c o m*/ match(where(MongoConstants.FieldNames.TENDER_PERIOD_START_DATE).exists(true).andOperator( getYearDefaultFilterCriteria(filter, MongoConstants.FieldNames.TENDER_PERIOD_START_DATE))), new CustomProjectionOperation(project), unwind("tender.items"), group("$tender." + Keys.ITEMS_CLASSIFICATION).count().as(Keys.TOTAL_TENDERS) .sum(MongoConstants.FieldNames.TENDER_VALUE_AMOUNT).as(Keys.TOTAL_TENDER_AMOUNT), sort(Direction.ASC, Fields.UNDERSCORE_ID)); return releaseAgg(agg); }
From source file:it.f2informatica.mongodb.repositories.impl.ConsultantRepositoryImpl.java
@Override public Education findEducation(String consultantId, String educationId) { Aggregation aggregation = newAggregation(match(where("id").is(consultantId)), group("educationList"), unwind(previousOperation()), match(where(previousOperation() + "." + Fields.UNDERSCORE_ID).is(educationId))); AggregationResults<Education> aggregationResults = mongoTemplate.aggregate(aggregation, Consultant.class, Education.class); return aggregationResults.getUniqueMappedResult(); }
From source file:org.devgateway.ocds.web.rest.controller.CorruptionRiskDashboardTablesController.java
@ApiOperation(value = "Returns data to show in the table on corruption risk overview page." + "This is presented as releases only with the information in the table present and unwinded by " + "flags.flaggedStats") @RequestMapping(value = "/api/corruptionRiskOverviewTable", method = { RequestMethod.POST, RequestMethod.GET }, produces = "application/json") public List<DBObject> corruptionRiskOverviewTable(@ModelAttribute @Valid final YearFilterPagingRequest filter) { Aggregation agg = newAggregation(//ww w.j ava 2 s. c o m match(where("flags.flaggedStats.0").exists(true).andOperator( getYearDefaultFilterCriteria(filter, MongoConstants.FieldNames.TENDER_PERIOD_START_DATE))), unwind("flags.flaggedStats"), project("ocid", "tender.procuringEntity.name", "tender.tenderPeriod", "flags", "tender.title", "tag").and("tender.value").as("tender.value").and("awards.value").as("awards.value") .and(MongoConstants.FieldNames.AWARDS_STATUS) .as(MongoConstants.FieldNames.AWARDS_STATUS).andExclude(Fields.UNDERSCORE_ID), sort(Sort.Direction.DESC, "flags.flaggedStats.count"), skip(filter.getSkip()), limit(filter.getPageSize())); return releaseAgg(agg); }
From source file:it.f2informatica.mongodb.repositories.impl.ConsultantRepositoryImpl.java
@Override public int updateExperience(Experience experience, String consultantId) { Query query = new Query( where(ID).is(consultantId).and(EXPERIENCES + "." + Fields.UNDERSCORE_ID).is(experience.getId())); Update update = new Update().set(EXPERIENCES + ".$", experience); return updateConsultant(query, update).getN(); }
From source file:org.devgateway.ocds.web.rest.controller.FrequentSuppliersTimeIntervalController.java
@ApiOperation(value = "Returns the frequent suppliers of a procuringEntity split by a time interval. " + "The time interval is " + "a parameter and represents the number of days to take as interval, starting with today and going back " + "till the last award date. The awards are grouped by procuringEntity, supplier and the time interval. " + "maxAwards parameter is used to designate what is the maximum number of awards granted to one supplier " + "by the same procuringEntity inside one timeInterval. The default value for maxAwards is 3 (days) and the" + " default value for intervalDays is 365.") @RequestMapping(value = "/api/frequentSuppliersTimeInterval", method = { RequestMethod.POST, RequestMethod.GET }, produces = "application/json") public List<FrequentSuppliersResponse> frequentSuppliersTimeInterval( @RequestParam(defaultValue = "365", required = false) Integer intervalDays, @RequestParam(defaultValue = "3", required = false) Integer maxAwards, @RequestParam(required = false) Date now) { if (now == null) { now = new Date(); }/*from w w w .jav a2s . c o m*/ DBObject project = new BasicDBObject(); project.put(MongoConstants.FieldNames.TENDER_PROCURING_ENTITY_ID, 1); project.put(MongoConstants.FieldNames.AWARDS_SUPPLIERS_ID, 1); project.put(MongoConstants.FieldNames.AWARDS_DATE, 1); project.put(Fields.UNDERSCORE_ID, 0); project.put("timeInterval", new BasicDBObject("$ceil", new BasicDBObject("$divide", Arrays.asList( new BasicDBObject("$divide", Arrays.asList( new BasicDBObject("$subtract", Arrays.asList(now, ref( MongoConstants.FieldNames.AWARDS_DATE))), DAY_MS)), intervalDays)))); Aggregation agg = Aggregation.newAggregation( match(where("tender.procuringEntity").exists(true).and("awards.suppliers.0").exists(true) .and(MongoConstants.FieldNames.AWARDS_DATE).exists(true)), unwind("awards"), unwind("awards.suppliers"), new CustomProjectionOperation(project), group(Fields.from( Fields.field("procuringEntityId", MongoConstants.FieldNames.TENDER_PROCURING_ENTITY_ID), Fields.field("supplierId", MongoConstants.FieldNames.AWARDS_SUPPLIERS_ID), Fields.field("timeInterval", "timeInterval"))).count().as("count"), project("count").and("identifier").previousOperation(), match(where("count").gt(maxAwards)), sort(Sort.Direction.DESC, "count")); return releaseAgg(agg, FrequentSuppliersResponse.class); }
From source file:org.devgateway.ocds.web.rest.controller.FrequentTenderersController.java
@ApiOperation(value = "Detect frequent pairs of tenderers that apply together to bids." + "We are only showing pairs if they applied to more than one bid together." + "We are sorting the results after the number of occurences, descending." + "You can use all the filters that are available along with pagination options.") @RequestMapping(value = "/api/frequentTenderers", method = { RequestMethod.POST, RequestMethod.GET }, produces = "application/json") public List<DBObject> frequentTenderers(@ModelAttribute @Valid final YearFilterPagingRequest filter) { Aggregation agg = newAggregation(//w w w.ja v a 2 s . c o m match(where("tender.tenderers.1").exists(true).and("awards.suppliers.0").exists(true) .and(MongoConstants.FieldNames.AWARDS_STATUS).is(Award.Status.active.toString()) .andOperator(getYearDefaultFilterCriteria(filter, MongoConstants.FieldNames.TENDER_PERIOD_START_DATE))), unwind("tender.tenderers"), unwind("awards"), unwind("awards.suppliers"), match(where(MongoConstants.FieldNames.AWARDS_STATUS).is(Award.Status.active.toString()) .andOperator(getYearFilterCriteria(filter.awardFiltering(), MongoConstants.FieldNames.TENDER_PERIOD_START_DATE))), project().and(MongoConstants.FieldNames.AWARDS_SUPPLIERS_ID).as("supplierId") .and("tender.tenderers._id").as("tendererId").andExclude(Fields.UNDERSCORE_ID) .and(ComparisonOperators.valueOf(MongoConstants.FieldNames.AWARDS_SUPPLIERS_ID) .compareTo("tender.tenderers._id")) .as("cmp"), match((where("cmp").ne(0))), project("supplierId", "tendererId", "cmp") .and(ConditionalOperators.when(Criteria.where("cmp").is(1)).thenValueOf("$supplierId") .otherwiseValueOf("$tendererId")) .as("tendererId1") .and(ConditionalOperators.when(Criteria.where("cmp").is(1)).thenValueOf("$tendererId") .otherwiseValueOf("$supplierId")) .as("tendererId2"), group("tendererId1", "tendererId2").count().as("pairCount"), sort(Sort.Direction.DESC, "pairCount"), skip(filter.getSkip()), limit(filter.getPageSize())); return releaseAgg(agg); }