From 70c91f938f066efebf7a57a8b0e7e75a45bb8ed7 Mon Sep 17 00:00:00 2001 From: JeremiahUy Date: Fri, 18 Oct 2024 12:14:32 +0200 Subject: [PATCH] ADD: databehandler endpoint to fetch databehandler from behandlingskatalog --- .../behandling/BehandlingController.java | 13 +++++++++++ .../behandling/BehandlingService.java | 10 ++++++++ .../integration/behandling/BkatClient.java | 16 +++++++++++++ .../behandling/dto/BkatProcessor.java | 23 +++++++++++++++++++ .../behandling/dto/DataBehandler.java | 16 +++++++++++++ 5 files changed, 78 insertions(+) create mode 100644 apps/backend/src/main/java/no/nav/data/integration/behandling/dto/BkatProcessor.java create mode 100644 apps/backend/src/main/java/no/nav/data/integration/behandling/dto/DataBehandler.java diff --git a/apps/backend/src/main/java/no/nav/data/integration/behandling/BehandlingController.java b/apps/backend/src/main/java/no/nav/data/integration/behandling/BehandlingController.java index f5f0b11e3..3a5a27d83 100644 --- a/apps/backend/src/main/java/no/nav/data/integration/behandling/BehandlingController.java +++ b/apps/backend/src/main/java/no/nav/data/integration/behandling/BehandlingController.java @@ -10,6 +10,7 @@ import no.nav.data.common.rest.RestResponsePage; import no.nav.data.common.utils.StreamUtils; import no.nav.data.integration.behandling.dto.Behandling; +import no.nav.data.integration.behandling.dto.DataBehandler; import no.nav.data.integration.team.domain.Team; import no.nav.data.integration.team.teamcat.TeamcatTeamClient; import org.springframework.http.ResponseEntity; @@ -80,6 +81,18 @@ public ResponseEntity> searchBehandlinger(@PathVari return ResponseEntity.ok(new RestResponsePage<>(behandlingList)); } + @Operation(summary = "Get Databehandler") + @ApiResponses(value = {@ApiResponse(description = "Databehandler fetched")}) + @GetMapping("/databehandler/{id}") + public ResponseEntity getDatabehandler(@PathVariable String id) { + log.info("Get Databehandler by id={}", id); + DataBehandler dataBehandler = service.getDataBehandler(id); + if (dataBehandler == null) { + throw new NotFoundException("behandling %s not found".formatted(id)); + } + return ResponseEntity.ok(dataBehandler); + } + public static class BehandlingPage extends RestResponsePage { } diff --git a/apps/backend/src/main/java/no/nav/data/integration/behandling/BehandlingService.java b/apps/backend/src/main/java/no/nav/data/integration/behandling/BehandlingService.java index 9baf6cc6f..24fa8dd36 100644 --- a/apps/backend/src/main/java/no/nav/data/integration/behandling/BehandlingService.java +++ b/apps/backend/src/main/java/no/nav/data/integration/behandling/BehandlingService.java @@ -4,6 +4,8 @@ import no.nav.data.common.rest.RestResponsePage; import no.nav.data.integration.behandling.dto.Behandling; import no.nav.data.integration.behandling.dto.BkatProcess; +import no.nav.data.integration.behandling.dto.BkatProcessor; +import no.nav.data.integration.behandling.dto.DataBehandler; import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; @@ -54,4 +56,12 @@ public RestResponsePage getAll(Pageable page) { private List convertBehandlinger(Collection processes) { return convert(processes, BkatProcess::convertToBehandling); } + + public DataBehandler getDataBehandler(String id) { + BkatProcessor dataBehandler = bkatClient.getProcessor(id); + if (dataBehandler == null) { + return null; + } + return dataBehandler.convertToDataBehandler(); + } } diff --git a/apps/backend/src/main/java/no/nav/data/integration/behandling/BkatClient.java b/apps/backend/src/main/java/no/nav/data/integration/behandling/BkatClient.java index a18122033..ae58463ec 100644 --- a/apps/backend/src/main/java/no/nav/data/integration/behandling/BkatClient.java +++ b/apps/backend/src/main/java/no/nav/data/integration/behandling/BkatClient.java @@ -11,6 +11,7 @@ import no.nav.data.integration.begrep.dto.BegrepResponse; import no.nav.data.integration.begrep.dto.PollyTerm; import no.nav.data.integration.behandling.dto.BkatProcess; +import no.nav.data.integration.behandling.dto.BkatProcessor; import org.springframework.stereotype.Service; import org.springframework.util.Assert; import org.springframework.web.reactive.function.client.WebClient; @@ -31,6 +32,7 @@ public class BkatClient implements BegrepService { private final WebClient client; private final LoadingCache> processSearchCache; private final LoadingCache processCache; + private final LoadingCache processorCache; private final Cache processPageCache; private final LoadingCache> processTeamCache; @@ -51,6 +53,12 @@ public BkatClient(WebClient.Builder webClientBuilder, BkatProperties properties) Caffeine.newBuilder().recordStats() .expireAfterWrite(Duration.ofMinutes(2)) .maximumSize(300).build(this::getProcess0)); + + this.processorCache = MetricUtils.register("bkatProcessorCache", + Caffeine.newBuilder().recordStats() + .expireAfterWrite(Duration.ofMinutes(2)) + .maximumSize(300).build(this::getProcessor0)); + this.processPageCache = MetricUtils.register("bkatProcessPageCache", Caffeine.newBuilder().recordStats() .expireAfterWrite(Duration.ofMinutes(2)) @@ -74,6 +82,10 @@ public BkatProcess getProcess(String id) { return processCache.get(id); } + public BkatProcessor getProcessor(String id) { + return processorCache.get(id); + } + public Map getProcessesById(Collection ids) { return processCache.getAll(ids, this::getProcesses0); } @@ -98,6 +110,10 @@ private BkatProcess getProcess0(String id) { return get("/process/{id}", BkatProcess.class, id); } + private BkatProcessor getProcessor0(String id) { + return get("/processor/{id}", BkatProcessor.class, id); + } + private Map getProcesses0(Iterable uncachedIds) { Map map = toMap(post("/process/shortbyid", uncachedIds, ProcessPage.class).getContent(), BkatProcess::getId); log.info("fetched {} processes from bkat", map.size()); diff --git a/apps/backend/src/main/java/no/nav/data/integration/behandling/dto/BkatProcessor.java b/apps/backend/src/main/java/no/nav/data/integration/behandling/dto/BkatProcessor.java new file mode 100644 index 000000000..157cc9ffd --- /dev/null +++ b/apps/backend/src/main/java/no/nav/data/integration/behandling/dto/BkatProcessor.java @@ -0,0 +1,23 @@ +package no.nav.data.integration.behandling.dto; + + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class BkatProcessor { + private String id; + private String name; + + public DataBehandler convertToDataBehandler() { + return DataBehandler.builder() + .id(id) + .navn(name) + .build(); + } +} diff --git a/apps/backend/src/main/java/no/nav/data/integration/behandling/dto/DataBehandler.java b/apps/backend/src/main/java/no/nav/data/integration/behandling/dto/DataBehandler.java new file mode 100644 index 000000000..27c223d3a --- /dev/null +++ b/apps/backend/src/main/java/no/nav/data/integration/behandling/dto/DataBehandler.java @@ -0,0 +1,16 @@ +package no.nav.data.integration.behandling.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class DataBehandler { + private String id; + private String navn; + +}