Skip to content

Commit

Permalink
Update endpoints and add LandkodeEncoder class in tpsmessagingservice
Browse files Browse the repository at this point in the history
#deploy-tps-messaging-service

Redesigned endpoints for personhistorikk and doedsmelding to receive request body instead of path variables. Also introduced a new utility class LandkodeEncoder to manage land code. Additionally, several import statements were adjusted to suit the current system configuration.
  • Loading branch information
krharum committed Mar 8, 2024
1 parent cf977f3 commit ccff4ab
Show file tree
Hide file tree
Showing 14 changed files with 435 additions and 86 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@
import no.nav.testnav.apps.tpsmessagingservice.service.SpraakService;
import no.nav.testnav.libs.data.kontoregister.v1.BankkontonrNorskDTO;
import no.nav.testnav.libs.data.kontoregister.v1.BankkontonrUtlandDTO;
import no.nav.testnav.libs.data.pdlforvalter.v1.PersonDTO;
import no.nav.testnav.libs.data.tpsmessagingservice.v1.AdressehistorikkDTO;
import no.nav.testnav.libs.data.tpsmessagingservice.v1.AdressehistorikkRequest;
import no.nav.testnav.libs.data.tpsmessagingservice.v1.DoedsmeldingRequest;
import no.nav.testnav.libs.data.tpsmessagingservice.v1.DoedsmeldingResponse;
import no.nav.testnav.libs.data.tpsmessagingservice.v1.FoedselsmeldingRequest;
import no.nav.testnav.libs.data.tpsmessagingservice.v1.FoedselsmeldingResponse;
import no.nav.testnav.libs.data.tpsmessagingservice.v1.PersonDTO;
import no.nav.testnav.libs.data.tpsmessagingservice.v1.PersonMiljoeDTO;
import no.nav.testnav.libs.data.tpsmessagingservice.v1.SpraakDTO;
import no.nav.testnav.libs.data.tpsmessagingservice.v1.TpsMeldingResponseDTO;
Expand Down Expand Up @@ -126,12 +128,11 @@ public List<TpsMeldingResponseDTO> opphoerBankkontonrUtland(@PathVariable String
return convert(bankkontoUtlandService.opphoerBankkontonrUtland(ident, miljoer));
}

