Skip to content

Commit

Permalink
Merge pull request #1431 from navikt/ORG-1906
Browse files Browse the repository at this point in the history
ORG-1906: Korrigere oppslag lederForRessurser
  • Loading branch information
erik-a-e authored Apr 11, 2024
2 parents 7590978 + 2082db8 commit bc56b42
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 25 deletions.
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

0 comments on commit bc56b42

Please sign in to comment.