Skip to content

Commit

Permalink
ADD: databehandler endpoint to fetch databehandler from behandlingska…
Browse files Browse the repository at this point in the history
…talog
  • Loading branch information
JeremiahUy committed Oct 18, 2024
1 parent 6b75b3b commit 70c91f9
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -80,6 +81,18 @@ public ResponseEntity<RestResponsePage<Behandling>> searchBehandlinger(@PathVari
return ResponseEntity.ok(new RestResponsePage<>(behandlingList));
}

@Operation(summary = "Get Databehandler")
@ApiResponses(value = {@ApiResponse(description = "Databehandler fetched")})
@GetMapping("/databehandler/{id}")
public ResponseEntity<DataBehandler> 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<Behandling> {

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -54,4 +56,12 @@ public RestResponsePage<Behandling> getAll(Pageable page) {
private List<Behandling> convertBehandlinger(Collection<BkatProcess> processes) {
return convert(processes, BkatProcess::convertToBehandling);
}

public DataBehandler getDataBehandler(String id) {
BkatProcessor dataBehandler = bkatClient.getProcessor(id);
if (dataBehandler == null) {
return null;
}
return dataBehandler.convertToDataBehandler();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -31,6 +32,7 @@ public class BkatClient implements BegrepService {
private final WebClient client;
private final LoadingCache<String, List<BkatProcess>> processSearchCache;
private final LoadingCache<String, BkatProcess> processCache;
private final LoadingCache<String, BkatProcessor> processorCache;
private final Cache<String, ProcessPage> processPageCache;
private final LoadingCache<String, List<BkatProcess>> processTeamCache;

Expand All @@ -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))
Expand All @@ -74,6 +82,10 @@ public BkatProcess getProcess(String id) {
return processCache.get(id);
}

public BkatProcessor getProcessor(String id) {
return processorCache.get(id);
}

public Map<String, BkatProcess> getProcessesById(Collection<String> ids) {
return processCache.getAll(ids, this::getProcesses0);
}
Expand All @@ -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<String, BkatProcess> getProcesses0(Iterable<? extends String> uncachedIds) {
Map<String, BkatProcess> map = toMap(post("/process/shortbyid", uncachedIds, ProcessPage.class).getContent(), BkatProcess::getId);
log.info("fetched {} processes from bkat", map.size());
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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;

}

0 comments on commit 70c91f9

Please sign in to comment.