Skip to content

Commit

Permalink
Add mapping to links and change database identificator
Browse files Browse the repository at this point in the history
  • Loading branch information
Sander14121 committed Nov 5, 2024
1 parent e37992c commit ad53c13
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package no.fintlabs.model.personopplysning;

import no.fintlabs.model.personopplysning.model.PersonopplysningEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
package no.fintlabs.model.personopplysning;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import no.fint.model.felles.kompleksedatatyper.Identifikator;
import no.fint.model.felles.kompleksedatatyper.Periode;
import no.fint.model.resource.Link;
import no.fint.model.resource.personvern.kodeverk.PersonopplysningResource;
import no.fintlabs.model.personopplysning.model.PersonopplysningEntity;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.UUID;
import java.util.List;
import java.util.Map;

@Service
public class PersonopplysningMappingService {

private static final ObjectMapper objectMapper = new ObjectMapper();

public static PersonopplysningResource toResource(PersonopplysningEntity personopplysningEntity) {
PersonopplysningResource personopplysningResource = new PersonopplysningResource();
Expand All @@ -21,6 +27,15 @@ public static PersonopplysningResource toResource(PersonopplysningEntity persono
personopplysningResource.setPassiv(personopplysningEntity.isPassiv());
personopplysningResource.setGyldighetsperiode(mapToPeriode(personopplysningEntity.getStartGyldighetsdato(), personopplysningEntity.getEndGyldighetsdato(), personopplysningEntity.getBeskrivelseGyldighetsPeriode()));
personopplysningResource.setSystemId(identifikator);

try {
String links = personopplysningEntity.getLinks();
personopplysningResource.setLinks(objectMapper.readValue(links, new TypeReference<Map<String, List<Link>>>() {
}));
} catch (Exception e) {
throw new RuntimeException("Could not parse links", e);
}

return personopplysningResource;
}

Expand All @@ -38,7 +53,16 @@ public static PersonopplysningEntity toEntity(PersonopplysningResource personopp
personopplysningEntity.setNavn(personopplysningResource.getNavn());
if (personopplysningResource.getPassiv() != null)
personopplysningEntity.setPassiv(personopplysningResource.getPassiv());
personopplysningEntity.setIdentifikatorVerdi(UUID.randomUUID().toString());
personopplysningEntity.setIdentifikatorVerdi(personopplysningResource.getSystemId().getIdentifikatorverdi());

if(personopplysningResource.getLinks() != null) {
try {
Map<String, List<Link>> links = personopplysningResource.getLinks();
personopplysningEntity.setLinks(objectMapper.writeValueAsString(links));
} catch (Exception e) {
throw new RuntimeException("Could not serialize personopplysning links", e);
}
}
return personopplysningEntity;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import no.fint.model.resource.personvern.kodeverk.PersonopplysningResource;
import no.fintlabs.adapter.events.WriteableResourceRepository;
import no.fintlabs.adapter.models.event.RequestFintEvent;
import no.fintlabs.model.personopplysning.model.PersonopplysningEntity;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package no.fintlabs.model.personopplysning;
package no.fintlabs.model.personopplysning.model;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
Expand All @@ -7,13 +7,17 @@
import lombok.Setter;

import java.util.Date;
import java.util.List;
import java.util.Map;

@Entity
@Getter
@Setter
public class PersonopplysningEntity {
@Id
@Column(nullable = false, unique = true)
private String identifikatorVerdi;

private String kode;

private Date startGyldighetsdato;
Expand All @@ -27,9 +31,9 @@ public class PersonopplysningEntity {

private boolean passiv;

private String identifikatorVerdi;

private Date startIdentifikatorDato;

private Date endIdentifikatorDato;

private String links;
}

0 comments on commit ad53c13

Please sign in to comment.