@Override public <O> AggregationResults<O> aggregate(Aggregation aggregation, String collectionName, Class<O> outputType) { return aggregate(aggregation, collectionName, outputType, null); }
@Override public AggregationResults<T> all() { return template.aggregate(aggregation, getCollectionName(aggregation), domainType); }
@Override public <O> AggregationResults<O> aggregate(TypedAggregation<?> aggregation, String inputCollectionName, Class<O> outputType) { Assert.notNull(aggregation, "Aggregation pipeline must not be null!"); AggregationOperationContext context = new TypeBasedAggregationOperationContext(aggregation.getInputType(), mappingContext, queryMapper); return aggregate(aggregation, inputCollectionName, outputType, context); }
@Override public <O> AggregationResults<O> aggregate(Aggregation aggregation, Class<?> inputType, Class<O> outputType) { return aggregate(aggregation, operations.determineCollectionName(inputType), outputType, new TypeBasedAggregationOperationContext(inputType, mappingContext, queryMapper)); }
@Override public <O> AggregationResults<O> aggregate(TypedAggregation<?> aggregation, Class<O> outputType) { return aggregate(aggregation, operations.determineCollectionName(aggregation.getInputType()), outputType); }
@Override public <O> AggregationResults<O> aggregate(Aggregation aggregation, String collectionName, Class<O> outputType) { return aggregate(aggregation, collectionName, outputType, null); }
@Override public AggregationResults<T> all() { return template.aggregate(aggregation, getCollectionName(aggregation), domainType); }
@Override public <O> AggregationResults<O> aggregate(TypedAggregation<?> aggregation, String inputCollectionName, Class<O> outputType) { Assert.notNull(aggregation, "Aggregation pipeline must not be null!"); AggregationOperationContext context = new TypeBasedAggregationOperationContext(aggregation.getInputType(), mappingContext, queryMapper); return aggregate(aggregation, inputCollectionName, outputType, context); }
@Override public <O> AggregationResults<O> aggregate(Aggregation aggregation, Class<?> inputType, Class<O> outputType) { return aggregate(aggregation, operations.determineCollectionName(inputType), outputType, new TypeBasedAggregationOperationContext(inputType, mappingContext, queryMapper)); }
@Override public <O> AggregationResults<O> aggregate(TypedAggregation<?> aggregation, Class<O> outputType) { return aggregate(aggregation, operations.determineCollectionName(aggregation.getInputType()), outputType); }
private Long countLatestLaunches(Queryable filter) { Long total = 0L; final String countKey = "count"; List<AggregationOperation> operations = latestLaunchesAggregationOperationsList(filter); operations.add(Aggregation.count().as(countKey)); Map result = mongoTemplate.aggregate(newAggregation(operations), Launch.class, Map.class).getUniqueMappedResult(); if (null != result && result.containsKey(countKey)) { total = Long.valueOf(result.get(countKey).toString()); } return total; }
@Override public List<String> findLogIdsByItemRefs(List<String> ids) { Aggregation aggregation = newAggregation(match(where("testItemRef").in(ids)), group("id")); AggregationResults<Map> results = mongoTemplate.aggregate(aggregation, Log.class, Map.class); return results.getMappedResults().stream().map(it -> it.get("_id").toString()).collect(toList()); }
@Override public List<String> findItemIdsByLaunchRef(List<String> launchRefs) { Aggregation aggregation = newAggregation(match(where(LAUNCH_REFERENCE).in(launchRefs)), group(ID_REFERENCE)); AggregationResults<Map> aggregationResults = mongoTemplate.aggregate(aggregation, TestItem.class, Map.class); return aggregationResults.getMappedResults().stream().map(it -> it.get("_id").toString()).collect(toList()); }
@Override public List<String> findLaunchIdsByProjectIds(List<String> ids) { Aggregation aggregation = newAggregation(match(where(PROJECT_ID_REFERENCE).in(ids)), group(ID_REFERENCE)); AggregationResults<Map> results = mongoTemplate.aggregate(aggregation, Launch.class, Map.class); return results.getMappedResults().stream().map(it -> it.get("_id").toString()).collect(toList()); }
@SuppressWarnings({ "rawtypes", "unchecked" }) @Override public List<String> getUniqueTicketsCount(List<Launch> launches) { List<String> launchIds = launches.stream().map(Launch::getId).collect(toList()); Aggregation aggregation = newAggregation(match(where(LAUNCH_REFERENCE).in(launchIds)), match(where(ISSUE_TICKET).exists(true)), unwind(ISSUE_TICKET), group(ISSUE_TICKET) ); // Count be as // Aggregation.group("issue.externalSystemIssues").count().as("count"); // but keep a whole AggregationResults<Map> result = mongoTemplate.aggregate(aggregation, TestItem.class, Map.class); return result.getMappedResults().stream().map(entry -> entry.get("ticketId").toString()).collect(toList()); }
@SuppressWarnings({ "rawtypes", "unchecked" }) @Override public List<String> findDistinctValues(String launchId, String containsValue, String distinctBy) { Aggregation aggregation = newAggregation(match(where(LAUNCH_REFERENCE).is(launchId)), unwind(distinctBy), match(where(distinctBy).regex("(?i).*" + Pattern.quote(containsValue) + ".*")), group(distinctBy) ); AggregationResults<Map> result = mongoTemplate.aggregate(aggregation, TestItem.class, Map.class); return result.getMappedResults().stream().map(entry -> entry.get("_id").toString()).collect(toList()); }
@Override public void findLatestWithCallback(Queryable filter, Sort sort, List<String> contentFields, long limit, DocumentCallbackHandler callbackHandler) { List<AggregationOperation> operations = latestLaunchesAggregationOperationsList(filter); operations.add(sort(sort)); operations.add(limit(limit)); DBObject results = mongoTemplate.aggregate(newAggregation(operations), mongoTemplate.getCollectionName(Launch.class), Launch.class) .getRawResults(); BasicDBList result = (BasicDBList) results.get(RESULT); result.stream().map(it -> (DBObject) it).forEach(callbackHandler::processDocument); }
private List<Launch> findLatest(Queryable filter, Pageable pageable) { List<AggregationOperation> operations = latestLaunchesAggregationOperationsList(filter); operations.add(sort(pageable.getSort())); operations.add(skip((long) pageable.getPageNumber() * pageable.getPageSize())); operations.add(limit(pageable.getPageSize())); return mongoTemplate.aggregate(newAggregation(operations), mongoTemplate.getCollectionName(Launch.class), Launch.class) .getMappedResults(); }
public List<ServiceCount> countServicesByType() { Aggregation aggregation = newAggregation( project("type"), group("type").count().as("number"), project("number").and("type").previousOperation(), sort(DESC, "number") ); AggregationResults<ServiceCount> results = template.aggregate(aggregation, Service.class, ServiceCount.class); return results.getMappedResults(); } }
@Override public List<RetryObject> findRetries(String launchId) { Aggregation aggregation = newAggregation(match(where(LAUNCH_REFERENCE).is(launchId).and("retryProcessed").exists(true)), sort(new Sort(Sort.Direction.ASC, "start_time")), group(Fields.fields("$uniqueId")).push(ROOT).as("retries") ); return mongoTemplate.aggregate(aggregation, mongoTemplate.getCollectionName(TestItem.class), RetryObject.class).getMappedResults(); }