@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> 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> 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 List<String> findBinaryIdsByLogRefs(List<String> ids) { Aggregation aggregation = newAggregation(match(where("id").in(ids).andOperator(where("binaryContent").exists(true))), group("binaryContent.binaryDataId", "binaryContent.thumbnailId")); AggregationResults<Map> results = mongoTemplate.aggregate(aggregation, Log.class, Map.class); return results.getMappedResults().stream().flatMap(it -> (Stream<String>) it.values().stream()).collect(toList()); }
@Override public List<String> findBinaryIdsByItemRefs(List<String> ids) { Aggregation aggregation = newAggregation(match(where("testItemRef").in(ids).andOperator(where("binaryContent").exists(true))), group("binaryContent.binaryDataId", "binaryContent.thumbnailId")); AggregationResults<Map> results = mongoTemplate.aggregate(aggregation, Log.class, Map.class); return results.getMappedResults().stream().flatMap(it -> (Stream<String>) it.values().stream()).collect(toList()); }
@Override public SensorSubstate find(final String code) { final Locale locale = LocaleContextHolder.getLocale(); // Translations searchs are by language and by language_country final String localeField = "translations." + locale.getLanguage(); final String localeLongField = "translations." + locale.toString(); final Aggregation agg = newAggregation( project(Fields.from(Fields.field("code"), Fields.field("defaultDesc", "text"), Fields.field("translateLocShort", localeField), Fields.field("translateLocLong", localeLongField))), sort(Sort.Direction.DESC, "code"), match(where("code").is(code))); final AggregationResults<SensorSubstate> results = mongoOps.aggregate(agg, "sensorSubstate", SensorSubstate.class); return results.getMappedResults().isEmpty() ? new SensorSubstate() : results.getMappedResults().get(0); } }
@SuppressWarnings({ "rawtypes" }) @Override public List<String> findValuesWithMode(String projectName, String containsValue, String distinctBy, String mode) { Aggregation aggregation = newAggregation(match(where(PROJECT_ID_REFERENCE).is(projectName)), match(where(MODE).is(mode)), match(where(distinctBy).regex("(?i).*" + Pattern.quote(containsValue) + ".*")), group(distinctBy), limit(AUTOCOMPLETE_LIMITATION) ); AggregationResults<Map> result = mongoTemplate.aggregate(aggregation, Launch.class, Map.class); return result.getMappedResults().stream().map(entry -> entry.get("_id").toString()).collect(toList()); }
@SuppressWarnings({ "rawtypes", "unchecked" }) @Override public List<String> findDistinctValues(String projectName, String containsValue, String distinctBy) { //@formatter:off Aggregation aggregation = newAggregation( match(where(PROJECT_ID_REFERENCE).is(projectName)), unwind(distinctBy), match(where(distinctBy).regex("(?i).*" + Pattern.quote(containsValue) + ".*")), group(distinctBy), limit(AUTOCOMPLETE_LIMITATION)); //@formatter:on AggregationResults<Map> result = mongoTemplate.aggregate(aggregation, Launch.class, Map.class); return result.getMappedResults().stream().map(it -> (String) it.get("_id")).collect(Collectors.toList()); }
@Override public List<SensorSubstate> findAll() { final Locale locale = LocaleContextHolder.getLocale(); // Translations searchs are by language and by language_country final String localeField = "translations." + locale.getLanguage(); final String localeLongField = "translations." + locale.toString(); final Aggregation agg = newAggregation(project(Fields.from(Fields.field("code"), Fields.field("defaultDesc", "text"), Fields.field("translateLocShort", localeField), Fields.field("translateLocLong", localeLongField))), sort(Sort.Direction.DESC, "code")); final AggregationResults<SensorSubstate> results = mongoOps.aggregate(agg, "sensorSubstate", SensorSubstate.class); return results.getMappedResults(); }
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(); }
@Override public List<SensorSubstate> findAll(final SensorState state) { final Locale locale = LocaleContextHolder.getLocale(); // Translations searchs are by language and by language_country final String localeField = "translations." + locale.getLanguage(); final String localeLongField = "translations." + locale.toString(); final Aggregation agg = newAggregation(project(Fields.from(Fields.field("code"), Fields.field("defaultDesc", "text"), Fields.field("translateLocShort", localeField), Fields.field("translateLocLong", localeLongField))), sort(Sort.Direction.DESC, "code"), match(where("state").is(state))); final AggregationResults<SensorSubstate> results = mongoOps.aggregate(agg, "sensorSubstate", SensorSubstate.class); return results.getMappedResults(); }
@Cacheable(value = { CacheConfiguration.PROJECT_INFO_CACHE }) @SuppressWarnings({ "rawtypes", "unchecked" }) @Override public Map<String, Integer> findGroupedLaunchesByOwner(String projectName, String mode, Date from) { Map<String, Integer> output = new HashMap<>(); Aggregation aggregation = newAggregation(match(where(PROJECT_ID_REFERENCE).is(projectName)), match(where(MODE).is(mode)), match(where(STATUS).ne(IN_PROGRESS.name())), match(where(START_TIME).gt(from)), group("$userRef").count().as("count") ); AggregationResults<Map> result = mongoTemplate.aggregate(aggregation, Launch.class, Map.class); for (Map<String, String> entry : result.getMappedResults()) { String username = entry.get("_id"); String count = String.valueOf(entry.get("count")); output.put(username, Integer.valueOf(count)); } return output; }
@Override public void cumulativeStatisticsGroupedByTag(Queryable filter, List<String> contentFields, long limit, String tagPrefix, DocumentCallbackHandler callbackHandler) { String tag = String.format(REGEX, tagPrefix); Aggregation aggregation = newAggregation(matchOperationFromFilter(filter, mongoTemplate, Launch.class), match(Criteria.where(TAGS).regex(tag)), unwind("$tags"), match(Criteria.where(TAGS).regex(tag)), groupByFieldWithStatisticsSumming(TAGS, contentFields), addFields("len", Collections.singletonMap("$strLenCP", "$_id")), sorting("len", DESC).and(DESC, "_id"), limit(limit) ); List<DBObject> mappedResults = mongoTemplate.aggregate(aggregation, mongoTemplate.getCollectionName(Launch.class), DBObject.class) .getMappedResults(); mappedResults.forEach(callbackHandler::processDocument); }
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<InvocationCount> aggregateDailyStatistics(String afterday, String beforeday) { // Build a query to pre-select the statistics that will be aggregated. Aggregation aggregation = newAggregation( match(Criteria.where("day").gte(afterday).lte(beforeday)), group("day").sum("dailyCount").as("number"), project("number").and("day").previousOperation(), sort(ASC, "day") ); AggregationResults<InvocationCount> results = template.aggregate(aggregation, DailyStatistic.class, InvocationCount.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(); }
@Override public BaseResponse getErrorLogGroupByAppName() throws BaseException { //查询条件信息 Criteria operator = new Criteria(); operator.andOperator( //查询当天的数据汇总 Criteria.where("execDate").is(DateUtil.today()) ); //查询条件 MatchOperation matchOperation = Aggregation.match(operator); //分组信息及返回count列命名 GroupOperation groupOperation = Aggregation.group("serUrl", "serPort", "appName", "appSer", "reqUrl", "execDate").count().as("count"); //排序信息 Sort sort = new Sort(new Sort.Order(Sort.Direction.DESC, "count")); SortOperation sortOperation = Aggregation.sort(sort); //组合条件 Aggregation aggregation = Aggregation.newAggregation(ErrorInfo.class, matchOperation, groupOperation, sortOperation); // 执行操作 AggregationResults<Map> aggregationResults = template.aggregate(aggregation, ErrorInfo.class, Map.class); return new BaseResponse(aggregationResults.getMappedResults()); }
return new BaseResponse(aggregationResults.getMappedResults());