Skip to content

Commit

Permalink
Merge branch 'master' into feature/spring-updates
Browse files Browse the repository at this point in the history
  • Loading branch information
stigus committed Jan 10, 2025
2 parents a3330c5 + e5518dc commit 9f0f1ad
Show file tree
Hide file tree
Showing 29 changed files with 592 additions and 87 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ public static void main(String[] args) {

SpringApplication.run(DollyBackendApplicationStarter.class, args);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import no.nav.dolly.domain.resultset.dokarkiv.RsDokarkiv;
import no.nav.dolly.domain.resultset.dolly.DollyPerson;
import no.nav.dolly.errorhandling.ErrorStatusDecoder;
import no.nav.dolly.service.DokumentService;
import no.nav.dolly.service.TransaksjonMappingService;
import no.nav.dolly.util.TransactionHelperService;
import no.nav.testnav.libs.reactivecore.utils.WebClientFilter;
Expand Down Expand Up @@ -47,6 +48,7 @@ public class DokarkivClient implements ClientRegister {

private final ApplicationConfig applicationConfig;
private final DokarkivConsumer dokarkivConsumer;
private final DokumentService dokumentService;
private final ErrorStatusDecoder errorStatusDecoder;
private final MapperFacade mapperFacade;
private final ObjectMapper objectMapper;
Expand All @@ -63,7 +65,7 @@ public Flux<ClientFuture> gjenopprett(RsDollyUtvidetBestilling bestilling, Dolly
.flatMap(dokarkiv -> Flux.from(getPersonData(dollyPerson.getIdent())
.flatMap(person -> getFilteredMiljoer(bestilling.getEnvironments())
.flatMapMany(miljoer -> Flux.fromIterable(miljoer)
.flatMap(env -> buildRequest(dokarkiv, person)
.flatMap(env -> buildRequest(dokarkiv, person, progress.getBestilling().getId())
.flatMap(request ->
!transaksjonMappingService.existAlready(DOKARKIV,
dollyPerson.getIdent(), env, bestilling.getId()) || isOpprettEndre ?
Expand Down Expand Up @@ -142,10 +144,11 @@ private Flux<PdlPersonBolk.PersonBolk> getPersonData(String ident) {
.filter(personBolk -> nonNull(personBolk.getPerson()));
}

private Mono<DokarkivRequest> buildRequest(RsDokarkiv rsDokarkiv, PdlPersonBolk.PersonBolk personBolk) {
private Mono<DokarkivRequest> buildRequest(RsDokarkiv rsDokarkiv, PdlPersonBolk.PersonBolk personBolk, Long bestillingId) {

var context = new MappingContext.Factory().getContext();
context.setProperty("personBolk", personBolk);
context.setProperty("dokumenter", dokumentService.getDokumenterByBestilling(bestillingId));

return Mono.just(mapperFacade.map(rsDokarkiv, DokarkivRequest.class, context));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package no.nav.dolly.bestilling.dokarkiv.domain;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.AllArgsConstructor;
import lombok.Builder;
Expand Down Expand Up @@ -100,6 +101,8 @@ public static class DokumentVariant {
private String filtype;
private String fysiskDokument;
private String variantformat;
@JsonIgnore
private Long dokumentReferanse;

@Override
public String toString() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,5 @@ public List<DokumentInfo> getDokumenter() {
public static class DokumentInfo {

private String dokumentInfoId;
private String brevkode;
private String tittel;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
import no.nav.dolly.bestilling.dokarkiv.domain.DokarkivRequest;
import no.nav.dolly.domain.PdlPerson;
import no.nav.dolly.domain.PdlPersonBolk;
import no.nav.dolly.domain.jpa.Dokument;
import no.nav.dolly.domain.resultset.dokarkiv.RsDokarkiv;
import no.nav.dolly.mapper.MappingStrategy;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.List;
import java.util.UUID;

import static java.util.Objects.isNull;
Expand All @@ -37,6 +39,7 @@ public void register(MapperFactory factory) {
@Override
public void mapAtoB(RsDokarkiv rsDokarkiv, DokarkivRequest dokarkivRequest, MappingContext context) {

var dokumenter = (List<Dokument>) context.getProperty("dokumenter");

dokarkivRequest.setEksternReferanseId(UUID.randomUUID().toString());
dokarkivRequest.setTittel(rsDokarkiv.getTittel());
Expand Down Expand Up @@ -72,7 +75,7 @@ public void mapAtoB(RsDokarkiv rsDokarkiv, DokarkivRequest dokarkivRequest, Mapp

dokarkivRequest.getDokumenter()
.addAll(mapperFacade.mapAsList(rsDokarkiv.getDokumenter(), DokarkivRequest.Dokument.class));
fyllDokarkivDokument(dokarkivRequest);
fyllDokarkivDokument(dokarkivRequest, dokumenter);
dokarkivRequest.setFerdigstill(rsDokarkiv.getFerdigstill());
}

Expand All @@ -86,7 +89,7 @@ private String getNavn(PdlPersonBolk.PersonBolk personBolk) {
.register();
}

private void fyllDokarkivDokument(DokarkivRequest dokarkivRequest) {
private void fyllDokarkivDokument(DokarkivRequest dokarkivRequest, List<Dokument> dokumenter) {

if (dokarkivRequest.getDokumenter().isEmpty()) {
dokarkivRequest.getDokumenter().add(new DokarkivRequest.Dokument());
Expand All @@ -100,8 +103,12 @@ private void fyllDokarkivDokument(DokarkivRequest dokarkivRequest) {
if (isBlank(dokarkivRequest.getDokumenter().getFirst().getDokumentvarianter().getFirst().getVariantformat())) {
dokarkivRequest.getDokumenter().getFirst().getDokumentvarianter().getFirst().setVariantformat(ARKIV);
}
if (isBlank(dokarkivRequest.getDokumenter().getFirst().getDokumentvarianter().getFirst().getFysiskDokument())) {
dokarkivRequest.getDokumenter().getFirst().getDokumentvarianter().getFirst().setFysiskDokument(PDF_VEDLEGG);
}
dokarkivRequest.getDokumenter()
.forEach(dokument -> dokument.getDokumentvarianter()
.forEach(dokumentVariant ->
dokumentVariant.setFysiskDokument(dokumenter.stream()
.filter(doku -> doku.getId().equals(dokumentVariant.getDokumentReferanse()))
.map(Dokument::getContents)
.findFirst().orElse(PDF_VEDLEGG))));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import no.nav.dolly.domain.resultset.dolly.DollyPerson;
import no.nav.dolly.domain.resultset.histark.RsHistark;
import no.nav.dolly.errorhandling.ErrorStatusDecoder;
import no.nav.dolly.service.DokumentService;
import no.nav.dolly.service.TransaksjonMappingService;
import no.nav.dolly.util.TransactionHelperService;
import org.springframework.stereotype.Service;
Expand All @@ -43,14 +44,15 @@ public class HistarkClient implements ClientRegister {
private final ObjectMapper objectMapper;
private final TransactionHelperService transactionHelperService;
private final ErrorStatusDecoder errorStatusDecoder;
private final DokumentService dokumentService;

@Override
public Flux<ClientFuture> gjenopprett(RsDollyUtvidetBestilling bestilling, DollyPerson dollyPerson, BestillingProgress progress, boolean isOpprettEndre) {

if (nonNull(bestilling.getHistark())) {

return Flux.just(dollyPerson.getIdent())
.map(person -> buildRequest(bestilling.getHistark(), person))
.map(person -> buildRequest(bestilling.getHistark(), person, progress.getBestilling().getId()))
.flatMap(request -> !transaksjonMappingService.existAlready(HISTARK,
dollyPerson.getIdent(), "NA", bestilling.getId()) || isOpprettEndre ?

Expand Down Expand Up @@ -100,10 +102,11 @@ private String getStatus(String ident, Long bestillingId, HistarkResponse respon
}
}

private HistarkRequest buildRequest(RsHistark rsHistark, String ident) {
private HistarkRequest buildRequest(RsHistark rsHistark, String ident, Long bestillingId) {

var context = new MappingContext.Factory().getContext();
context.setProperty("personIdent", ident);
context.setProperty("dokumenter", dokumentService.getDokumenterByBestilling(bestillingId));

return mapperFacade.map(rsHistark, HistarkRequest.class, context);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,12 @@
import no.nav.testnav.libs.securitycore.domain.ServerProperties;
import no.nav.testnav.libs.standalone.servletsecurity.exchange.TokenExchange;
import org.springframework.stereotype.Service;
import org.springframework.web.reactive.function.client.ExchangeFilterFunction;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Flux;

import java.util.UUID;

import static java.lang.String.format;
import static java.util.Objects.nonNull;
import static no.nav.dolly.domain.CommonKeysAndUtils.CONSUMER;
import static no.nav.dolly.util.JacksonExchangeStrategyUtil.getJacksonStrategy;

Expand All @@ -38,7 +36,6 @@ public HistarkConsumer(
this.tokenService = tokenService;
this.webClient = webClientBuilder
.baseUrl(serverProperties.getUrl())
.filters(exchangeFilterFunctions -> exchangeFilterFunctions.add(logRequest()))
.exchangeStrategies(getJacksonStrategy(objectMapper))
.build();
}
Expand All @@ -54,28 +51,6 @@ public Flux<HistarkResponse> postHistark(HistarkRequest histarkRequest) {
token.getTokenValue()).call());
}

private ExchangeFilterFunction logRequest() {

return (clientRequest, next) -> {
var buffer = new StringBuilder(250)
.append("Request: ")
.append(clientRequest.method())
.append(' ')
.append(clientRequest.url())
.append(System.lineSeparator());

clientRequest.headers()
.forEach((name, values) -> values
.forEach(value -> buffer.append('\t')
.append(name)
.append('=')
.append(nonNull(value) && value.contains("Bearer ") ? "Bearer token" : value)
.append(System.lineSeparator())));
log.trace(buffer.substring(0, buffer.length() - 1));
return next.exchange(clientRequest);
};
}

private static String getNavCallId() {
return format("%s %s", CONSUMER, UUID.randomUUID());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import ma.glasnost.orika.MapperFactory;
import ma.glasnost.orika.MappingContext;
import no.nav.dolly.bestilling.histark.domain.HistarkRequest;
import no.nav.dolly.domain.jpa.Dokument;
import no.nav.dolly.domain.resultset.histark.RsHistark;
import no.nav.dolly.exceptions.DollyFunctionalException;
import no.nav.dolly.mapper.MappingStrategy;
Expand All @@ -16,9 +17,9 @@
import java.io.IOException;
import java.io.InputStream;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Optional;

import static io.micrometer.common.util.StringUtils.isBlank;
import static no.nav.dolly.bestilling.dokarkiv.mapper.PdfVedlegg.PDF_VEDLEGG;

@Slf4j
Expand All @@ -36,11 +37,15 @@ public void register(MapperFactory factory) {
@Override
public void mapAtoB(RsHistark histark, HistarkRequest histarkRequest, MappingContext context) {

var dokumenter = (List<Dokument>) context.getProperty("dokumenter");

histark.getDokumenter().forEach(dokument -> {


String fysiskDokument = isBlank(dokument.getFysiskDokument()) ? PDF_VEDLEGG : dokument.getFysiskDokument();
var fysiskDokument = dokumenter.stream()
.filter(dok -> dokument.getDokumentReferanse().equals(dok.getId()))
.map(Dokument::getContents)
.findFirst()
.orElse(PDF_VEDLEGG);

histarkRequest.getHistarkDokumenter().add(HistarkRequest.HistarkDokument.builder()
.file(fysiskDokument)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package no.nav.dolly.config;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import no.nav.dolly.service.MigrateDokumentService;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;

import javax.annotation.PostConstruct;

@Slf4j
@Configuration
@Profile("!test")
@RequiredArgsConstructor
public class MigrationConfig {

private final MigrateDokumentService migrateDokumentService;

@PostConstruct
public void migrateDokumenter() {

var time = System.currentTimeMillis();
log.info("Starter migrering av dokumenter.");

migrateDokumentService.migrateDokumenter();

log.info("Migrering av dokumenter ferdig, medgått tid: {} sekunder", (System.currentTimeMillis() - time) / 1000);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package no.nav.dolly.domain.jpa;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import jakarta.persistence.Version;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.hibernate.annotations.UpdateTimestamp;

import java.io.Serializable;
import java.time.LocalDateTime;

@Entity
@Getter
@Setter
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Table(name = "DOKUMENT")
public class Dokument implements Serializable {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@Version
@Column(name = "VERSJON")
private Long versjon;

@Column(name = "BESTILLING_ID")
private Long bestillingId;

@Column(name = "DOKUMENT_TYPE")
@Enumerated(value = EnumType.STRING)
private DokumentType dokumentType;

@Column(name = "SIST_OPPDATERT")
@UpdateTimestamp
private LocalDateTime sistOppdatert;

@Column(name = "CONTENTS")
private String contents;

@Override
public boolean equals(Object o) {
if (this == o) return true;

if (o == null || getClass() != o.getClass()) return false;

Dokument dokument = (Dokument) o;

return new EqualsBuilder()
.append(id, dokument.id)
.append(versjon, dokument.versjon)
.append(bestillingId, dokument.bestillingId)
.append(dokumentType, dokument.dokumentType)
.append(sistOppdatert, dokument.sistOppdatert)
.append(contents, dokument.contents)
.isEquals();
}

@Override
public int hashCode() {
return new HashCodeBuilder(17, 37)
.append(id)
.append(versjon)
.append(bestillingId)
.append(dokumentType)
.append(sistOppdatert)
.append(contents)
.toHashCode();
}

public enum DokumentType {
BESTILLING_DOKARKIV,
BESTILLING_HISTARK,
MAL_BESTILLING_DOKARKIV,
MAL_BESTILLING_HISTARK
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ public static class DokumentVariant {
@Field(enabled = false)
private String fysiskDokument;

@Schema(description = "Referanse til dokumentet")
private Long dokumentReferanse;

@Schema(description = """
ARKIV brukes for dokumentvarianter i menneskelesbart format (for eksempel PDFA).
Gosys og nav.no henter arkivvariant og viser denne til bruker.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,8 @@ public static class RsHistarkDokument {
@Schema(description = "Selve PDF dokumentet. Ved fysisk dokument brukes bytearray.")
@Field(enabled = false)
private String fysiskDokument;

@Schema(description = "Referanse til dokumentet")
private Long dokumentReferanse;
}
}
Loading

0 comments on commit 9f0f1ad

Please sign in to comment.