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

Feature/ae 1977 #1041

Merged
merged 18 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
89f7d07
AE-1977: Test fetching käskypäätös / varsinainen päätös documents
Juholei Nov 9, 2023
d1fb818
AE-1977: Move henkilot and yritykset to their own contexts in doc urls
Juholei Nov 9, 2023
4b7695c
AE-1977: Check in document fetch test that content-type is pdf
Juholei Nov 9, 2023
e221b26
AE-1977: Add endpoint for fetching hao-liite in toimenpide for person
Juholei Nov 9, 2023
43999c6
AE-1977: Remove hallinto-oikeus-liite from käskypäätös / varsinainen …
Juholei Nov 9, 2023
a61f01a
AE-1977: Add docstrings to functions for storing and retrieving käytö…
Juholei Nov 9, 2023
665c216
AE-1977: Fix lint issues in file storage service
Juholei Nov 9, 2023
4f556be
AE-1977: Save hallinto-oikeus attachment to object storage for osapuo…
Juholei Nov 9, 2023
cb1cc68
AE-1977: Fetch attachment from blob storage when calling hallinto-oik…
Juholei Nov 10, 2023
91a3c78
AE-1977: Fetch attachment from blob storage when calling hallinto-oik…
Juholei Nov 10, 2023
343716b
AE-1977: Test that the returned hao attachment is correct one
Juholei Nov 10, 2023
eced37b
AE-1977: Test for yritysosapuoli that attachment store fn is called
Juholei Nov 10, 2023
0df24be
AE-1977: Add authentication tests for fetching käytönvalvonta files
Juholei Nov 10, 2023
4547089
AE-1977: Remove add-hallinto-oikeus-attachment as unused
Juholei Nov 13, 2023
934dac2
AE-1977: Make attachment-for-hallinto-oikeus-id to return the file as…
Juholei Nov 13, 2023
8fa2280
AE-1977: Add attachments to asha in log-toimenpide!
Juholei Nov 13, 2023
8f1556e
AE-1977: add ! to store-document and store-hallinto-oikeus-attachment…
Juholei Nov 16, 2023
d01336e
AE-1977: Add hallinto-oikeusliite to sakkopäätös / varsinainen päätös…
Juholei Nov 17, 2023
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 @@ -16,13 +16,13 @@
{:get {:summary "Hae käytönvalvonnan toimenpiteet."
:parameters {:path {:id common-schema/Key}}
:responses {200 {:body [kaytto-schema/Toimenpide]}}
:access rooli-service/paakayttaja?
:access rooli-service/paakayttaja?
:handler (fn [{{{:keys [id]} :path} :parameters :keys [db]}]
(api-response/get-response
(valvonta-service/find-toimenpiteet db id)
(api-response/msg-404 "kaytonvalvonta" id)))}
:post {:summary "Lisää käytönvalvonnan toimenpide."
:access rooli-service/paakayttaja?
:access rooli-service/paakayttaja?
:parameters {:path {:id common-schema/Key}
:body kaytto-schema/ToimenpideAdd}
:responses {201 {:body common-schema/Id}
Expand All @@ -31,7 +31,7 @@
:parameters :keys [db aws-s3-client whoami uri]}]
(api-response/with-exceptions
#(api-response/created uri
(valvonta-service/add-toimenpide! db aws-s3-client whoami id body))
(valvonta-service/add-toimenpide! db aws-s3-client whoami id body))
[{:constraint :toimenpide-vk-valvonta-id-fkey
:response 404}]))}}]
["/henkilot/:henkilo-id/preview"
Expand Down Expand Up @@ -69,49 +69,82 @@
["/:toimenpide-id"
[""
{:conflicting true
:put {:summary "Muuta toimenpiteen tietoja."
:access rooli-service/paakayttaja?
:parameters {:path {:id common-schema/Key
:toimenpide-id common-schema/Key}
:body kaytto-schema/ToimenpideUpdate}
:responses {200 {:body nil}
404 {:body schema/Str}}
:handler (fn [{{{:keys [id toimenpide-id]} :path :keys [body]}
:parameters :keys [db]}]
(api-response/ok|not-found
(valvonta-service/update-toimenpide!
db toimenpide-id body)
(toimenpide-404-msg id toimenpide-id)))}}]

["/henkilot/:henkilo-id/document/:filename"
{:get {:summary "Henkilö-osapuolen toimenpiteen esikatselu tai lataus"
:parameters {:path {:id common-schema/Key
:toimenpide-id common-schema/Key
:henkilo-id common-schema/Key
:filename schema/Str}}
:access rooli-service/paakayttaja?
:responses {200 {:body nil}
404 {:body schema/Str}}
:handler (fn [{{{:keys [id toimenpide-id henkilo-id filename]} :path}
:parameters :keys [db aws-s3-client]}]
(api-response/pdf-response
(valvonta-service/find-toimenpide-henkilo-document
db aws-s3-client id toimenpide-id henkilo-id)
filename
(api-response/msg-404 "henkilo" id toimenpide-id henkilo-id)))}}]
["/yritykset/:yritys-id/document/:filename"
{:get {:summary "Yritys-osapuolen toimenpiteen esikatselu tai lataus"
:parameters {:path {:id common-schema/Key
:toimenpide-id common-schema/Key
:yritys-id common-schema/Key
:filename schema/Str}}
:access rooli-service/paakayttaja?
:responses {200 {:body nil}
404 {:body schema/Str}}
:handler (fn [{{{:keys [id toimenpide-id yritys-id filename]} :path}
:parameters :keys [db aws-s3-client]}]
(api-response/pdf-response
(valvonta-service/find-toimenpide-yritys-document
db aws-s3-client id toimenpide-id yritys-id)
filename
(api-response/msg-404 "yritys "id toimenpide-id yritys-id)))}}]]])
:put {:summary "Muuta toimenpiteen tietoja."
:access rooli-service/paakayttaja?
:parameters {:path {:id common-schema/Key
:toimenpide-id common-schema/Key}
:body kaytto-schema/ToimenpideUpdate}
:responses {200 {:body nil}
404 {:body schema/Str}}
:handler (fn [{{{:keys [id toimenpide-id]} :path :keys [body]}
:parameters :keys [db]}]
(api-response/ok|not-found
(valvonta-service/update-toimenpide!
db toimenpide-id body)
(toimenpide-404-msg id toimenpide-id)))}}]
["/henkilot"
["/:henkilo-id"
["/document/:filename"
{:get {:summary "Henkilö-osapuolen toimenpiteen dokumentin lataus"
:parameters {:path {:id common-schema/Key
:toimenpide-id common-schema/Key
:henkilo-id common-schema/Key
:filename schema/Str}}
:access rooli-service/paakayttaja?
:responses {200 {:body nil}
404 {:body schema/Str}}
:handler (fn [{{{:keys [id toimenpide-id henkilo-id filename]} :path}
:parameters :keys [db aws-s3-client]}]
(api-response/pdf-response
(valvonta-service/find-toimenpide-henkilo-document
db aws-s3-client id toimenpide-id henkilo-id)
filename
(api-response/msg-404 "henkilo" id toimenpide-id henkilo-id)))}}]
["/attachment"
["/hallinto-oikeus.pdf"
{:get {:summary "Henkilö-osapuolen toimenpiteeseen liittyvän hallinto-oikeus-liitteen lataus"
:parameters {:path {:id common-schema/Key
:toimenpide-id common-schema/Key
:henkilo-id common-schema/Key}}
:access rooli-service/paakayttaja?
:responses {200 {:body nil}
404 {:body schema/Str}}
:handler (fn [{{{:keys [id toimenpide-id henkilo-id]} :path}
:parameters :keys [db aws-s3-client]}]
(api-response/pdf-response
(valvonta-service/find-henkilo-hallinto-oikeus-attachment db aws-s3-client id toimenpide-id henkilo-id)
"hallinto-oikeus.pdf"
(api-response/msg-404 "henkilo" id toimenpide-id henkilo-id)))}}]]]]
["/yritykset"
["/:yritys-id"
["/document/:filename"
{:get {:summary "Yritys-osapuolen toimenpiteen esikatselu tai lataus"
:parameters {:path {:id common-schema/Key
:toimenpide-id common-schema/Key
:yritys-id common-schema/Key
:filename schema/Str}}
:access rooli-service/paakayttaja?
:responses {200 {:body nil}
404 {:body schema/Str}}
:handler (fn [{{{:keys [id toimenpide-id yritys-id filename]} :path}
:parameters :keys [db aws-s3-client]}]
(api-response/pdf-response
(valvonta-service/find-toimenpide-yritys-document
db aws-s3-client id toimenpide-id yritys-id)
filename
(api-response/msg-404 "yritys " id toimenpide-id yritys-id)))}}]
["/attachment"
["/hallinto-oikeus.pdf"
{:get {:summary "Yritys-osapuolen toimenpiteeseen liittyvän hallinto-oikeus-liitteen lataus"
:parameters {:path {:id common-schema/Key
:toimenpide-id common-schema/Key
:yritys-id common-schema/Key}}
:access rooli-service/paakayttaja?
:responses {200 {:body nil}
404 {:body schema/Str}}
:handler (fn [{{{:keys [id toimenpide-id yritys-id]} :path}
:parameters :keys [db aws-s3-client]}]
(api-response/pdf-response
(valvonta-service/find-yritys-hallinto-oikeus-attachment db aws-s3-client id toimenpide-id yritys-id)
"hallinto-oikeus.pdf"
(api-response/msg-404 "yritys " id toimenpide-id yritys-id)))}}]]]]]])
107 changes: 64 additions & 43 deletions etp-backend/src/main/clj/solita/etp/service/asha.clj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
[solita.etp.config :as config]
[clojure.string :as str])
(:import (java.nio.charset StandardCharsets)
(java.time Instant)
(java.util Base64)))

