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

Commit

Permalink
AE-1977: Save hallinto-oikeus attachment to object storage for osapuo…
Browse files Browse the repository at this point in the history
…li when creating käskypäätös / varsinainen päätös toimenpide
  • Loading branch information
Juholei committed Nov 10, 2023
1 parent e1427f4 commit 56e50e1
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,14 @@
(filter #(contains? osapuolet-with-document (:id %)) osapuolet))
osapuolet))

(defn store-hallinto-oikeus-attachment! [db aws-s3-client valvonta-id toimenpide osapuoli]
(let [hallinto-oikeus-id (-> toimenpide
:type-specific-data
:osapuoli-specific-data
(type-specific-data/find-administrative-court-id-from-osapuoli-specific-data (:id osapuoli)))
attachment (hao-attachment/attachment-for-hallinto-oikeus-id db hallinto-oikeus-id)]
(store/store-hallinto-oikeus-attachment aws-s3-client valvonta-id (:id toimenpide) osapuoli attachment)))

(defn log-toimenpide! [db aws-s3-client whoami valvonta toimenpide osapuolet ilmoituspaikat roolit]
(let [request-id (request-id (:id valvonta) (:id toimenpide))
sender-id (:email whoami)
Expand All @@ -254,6 +262,10 @@
(let [document (generate-pdf-document db whoami valvonta toimenpide ilmoituspaikat
osapuoli osapuolet roolit)]
(store/store-document aws-s3-client (:id valvonta) (:id toimenpide) osapuoli document)

(when (toimenpide/kaskypaatos-varsinainen-paatos? toimenpide)
(store-hallinto-oikeus-attachment! db aws-s3-client (:id valvonta) toimenpide osapuoli))

document)))))]
(asha/log-toimenpide!
sender-id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
[clojure.java.io :as io]))

(def document-file-key-prefix "valvonta/kaytto")
(def hallinto-oikeus-attachment-file-key-prefix "valvonta/kaytto/hallinto-oikeus-attachment")

(defn- file-path [file-key-prefix valvonta-id toimenpide-id osapuoli]
(cond
Expand All @@ -25,3 +26,11 @@

(defn info-letter []
(-> "pdf/Saate_rakennuksen_omistaja_su_ru.pdf" io/resource io/input-stream))

(defn ^:dynamic store-hallinto-oikeus-attachment
"Store the hallinto-oikeus attachment of the käytönvalvonta toimenpide to the object storage"
[aws-s3-client valvonta-id toimenpide-id osapuoli document]
(file-service/upsert-file-from-bytes
aws-s3-client
(file-path hallinto-oikeus-attachment-file-key-prefix valvonta-id toimenpide-id osapuoli)
document))
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@
[solita.etp.schema.valvonta-kaytto :as valvonta-schema]
[solita.etp.service.pdf :as pdf]
[solita.etp.service.valvonta-kaytto :as valvonta-service]
[solita.etp.service.valvonta-kaytto.store :as file-store]
[solita.etp.test-data.generators :as generators]
[solita.etp.test-data.kayttaja :as test-kayttajat]
[solita.etp.test-system :as ts])
(:import (java.time Clock LocalDate ZoneId)))

(t/use-fixtures :each ts/fixture)

(def original-store-hallinto-oikeus-attachment file-store/store-hallinto-oikeus-attachment)

(t/deftest kaskypaatos-varsinainen-paatos-test
;; Add the main user for the following tests
(test-kayttajat/insert-virtu-paakayttaja!
Expand All @@ -39,6 +42,7 @@
(.atStartOfDay (ZoneId/systemDefault))
.toInstant)
html->pdf-called? (atom false)
store-hallinto-oikeus-attachment-called? (atom false)
;; Add osapuoli to the valvonta
osapuoli-id (valvonta-service/add-henkilo!
ts/*db*
Expand Down Expand Up @@ -85,7 +89,11 @@
time/timezone)
#'pdf/html->pdf (partial html->pdf-with-assertion
"documents/kaskypaatos-varsinainen-paatos-yksityishenkilo.html"
html->pdf-called?)}
html->pdf-called?)
#'file-store/store-hallinto-oikeus-attachment
(fn [aws-s3-client valvonta-id toimenpide-id osapuoli document]
(reset! store-hallinto-oikeus-attachment-called? true)
(original-store-hallinto-oikeus-attachment aws-s3-client valvonta-id toimenpide-id osapuoli document))}
(let [new-toimenpide {:type-id 8
:deadline-date (str (LocalDate/of 2023 10 4))
:template-id 6
Expand All @@ -107,6 +115,7 @@
(test-kayttajat/with-virtu-user)
(mock/header "Accept" "application/json")))]
(t/is (true? @html->pdf-called?))
(t/is (true? @store-hallinto-oikeus-attachment-called?))
(t/is (= (:status response) 201))))

(t/testing "Created document can be downloaded through the api"
Expand Down

0 comments on commit 56e50e1

Please sign in to comment.