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

Commit

Permalink
Merge pull request #1041 from solita/feature/AE-1977
Browse files Browse the repository at this point in the history
Feature/ae 1977
  • Loading branch information
Juholei authored Nov 17, 2023
2 parents 9f0501c + d01336e commit f43f106
Show file tree
Hide file tree
Showing 13 changed files with 385 additions and 143 deletions.
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]
(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

0 comments on commit f43f106

Please sign in to comment.