(def toplevel-processing-actions
Expand Down Expand Up @@ -218,48 +219,68 @@
(fn [name-identity] (reduce toplevel-processing-action-max
(cons name-identity (keys states))))))

(defn log-toimenpide! [sender-id request-id case-number processing-action & [documents]]
(let [processing-action-states (resolve-case-processing-action-state sender-id
request-id
case-number)
require-vireillepano (= {"Vireillepano" "NEW"} processing-action-states)
processing-action (-> processing-action
;; Possibly redirect the processing action to Vireillepano
(with-vireillepano require-vireillepano)
;; Prevent going backwards in the process
(with-latest-processing-action processing-action-states))]
(move-processing-action!
sender-id
request-id
case-number
processing-action-states
(-> processing-action :identity :processing-action :name-identity))
(take-processing-action!
sender-id
request-id
case-number
(-> processing-action :identity :processing-action :name-identity))

(execute-operation! {:request-id request-id
:sender-id sender-id
:identity (:identity processing-action)
:processing-action (:processing-action processing-action)})

(doseq [document documents]
(add-documents-to-processing-action!
sender-id
request-id
case-number
(-> processing-action :processing-action :name)
[{:content (bytes->base64 document)
:type (-> processing-action :document :type)
:name (-> processing-action :document :filename)}]))
(take-processing-action! sender-id request-id case-number (-> processing-action :processing-action :name))
(mark-processing-action-as-ready!
sender-id
request-id
case-number
(-> processing-action :processing-action :name))))
(defn log-toimenpide!
([sender-id request-id case-number processing-action]
(log-toimenpide! sender-id request-id case-number processing-action [] []))
([sender-id request-id case-number processing-action documents]
(log-toimenpide! sender-id request-id case-number processing-action documents []))
([sender-id request-id case-number processing-action documents attachments]
(let [processing-action-states (resolve-case-processing-action-state sender-id
request-id
case-number)
require-vireillepano (= {"Vireillepano" "NEW"} processing-action-states)
processing-action (-> processing-action
;; Possibly redirect the processing action to Vireillepano
(with-vireillepano require-vireillepano)
;; Prevent going backwards in the process
(with-latest-processing-action processing-action-states))]
(move-processing-action!
sender-id
request-id
case-number
processing-action-states
(-> processing-action :identity :processing-action :name-identity))
(take-processing-action!
sender-id
request-id
case-number
(-> processing-action :identity :processing-action :name-identity))

(execute-operation! {:request-id request-id
:sender-id sender-id
:identity (:identity processing-action)
:processing-action (:processing-action processing-action)})

(doseq [document documents]
(add-documents-to-processing-action!
sender-id
request-id
case-number
(-> processing-action :processing-action :name)
[{:content (bytes->base64 document)
:type (-> processing-action :document :type)
:name (-> processing-action :document :filename)}]))

(doseq [attachment attachments]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nyt ei vissiin testata että liitteet liitetään? Ei taideta kyllä testata dokumenttejakaan sen puoleen.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Joo, en lähtenyt perehtymään siihen ashalle lähtevän sanoman testaamiseen. Onko sulla kokemusta miten se onnistuisi kätevästi?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kätevästi ei. Kai se samankaltainen pyyntö on kuin muutkin asha-testin pyynnöt, mutta vaatisi oikeanlaisen jotain vakoilua että saisi oikeanlaisen kysymys ja vastaus formaatin

(when (nil? (-> processing-action :attachment))
(throw (Exception.
(format "Received attachment for processing action %s but it has no attachments defined"
(-> processing-action :processing-action :name)))))
(add-documents-to-processing-action!
sender-id
request-id
case-number
(-> processing-action :processing-action :name)
[{:content (bytes->base64 attachment)
:type (-> processing-action :attachment :type)
:name (-> processing-action :attachment :filename)}]))

(take-processing-action! sender-id request-id case-number (-> processing-action :processing-action :name))
(mark-processing-action-as-ready!
sender-id
request-id
case-number
(-> processing-action :processing-action :name)))))

