Skip to content

Commit

Permalink
Fix top overviews grouping
Browse files Browse the repository at this point in the history
  • Loading branch information
mnhock committed Jul 30, 2023
1 parent f59f3cd commit a2c6e2a
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -55,18 +54,17 @@ public Page<OverviewDeployment> 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -45,18 +44,17 @@ public Page<OverviewGroup> 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -44,20 +43,18 @@ public Page<OverviewGroup> 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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -48,18 +45,17 @@ public Page<TechnologyGroup> 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)
Expand Down

0 comments on commit a2c6e2a

Please sign in to comment.