-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #70 from navikt/putOppgaveKopi
Lagt til OppgaveKopi domeneklasse, samt Repository for å lagre til db ved mottak fra Oppgave
- Loading branch information
Showing
11 changed files
with
368 additions
and
2 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
src/main/kotlin/no/nav/klage/oppgave/config/OppgaveKopiRepositoryConfiguration.kt
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,32 @@ | ||
package no.nav.klage.oppgave.config | ||
|
||
import no.nav.klage.oppgave.repositories.OppgaveKopiRepository | ||
import org.springframework.context.annotation.Bean | ||
import org.springframework.context.annotation.Configuration | ||
import org.springframework.jdbc.support.incrementer.PostgresSequenceMaxValueIncrementer | ||
import javax.sql.DataSource | ||
|
||
@Configuration | ||
class OppgaveKopiRepositoryConfiguration(val dataSource: DataSource) { | ||
|
||
@Bean | ||
fun identIdIncrementer(): PostgresSequenceMaxValueIncrementer = | ||
PostgresSequenceMaxValueIncrementer(dataSource, "oppgave.ident_seq") | ||
|
||
@Bean | ||
fun metadataIdIncrementer(): PostgresSequenceMaxValueIncrementer = | ||
PostgresSequenceMaxValueIncrementer(dataSource, "oppgave.metadata_seq") | ||
|
||
@Bean | ||
fun versjonMetadataIdIncrementer(): PostgresSequenceMaxValueIncrementer = | ||
PostgresSequenceMaxValueIncrementer(dataSource, "oppgave.versjonmetadata_seq") | ||
|
||
@Bean | ||
fun oppgaveKopiRepository(): OppgaveKopiRepository = | ||
OppgaveKopiRepository( | ||
dataSource, | ||
identIdIncrementer(), | ||
metadataIdIncrementer(), | ||
versjonMetadataIdIncrementer() | ||
) | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/kotlin/no/nav/klage/oppgave/domain/oppgavekopi/Ident.kt
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,10 @@ | ||
package no.nav.klage.oppgave.domain.oppgavekopi | ||
|
||
import java.time.LocalDate | ||
|
||
data class Ident( | ||
val identType: IdentType, | ||
val verdi: String, | ||
val folkeregisterident: String? = null, | ||
val registrertDato: LocalDate? = null | ||
) |
5 changes: 5 additions & 0 deletions
5
src/main/kotlin/no/nav/klage/oppgave/domain/oppgavekopi/IdentType.kt
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,5 @@ | ||
package no.nav.klage.oppgave.domain.oppgavekopi | ||
|
||
enum class IdentType { | ||
AKTOERID, ORGNR, SAMHANDLERNR, BNR | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/kotlin/no/nav/klage/oppgave/domain/oppgavekopi/MetadataNoekkel.kt
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,13 @@ | ||
package no.nav.klage.oppgave.domain.oppgavekopi | ||
|
||
enum class MetadataNoekkel { | ||
NORM_DATO, | ||
SOKNAD_ID, | ||
REVURDERINGSTYPE, | ||
KRAV_ID, | ||
MOTTATT_DATO, | ||
EKSTERN_HENVENDELSE_ID, | ||
SKANNET_DATO, | ||
RINA_SAKID, | ||
HJEMMEL | ||
} |
38 changes: 38 additions & 0 deletions
38
src/main/kotlin/no/nav/klage/oppgave/domain/oppgavekopi/OppgaveKopi.kt
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,38 @@ | ||
package no.nav.klage.oppgave.domain.oppgavekopi | ||
|
||
import java.time.LocalDate | ||
import java.time.LocalDateTime | ||
|
||
data class OppgaveKopi( | ||
|
||
val id: Long, | ||
val versjon: Int, | ||
val journalpostId: String? = null, | ||
val saksreferanse: String? = null, | ||
val mappeId: Long? = null, | ||
val status: Status, | ||
val tildeltEnhetsnr: String, | ||
val opprettetAvEnhetsnr: String? = null, | ||
val endretAvEnhetsnr: String? = null, | ||
val tema: String, | ||
val temagruppe: String? = null, | ||
val behandlingstema: String? = null, | ||
val oppgavetype: String, | ||
val behandlingstype: String? = null, | ||
val prioritet: Prioritet, | ||
val tilordnetRessurs: String? = null, | ||
val beskrivelse: String? = null, | ||
val fristFerdigstillelse: LocalDate, | ||
val aktivDato: LocalDate, | ||
val opprettetAv: String, | ||
val endretAv: String? = null, | ||
val opprettetTidspunkt: LocalDateTime, | ||
val endretTidspunkt: LocalDateTime? = null, | ||
val ferdigstiltTidspunkt: LocalDateTime? = null, | ||
val behandlesAvApplikasjon: String? = null, | ||
val journalpostkilde: String? = null, | ||
val ident: Ident? = null, | ||
val metadata: Map<MetadataNoekkel, String>? = null | ||
) { | ||
fun statuskategori(): Statuskategori = status.kategoriForStatus() | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/kotlin/no/nav/klage/oppgave/domain/oppgavekopi/Prioritet.kt
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,7 @@ | ||
package no.nav.klage.oppgave.domain.oppgavekopi | ||
|
||
enum class Prioritet { | ||
HOY, | ||
NORM, | ||
LAV | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/kotlin/no/nav/klage/oppgave/domain/oppgavekopi/Status.kt
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,23 @@ | ||
package no.nav.klage.oppgave.domain.oppgavekopi | ||
|
||
enum class Status(val statusId: Long) { | ||
|
||
OPPRETTET(1), | ||
AAPNET(2), | ||
UNDER_BEHANDLING(3), | ||
FERDIGSTILT(4), | ||
FEILREGISTRERT(5); | ||
|
||
companion object { | ||
fun kategoriForStatus(status: Status): Statuskategori { | ||
return when (status) { | ||
AAPNET, OPPRETTET, UNDER_BEHANDLING -> Statuskategori.AAPEN | ||
FEILREGISTRERT, FERDIGSTILT -> Statuskategori.AVSLUTTET | ||
} | ||
} | ||
} | ||
|
||
fun kategoriForStatus(): Statuskategori { | ||
return kategoriForStatus(this) | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/kotlin/no/nav/klage/oppgave/domain/oppgavekopi/Statuskategori.kt
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,21 @@ | ||
package no.nav.klage.oppgave.domain.oppgavekopi | ||
|
||
enum class Statuskategori { | ||
AAPEN, | ||
AVSLUTTET; | ||
|
||
fun statuserForKategori(kategori: Statuskategori): List<Status> { | ||
return when (kategori) { | ||
AAPEN -> aapen() | ||
AVSLUTTET -> avsluttet() | ||
} | ||
} | ||
|
||
fun avsluttet(): List<Status> { | ||
return listOf(Status.FERDIGSTILT, Status.FEILREGISTRERT) | ||
} | ||
|
||
fun aapen(): List<Status> { | ||
return listOf(Status.OPPRETTET, Status.AAPNET, Status.UNDER_BEHANDLING) | ||
} | ||
} |
102 changes: 102 additions & 0 deletions
102
src/main/kotlin/no/nav/klage/oppgave/repositories/OppgaveKopiRepository.kt
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,102 @@ | ||
package no.nav.klage.oppgave.repositories | ||
|
||
import no.nav.klage.oppgave.domain.oppgavekopi.Ident | ||
import no.nav.klage.oppgave.domain.oppgavekopi.MetadataNoekkel | ||
import no.nav.klage.oppgave.domain.oppgavekopi.OppgaveKopi | ||
import org.springframework.jdbc.core.simple.SimpleJdbcInsert | ||
import org.springframework.jdbc.support.incrementer.PostgresSequenceMaxValueIncrementer | ||
import javax.sql.DataSource | ||
|
||
class OppgaveKopiRepository( | ||
val dataSource: DataSource, | ||
val identIdIncrementer: PostgresSequenceMaxValueIncrementer, | ||
val metadataIdIncrementer: PostgresSequenceMaxValueIncrementer, | ||
val versjonMetadataIdIncrementer: PostgresSequenceMaxValueIncrementer | ||
) { | ||
|
||
private fun identParameterMap(ident: Ident, identId: Long) = | ||
mapOf( | ||
"id" to identId, | ||
"TYPE" to ident.identType.name, | ||
"verdi" to ident.verdi, | ||
"folkeregisterident" to ident.folkeregisterident, | ||
"registrert_dato" to ident.registrertDato | ||
) | ||
|
||
private fun metadataParameterMap(oppgaveKopi: OppgaveKopi, noekkel: MetadataNoekkel, verdi: String) = | ||
mapOf( | ||
"id" to metadataIdIncrementer.nextLongValue(), | ||
"oppgave_id" to oppgaveKopi.id, | ||
"nokkel" to noekkel.name, | ||
"verdi" to verdi, | ||
) | ||
|
||
private fun versjonMetadataParameterMap(oppgaveKopi: OppgaveKopi, noekkel: MetadataNoekkel, verdi: String) = | ||
mapOf( | ||
"id" to versjonMetadataIdIncrementer.nextLongValue(), | ||
"oppgave_id" to oppgaveKopi.id, | ||
"oppgave_versjon" to oppgaveKopi.versjon, | ||
"nokkel" to noekkel.name, | ||
"verdi" to verdi | ||
) | ||
|
||
private fun oppgaveParameterMap(oppgaveKopi: OppgaveKopi, identId: Long?) = | ||
mapOf( | ||
"id" to oppgaveKopi.id, | ||
"versjon" to oppgaveKopi.versjon, | ||
"journalpostid" to oppgaveKopi.journalpostId, | ||
"saksreferanse" to oppgaveKopi.saksreferanse, | ||
"mappe_id" to oppgaveKopi.mappeId, | ||
"status_id" to oppgaveKopi.status.statusId, | ||
"tildelt_enhetsnr" to oppgaveKopi.tildeltEnhetsnr, | ||
"opprettet_av_enhetsnr" to oppgaveKopi.opprettetAvEnhetsnr, | ||
"endret_av_enhetsnr" to oppgaveKopi.endretAvEnhetsnr, | ||
"tema" to oppgaveKopi.tema, | ||
"temagruppe" to oppgaveKopi.temagruppe, | ||
"behandlingstema" to oppgaveKopi.behandlingstema, | ||
"oppgavetype" to oppgaveKopi.oppgavetype, | ||
"behandlingstype" to oppgaveKopi.behandlingstype, | ||
"prioritet" to oppgaveKopi.prioritet.name, | ||
"tilordnet_ressurs" to oppgaveKopi.tilordnetRessurs, | ||
"beskrivelse" to oppgaveKopi.beskrivelse, | ||
"frist_ferdigstillelse" to oppgaveKopi.fristFerdigstillelse, | ||
"aktiv_dato" to oppgaveKopi.aktivDato, | ||
"opprettet_av" to oppgaveKopi.opprettetAv, | ||
"endret_av" to oppgaveKopi.endretAv, | ||
"opprettet_tidspunkt" to oppgaveKopi.opprettetTidspunkt, | ||
"endret_tidspunkt" to oppgaveKopi.endretTidspunkt, | ||
"ferdigstilt_tidspunkt" to oppgaveKopi.ferdigstiltTidspunkt, | ||
"behandles_av_applikasjon" to oppgaveKopi.behandlesAvApplikasjon, | ||
"journalpostkilde" to oppgaveKopi.journalpostkilde, | ||
"ident_id" to identId | ||
) | ||
|
||
val oppgaveJdbcInsert = SimpleJdbcInsert(dataSource).withSchemaName("oppgave").withTableName("oppgave") | ||
val oppgaveVersjonJdbcInsert = | ||
SimpleJdbcInsert(dataSource).withSchemaName("oppgave").withTableName("oppgaveversjon") | ||
val metadataJdbcInsert = SimpleJdbcInsert(dataSource).withSchemaName("oppgave").withTableName("metadata") | ||
val versjonMetadataJdbcInsert = | ||
SimpleJdbcInsert(dataSource).withSchemaName("oppgave").withTableName("versjonmetadata") | ||
val identJdbcInsert = SimpleJdbcInsert(dataSource).withSchemaName("oppgave").withTableName("ident") | ||
|
||
private fun lagreIdentAndReturnId(ident: Ident?): Long? { | ||
return ident?.let { | ||
val identId = identIdIncrementer.nextLongValue() | ||
val identParameterMap = identParameterMap(it, identId) | ||
identJdbcInsert.execute(identParameterMap) | ||
identId | ||
} | ||
} | ||
|
||
fun lagreOppgaveKopi(oppgaveKopi: OppgaveKopi) { | ||
val identId = lagreIdentAndReturnId(oppgaveKopi.ident) | ||
oppgaveJdbcInsert.execute(oppgaveParameterMap(oppgaveKopi, identId)) | ||
oppgaveKopi.metadata?.forEach { metadataNoekkel, verdi -> | ||
metadataJdbcInsert.execute(metadataParameterMap(oppgaveKopi, metadataNoekkel, verdi)) | ||
} | ||
oppgaveVersjonJdbcInsert.execute(oppgaveParameterMap(oppgaveKopi, identId)) | ||
oppgaveKopi.metadata?.forEach { metadataNoekkel, verdi -> | ||
versjonMetadataJdbcInsert.execute(versjonMetadataParameterMap(oppgaveKopi, metadataNoekkel, verdi)) | ||
} | ||
} | ||
} |
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
117 changes: 117 additions & 0 deletions
117
src/test/kotlin/no/nav/klage/oppgave/repositories/OppgaveKopiRepositoryTest.kt
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,117 @@ | ||
package no.nav.klage.oppgave.repositories | ||
|
||
import no.nav.klage.oppgave.config.OppgaveKopiRepositoryConfiguration | ||
import no.nav.klage.oppgave.domain.oppgavekopi.* | ||
import org.assertj.core.api.Assertions.assertThat | ||
import org.junit.jupiter.api.Test | ||
import org.springframework.beans.factory.annotation.Autowired | ||
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest | ||
import org.springframework.context.annotation.Import | ||
import org.springframework.jdbc.core.JdbcTemplate | ||
import org.springframework.test.context.ActiveProfiles | ||
import java.time.LocalDate | ||
import java.time.LocalDateTime | ||
|
||
@ActiveProfiles("local") | ||
@DataJpaTest | ||
@Import(OppgaveKopiRepositoryConfiguration::class) | ||
class OppgaveKopiRepositoryTest { | ||
|
||
@Autowired | ||
lateinit var oppgaveKopiRepository: OppgaveKopiRepository | ||
|
||
@Autowired | ||
lateinit var jdbcTemplate: JdbcTemplate | ||
|
||
@Test | ||
fun oppgaveKopiWithOnlyMandatoryValuesShouldBeStoredProperly() { | ||
val oppgaveKopi = OppgaveKopi( | ||
id = 1001L, | ||
versjon = 1, | ||
tema = "tema", | ||
status = Status.OPPRETTET, | ||
tildeltEnhetsnr = "4219", | ||
oppgavetype = "KLAGE", | ||
prioritet = Prioritet.NORM, | ||
fristFerdigstillelse = LocalDate.now(), | ||
aktivDato = LocalDate.now(), | ||
opprettetAv = "H149290", | ||
opprettetTidspunkt = LocalDateTime.now() | ||
) | ||
oppgaveKopiRepository.lagreOppgaveKopi(oppgaveKopi) | ||
|
||
val oppgaveCount = jdbcTemplate.queryForObject( | ||
"SELECT count(*) FROM oppgave.oppgave", | ||
emptyArray(), | ||
Integer::class.java | ||
) | ||
assertThat(oppgaveCount).isEqualTo(1) | ||
|
||
val oppgaveVersjonCount = jdbcTemplate.queryForObject( | ||
"SELECT count(*) FROM oppgave.oppgaveversjon", | ||
emptyArray(), | ||
Integer::class.java | ||
) | ||
assertThat(oppgaveVersjonCount).isEqualTo(1) | ||
} | ||
|
||
@Test | ||
fun oppgaveKopiWithIdentShouldBeStoredProperly() { | ||
val oppgaveKopi = OppgaveKopi( | ||
id = 1001L, | ||
versjon = 1, | ||
tema = "tema", | ||
status = Status.OPPRETTET, | ||
tildeltEnhetsnr = "4219", | ||
oppgavetype = "KLAGE", | ||
prioritet = Prioritet.NORM, | ||
fristFerdigstillelse = LocalDate.now(), | ||
aktivDato = LocalDate.now(), | ||
opprettetAv = "H149290", | ||
opprettetTidspunkt = LocalDateTime.now(), | ||
ident = Ident(IdentType.AKTOERID, "12345", null, null) | ||
) | ||
oppgaveKopiRepository.lagreOppgaveKopi(oppgaveKopi) | ||
|
||
val identCount = jdbcTemplate.queryForObject( | ||
"SELECT count(*) FROM oppgave.ident", | ||
emptyArray(), | ||
Integer::class.java | ||
) | ||
assertThat(identCount).isEqualTo(1) | ||
} | ||
|
||
@Test | ||
fun oppgaveKopiWithMetadataShouldBeStoredProperly() { | ||
val oppgaveKopi = OppgaveKopi( | ||
id = 1001L, | ||
versjon = 1, | ||
tema = "tema", | ||
status = Status.OPPRETTET, | ||
tildeltEnhetsnr = "4219", | ||
oppgavetype = "KLAGE", | ||
prioritet = Prioritet.NORM, | ||
fristFerdigstillelse = LocalDate.now(), | ||
aktivDato = LocalDate.now(), | ||
opprettetAv = "H149290", | ||
opprettetTidspunkt = LocalDateTime.now(), | ||
metadata = mapOf(MetadataNoekkel.HJEMMEL to "8-25") | ||
) | ||
oppgaveKopiRepository.lagreOppgaveKopi(oppgaveKopi) | ||
|
||
val metadataCount = jdbcTemplate.queryForObject( | ||
"SELECT count(*) FROM oppgave.metadata", | ||
emptyArray(), | ||
Integer::class.java | ||
) | ||
assertThat(metadataCount).isEqualTo(1) | ||
|
||
val versjonMetadataCount = jdbcTemplate.queryForObject( | ||
"SELECT count(*) FROM oppgave.versjonmetadata", | ||
emptyArray(), | ||
Integer::class.java | ||
) | ||
assertThat(versjonMetadataCount).isEqualTo(1) | ||
} | ||
|
||
} |