Skip to content
This repository has been archived by the owner on Feb 7, 2024. It is now read-only.

Commit

Permalink
AE-1860: Add hallinto-oikeus specific attachment in the end of käskyp…
Browse files Browse the repository at this point in the history
…äätös / varsinainen päätös document
  • Loading branch information
Juholei committed Aug 23, 2023
1 parent ac25318 commit a6670cf
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
(ns solita.etp.service.valvonta-kaytto.asha
(:require [solita.common.time :as time]
(:require [clojure.java.io :as io]
[solita.common.time :as time]
[solita.etp.exception :as exception]
[solita.etp.service.asha :as asha]
[solita.etp.service.valvonta-kaytto.hallinto-oikeus-attachment :as hao-attachment]
[solita.etp.service.valvonta-kaytto.toimenpide :as toimenpide]
[solita.etp.service.valvonta-kaytto.template :as template]
[solita.etp.service.valvonta-kaytto.store :as store]
Expand Down Expand Up @@ -216,6 +218,12 @@
(:ilmoitustunnus valvonta)])
:attach {:contact (map osapuoli->contact osapuolet)}}))

(defn add-hallinto-oikeus-attachment
"Adds hallinto-oikeus specific attachment to the end of the given pdf"
[db pdf hallinto-oikeus-id]
(pdf/merge-pdf [(io/input-stream pdf)
(hao-attachment/attachment-for-hallinto-oikeus-id db hallinto-oikeus-id)]))

(defn generate-pdf-document
[db whoami valvonta toimenpide ilmoituspaikat osapuoli osapuolet roolit]
(let [template-id (:template-id toimenpide)
Expand All @@ -224,9 +232,12 @@
tiedoksi (if (template/send-tiedoksi? template) (filter osapuoli/tiedoksi? osapuolet) [])
template-data (template-data db whoami valvonta toimenpide
osapuoli documents ilmoituspaikat
tiedoksi roolit)]
(pdf/generate-pdf->bytes {:template (:content template)
:data template-data})))
tiedoksi roolit)
generated-pdf (pdf/generate-pdf->bytes {:template (:content template)
:data template-data})]
(if (toimenpide/kaskypaatos-varsinainen-paatos? toimenpide)
(add-hallinto-oikeus-attachment db generated-pdf (-> toimenpide :type-specific-data :court))
generated-pdf)))

(defn log-toimenpide! [db aws-s3-client whoami valvonta toimenpide osapuolet ilmoituspaikat roolit]
(let [request-id (request-id (:id valvonta) (:id toimenpide))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
(ns solita.etp.service.valvonta-kaytto.hallinto-oikeus-attachment
(:require [solita.etp.db :as db]
[clojure.java.io :as io]))

(db/require-queries 'hallinto-oikeus)

(def attachment-directory-path "pdf/hallinto-oikeudet/")

(defn attachment-for-hallinto-oikeus-id [db hallinto-oikeus-id]
(if-let [attachment-name (->> {:hallinto-oikeus-id hallinto-oikeus-id}
(hallinto-oikeus-db/find-attachment-name-by-hallinto-oikeus-id db)
first
:attachment-name)]
(io/input-stream (io/resource (str attachment-directory-path attachment-name)))
(throw (Exception. (str "Attachment not found for hallinto-oikeus-id: " hallinto-oikeus-id)))))
4 changes: 4 additions & 0 deletions etp-backend/src/main/sql/solita/etp/db/hallinto-oikeus.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- name: find-attachment-name-by-hallinto-oikeus-id
select attachment_name
from hallinto_oikeus
where id = :hallinto-oikeus-id;

0 comments on commit a6670cf

Please sign in to comment.