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 #1048 from solita/feature/AE-2014
Browse files Browse the repository at this point in the history
Feature/ae 2014
  • Loading branch information
Juholei authored Dec 20, 2023
2 parents d362893 + abd1b02 commit f462500
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 56 deletions.
68 changes: 45 additions & 23 deletions etp-backend/src/main/clj/solita/etp/service/asha.clj
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
["Vireillepano"
"Käsittely"
"Päätöksenteko"
"Tiedoksianto ja toimeenpano"
"Valitusajan umpeutuminen"])
"Tiedoksianto ja toimeenpano"])

(defn- must-exist! [n]
(when (< n 0)
Expand Down Expand Up @@ -182,18 +181,49 @@
last))

(defn move-processing-action!
"Move the case to the next step, if it the new action (processing-action parameter) is in Käsittely or Päätöksenteko
and the desired state is not already reached (not in processing-action-states)."
[sender-id request-id case-number processing-action-states processing-action]
(when-let [action (case processing-action
"Käsittely" {:processing-action "Vireillepano"
:decision "Siirry käsittelyyn"}
"Päätöksenteko" {:processing-action "Käsittely"
:decision "Siirry päätöksentekoon"}
"Valitusajan umpeutuminen" {:processing-action "Tiedoksianto ja toimeenpano"
:decision "Valmis"}
nil)]
(when (not (get processing-action-states processing-action))
"Move the case to the next step, if the new action (wanted-processing-action parameter) is valid and
the case is not already in that state.
`processing-action-states` parameter is a map containing the processing actions that are already made and their states.
Note that this is used for both käytönvalvonta and oikeellisuuden valvonta."
[sender-id request-id case-number processing-action-states wanted-processing-action]
(when-let [action (cond
;; First time going to käsittely, Tiedoksianto ja toimeenpano toimenpide doesn't exist yet
;; Transition from Vireillepano to Käsittely is Siirry käsittelyyn
(and (= wanted-processing-action "Käsittely")
(every? #(not= ["Tiedoksianto ja toimeenpano" "UNFINISHED"] %) processing-action-states))
{:processing-action "Vireillepano"
:decision "Siirry käsittelyyn"}

;; Moving from Käsittely to Päätöksenteko is done by Siirry päätöksentekoon transition.
;; The transition is the same no matter if it's the first or second or
;; nth time moving to Päätöksenteko
(= wanted-processing-action "Päätöksenteko")
{:processing-action "Käsittely"
:decision "Siirry päätöksentekoon"}

;; Moving from Päätöksenteko to Tiedoksianto ja toimeenpano is done by Siirry tiedoksiantoon transition.
;; The transition is the same no matter if it's the first or second or
;; nth time moving to Tiedoksianto ja toimeenpano
(= wanted-processing-action "Tiedoksianto ja toimeenpano")
{:processing-action "Päätöksenteko"
:decision "Siirry tiedoksiantoon"}

;; Moving from Tiedoksianto ja toimeenpano to Käsittely is done by Uudelleenkäsittele asia transition.
;; If wanted-processing-action is Käsittely and Tiedoksianto ja toimeenpano toimenpide exists
;; and is UNFINISHED, Uudelleenkäsittele asia transition is used.
;; This is used in käytönvalvonta when moving to Sakkopäätös / kuulemiskirje toimenpide.
(and (= wanted-processing-action "Käsittely")
(some #(= ["Tiedoksianto ja toimeenpano" "UNFINISHED"] %) processing-action-states))
{:processing-action "Tiedoksianto ja toimeenpano"
:decision "Uudelleenkäsittele asia"}

:else nil)]

;; If the action is already in the desired state, do nothing. It is allowed to move to a state that
;; has already been handled previously (state is READY).
(when-not (contains? #{"NEW" "UNFINISHED"} (get processing-action-states wanted-processing-action))
(proceed-operation! sender-id request-id case-number (:processing-action action) (:decision action)))))

(defn mark-processing-action-as-ready! [sender-id request-id case-number processing-action]
Expand All @@ -213,12 +243,6 @@
"Vireillepano")
processing-action))

(defn with-latest-processing-action [processing-action states]
(update-in processing-action
[:identity :processing-action :name-identity]
(fn [name-identity] (reduce toplevel-processing-action-max
(cons name-identity (keys states))))))

(defn log-toimenpide!
([sender-id request-id case-number processing-action]
(log-toimenpide! sender-id request-id case-number processing-action [] []))
Expand All @@ -231,9 +255,7 @@
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))]
(with-vireillepano require-vireillepano))]
(move-processing-action!
sender-id
request-id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,24 +137,17 @@
:contact (map osapuoli->contact osapuolet)}
:document (toimenpide-type->document (:type-id toimenpide))}
:decision-order-hearing-letter {:identity {:case {:number (:diaarinumero toimenpide)}
:processing-action {:name-identity "Päätöksenteko"}}
:processing-action {:name-identity "Käsittely"}}
:document (toimenpide-type->document (:type-id toimenpide))
:processing-action {:name "Kuulemiskirje käskypäätöksestä"
:processing-action {:name "Kuuleminen uhkasakon asettamisesta"
:reception-date (Instant/now)
:contacting-direction "SENT"
:contact (map osapuoli->contact osapuolet)}}
: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"
:contact (map osapuoli->contact osapuolet)}}
:decision-order-notice-first-mailing {:identity {:case {:number (:diaarinumero toimenpide)}
:processing-action {:name-identity "Tiedoksianto ja toimeenpano"}}
:document (toimenpide-type->document (:type-id toimenpide))
:processing-action {:name "Päätös tiedoksi - ensimmäinen postitus"
:processing-action {:name "Uhkasakon asettaminen"
:reception-date (Instant/now)
:contacting-direction "SENT"
:contact (map osapuoli->contact osapuolet)}}
Expand All @@ -166,24 +159,17 @@
:contacting-direction "SENT"
:contact (map osapuoli->contact osapuolet)}}
:penalty-decision-hearing-letter {:identity {:case {:number (:diaarinumero toimenpide)}
:processing-action {:name-identity "Päätöksenteko"}}
:processing-action {:name-identity "Käsittely"}}
:document (toimenpide-type->document (:type-id toimenpide))
:processing-action {:name "Kuulemiskirje uhkasakkopäätöksestä"
:processing-action {:name "Kuuleminen uhkasakon tuomitsemisesta"
:reception-date (Instant/now)
:contacting-direction "SENT"
:contact (map osapuoli->contact osapuolet)}}
:penalty-decision-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 "Sakkopäätös"
:reception-date (Instant/now)
:contacting-direction "SENT"
:contact (map osapuoli->contact osapuolet)}}
:penalty-decision-notice-first-mailing {:identity {:case {:number (:diaarinumero toimenpide)}
:processing-action {:name-identity "Päätöksenteko"}}
:document (toimenpide-type->document (:type-id toimenpide))
:processing-action {:name "Uhkasakkopäätös tiedoksi - ensimmäinen postitus"
:processing-action {:name "Uhkasakon tuomitseminen maksettavaksi"
:reception-date (Instant/now)
:contacting-direction "SENT"
:contact (map osapuoli->contact osapuolet)}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,9 @@
:rfi-warning
:decision-order-hearing-letter
:decision-order-actual-decision
:decision-order-notice-first-mailing
:decision-order-notice-bailiff
:penalty-decision-hearing-letter
:penalty-decision-actual-decision
:penalty-decision-notice-first-mailing
:penalty-decision-notice-bailiff}))


