From 5b8b80ae0ac97e37a07b4fe19dfd3fb0aaa531aa Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Matti=20Pitka=CC=88ma=CC=88ki?= <matti.pitkamaki@gofore.com>
Date: Wed, 22 Jan 2025 13:17:05 +0200
Subject: [PATCH] Fixed schema problem

---
 src/clj/ataru/applications/application_service.clj |  5 ++---
 src/clj/ataru/applications/excel_export.clj        | 14 ++++++++------
 src/cljc/ataru/schema/form_properties_schema.cljc  |  3 ++-
 3 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/src/clj/ataru/applications/application_service.clj b/src/clj/ataru/applications/application_service.clj
index 759d288543..c5531be80f 100644
--- a/src/clj/ataru/applications/application_service.clj
+++ b/src/clj/ataru/applications/application_service.clj
@@ -563,13 +563,12 @@
                                                           distinct
                                                           (filter some?)
                                                           (person-service/get-persons person-service))
-            applications-with-persons-and-tutkinnot  (map (fn [application]
+            applications-with-persons                (map (fn [application]
                                                             (assoc application
                                                               :person (->> (:person-oid application)
                                                                           (get onr-persons)
                                                                           (person-service/parse-person-with-master-oid application))))
                                                           applications)
-                                                          ;TODO lisää tutkinnot
             hakukohteiden-ehdolliset         (delay (hakukohteiden-ehdolliset valinta-tulos-service applications))
             skip-answers-to-preserve-memory? (if (not-empty included-ids)
                                                (<= 200000 (count applications))
@@ -577,7 +576,7 @@
             lang                             (keyword (or (-> session :identity :lang) :fi))]
         (when skip-answers-to-preserve-memory? (log/warn "Answers will be skipped to preserve memory"))
         (if-let [xls (ByteArrayInputStream. (excel/export-applications liiteri-cas-client
-                                                                       applications-with-persons-and-tutkinnot
+                                                                       applications-with-persons
                                                                        application-reviews
                                                                        application-review-notes
                                                                        selected-hakukohde
diff --git a/src/clj/ataru/applications/excel_export.clj b/src/clj/ataru/applications/excel_export.clj
index 0be0b9a2e6..c3d7fbe2b6 100644
--- a/src/clj/ataru/applications/excel_export.clj
+++ b/src/clj/ataru/applications/excel_export.clj
@@ -8,6 +8,7 @@
                                         kasittelymerkinnat-field-labels]]
             [ataru.files.file-store :as file-store]
             [ataru.forms.form-store :as form-store]
+            [ataru.applications.application-store :as application-store]
             [ataru.koodisto.koodisto :as koodisto]
             [ataru.tarjonta-service.tarjonta-parser :as tarjonta-parser]
             [ataru.translations.texts :refer [excel-texts virkailija-texts]]
@@ -751,12 +752,13 @@
                                                     person                       (:person application)
                                                     ; Getting ehdollinen? is quite expensive operation. Do it later and only if ehdollinen-column is included.
                                                     ehdollinen?                  (delay (get-ehdollinen? get-hakukohde hakukohteiden-ehdolliset application selected-hakukohde-oids))
-                                                    tutkinnot                    (some->> (when
-                                                                                            (tutkinto-util/koski-tutkinnot-in-application? application) (:person-oid application))
-                                                                                          (koski/get-tutkinnot-for-oppija koski-service false)
-                                                                                          :opiskeluoikeudet
-                                                                                          (parse-koski-tutkinnot tutkinto-levels)
-                                                                                          (tutkinto-util/sort-koski-tutkinnot))]
+                                                    tutkinnot                    (when (tutkinto-util/koski-tutkinnot-in-application? application)
+                                                                                   (if (tutkinto-util/save-koski-tutkinnot? form)
+                                                                                     (application-store/koski-tutkinnot-for-application (:key application))
+                                                                                     (some->> (:person-oid application)
+                                                                                               (koski/get-tutkinnot-for-oppija koski-service false)
+                                                                                               :opiskeluoikeudet
+                                                                                               (parse-koski-tutkinnot tutkinto-levels))))]
                                                 (write-application! liiteri-cas-client
                                                                     row-writer
                                                                     application
diff --git a/src/cljc/ataru/schema/form_properties_schema.cljc b/src/cljc/ataru/schema/form_properties_schema.cljc
index 1cd1777845..853c21a5c7 100644
--- a/src/cljc/ataru/schema/form_properties_schema.cljc
+++ b/src/cljc/ataru/schema/form_properties_schema.cljc
@@ -14,7 +14,8 @@
 (s/defschema TutkintoProperties
              (merge FormCategoryProperties
                     {(s/optional-key :show-completed-studies)   s/Bool
-                     (s/optional-key :save-koski-tutkinnot)     s/Bool}))
+                     (s/optional-key :save-koski-tutkinnot)     s/Bool
+                     (s/optional-key :koski-update-allways)     s/Bool}))
 
 (s/defschema FormProperties
              {(s/optional-key :auto-expand-hakukohteet)          s/Bool