From 1f4d2dff42c489e7bcd578c0d9a02297727bdc3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Severi=20J=C3=A4=C3=A4skel=C3=A4inen?= Date: Wed, 18 Sep 2024 13:17:33 +0300 Subject: [PATCH] Fix based on PR comment --- .../tep/kestojenUudelleenlaskentaHandler.clj | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/oph/heratepalvelu/tep/kestojenUudelleenlaskentaHandler.clj b/src/oph/heratepalvelu/tep/kestojenUudelleenlaskentaHandler.clj index 3c7f1890..f61479a4 100644 --- a/src/oph/heratepalvelu/tep/kestojenUudelleenlaskentaHandler.clj +++ b/src/oph/heratepalvelu/tep/kestojenUudelleenlaskentaHandler.clj @@ -2,6 +2,7 @@ "Handler tyƶpaikkajaksojen kestojen uudelleenlaskentaa varten." (:require [clojure.tools.logging :as log] [environ.core :refer [env]] + [medley.core :refer [find-first]] [oph.heratepalvelu.db.dynamodb :as ddb] [oph.heratepalvelu.log.caller-log :refer [log-caller-details-scheduled]] @@ -36,13 +37,19 @@ (let [jaksot (:items resp)] (log/info "Processing" (count jaksot) "jaksoa.") (doseq [jakso jaksot] - (let [concurrent-jaksot (nh/get-concurrent-jaksot-from-ehoks! [jakso]) - opiskeluoikeudet (nh/get-and-memoize-opiskeluoikeudet! - concurrent-jaksot) - kestot (nh/oppijan-jaksojen-kestot - concurrent-jaksot opiskeluoikeudet) - jakso-key (nh/ids jakso)] - (if-let [new-kesto (get kestot jakso-key 0)] + (let [hankkimistapa_id (:hankkimistapa_id jakso) + concurrent-jaksot (nh/get-concurrent-jaksot-from-ehoks! [jakso]) + jakso-key (nh/ids jakso) + new-kesto + (if (find-first #(= (:hankkimistapa_id %) hankkimistapa_id) + concurrent-jaksot) + (get (nh/oppijan-jaksojen-kestot + concurrent-jaksot + (nh/get-and-memoize-opiskeluoikeudet! + concurrent-jaksot)) + jakso-key) + 0)] + (if (some? new-kesto) (do (log/info "Updating jakso" jakso-key "with kesto" new-kesto) (tc/update-jakso jakso