Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for setting datoMottatt. #1025

Merged
merged 4 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class DokumentUnderArbeidController(
innloggetIdent = innloggetSaksbehandlerService.getInnloggetIdent(),
tittel = opplastetFil.title,
parentId = input.parentId,
datoMottatt = input.datoMottatt,
),
journalpost = null,
)
Expand Down Expand Up @@ -102,6 +103,23 @@ class DokumentUnderArbeidController(
)
}

@PutMapping("/{dokumentId}/datomottatt")
fun setDatoMottatt(
@PathVariable("behandlingId") behandlingId: UUID,
@PathVariable("dokumentId") dokumentId: UUID,
@RequestBody input: DatoMottattInput
): DokumentView {
return dokumentMapper.mapToDokumentView(
dokumentUnderArbeid = dokumentUnderArbeidService.updateDatoMottatt(
behandlingId = behandlingId,
dokumentId = dokumentId,
datoMottatt = input.datoMottatt,
innloggetIdent = innloggetSaksbehandlerService.getInnloggetIdent()
),
journalpost = null,
)
}

@ResponseBody
@GetMapping("/{dokumentId}/pdf")
fun getPdf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ package no.nav.klage.dokument.api.view
import com.fasterxml.jackson.databind.JsonNode
import no.nav.klage.kodeverk.DokumentType
import org.springframework.web.multipart.MultipartFile
import java.time.LocalDate
import java.util.*

data class FilInput(
val file: MultipartFile,
val dokumentTypeId: String = DokumentType.NOTAT.id,
val parentId: UUID?,
val datoMottatt: LocalDate?,
)

