List of usage examples for org.springframework.data.mongodb.core.aggregation Fields fields
List fields
To view the source code for org.springframework.data.mongodb.core.aggregation Fields fields.
Click Source Link
From source file:com.epam.ta.reportportal.database.dao.TestItemRepositoryCustomImpl.java
@SuppressWarnings({ "rawtypes", "unchecked" }) @Override//from w ww. j a va2 s.co m public Map<String, String> getMostFailedTestCases(List<Launch> launches, String criteria) { Map<String, String> output = new HashMap<>(); List<String> launchIds = launches.stream().map(Launch::getId).collect(toList()); GroupOperation operationTotal = new GroupOperation(Fields.fields("$name")).count().as("count"); Aggregation aggregationTotal = newAggregation(match(where(LAUNCH_REFERENCE).in(launchIds)), match(where(HAS_CHILD).is(false)), operationTotal); AggregationResults<Map> resultTotal = mongoTemplate.aggregate(aggregationTotal, TestItem.class, Map.class); Map<String, String> values = resultTotal.getMappedResults().stream() .collect(toMap(key -> key.get("_id").toString(), value -> value.get("count").toString())); GroupOperation operation = new GroupOperation(Fields.fields("$name")).count().as("count").last("$startTime") .as("last"); Aggregation aggregation = newAggregation(match(where(LAUNCH_REFERENCE).in(launchIds)), match(where(criteria).is(1)), match(where(HAS_CHILD).is(false)), operation); AggregationResults<Map> result = mongoTemplate.aggregate(aggregation, TestItem.class, Map.class); for (Map<String, ?> entry : result.getMappedResults()) { String itemName = String.valueOf(entry.get("_id")); String count = String.valueOf(entry.get("count")); Date date = (Date) entry.get("last"); String total = values.get(itemName); // FIXME Update dirty # separator with common case // And update after {@link MostFailedTestCasesFilterStrategy} output.put(itemName, count + "#" + date.getTime() + "#" + total); } return output; }