-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: legge til hentUtvidetOrganisasjon i EReg-klient (#1358)
Co-authored-by: Jens-Otto Larsen <46576810+jolarsen@users.noreply.github.com>
- Loading branch information
1 parent
27aa641
commit 8032cf0
Showing
4 changed files
with
77 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
.../src/main/java/no/nav/vedtak/felles/integrasjon/organisasjon/UtvidetOrganisasjonEReg.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package no.nav.vedtak.felles.integrasjon.organisasjon; | ||
|
||
import java.time.LocalDate; | ||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
|
||
import no.nav.vedtak.konfig.Tid; | ||
|
||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
public record UtvidetOrganisasjonEReg(String organisasjonsnummer, OrganisasjonstypeEReg type, OrganisasjonDetaljer organisasjonDetaljer, | ||
List<DriverVirksomhet> driverVirksomheter) { | ||
|
||
|
||
public List<String> getEksaktVirksomhetForDato(LocalDate hentedato) { | ||
if (!OrganisasjonstypeEReg.JURIDISK_ENHET.equals(type) || getOpphørsdatoNonNull().isBefore(hentedato)) { | ||
return List.of(); | ||
} | ||
return Optional.ofNullable(driverVirksomheter) | ||
.orElse(List.of()) | ||
.stream() | ||
.filter(v -> v.gyldighetsperiode().fom().isBefore(hentedato) && v.gyldighetsperiode().getTomNonNull().isAfter(hentedato)) | ||
.map(DriverVirksomhet::organisasjonsnummer) | ||
.toList(); | ||
} | ||
|
||
public LocalDate getRegistreringsdato() { | ||
return Optional.ofNullable(organisasjonDetaljer).map(OrganisasjonDetaljer::registreringsdato).map(LocalDateTime::toLocalDate).orElse(null); | ||
} | ||
|
||
public LocalDate getOpphørsdato() { | ||
return Optional.ofNullable(organisasjonDetaljer).map(OrganisasjonDetaljer::opphoersdato).orElse(null); | ||
} | ||
|
||
private LocalDate getOpphørsdatoNonNull() { | ||
return Optional.ofNullable(organisasjonDetaljer).map(OrganisasjonDetaljer::opphoersdato).orElse(Tid.TIDENES_ENDE); | ||
} | ||
|
||
private record OrganisasjonDetaljer(LocalDateTime registreringsdato, LocalDate opphoersdato) { | ||
} | ||
|
||
private record DriverVirksomhet(String organisasjonsnummer, Periode gyldighetsperiode) { | ||
} | ||
|
||
private record Periode(LocalDate fom, LocalDate tom) { | ||
|
||
public LocalDate getTomNonNull() { | ||
return Optional.ofNullable(tom).orElse(Tid.TIDENES_ENDE); | ||
} | ||
|
||
} | ||
|
||
} | ||
|