diff --git a/naikan-core/src/main/java/com/enofex/naikan/overview/deployment/support/OverviewDeploymentMongoRepository.java b/naikan-core/src/main/java/com/enofex/naikan/overview/deployment/support/OverviewDeploymentMongoRepository.java index 072c9ec3..cde912a2 100644 --- a/naikan-core/src/main/java/com/enofex/naikan/overview/deployment/support/OverviewDeploymentMongoRepository.java +++ b/naikan-core/src/main/java/com/enofex/naikan/overview/deployment/support/OverviewDeploymentMongoRepository.java @@ -4,7 +4,6 @@ import static org.springframework.data.mongodb.core.aggregation.Aggregation.group; import static org.springframework.data.mongodb.core.aggregation.Aggregation.limit; import static org.springframework.data.mongodb.core.aggregation.Aggregation.match; -import static org.springframework.data.mongodb.core.aggregation.Aggregation.newAggregation; import static org.springframework.data.mongodb.core.aggregation.Aggregation.project; import static org.springframework.data.mongodb.core.aggregation.Aggregation.sort; import static org.springframework.data.mongodb.core.aggregation.Aggregation.unwind; @@ -19,7 +18,7 @@ import java.util.List; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; -import org.springframework.data.domain.Sort; +import org.springframework.data.domain.Sort.Direction; import org.springframework.data.mongodb.core.MongoTemplate; import org.springframework.data.mongodb.core.aggregation.Aggregation; import org.springframework.data.mongodb.core.aggregation.AggregationOperation; @@ -55,18 +54,17 @@ public Page findAll(Filterable filterable, Pageable pageable @Override public OverviewTopGroups findTopProjects(long topN) { - Aggregation aggregation = newAggregation( + Aggregation aggregation = Aggregation.newAggregation( unwind("deployments"), group("project.name").count().as("count"), - project("count").and("project.name").previousOperation(), - sort(Sort.Direction.DESC, "count"), - group().push("project.name").as("names").push("count").as("counts"), - project("names", "counts"), - unwind("names"), - sort(Sort.Direction.DESC, "counts"), - sort(Sort.Direction.ASC, "names"), + sort(Direction.DESC, "count").and(Direction.ASC, "project.name"), limit(topN), - group().push("names").as("names").first("counts").as("counts") + group() + .push("_id").as("names") + .push("count").as("counts"), + project() + .and("names").as("names") + .and("counts").as("counts") ); return template().aggregate(aggregation, collectionName(), OverviewTopGroups.class) diff --git a/naikan-core/src/main/java/com/enofex/naikan/overview/environment/support/OverviewEnvironmentMongoRepository.java b/naikan-core/src/main/java/com/enofex/naikan/overview/environment/support/OverviewEnvironmentMongoRepository.java index fa6e6ec5..d1cdd451 100644 --- a/naikan-core/src/main/java/com/enofex/naikan/overview/environment/support/OverviewEnvironmentMongoRepository.java +++ b/naikan-core/src/main/java/com/enofex/naikan/overview/environment/support/OverviewEnvironmentMongoRepository.java @@ -2,7 +2,6 @@ import static org.springframework.data.mongodb.core.aggregation.Aggregation.group; import static org.springframework.data.mongodb.core.aggregation.Aggregation.limit; -import static org.springframework.data.mongodb.core.aggregation.Aggregation.newAggregation; import static org.springframework.data.mongodb.core.aggregation.Aggregation.project; import static org.springframework.data.mongodb.core.aggregation.Aggregation.sort; import static org.springframework.data.mongodb.core.aggregation.Aggregation.unwind; @@ -16,7 +15,7 @@ import java.util.List; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; -import org.springframework.data.domain.Sort; +import org.springframework.data.domain.Sort.Direction; import org.springframework.data.mongodb.core.MongoTemplate; import org.springframework.data.mongodb.core.aggregation.Aggregation; import org.springframework.data.mongodb.core.aggregation.AggregationOperation; @@ -45,18 +44,17 @@ public Page findAll(Filterable filterable, Pageable pageable) { @Override public OverviewTopGroups findTopEnvironments(long topN) { - Aggregation aggregation = newAggregation( + Aggregation aggregation = Aggregation.newAggregation( unwind("environments"), group("environments.name").count().as("count"), - project("count").and("environments.name").previousOperation(), - sort(Sort.Direction.DESC, "count"), - group().push("environments.name").as("names").push("count").as("counts"), - project("names", "counts"), - unwind("names"), - sort(Sort.Direction.DESC, "counts"), - sort(Sort.Direction.ASC, "names"), + sort(Direction.DESC, "count").and(Direction.ASC, "environments.name"), limit(topN), - group().push("names").as("names").first("counts").as("counts") + group() + .push("_id").as("names") + .push("count").as("counts"), + project() + .and("names").as("names") + .and("counts").as("counts") ); return template().aggregate(aggregation, collectionName(), OverviewTopGroups.class) diff --git a/naikan-core/src/main/java/com/enofex/naikan/overview/team/support/OverviewTeamMongoRepository.java b/naikan-core/src/main/java/com/enofex/naikan/overview/team/support/OverviewTeamMongoRepository.java index 91aa7775..dd6953c7 100644 --- a/naikan-core/src/main/java/com/enofex/naikan/overview/team/support/OverviewTeamMongoRepository.java +++ b/naikan-core/src/main/java/com/enofex/naikan/overview/team/support/OverviewTeamMongoRepository.java @@ -2,7 +2,6 @@ import static org.springframework.data.mongodb.core.aggregation.Aggregation.group; import static org.springframework.data.mongodb.core.aggregation.Aggregation.limit; -import static org.springframework.data.mongodb.core.aggregation.Aggregation.newAggregation; import static org.springframework.data.mongodb.core.aggregation.Aggregation.project; import static org.springframework.data.mongodb.core.aggregation.Aggregation.sort; import static org.springframework.data.mongodb.core.aggregation.Aggregation.unwind; @@ -16,7 +15,7 @@ import java.util.List; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; -import org.springframework.data.domain.Sort; +import org.springframework.data.domain.Sort.Direction; import org.springframework.data.mongodb.core.MongoTemplate; import org.springframework.data.mongodb.core.aggregation.Aggregation; import org.springframework.data.mongodb.core.aggregation.AggregationOperation; @@ -44,20 +43,18 @@ public Page findAll(Filterable filterable, Pageable pageable) { @Override public OverviewTopGroups findTopTeams(long topN) { - Aggregation aggregation = newAggregation( + Aggregation aggregation = Aggregation.newAggregation( unwind("teams"), group("teams.name").count().as("count"), - project("count").and("teams.name").previousOperation(), - sort(Sort.Direction.DESC, "count"), - group().push("teams.name").as("names").push("count").as("counts"), - project("names", "counts"), - unwind("names"), - sort(Sort.Direction.DESC, "counts"), - sort(Sort.Direction.ASC, "names"), + sort(Direction.DESC, "count").and(Direction.ASC, "teams.name"), limit(topN), - group().push("names").as("names").first("counts").as("counts") + group() + .push("_id").as("names") + .push("count").as("counts"), + project() + .and("names").as("names") + .and("counts").as("counts") ); - return template().aggregate(aggregation, collectionName(), OverviewTopGroups.class) .getUniqueMappedResult(); } diff --git a/naikan-core/src/main/java/com/enofex/naikan/overview/technology/support/OverviewTechnologyMongoRepository.java b/naikan-core/src/main/java/com/enofex/naikan/overview/technology/support/OverviewTechnologyMongoRepository.java index 08af715a..5976c594 100644 --- a/naikan-core/src/main/java/com/enofex/naikan/overview/technology/support/OverviewTechnologyMongoRepository.java +++ b/naikan-core/src/main/java/com/enofex/naikan/overview/technology/support/OverviewTechnologyMongoRepository.java @@ -2,8 +2,6 @@ import static org.springframework.data.mongodb.core.aggregation.Aggregation.group; import static org.springframework.data.mongodb.core.aggregation.Aggregation.limit; - -import static org.springframework.data.mongodb.core.aggregation.Aggregation.newAggregation; import static org.springframework.data.mongodb.core.aggregation.Aggregation.project; import static org.springframework.data.mongodb.core.aggregation.Aggregation.sort; import static org.springframework.data.mongodb.core.aggregation.Aggregation.unwind; @@ -12,14 +10,13 @@ import com.enofex.naikan.FilterableCriteriaBuilder; import com.enofex.naikan.overview.OverviewRepository; import com.enofex.naikan.overview.OverviewTopGroups; - import com.enofex.naikan.overview.technology.OverviewTechnologyRepository; - import com.enofex.naikan.overview.technology.TechnologyGroup; + import java.util.List; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; -import org.springframework.data.domain.Sort; +import org.springframework.data.domain.Sort.Direction; import org.springframework.data.mongodb.core.MongoTemplate; import org.springframework.data.mongodb.core.aggregation.Aggregation; import org.springframework.data.mongodb.core.aggregation.AggregationOperation; @@ -48,18 +45,17 @@ public Page findAll(Filterable filterable, Pageable pageable) { @Override public OverviewTopGroups findTopTechnologies(long topN) { - Aggregation aggregation = newAggregation( + Aggregation aggregation = Aggregation.newAggregation( unwind("technologies"), group("technologies.name").count().as("count"), - project("count").and("technologies.name").previousOperation(), - sort(Sort.Direction.DESC, "count"), - group().push("technologies.name").as("names").push("count").as("counts"), - project("names", "counts"), - unwind("names"), - sort(Sort.Direction.DESC, "counts"), - sort(Sort.Direction.ASC, "names"), + sort(Direction.DESC, "count").and(Direction.ASC, "technologies.name"), limit(topN), - group().push("names").as("names").first("counts").as("counts") + group() + .push("_id").as("names") + .push("count").as("counts"), + project() + .and("names").as("names") + .and("counts").as("counts") ); return template().aggregate(aggregation, collectionName(), OverviewTopGroups.class)