data class SmartHovedDokumentInput(
Expand Down Expand Up @@ -42,6 +44,8 @@ data class DokumentTitleInput(val title: String)

data class DokumentTypeInput(val dokumentTypeId: String)

data class DatoMottattInput(val datoMottatt: LocalDate)

data class FerdigstillDokumentInput(
val brevmottakerIds: Set<String>?
)
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import jakarta.persistence.DiscriminatorValue
import jakarta.persistence.Entity
import no.nav.klage.kodeverk.DokumentType
import no.nav.klage.oppgave.domain.klage.BehandlingRole
import java.time.LocalDate
import java.time.LocalDateTime
import java.util.*

Expand All @@ -18,6 +19,8 @@ class OpplastetDokumentUnderArbeidAsHoveddokument(
override var mellomlagerId: String?,
@Column(name = "mellomlagret_date")
override var mellomlagretDate: LocalDateTime?,
@Column(name = "dato_mottatt")
var datoMottatt: LocalDate?,

//Common properties
id: UUID = UUID.randomUUID(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class OpplastetDokumentUnderArbeidAsVedlegg(
creatorIdent = creatorIdent,
creatorRole = creatorRole,
dokumentType = dokumentType,
datoMottatt = null,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import org.springframework.beans.factory.annotation.Value
import org.springframework.context.ApplicationEventPublisher
import org.springframework.http.MediaType
import org.springframework.stereotype.Service
import java.time.LocalDate
import java.time.LocalDateTime
import java.util.*

Expand Down Expand Up @@ -81,6 +82,7 @@ class DokumentUnderArbeidService(
innloggetIdent: String,
tittel: String,
parentId: UUID?,
datoMottatt: LocalDate?,
): DokumentUnderArbeid {
//Sjekker lesetilgang på behandlingsnivå:
val behandling = behandlingService.getBehandlingAndCheckLeseTilgangForPerson(behandlingId)
Expand Down Expand Up @@ -116,6 +118,7 @@ class DokumentUnderArbeidService(
creatorRole = behandlingRole,
created = now,
modified = now,
datoMottatt = if (dokumentType == DokumentType.KJENNELSE_FRA_TRYGDERETTEN) datoMottatt else null,
)
)
} else {
Expand Down Expand Up @@ -488,6 +491,47 @@ class DokumentUnderArbeidService(
return dokumentUnderArbeid
}

fun updateDatoMottatt(
behandlingId: UUID, //Kan brukes i finderne for å "være sikker", men er egentlig overflødig..
dokumentId: UUID,
datoMottatt: LocalDate,
innloggetIdent: String
): DokumentUnderArbeid {
val dokumentUnderArbeid = dokumentUnderArbeidRepository.findById(dokumentId).get()

//Sjekker tilgang på behandlingsnivå:
val behandling = behandlingService.getBehandlingAndCheckLeseTilgangForPerson(behandlingId)

if (dokumentUnderArbeid.erMarkertFerdig()) {
throw DokumentValidationException("Kan ikke sette dato mottatt på et dokument som er ferdigstilt")
}

if (datoMottatt.isAfter(LocalDate.now())) {
throw DokumentValidationException("Kan ikke sette dato mottatt i fremtiden")
}

if (dokumentUnderArbeid.dokumentType != DokumentType.KJENNELSE_FRA_TRYGDERETTEN) {
throw DokumentValidationException("Kan bare sette dato mottatt på inngående dokument.")
}

dokumentUnderArbeid as OpplastetDokumentUnderArbeidAsHoveddokument

val previousValue = dokumentUnderArbeid.datoMottatt
dokumentUnderArbeid.datoMottatt = datoMottatt

dokumentUnderArbeid.modified = LocalDateTime.now()

behandling.publishEndringsloggEvent(
saksbehandlerident = innloggetIdent,
felt = Felt.DOKUMENT_UNDER_ARBEID_DATO_MOTTATT,
fraVerdi = previousValue.toString(),
tilVerdi = dokumentUnderArbeid.datoMottatt.toString(),
tidspunkt = dokumentUnderArbeid.modified,
)

return dokumentUnderArbeid
}

private fun DokumentUnderArbeid.isVedlegg(): Boolean {
val duaUnproxied = Hibernate.unproxy(this)
return duaUnproxied is SmartdokumentUnderArbeidAsVedlegg ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import no.nav.klage.oppgave.util.getLogger
import no.nav.klage.oppgave.util.getPartIdFromIdentifikator
import no.nav.klage.oppgave.util.getSecureLogger
import org.springframework.stereotype.Service
import java.time.LocalDate

@Service
class KabalDocumentMapper(
Expand Down Expand Up @@ -61,6 +62,11 @@ class KabalDocumentMapper(
vedlegg.filterIsInstance<JournalfoertDokumentUnderArbeidAsVedlegg>()
.sortedByDescending { it.sortKey }

val datoMottatt = if (hovedDokument.dokumentType == DokumentType.KJENNELSE_FRA_TRYGDERETTEN) {
hovedDokument as OpplastetDokumentUnderArbeidAsHoveddokument
hovedDokument.datoMottatt
} else null

return DokumentEnhetWithDokumentreferanserInput(
brevMottakere = mapBrevmottakerIdentToBrevmottakerInput(
behandling,
Expand All @@ -85,7 +91,8 @@ class KabalDocumentMapper(
key = KLAGEBEHANDLING_ID_KEY,
value = behandling.id.toString()
),
inngaaendeKanal = if (hovedDokument.dokumentType == DokumentType.KJENNELSE_FRA_TRYGDERETTEN) Kanal.ALTINN_INNBOKS else null
inngaaendeKanal = if (hovedDokument.dokumentType == DokumentType.KJENNELSE_FRA_TRYGDERETTEN) Kanal.ALTINN_INNBOKS else null,
datoMottatt = datoMottatt,
),
dokumentreferanser = DokumentEnhetWithDokumentreferanserInput.DokumentInput(
hoveddokument = mapDokumentUnderArbeidToDokumentReferanse(hovedDokument),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package no.nav.klage.oppgave.clients.kabaldocument.model.request

import java.time.LocalDate

data class JournalfoeringDataInput(
val sakenGjelder: PartIdInput,
val temaId: String,
Expand All @@ -12,6 +14,7 @@ data class JournalfoeringDataInput(
val brevKode: String,
val tilleggsopplysning: TilleggsopplysningInput?,
val inngaaendeKanal: Kanal?,
val datoMottatt: LocalDate?,
)

enum class Kanal {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ enum class Felt {
DOKUMENT_UNDER_ARBEID_OPPLASTET,
DOKUMENT_UNDER_ARBEID_SLETTET,
DOKUMENT_UNDER_ARBEID_TYPE,
DOKUMENT_UNDER_ARBEID_DATO_MOTTATT,
DOKUMENT_UNDER_ARBEID_ID,
DOKUMENT_UNDER_ARBEID_MARKERT_FERDIG,
DOKUMENT_UNDER_ARBEID_NAME,
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/db/migration/V104__Add_dato_mottatt.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE klage.dokument_under_arbeid
ADD COLUMN dato_mottatt DATE;
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ internal class DokumentUnderArbeidControllerTest {
any(),
any(),
any(),
any(),
)
} returns OpplastetDokumentUnderArbeidAsHoveddokument(
mellomlagerId = "mellomlagerId",
Expand All @@ -101,6 +102,7 @@ internal class DokumentUnderArbeidControllerTest {
id = UUID.randomUUID(),
creatorIdent = "null",
creatorRole = BehandlingRole.KABAL_SAKSBEHANDLING,
datoMottatt = null,
)

val file =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class DokumentUnderArbeidRepositoryTest {
creatorRole = KABAL_SAKSBEHANDLING,
created = LocalDateTime.now(),
modified = LocalDateTime.now(),
datoMottatt = null,
)
hovedDokument.markerFerdigHvisIkkeAlleredeMarkertFerdig(LocalDateTime.now(), "S123456")
hovedDokument.ferdigstillHvisIkkeAlleredeFerdigstilt(LocalDateTime.now())
Expand All @@ -79,6 +80,7 @@ class DokumentUnderArbeidRepositoryTest {
creatorRole = KABAL_SAKSBEHANDLING,
created = LocalDateTime.now(),
modified = LocalDateTime.now(),
datoMottatt = null,
)
dokumentUnderArbeidRepository.save(hovedDokument)

Expand Down Expand Up @@ -124,6 +126,7 @@ class DokumentUnderArbeidRepositoryTest {
creatorRole = KABAL_SAKSBEHANDLING,
created = LocalDateTime.now(),
modified = LocalDateTime.now(),
datoMottatt = null
)
dokumentUnderArbeidRepository.save(hovedDokument)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ class DokumentUnderArbeidServiceTest {
creatorRole = KABAL_SAKSBEHANDLING,
created = LocalDateTime.now(),
modified = LocalDateTime.now(),
datoMottatt = null,
)
dokumentUnderArbeidRepository.save(hovedDokument)
}
Expand Down