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

Commit

Permalink
AE-1977: Add attachments to asha in log-toimenpide!
Browse files Browse the repository at this point in the history
- Hallinto-oikeus attachments are sent to asha when creating käskypäätös / varsinainen päätös toimenpide
- Refactor log-toimenpide! to multiarity function from variadic
  • Loading branch information
Juholei committed Nov 16, 2023
1 parent 934dac2 commit 8fa2280
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 59 deletions.
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
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@
:filename "haastemies-tiedoksianto.pdf"}}]
(get documents type-key)))

(defn toimenpide-type->attachment [type-id]
(let [type-key (toimenpide/type-key type-id)
attachments {:decision-order-actual-decision {:type "Kirje"
:filename "hallinto-oikeus.pdf"}}]
(get attachments type-key)))

(defn find-kaytto-valvonta-documents [db valvonta-id]
(->> (valvonta-kaytto-db/select-valvonta-documents db {:valvonta-id valvonta-id})
(map (fn [toimenpide]
Expand Down Expand Up @@ -134,6 +140,7 @@
:decision-order-actual-decision {:identity {:case {:number (:diaarinumero toimenpide)}
:processing-action {:name-identity "Päätöksenteko"}}
:document (toimenpide-type->document (:type-id toimenpide))
:attachment (toimenpide-type->attachment (:type-id toimenpide))
:processing-action {:name "Käskypäätös"
:reception-date (Instant/now)
:contacting-direction "SENT"
Expand Down Expand Up @@ -251,7 +258,8 @@
: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)))
(store/store-hallinto-oikeus-attachment aws-s3-client valvonta-id (:id toimenpide) osapuoli attachment)
attachment))

(defn log-toimenpide! [db aws-s3-client whoami valvonta toimenpide osapuolet ilmoituspaikat roolit]
(let [request-id (request-id (:id valvonta) (:id toimenpide))
Expand All @@ -270,13 +278,20 @@
(when (toimenpide/kaskypaatos-varsinainen-paatos? toimenpide)
(store-hallinto-oikeus-attachment! db aws-s3-client (:id valvonta) toimenpide osapuoli))

document)))))]
document)))))
attachments (when (toimenpide/kaskypaatos-varsinainen-paatos? toimenpide)
(->> osapuolet
(filter osapuoli/omistaja?)
(remove-osapuolet-with-no-document toimenpide)
(mapv (fn [osapuoli]
(store-hallinto-oikeus-attachment! db aws-s3-client (:id valvonta) toimenpide osapuoli)))))]
(asha/log-toimenpide!
sender-id
request-id
case-number
processing-action
documents)))
documents
attachments)))

(defn close-case! [whoami valvonta-id toimenpide]
(asha/close-case!
Expand Down
51 changes: 38 additions & 13 deletions etp-backend/src/test/clj/solita/etp/service/asha_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
[clojure.string :as str]
[clojure.test :as t]
[solita.etp.service.asha :as asha-service]
[solita.etp.service.valvonta-kaytto.hallinto-oikeus-attachment :as hao]
[solita.etp.test-system :as ts]
[clostache.parser :refer [render-resource]])
(:import (java.nio.charset StandardCharsets)
Expand Down Expand Up @@ -207,10 +208,10 @@
:request-received take-processing-action-called}

(render-resource "asha/logtoimenpide/create-processing-action-operation-template.xml"
(merge render-context {:processing-action used-processing-action
:processing-action-operation-name processing-action-operation-name
:description description
:reception-date now}))
(merge render-context {:processing-action used-processing-action
:processing-action-operation-name processing-action-operation-name
:description description
:reception-date now}))
{:response-status 200
:request-received create-processing-action-operation}

Expand All @@ -232,7 +233,31 @@
(t/is (= 1 @take-processing-action-called))
(t/is (= 1 @create-processing-action-operation))
(t/is (= 1 @take-processing-action-for-operation))
(t/is (= 1 @mark-processing-action-operation-ready)))))
(t/is (= 1 @mark-processing-action-operation-ready))))

(t/testing "Exception is thrown when log-toimenpide is called with attachments but the toimenpidetype doesn't have attachments defined"
(let [request-id "request-id"
case-number 100
sender-id "solita"
original-processing-action "Käsittely"
processing-action-operation-name "Kehotus"
description "Kuvaus"
now (Instant/now)]
(t/is (thrown-with-msg?
Exception
#"Received attachment for processing action Kehotus but it has no attachments defined"
(asha-service/log-toimenpide! sender-id
request-id
case-number
{:identity {:case {:number case-number}
:processing-action {:name-identity original-processing-action}}
:processing-action {:name processing-action-operation-name
:reception-date now
:description description}}
;; Using hallinto-oikeus attachment as a document and an attachment
;; here to just have some file
[(hao/attachment-for-hallinto-oikeus-id ts/*db* 3)]
(hao/attachment-for-hallinto-oikeus-id ts/*db* 4)))))))

(t/deftest move-processing-action-test
(binding [asha-service/post! (handle-requests {})] ;; There should be no requests - fail all
Expand All @@ -254,10 +279,10 @@
[asha-service/post!
(handle-requests
{(render-resource "asha/moveaction/move-template.xml" {:sender-id sender-id
:request-id request-id
:case-number case-number
:processing-action "Vireillepano"
:proceed-decision "Siirry käsittelyyn"})
:request-id request-id
:case-number case-number
:processing-action "Vireillepano"
:proceed-decision "Siirry käsittelyyn"})
{:response-body "Irrelevant"
:response-status 200
:request-received move-called}})]
Expand All @@ -266,10 +291,10 @@
(t/testing "Move from Päätöksenteko to Käsittely"
(let [move-called (atom 0)]
(binding [asha-service/post! (handle-requests {(render-resource "asha/moveaction/move-template.xml" {:sender-id sender-id
:request-id request-id
:case-number case-number
:processing-action "Käsittely"
:proceed-decision "Siirry päätöksentekoon"})
:request-id request-id
:case-number case-number
:processing-action "Käsittely"
:proceed-decision "Siirry päätöksentekoon"})
{:response-body "Irrelevant"
:response-status 200
:request-received move-called}})]
Expand Down

0 comments on commit 8fa2280

Please sign in to comment.