Expand Down
40 changes: 33 additions & 7 deletions etp-backend/src/test/clj/solita/etp/service/asha_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
[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)
(:import (clojure.lang ExceptionInfo)
(java.nio.charset StandardCharsets)
(java.time Instant)
(java.util Base64)))

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

(defn- handle-request [request-resource response-resource response-status & [exception]]
(defn- handle-request [request-resource response-resource response-status & [^String exception]]
(fn [request]
(t/is (= (str/trim request) (-> request-resource io/resource slurp str/trim)))
(if exception
Expand Down Expand Up @@ -99,7 +100,7 @@
"asha/case-create-response-without-sender-id.xml"
400
"clj-http: status 400")]
(t/is (thrown-with-msg? clojure.lang.ExceptionInfo
(t/is (thrown-with-msg? ExceptionInfo
#"Asiahallinta request failed. Posting the request failed."
(asha-service/open-case!
{:request-id "ETP-1"
Expand Down Expand Up @@ -266,9 +267,7 @@
case-number 100]
(t/testing "Move ignores the toimenpide if the action is"
(t/testing "Vireillepano"
(asha-service/move-processing-action! sender-id request-id case-number {} "Vireillepano"))
(t/testing "Tiedoksianto ja toimeenpano"
(asha-service/move-processing-action! sender-id request-id case-number {} "Tiedoksianto ja toimeenpano")))
(asha-service/move-processing-action! sender-id request-id case-number {} "Vireillepano")))
(t/testing "Move is skipped if the toimenpide is already in correct state"
(let [processing-action-states {"Vireillepano" "READY" "Käsittely" "NEW"}
processing-action "Käsittely"]
Expand All @@ -288,7 +287,7 @@
:request-received move-called}})]
(asha-service/move-processing-action! sender-id request-id case-number {} "Käsittely")
(t/is (= 1 @move-called)))))
(t/testing "Move from Päätöksenteko to Käsittely"
(t/testing "Move from Käsittely to Päätöksenteko"
(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
Expand All @@ -299,4 +298,31 @@
:response-status 200
:request-received move-called}})]
(asha-service/move-processing-action! sender-id request-id case-number {} "Päätöksenteko")
(t/is (= 1 @move-called)))))