@GetMapping("/{ident}/adressehistorikk")
public List<AdressehistorikkDTO> personhistorikk(@PathVariable String ident,
@RequestParam(required = false) LocalDate aksjonsdato,
@GetMapping("/adressehistorikk")
public List<AdressehistorikkDTO> personhistorikk(@RequestBody AdressehistorikkRequest request,
@RequestParam(required = false) List<String> miljoer) {

return adressehistorikkService.hentIdent(ident, aksjonsdato, isNull(miljoer) ? emptyList() : miljoer);
return adressehistorikkService.hentHistorikk(request, isNull(miljoer) ? emptyList() : miljoer);
}

@PostMapping("/foedselsmelding")
Expand All @@ -141,12 +142,11 @@ public FoedselsmeldingResponse sendFoedselsmelding(@RequestParam(required = fals
return foedselsmeldingService.sendFoedselsmelding(persondata, isNull(miljoer) ? emptyList() : miljoer);
}

@PostMapping("{ident}/doedsmelding")
public DoedsmeldingResponse sendDoedsmelding(@PathVariable String ident,
@RequestParam LocalDate doedsdato,
@PostMapping("/doedsmelding")
public DoedsmeldingResponse sendDoedsmelding(@RequestBody DoedsmeldingRequest request,
@RequestParam(required = false) List<String> miljoer) {

return doedsmeldingService.sendDoedsmelding(ident, doedsdato, isNull(miljoer) ? emptyList() : miljoer);
return doedsmeldingService.sendDoedsmelding(request, isNull(miljoer) ? emptyList() : miljoer);
}

@DeleteMapping("/doedsmelding")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import no.nav.testnav.apps.tpsmessagingservice.utils.ResponseStatus;
import no.nav.testnav.apps.tpsmessagingservice.utils.ServiceRutineUtil;
import no.nav.testnav.libs.data.tpsmessagingservice.v1.AdressehistorikkDTO;
import no.nav.testnav.libs.data.tpsmessagingservice.v1.AdressehistorikkRequest;
import no.nav.tps.xjc.ctg.domain.s018.S018PersonType;
import no.nav.tps.xjc.ctg.domain.s018.SRnavnType;
import org.json.XML;
import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -49,29 +51,40 @@ public AdressehistorikkService(TestmiljoerServiceConsumer testmiljoerServiceCons
this.objectMapper = objectMapper;
}

public List<AdressehistorikkDTO> hentIdent(String ident, LocalDate aksjonsdato, List<String> miljoer) {
public List<AdressehistorikkDTO> hentHistorikk(AdressehistorikkRequest request, List<String> miljoer) {

if (miljoer.isEmpty()) {
miljoer = testmiljoerServiceConsumer.getMiljoer();
}

var tpsPersoner = readFromTps(ident, nonNull(aksjonsdato) ? aksjonsdato : LocalDate.now(), miljoer);
var tpsPersoner = readFromTps(request.getIdent(),
nonNull(request.getAksjonsdato()) ? request.getAksjonsdato() : LocalDate.now(),
miljoer);

return tpsPersoner.entrySet().stream()
.map(entry -> {
var status = ResponseStatus.decodeStatus(nonNull(entry.getValue()) && nonNull(entry.getValue().getTpsPersonData().getTpsSvar()) ?
var status = ResponseStatus.decodeStatus(nonNull(entry.getValue()) &&
nonNull(entry.getValue().getTpsPersonData().getTpsSvar()) ?
entry.getValue().getTpsPersonData().getTpsSvar().getSvarStatus() : null);
return AdressehistorikkDTO.builder()
.miljoe(entry.getKey())
.status(mapperFacade.map(status, AdressehistorikkDTO.TpsMeldingResponse.class))
.persondata("OK".equals(status.getReturStatus()) ?
mapperFacade.map(entry.getValue().getTpsPersonData().getTpsSvar().getPersonDataS018(), AdressehistorikkDTO.PersonData.class) :
mapAdressehistorikk(request.getIdent(),
entry.getValue().getTpsPersonData().getTpsSvar().getPersonDataS018()) :
null)
.build();
})
.toList();
}

private AdressehistorikkDTO.PersonData mapAdressehistorikk(String ident, S018PersonType persondataS18) {

var persondata = mapperFacade.map(persondataS18, AdressehistorikkDTO.PersonData.class);
persondata.setIdent(ident);
return persondata;
}

private Map<String, TpsServicerutineS018Response> readFromTps(String ident, LocalDate foedselsdato, List<String> miljoer) {

var request = TpsServicerutineAksjonsdatoRequest.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import no.nav.testnav.apps.tpsmessagingservice.consumer.TestmiljoerServiceConsumer;
import no.nav.testnav.apps.tpsmessagingservice.dto.endringsmeldinger.SkdMeldingsheader;
import no.nav.testnav.apps.tpsmessagingservice.service.skd.DoedsmeldingAnnulleringBuilderService;
import no.nav.testnav.apps.tpsmessagingservice.service.skd.DoedsmeldingBuilderService;
import no.nav.testnav.apps.tpsmessagingservice.service.skd.SendSkdMeldinger;
import no.nav.testnav.apps.tpsmessagingservice.utils.ResponseStatus;
import no.nav.testnav.libs.data.pdlforvalter.v1.PersonDTO;
import no.nav.testnav.libs.data.tpsmessagingservice.v1.DoedsmeldingRequest;
import no.nav.testnav.libs.data.tpsmessagingservice.v1.DoedsmeldingResponse;
import no.nav.testnav.libs.data.tpsmessagingservice.v1.PersonDTO;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.List;
import java.util.Map;

Expand All @@ -26,20 +25,19 @@ public class DoedsmeldingService {
private final DoedsmeldingAnnulleringBuilderService doedsmeldingAnnulleringBuilderService;
private final TestmiljoerServiceConsumer testmiljoerServiceConsumer;

public DoedsmeldingResponse sendDoedsmelding(String ident, LocalDate doedsdato, List<String> miljoer) {
public DoedsmeldingResponse sendDoedsmelding(DoedsmeldingRequest request, List<String> miljoer) {

if (miljoer.isEmpty()) {
miljoer = testmiljoerServiceConsumer.getMiljoer();
}

var skdMelding = doedsmeldingBuilderService.build(ident, doedsdato);
var skdMeldingMedHeader = SkdMeldingsheader.appendHeader(skdMelding.toString());
var skdMelding = doedsmeldingBuilderService.build(request);

var miljoerStatus = sendSkdMeldinger.sendMeldinger(skdMeldingMedHeader, miljoer);
var miljoerStatus = sendSkdMeldinger.sendMeldinger(skdMelding.toString(), miljoer);
prepareStatus(miljoerStatus);

return DoedsmeldingResponse.builder()
.ident(ident)
.ident(request.getIdent())
.miljoStatus(miljoerStatus)
.build();
}
Expand All @@ -51,9 +49,8 @@ public DoedsmeldingResponse annulerDoedsmelding(PersonDTO person, List<String> m
}

var skdMelding = doedsmeldingAnnulleringBuilderService.execute(person);
var skdMeldingMedHeader = SkdMeldingsheader.appendHeader(skdMelding.toString());

var miljoerStatus = sendSkdMeldinger.sendMeldinger(skdMeldingMedHeader, miljoer);
var miljoerStatus = sendSkdMeldinger.sendMeldinger(skdMelding.toString(), miljoer);
prepareStatus(miljoerStatus);

return DoedsmeldingResponse.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import lombok.RequiredArgsConstructor;
import no.nav.testnav.apps.tpsmessagingservice.consumer.TestmiljoerServiceConsumer;
import no.nav.testnav.apps.tpsmessagingservice.dto.endringsmeldinger.SkdMeldingsheader;
import no.nav.testnav.apps.tpsmessagingservice.service.skd.FoedselsmeldingBuilderService;
import no.nav.testnav.apps.tpsmessagingservice.service.skd.SendSkdMeldinger;
import no.nav.testnav.apps.tpsmessagingservice.utils.ResponseStatus;
Expand All @@ -28,9 +27,8 @@ public FoedselsmeldingResponse sendFoedselsmelding(FoedselsmeldingRequest person
}

var skdMelding = foedselsmeldingBuilderService.build(persondata);
var skdMeldingMedHeader = SkdMeldingsheader.appendHeader(skdMelding.toString());

var miljoerStatus = sendSkdMeldinger.sendMeldinger(skdMeldingMedHeader, miljoer);
var miljoerStatus = sendSkdMeldinger.sendMeldinger(skdMelding.toString(), miljoer);
prepareStatus(miljoerStatus);

return FoedselsmeldingResponse.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
import no.nav.testnav.apps.tpsmessagingservice.utils.ConvertDateToStringUtility;
import no.nav.testnav.apps.tpsmessagingservice.utils.HentDatoFraIdentUtility;
import no.nav.testnav.apps.tpsmessagingservice.utils.HusbokstavEncoder;
import no.nav.testnav.apps.tpsmessagingservice.utils.LandkodeEncoder;
import no.nav.testnav.apps.tpsmessagingservice.utils.NullcheckUtil;
import no.nav.testnav.libs.data.pdlforvalter.v1.PersonDTO;
import no.nav.testnav.libs.data.pdlforvalter.v1.VegadresseDTO;
import no.nav.testnav.libs.data.tpsmessagingservice.v1.AdresseDTO;
import no.nav.testnav.libs.data.tpsmessagingservice.v1.GateadresseDTO;
import no.nav.testnav.libs.data.tpsmessagingservice.v1.MatrikkeladresseDTO;
import no.nav.testnav.libs.data.tpsmessagingservice.v1.PersonDTO;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

Expand All @@ -28,37 +31,52 @@ public class AdresseAppenderService {
public void execute(SkdMeldingTrans1 skdMeldingTrans1, PersonDTO person) {

/* Boadresse */
if (!person.getBostedsadresse().isEmpty()) {
var boadresse = person.getBostedsadresse().getFirst();
if (nonNull(person.getBoadresse())) {

if (nonNull(boadresse.getMatrikkeladresse())) {
var matrikkeladresse = boadresse.getMatrikkeladresse();
skdMeldingTrans1.setAdressetype("M");
skdMeldingTrans1.setGateGaard(prepad(matrikkeladresse.getGaardsnummer().toString(), 5));
skdMeldingTrans1.setHusBruk(prepad(matrikkeladresse.getBruksnummer().toString(), 4));
skdMeldingTrans1.setAdressenavn(matrikkeladresse.getTilleggsnavn());
skdMeldingTrans1.setKommunenummer(matrikkeladresse.getKommunenummer());
skdMeldingTrans1.setPostnummer(matrikkeladresse.getPostnummer());
skdMeldingTrans1.setTilleggsadresse(matrikkeladresse.getTilleggsnavn());

} else if (nonNull(boadresse.getVegadresse())) {
var vegadresse = boadresse.getVegadresse();
if (AdresseDTO.Adressetype.GATE == person.getBoadresse().getAdressetype()) {

var gateadresse = (GateadresseDTO) person.getBoadresse();
skdMeldingTrans1.setAdressetype("O");
skdMeldingTrans1.setGateGaard(fixGatekode(vegadresse.getAdressekode()));
addHusBrukAndBokstavFestenr(skdMeldingTrans1, vegadresse);
skdMeldingTrans1.setAdressenavn(StringUtils.abbreviate(vegadresse.getAdressenavn(), 25));
skdMeldingTrans1.setKommunenummer(vegadresse.getKommunenummer());
skdMeldingTrans1.setPostnummer(vegadresse.getPostnummer());
skdMeldingTrans1.setTilleggsadresse(vegadresse.getTilleggsnavn());
skdMeldingTrans1.setGateGaard(fixGatekode(gateadresse.getGatekode()));
addHusBrukAndBokstavFestenr(skdMeldingTrans1, gateadresse);
skdMeldingTrans1.setAdressenavn(StringUtils.abbreviate(gateadresse.getAdresse(), 25));
skdMeldingTrans1.setKommunenummer(gateadresse.getKommunenr());
skdMeldingTrans1.setPostnummer(gateadresse.getPostnr());
skdMeldingTrans1.setTilleggsadresse(gateadresse.getTilleggsadresse());
skdMeldingTrans1.setFlyttedatoAdr(ConvertDateToStringUtility.yyyyMMdd(
enforceValidTpsDate(NullcheckUtil.nullcheckSetDefaultValue(gateadresse.getFlyttedato(),
HentDatoFraIdentUtility.extract(person.getIdent())))));

} else if (AdresseDTO.Adressetype.MATR == person.getBoadresse().getAdressetype()) {

var matrikkeladresse = (MatrikkeladresseDTO) person.getBoadresse();
skdMeldingTrans1.setAdressetype("M");
skdMeldingTrans1.setGateGaard(prepad(matrikkeladresse.getGardsnr(), 5));
skdMeldingTrans1.setHusBruk(prepad(matrikkeladresse.getBruksnr(), 4));
skdMeldingTrans1.setAdressenavn(matrikkeladresse.getMellomnavn());
skdMeldingTrans1.setKommunenummer(matrikkeladresse.getKommunenr());
skdMeldingTrans1.setPostnummer(matrikkeladresse.getPostnr());
skdMeldingTrans1.setTilleggsadresse(matrikkeladresse.getTilleggsadresse());
skdMeldingTrans1.setFlyttedatoAdr(ConvertDateToStringUtility.yyyyMMdd(
enforceValidTpsDate(NullcheckUtil.nullcheckSetDefaultValue(matrikkeladresse.getFlyttedato(),
HentDatoFraIdentUtility.extract(person.getIdent())))));

}

skdMeldingTrans1.setFlyttedatoAdr(ConvertDateToStringUtility.yyyyMMdd(
enforceValidTpsDate(NullcheckUtil.nullcheckSetDefaultValue(boadresse.getAngittFlyttedato(),
HentDatoFraIdentUtility.extract(person.getIdent())))));
} else {
skdMeldingTrans1.setFlyttedatoAdr(ConvertDateToStringUtility.yyyyMMdd(enforceValidTpsDate(
HentDatoFraIdentUtility.extract(person.getIdent()))));
}

/* Postadresse */
if (nonNull(person.getPostadresse())) {

var postadresse = person.getPostadresse();
skdMeldingTrans1.setPostadresse1(postadresse.getPostLinje1());
skdMeldingTrans1.setPostadresse2(postadresse.getPostLinje2());
skdMeldingTrans1.setPostadresse3(postadresse.getPostLinje3());
skdMeldingTrans1.setPostadresseLand(LandkodeEncoder.encode(postadresse.getPostLand()));
}
}

private static String fixGatekode(String gatekode) {
Expand All @@ -72,7 +90,7 @@ private static String prepad(String value, int length) {
return format(formatter, nonNull(value) ? value : '0').replace(' ', '0');
}

private void addHusBrukAndBokstavFestenr(SkdMeldingTrans1 skdMeldingTrans1, VegadresseDTO gateadresse) {
private void addHusBrukAndBokstavFestenr(SkdMeldingTrans1 skdMeldingTrans1, GateadresseDTO gateadresse) {

if (isNotBlank(gateadresse.getHusnummer())) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import no.nav.testnav.apps.tpsmessagingservice.dto.endringsmeldinger.SkdMeldingTrans1;
import no.nav.testnav.apps.tpsmessagingservice.utils.ConvertDateToStringUtility;
import no.nav.testnav.libs.data.pdlforvalter.v1.PersonDTO;
import no.nav.testnav.libs.data.tpsmessagingservice.v1.PersonDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import no.nav.testnav.apps.tpsmessagingservice.utils.ConvertDateToStringUtility;
import no.nav.testnav.apps.tpsmessagingservice.utils.IdenttypeFraIdentUtility;
import no.nav.testnav.libs.data.pdlforvalter.v1.Identtype;
import no.nav.testnav.libs.data.tpsmessagingservice.v1.DoedsmeldingRequest;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.LocalDateTime;

@Service
Expand All @@ -20,22 +20,22 @@ public class DoedsmeldingBuilderService {
private static final String STATUSKODE_DNR = "2";
private static final String TILDELINGSKODE_DOEDSMELDING = "0";

public SkdMeldingTrans1 build(String ident, LocalDate doedsdato) {
public SkdMeldingTrans1 build(DoedsmeldingRequest request) {

var skdMeldingTrans1 = new SkdMeldingTrans1();
skdMeldingTrans1.setTildelingskode(TILDELINGSKODE_DOEDSMELDING);

addSkdParametersExtractedFromPerson(skdMeldingTrans1, ident, doedsdato);
addSkdParametersExtractedFromPerson(skdMeldingTrans1, request);

return skdMeldingTrans1;
}

private void addSkdParametersExtractedFromPerson(SkdMeldingTrans1 skdMeldingTrans1, String ident, LocalDate doedsdato) {
private void addSkdParametersExtractedFromPerson(SkdMeldingTrans1 skdMeldingTrans1, DoedsmeldingRequest request) {

skdMeldingTrans1.setFodselsdato(ident.substring(0, 6));
skdMeldingTrans1.setPersonnummer(ident.substring(6, 11));
skdMeldingTrans1.setFodselsdato(request.getIdent().substring(0, 6));
skdMeldingTrans1.setPersonnummer(request.getIdent().substring(6, 11));

var datoDoed = ConvertDateToStringUtility.yyyyMMdd(doedsdato.atStartOfDay());
var datoDoed = ConvertDateToStringUtility.yyyyMMdd(request.getDoedsdato().atStartOfDay());

skdMeldingTrans1.setMaskintid(ConvertDateToStringUtility.hhMMss(LocalDateTime.now()));
skdMeldingTrans1.setMaskindato(ConvertDateToStringUtility.yyyyMMdd(LocalDateTime.now()));
Expand All @@ -45,7 +45,7 @@ private void addSkdParametersExtractedFromPerson(SkdMeldingTrans1 skdMeldingTran
skdMeldingTrans1.setDatoDoed(datoDoed);

skdMeldingTrans1.setAarsakskode(AARSAKSKODE_FOR_DOEDSMELDING);
skdMeldingTrans1.setStatuskode(Identtype.FNR == IdenttypeFraIdentUtility.getIdenttype(ident) ?
skdMeldingTrans1.setStatuskode(Identtype.FNR == IdenttypeFraIdentUtility.getIdenttype(request.getIdent()) ?
STATUSKODE_FNR : STATUSKODE_DNR);
skdMeldingTrans1.setTranstype(TRANSTYPE_FOR_DOEDSMELDING);
}
Expand Down
Loading

0 comments on commit ccff4ab

Please sign in to comment.