Skip to content

Commit

Permalink
OY-3070 read synthetic application enabled flag and form key from ohj…
Browse files Browse the repository at this point in the history
…ausparametrit
  • Loading branch information
vaeinoe committed Nov 20, 2023
1 parent b4bb354 commit 1a45cd7
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 29 deletions.
4 changes: 4 additions & 0 deletions spec/ataru/fixtures/synthetic_application.clj
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
:toisenAsteenSuoritusmaa nil
})

; Mock ohjausparametrit service returns false / empty synthetic application data with this haku OID
(def synthetic-application-with-disabled-haku
(merge synthetic-application-basic {:hakuOid "1.2.246.562.29.12345678910"}))

(def synthetic-application-foreign
{:hakuOid "1.2.246.562.29.93102260101"
:hakukohdeOid "1.2.246.562.20.49028196522"
Expand Down
6 changes: 5 additions & 1 deletion spec/ataru/virkailija/virkailija_routes_spec.clj
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@
(do
(should-be-nil (:hakemusOid application))
(should-not-be-nil (:failures application))
(should= "application-validation-failed-error" (:code application)))
(should-not-be-nil (:code application)))
(do
(should-be-nil (:failures application))
(should-be-nil (:code application))
Expand Down Expand Up @@ -465,6 +465,10 @@
synthetic-application-fixtures/synthetic-application-foreign]
(check-synthetic-applications resp 2 #{})))

(it "should not validate and store synthetic application for haku that doesn't have synthetic applications enabled"
(with-synthetic-response :post resp [synthetic-application-fixtures/synthetic-application-with-disabled-haku]
(check-synthetic-applications resp 1 #{0})))

(it "should not store anything when one or more applications fail validation"
(with-synthetic-response :post resp [synthetic-application-fixtures/synthetic-application-basic
synthetic-application-fixtures/synthetic-application-malformed
Expand Down
8 changes: 3 additions & 5 deletions src/clj/ataru/hakija/hakija_form_service.clj
Original file line number Diff line number Diff line change
Expand Up @@ -356,11 +356,9 @@
roles
use-toisen-asteen-yhteishaku-restrictions?))))

(defn latest-form-id-by-haku-oid
[haku-oid tarjonta-service]
(some-> (tarjonta/get-haku tarjonta-service haku-oid)
:ataru-form-key
form-store/latest-id-by-key))
(defn latest-form-id-by-key
[key]
(form-store/latest-id-by-key key))

(defn- form-by-haku-oid-cache-key
[haku-oid roles]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
(defrecord MockOhjausparametritService []
OhjausparametritService

(get-parametri [_ _]
(get-parametri [_ haku-oid]
{:PH_SS {:dateStart 1506920400000, :dateEnd nil},
:PH_OPVP {:date nil},
:PH_HKMT {:date nil},
Expand All @@ -20,5 +20,7 @@
:target "1.2.246.562.29.75477542726",
:PH_VTJH {:dateStart nil, :dateEnd nil},
:PH_IP {:date nil},
:synteettisetHakemukset (not (= haku-oid "1.2.246.562.29.12345678910")),
:synteettisetLomakeavain (if (= haku-oid "1.2.246.562.29.12345678910") "" "synthetic-application-test-form"),
:__modifiedBy__ "1.2.246.562.24.64667668834",
:__modified__ 1508400869203}))
71 changes: 49 additions & 22 deletions src/clj/ataru/virkailija/virkailija_application_service.clj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,17 @@
[ataru.tarjonta-service.tarjonta-parser :as tarjonta-parser]
[ataru.util :as util]
[taoensso.timbre :as log]
[ataru.person-service.person-integration :as person-integration]))
[ataru.person-service.person-integration :as person-integration]
[ataru.ohjausparametrit.ohjausparametrit-protocol :as ohjausparametrit]))

(defn- uses-synthetic-applications?
[ohjausparametrit-service haku-oid]
(get (ohjausparametrit/get-parametri ohjausparametrit-service haku-oid) :synteettisetHakemukset))

(defn- synthetic-application-form-key
[ohjausparametrit-service haku-oid]
(get (ohjausparametrit/get-parametri ohjausparametrit-service haku-oid) :synteettisetLomakeavain))


(defn- store-synthetic-application [{:keys [application form applied-hakukohteet]}
{:keys [session audit-logger job-runner person-service]}]
Expand Down Expand Up @@ -35,25 +45,41 @@
applied-hakukohteet (filter #(contains? (set (:hakukohde application)) (:oid %))
hakukohteet)
applied-hakukohderyhmat (set (mapcat :hakukohderyhmat applied-hakukohteet))
form (hakija-form-service/fetch-form-by-id
(:form application)
[:virkailija] ; TODO is this the correct role?
form-by-id-cache
koodisto-cache
nil
false
{}
false)
validation-result (validator/valid-application?
koodisto-cache
false ; TODO: has-applied OK?
application
form
applied-hakukohderyhmat
true
"NEW_APPLICATION_ID"
"NEW_APPLICATION_KEY")
form (when (:form application) (hakija-form-service/fetch-form-by-id
(:form application)
[:virkailija]
form-by-id-cache
koodisto-cache
nil
false
{}
false))
validation-result (when form (validator/valid-application?
koodisto-cache
false ; TODO: has-applied OK?
application
form
applied-hakukohderyhmat
true
"NEW_APPLICATION_ID"
"NEW_APPLICATION_KEY"))
result (cond
(and (:haku application)
(not (uses-synthetic-applications? ohjausparametrit-service (:haku application))))
{:passed? false
:failures ["Synthetic applications not enabled for haku"]
:code :internal-server-error}

(not (:form application))
{:passed? false
:failures ["Synthetic form key not defined for haku"]
:code :internal-server-error}

(not form)
{:passed? false
:failures ["Synthetic form was not found with form key"]
:code :internal-server-error}

(and (:haku application)
(empty? (:hakukohde application)))
{:passed? false
Expand Down Expand Up @@ -84,9 +110,10 @@
(log/warn "Synthetic application failed verification" result)
result))))

(defn- convert-synthetic-application
[application {:keys [tarjonta-service]}]
(let [form-id (hakija-form-service/latest-form-id-by-haku-oid (:hakuOid application) tarjonta-service)
(defn- convert-synthetic-application
[application {:keys [ohjausparametrit-service]}]
(let [haku-oid (:hakuOid application)
form-id (hakija-form-service/latest-form-id-by-key (synthetic-application-form-key ohjausparametrit-service haku-oid))
converted (synthetic-application-util/synthetic-application->application application form-id)]
(log/info "Synthetic application submitted and converted" converted)
converted))
Expand Down

0 comments on commit 1a45cd7

Please sign in to comment.