Skip to content

Commit

Permalink
Refactor OrdreStatusService filtering logic
Browse files Browse the repository at this point in the history
#deploy-organisasjon-forvalter

Simplified the filtering logic in OrdreStatusService by merging similar conditions and reducing redundant checks. This improves readability and ensures that only relevant statuses are processed based on the updated criteria.
  • Loading branch information
krharum committed Sep 13, 2024
1 parent 92d45d5 commit 12771b1
Showing 1 changed file with 17 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,21 +71,24 @@ public OrdreResponse getStatus(List<String> orgnumre) {

var orgStatus = new ArrayList<BestillingStatus>();

if (oppdatertStatus.stream().noneMatch(status -> orgImiljo.stream()
.map(Map::entrySet)
.flatMap(Collection::stream)
.anyMatch(iMiljoe -> iMiljoe.getValue().getOrganisasjonsnummer()
.equals(status.getOrganisasjonsnummer())))) {

orgStatus.addAll(Flux.fromIterable(oppdatertStatus)
.filter(status -> isNotBlank(status.getBestId()))
.flatMap(organisasjonBestillingConsumer::getBestillingStatus)
.collectList()
.block());
}

orgStatus.addAll(statusMap.stream()
orgStatus.addAll(Flux.fromIterable(oppdatertStatus)
.filter(status -> isNotBlank(status.getBestId()))
.filter(status -> orgImiljo.stream()
.map(Map::entrySet)
.flatMap(Collection::stream)
.noneMatch(iMiljo -> status.getMiljoe().equals(iMiljo.getKey()) &&
status.getOrganisasjonsnummer().equals(iMiljo.getValue().getOrganisasjonsnummer())))
.flatMap(organisasjonBestillingConsumer::getBestillingStatus)
.collectList()
.block());

orgStatus.addAll(oppdatertStatus.stream()
.filter(status -> isBlank(status.getBestId()))
.filter(status -> orgImiljo.stream()
.map(Map::entrySet)
.flatMap(Collection::stream)
.noneMatch(iMiljo -> status.getMiljoe().equals(iMiljo.getKey()) &&
status.getOrganisasjonsnummer().equals(iMiljo.getValue().getOrganisasjonsnummer())))
.map(status -> BestillingStatus.builder()
.orgnummer(status.getOrganisasjonsnummer())
.miljoe(status.getMiljoe())
Expand Down

0 comments on commit 12771b1

Please sign in to comment.