Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ORG-1906: Korrigere oppslag lederForRessurser #1431

Merged
merged 1 commit into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
import no.nav.data.team.resource.dto.NomGraphQlResponse.SingleRessurs;
import no.nav.data.team.resource.dto.NomGraphQlResponse.SingleRessurs.DataWrapper;
import no.nav.data.team.resource.dto.ResourceUnitsResponse;
import no.nav.nom.graphql.model.*;
import no.nav.nom.graphql.model.LederOrgEnhetDto;
import no.nav.nom.graphql.model.OrgEnhetDto;
import no.nav.nom.graphql.model.OrgEnhetsKoblingDto;
import no.nav.nom.graphql.model.RessursDto;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.http.HttpHeaders;
import org.springframework.http.client.ClientHttpRequestInterceptor;
Expand All @@ -33,13 +36,15 @@

import java.lang.reflect.Method;
import java.time.Duration;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Stream;
import java.util.UUID;
import java.util.stream.Stream;

import static java.util.Objects.requireNonNull;
import static no.nav.data.common.utils.StreamUtils.distinctByKey;
Expand Down Expand Up @@ -137,33 +142,33 @@ public List<String> getLeaderMembers(String navIdent) {
.map(LederOrgEnhetDto::getOrgEnhet)
.filter(org -> DateUtil.isNow(org.getGyldigFom(), org.getGyldigTom())).toList();

var directMembers = orgenheter
.stream()
.map(OrgEnhetDto::getKoblinger)
.flatMap(Collection::stream)
.map(OrgEnhetsKoblingDto::getRessurs)
.map(RessursDto::getNavident)
.filter(Objects::nonNull)
.filter(id -> !id.equals(navIdent));

var subDepMembers = orgenheter.stream()
.map(OrgEnhetDto::getOrganiseringer)
.flatMap(Collection::stream)
.map(OrganiseringDto::getOrgEnhet)
.map(OrgEnhetDto::getLeder)
.flatMap(Collection::stream)
.map(OrgEnhetsLederDto::getRessurs)
.map(RessursDto::getNavident)
.filter(Objects::nonNull)
.filter(id -> !id.equals(navIdent));
var directMembers = new ArrayList<String>();
for (var org : orgenheter) {
var refId = org.getId();
var ressurser = org.getKoblinger().stream().map(OrgEnhetsKoblingDto::getRessurs);
var okRessurser = ressurser.filter(it -> !it.getNavident().equals(navIdent) && this.ressursHarEnRelevantOrgtilknytning(it, refId));
directMembers.addAll(okRessurser.map(RessursDto::getNavident).filter(Objects::nonNull).toList());
}

var dm = directMembers.toList();
var sdm = subDepMembers.toList();
var subDepMembers = new ArrayList<String>();
for (var org : orgenheter) {
for (var organisering : org.getOrganiseringer()){
var oe = organisering.getOrgEnhet();
var ledere = oe.getLeder();
for(var l : ledere){
var lRes = l.getRessurs();
var skalTa = !lRes.getNavident().equals(navIdent) && ressursHarEnRelevantOrgtilknytning(lRes,org.getId());
if(skalTa){
subDepMembers.add(lRes.getNavident());
}
}
}
}

var x = UUID.randomUUID();
log.debug("{}: getLeaderMembers for {}: orgenheter size {}, directMembers size {}, subDepartmentMembers size {}",x, navIdent, orgenheter.size(), dm.size(), sdm.size());
log.debug("{}: getLeaderMembers for {}: orgenheter size {}, directMembers size {}, subDepartmentMembers size {}",x, navIdent, orgenheter.size(), directMembers.size(), subDepMembers.size());
log.debug("{}\n{}",x,res.getBody().toString());
return Stream.concat(dm.stream(), sdm.stream())
return Stream.concat(directMembers.stream(), subDepMembers.stream())
.distinct()
.toList();
});
Expand All @@ -189,6 +194,19 @@ private RestOperations template() {
return restTemplate;
}

private boolean ressursHarEnRelevantOrgtilknytning(RessursDto ressursDto, String akseptertOrgenhetId){
for(var orgTilknytning : ressursDto.getOrgTilknytning()){
var idErRelevant = orgTilknytning.getOrgEnhet().getId().equals(akseptertOrgenhetId);
if(!idErRelevant && !orgTilknytning.getErDagligOppfolging()){
continue;
}
var intervallOkBefore = orgTilknytning.getGyldigFom().isBefore(LocalDate.now().plusDays(1));
var intervallOkAfter = (orgTilknytning.getGyldigTom() == null || LocalDate.now().minusDays(1).isBefore(orgTilknytning.getGyldigTom()));
return intervallOkBefore && intervallOkAfter;
}
return false;
}

@SneakyThrows
private ClientHttpRequestInterceptor tokenInterceptor() {
return (request, body, execution) -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,22 @@ query getRessurserForOrgLeadBy($navident: String) {
navident
lederFor {
orgEnhet {
id
agressoId
orgNiv
gyldigFom
gyldigTom
koblinger {
ressurs {
navident
orgTilknytning {
erDagligOppfolging
gyldigFom
gyldigTom
orgEnhet {
id
}
}
}
}
organiseringer(retning: under) {
Expand Down
Loading