(defn close-case! [sender-id request-id case-number description]
(let [latest-prosessing-action (resolve-latest-case-processing-action-state sender-id request-id case-number)]
Expand All @@ -271,7 +292,7 @@
{:identity {:case {:number case-number}
:processing-action {:name-identity latest-prosessing-action}}
:processing-action {:name "Asian sulkeminen"
:reception-date (java.time.Instant/now)
:reception-date (Instant/now)
:description description}}))
(proceed-operation! sender-id request-id case-number latest-prosessing-action "Sulje asia")))

Expand Down
7 changes: 4 additions & 3 deletions etp-backend/src/main/clj/solita/etp/service/file.clj
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
(ns solita.etp.service.file
(:require [clojure.java.io :as io]
[solita.common.aws :as aws])
(:import (java.io FileInputStream)))
(:import (clojure.lang ExceptionInfo)
(java.io File FileInputStream)))

(defn file->byte-array [file]
(defn file->byte-array [^File file]
(-> file FileInputStream. .readAllBytes))

(defn upsert-file-from-bytes [aws-s3-client key bytes]
Expand All @@ -23,7 +24,7 @@
(try
(aws/get-object-head aws-s3-client key)
true
(catch clojure.lang.ExceptionInfo e
(catch ExceptionInfo e
(let [{:keys [type]} (ex-data e)]
(if (= type :resource-not-found)
false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,12 @@
(defn find-toimenpide-yritys-document [db aws-s3-client valvonta-id toimenpide-id yritys-id]
(store/find-document aws-s3-client valvonta-id toimenpide-id (find-yritys db yritys-id)))

(defn find-henkilo-hallinto-oikeus-attachment [db aws-s3-client valvonta-id toimenpide-id henkilo-id]
(store/find-hallinto-oikeus-attachment aws-s3-client valvonta-id toimenpide-id (find-henkilo db henkilo-id)))

(defn find-yritys-hallinto-oikeus-attachment [db aws-s3-client valvonta-id toimenpide-id yritys-id]
(store/find-hallinto-oikeus-attachment aws-s3-client valvonta-id toimenpide-id (find-yritys db yritys-id)))

(defn find-notes [db id]
(valvonta-kaytto-db/select-valvonta-notes
db {:valvonta-id id}))
Expand Down
Loading