Skip to content

Commit

Permalink
Merge pull request #1354 from navikt/require_address
Browse files Browse the repository at this point in the history
Validate if distribution will go to central print and there's no addr…
  • Loading branch information
oyvind-wedoe authored Feb 24, 2025
2 parents 582fdb4 + d208726 commit 238f98e
Showing 1 changed file with 49 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class DokumentUnderArbeidService(
validateCanCreateDocuments(
behandlingRole = behandlingRole,
parentDocument = if (parentId != null) getDokumentUnderArbeid(parentId)
as DokumentUnderArbeidAsHoveddokument else null
as DokumentUnderArbeidAsHoveddokument else null
)
}
}
Expand Down Expand Up @@ -356,7 +356,7 @@ class DokumentUnderArbeidService(
validateCanCreateDocuments(
behandlingRole = behandlingRole,
parentDocument = if (parentId != null) getDokumentUnderArbeid(parentId)
as DokumentUnderArbeidAsHoveddokument else null
as DokumentUnderArbeidAsHoveddokument else null
)
}

Expand All @@ -372,7 +372,7 @@ class DokumentUnderArbeidService(

val parentDocument =
getDokumentUnderArbeid(journalfoerteDokumenterInput.parentId)
as DokumentUnderArbeidAsHoveddokument
as DokumentUnderArbeidAsHoveddokument

if (parentDocument.isInngaaende()) {
throw DokumentValidationException("Kan ikke sette journalførte dokumenter som vedlegg til ${parentDocument.dokumentType.navn}.")
Expand Down Expand Up @@ -547,9 +547,10 @@ class DokumentUnderArbeidService(
}
}

fun getDokumentUnderArbeid(dokumentId: UUID): DokumentUnderArbeid = dokumentUnderArbeidRepository.findById(dokumentId).orElseThrow {
throw DocumentDoesNotExistException("Dokumentet med id $dokumentId finnes ikke.")
}
fun getDokumentUnderArbeid(dokumentId: UUID): DokumentUnderArbeid =
dokumentUnderArbeidRepository.findById(dokumentId).orElseThrow {
throw DocumentDoesNotExistException("Dokumentet med id $dokumentId finnes ikke.")
}

fun updateDokumentType(
behandlingId: UUID, //Kan brukes i finderne for å "være sikker", men er egentlig overflødig..
Expand Down Expand Up @@ -1305,21 +1306,40 @@ class DokumentUnderArbeidService(

fun validateDokumentUnderArbeidAndVedlegg(dokumentUnderArbeidId: UUID): List<DocumentValidationResponse> {
val dokumentUnderArbeid = getDokumentUnderArbeid(dokumentUnderArbeidId)
as DokumentUnderArbeidAsHoveddokument
as DokumentUnderArbeidAsHoveddokument
return validateDokumentUnderArbeidAndVedlegg(dokumentUnderArbeid = dokumentUnderArbeid)
}

private fun validateDokumentUnderArbeidAndVedlegg(dokumentUnderArbeid: DokumentUnderArbeidAsHoveddokument): List<DocumentValidationResponse> {

val behandling = behandlingService.getBehandlingForReadWithoutCheckForAccess(
behandlingId = dokumentUnderArbeid.behandlingId
)

val errors = mutableListOf<DocumentValidationResponse>()

dokumentUnderArbeid.avsenderMottakerInfoSet.forEach { mottaker ->
if (mottaker.identifikator != null) {
val part = partSearchService.searchPart(
val part = partSearchService.searchPartWithUtsendingskanal(
identifikator = mottaker.identifikator,
skipAccessControl = true
skipAccessControl = true,
sakenGjelderId = behandling.sakenGjelder.partId.value,
tema = behandling.ytelse.toTema(),
)

if (documentWillGoToCentralPrint(mottaker, part)) {
if (mottaker.address == null && part.address == null) {
errors += DocumentValidationResponse(
dokumentId = dokumentUnderArbeid.id,
errors = listOf(
DocumentValidationResponse.DocumentValidationError(
type = DocumentValidationResponse.DocumentValidationError.SmartDocumentErrorType.INVALID_RECIPIENT,
)
)
)
}
}

when (part.type) {
BehandlingDetaljerView.IdType.FNR -> if (part.statusList.any { it.status == BehandlingDetaljerView.PartStatus.Status.DEAD }) {
errors += DocumentValidationResponse(
Expand All @@ -1342,6 +1362,10 @@ class DokumentUnderArbeidService(
)
)
}

else -> {
error("Missing type in part")
}
}
}
}
Expand Down Expand Up @@ -1384,6 +1408,14 @@ class DokumentUnderArbeidService(

}

private fun documentWillGoToCentralPrint(
mottaker: DokumentUnderArbeidAvsenderMottakerInfo,
part: BehandlingDetaljerView.PartViewWithUtsendingskanal
): Boolean {
return mottaker.forceCentralPrint ||
(!mottaker.localPrint && part.utsendingskanal == BehandlingDetaljerView.Utsendingskanal.SENTRAL_UTSKRIFT)
}

private fun validateDocumentBeforeFerdig(
hovedDokument: DokumentUnderArbeidAsHoveddokument,
) {
Expand Down Expand Up @@ -1474,8 +1506,14 @@ class DokumentUnderArbeidService(

is DokumentUnderArbeidAsSmartdokument -> {
if (dokumentUnderArbeid.isPDFGenerationNeeded()) {
dokumentUnderArbeid.name to ByteArrayResource(mellomlagreNyVersjonAvSmartEditorDokumentAndGetPdf(dokumentUnderArbeid).bytes)
} else dokumentUnderArbeid.name to mellomlagerService.getUploadedDocumentAsSignedURL(dokumentUnderArbeid.mellomlagerId!!)
dokumentUnderArbeid.name to ByteArrayResource(
mellomlagreNyVersjonAvSmartEditorDokumentAndGetPdf(
dokumentUnderArbeid
).bytes
)
} else dokumentUnderArbeid.name to mellomlagerService.getUploadedDocumentAsSignedURL(
dokumentUnderArbeid.mellomlagerId!!
)
}

is JournalfoertDokumentUnderArbeidAsVedlegg -> {
Expand Down

0 comments on commit 238f98e

Please sign in to comment.