(t/testing "Move from Päätöksenteko to Tiedoksianto ja toimeenpano"
(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 "Päätöksenteko"
:proceed-decision "Siirry tiedoksiantoon"})
{:response-body "Irrelevant"
:response-status 200
:request-received move-called}})]
(asha-service/move-processing-action! sender-id request-id case-number {} "Tiedoksianto ja toimeenpano")
(t/is (= 1 @move-called)))))

(t/testing "Move from Tiedoksianto ja toimeenpano to Käsittely using 'uudelleenkäsittele asia' decision"
(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 "Tiedoksianto ja toimeenpano"
:proceed-decision "Uudelleenkäsittele asia"})
{:response-body "Irrelevant"
:response-status 200
:request-received move-called}})]
(asha-service/move-processing-action! sender-id request-id case-number {"Tiedoksianto ja toimeenpano" "UNFINISHED"
"Käsittely" "FINISHED"} "Käsittely")
(t/is (= 1 @move-called))))))))
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@
(t/is (true? (toimenpide/kaskypaatos-toimenpide? {:type-id 9}))))
(t/testing "is not sakkopaatos-toimenpide?"
(t/is (false? (toimenpide/sakkopaatos-toimenpide? {:type-id 9}))))
(t/testing "is asha-toimenpide?"
(t/is (true? (toimenpide/asha-toimenpide? {:type-id 9})))))
(t/testing "is not asha-toimenpide?"
(t/is (false? (toimenpide/asha-toimenpide? {:type-id 9})))))

(t/testing "Käskypäätös / tiedoksianto (toinen postitus)"
(t/testing "has type-id 10 and type-key :decision-order-notice-second-mailing"
Expand Down Expand Up @@ -234,8 +234,8 @@
(t/is (false? (toimenpide/kaskypaatos-toimenpide? {:type-id 16}))))
(t/testing "is sakkopaatos-toimenpide?"
(t/is (true? (toimenpide/sakkopaatos-toimenpide? {:type-id 16}))))
(t/testing "is asha-toimenpide?"
(t/is (true? (toimenpide/asha-toimenpide? {:type-id 16})))))
(t/testing "is not asha-toimenpide?"
(t/is (false? (toimenpide/asha-toimenpide? {:type-id 16})))))

(t/testing "Sakkopäätös / tiedoksianto (toinen postitus)"
(t/testing "has type-id 17 and type-key :penalty-decision-notice-second-mailing"
Expand Down

0 comments on commit f462500

Please sign in to comment.