From 392893648cb384fcdf7757978fb34ec3b11f8974 Mon Sep 17 00:00:00 2001 From: erik-a-e <65284304+erik-a-e@users.noreply.github.com> Date: Fri, 5 Apr 2024 12:30:31 +0200 Subject: [PATCH] ORG- 1902: Filtrere ut inaktive underordnede --- .../no/nav/data/team/member/MemberExportService.java | 2 +- .../no/nav/data/team/resource/NomGraphClient.java | 11 ++++++++++- .../nav/data/team/member/MemberExportServiceTest.java | 2 +- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/apps/backend/src/main/java/no/nav/data/team/member/MemberExportService.java b/apps/backend/src/main/java/no/nav/data/team/member/MemberExportService.java index 0f2c2b45d..5dc48bd34 100644 --- a/apps/backend/src/main/java/no/nav/data/team/member/MemberExportService.java +++ b/apps/backend/src/main/java/no/nav/data/team/member/MemberExportService.java @@ -59,7 +59,7 @@ public byte[] generateSpreadsheet(SpreadsheetType type, String filter) { case TEAM -> mapTeamMembers(List.of(teamService.get(StringUtils.toUUID(filter))), pas, clusters).collect(toList()); case ROLE -> filter(getAll(pas, clusters), m -> convert(m.member().getRoles(), Enum::name).contains(filter)); case LEADER -> filter(getAll(pas, clusters), m -> { - var leaderMembers = nomGraphClient.getLeaderMembers(filter); + var leaderMembers = nomGraphClient.getLeaderMembersActiveOnly(filter); return leaderMembers.contains(m.member().getNavIdent()); }); }; diff --git a/apps/backend/src/main/java/no/nav/data/team/resource/NomGraphClient.java b/apps/backend/src/main/java/no/nav/data/team/resource/NomGraphClient.java index 6ea860735..1f04d8dc4 100644 --- a/apps/backend/src/main/java/no/nav/data/team/resource/NomGraphClient.java +++ b/apps/backend/src/main/java/no/nav/data/team/resource/NomGraphClient.java @@ -14,6 +14,7 @@ import no.nav.data.common.utils.StreamUtils; import no.nav.data.team.integration.process.GraphQLRequest; import no.nav.data.team.org.OrgUrlId; +import no.nav.data.team.resource.domain.Resource; import no.nav.data.team.resource.dto.NomGraphQlResponse.MultiRessurs; import no.nav.data.team.resource.dto.NomGraphQlResponse.SingleOrg; import no.nav.data.team.resource.dto.NomGraphQlResponse.SingleRessurs; @@ -102,7 +103,7 @@ public Optional getOrgEnhet(String orgUrl) { public Optional getUnits(String navIdent) { return getRessurs(navIdent) - .map(r -> ResourceUnitsResponse.from(r, getLeaderMembers(navIdent), this::getOrgEnhet)); + .map(r -> ResourceUnitsResponse.from(r, getLeaderMembersActiveOnly(navIdent), this::getOrgEnhet)); } private Map getRessurser(List navIdents) { @@ -114,6 +115,14 @@ private Map getRessurser(List navIdents) { }); } + public List getLeaderMembersActiveOnly(String navIdent) { + var nomClient = NomClient.getInstance(); + return getLeaderMembers(navIdent).stream() + .map(nomClient::getByNavIdent) + .filter(Optional::isPresent).map(Optional::get) + .filter(it -> !it.isInactive()).map(Resource::getNavIdent).toList(); + } + public List getLeaderMembers(String navIdent) { return leaderCache.get(navIdent, ident -> { var req = new GraphQLRequest(getLeaderMemberQuery, Map.of("navident", navIdent)); diff --git a/apps/backend/src/test/java/no/nav/data/team/member/MemberExportServiceTest.java b/apps/backend/src/test/java/no/nav/data/team/member/MemberExportServiceTest.java index fa3a734ba..6ae99938b 100644 --- a/apps/backend/src/test/java/no/nav/data/team/member/MemberExportServiceTest.java +++ b/apps/backend/src/test/java/no/nav/data/team/member/MemberExportServiceTest.java @@ -65,7 +65,7 @@ void setUp() { createTeam(3, null, List.of(clusterOne.getId(), clusterTwo.getId()))) ); lenient().when(teamService.get(teamOne.getId())).thenReturn(teamOne); - lenient().when(nomGraphClient.getLeaderMembers("A123456")).thenReturn(List.of(createNavIdent(101), createNavIdent(102))); + lenient().when(nomGraphClient.getLeaderMembersActiveOnly("A123456")).thenReturn(List.of(createNavIdent(101), createNavIdent(102))); UrlGeneratorTestUtil.get(); }