Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Joint degree functionaliteit #353

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/nl/surf/eduhub_rio_mapper/commands/processing.clj
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
[nl.jomco.http-status-codes :as http-status]
[nl.surf.eduhub-rio-mapper.commands.dry-run :as dry-run]
[nl.surf.eduhub-rio-mapper.commands.link :as link]
[nl.surf.eduhub-rio-mapper.ooapi.base :as ooapi-base]
[nl.surf.eduhub-rio-mapper.ooapi.loader :as ooapi.loader]
[nl.surf.eduhub-rio-mapper.rio.loader :as rio.loader]
[nl.surf.eduhub-rio-mapper.rio.mutator :as mutator]
Expand Down Expand Up @@ -63,10 +64,14 @@
(ooapi.loader/load-entities validating-loader request)))))

(defn- make-updater-resolve-phase [{:keys [resolver]}]
(fn resolve-phase [{::ooapi/keys [type id] :keys [institution-oin action] ::rio/keys [opleidingscode] :as request}]
(fn resolve-phase [{:keys [institution-oin action]
::ooapi/keys [type id entity]
::rio/keys [opleidingscode] :as request}]
{:pre [institution-oin]}
(let [resolve-eduspec (= type "education-specification")
edu-id (updated-handler/education-specification-id request)
edu-id (if (= type "education-specification")
id
(ooapi-base/education-specification-id entity))
oe-code (or opleidingscode
(resolver "education-specification" edu-id institution-oin))
ao-code (when-not resolve-eduspec (resolver type id institution-oin))]
Expand Down
49 changes: 25 additions & 24 deletions src/nl/surf/eduhub_rio_mapper/ooapi/loader.clj
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
[nl.surf.eduhub-rio-mapper.specs.ooapi :as ooapi]
[nl.surf.eduhub-rio-mapper.specs.program :as program]
[nl.surf.eduhub-rio-mapper.specs.request :as request]
[nl.surf.eduhub-rio-mapper.specs.rio :as rio]
[nl.surf.eduhub-rio-mapper.utils.http-utils :as http-utils]
[nl.surf.eduhub-rio-mapper.utils.ooapi :as ooapi-utils]))

Expand Down Expand Up @@ -163,33 +164,33 @@
"Loads ooapi entity, including associated offerings and education specification, if applicable."
[loader {::ooapi/keys [type] :as request}]
(let [entity (loader request)
rio-consumer (ooapi-utils/extract-rio-consumer (:consumers entity))
joint-program? (= "true" (str (:jointProgram rio-consumer)))
offerings (load-offerings loader request)
education-specification (if (= type "education-specification")
entity
eduspec-type (cond
joint-program?
"program"

(= type "education-specification")
(:educationSpecificationType entity)

:else
(-> request
(assoc ::ooapi/type "education-specification"
::ooapi/id (ooapi-base/education-specification-id entity))
(loader)))]
(loader)
:educationSpecificationType))]

(when (and (not= type "education-specification")
(= "program" (:educationSpecificationType education-specification)))
(= "program" eduspec-type))
(validate-entity entity ::program/ProgramType "ProgramType")
(validate-entity (ooapi-utils/extract-rio-consumer (:consumers entity)) ::program/ProgramConsumerType "ProgramConsumerType"))
(assoc request
::ooapi/entity (assoc entity :offerings offerings)
::ooapi/education-specification education-specification)))

(defn wrap-load-entities
"Middleware for loading and validating ooapi entitites.

Gets ooapi/type and ooapi/id from the request and fetches the given
entity + its related offerings and its education-specification.

The resulting entity is passed along as ::ooapi/entity
with :offerings. The related education-specification is passed
as ::ooapi/education-specification."
[f ooapi-loader]
(let [loader (validating-loader ooapi-loader)]
(fn wrapped-load-entities [{:keys [::ooapi/type] :as request}]
(if (= "relation" type)
(f request)
(->> request (load-entities loader) (f))))))
(validate-entity rio-consumer ::program/ProgramConsumerType "ProgramConsumerType"))
(cond-> request
true
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Misschien moet we voor :always gaan ipv true en deze onderaan zetten. Net als dat we bij cond een :else hebben.

(assoc
::ooapi/entity (assoc entity :offerings offerings)
::ooapi/education-specification-type eduspec-type)

joint-program?
(assoc
::rio/opleidingscode (:educationUnitCode rio-consumer)))))
62 changes: 30 additions & 32 deletions src/nl/surf/eduhub_rio_mapper/rio/aangeboden_opleiding.clj
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
(ns nl.surf.eduhub-rio-mapper.rio.aangeboden-opleiding
(:require [clojure.string :as str]
[nl.surf.eduhub-rio-mapper.rio.helper :as rio-helper]
[nl.surf.eduhub-rio-mapper.specs.rio :as rio]
[nl.surf.eduhub-rio-mapper.utils.ooapi :as ooapi-utils])
(:import [java.time Period Duration]))

Expand Down Expand Up @@ -58,7 +57,6 @@
:eersteInstroomDatum [:firstStartDate false]
:onderwijsaanbiedercode [:educationOffererCode true]
:onderwijslocatiecode [:educationLocationCode true]
:opleidingseenheidSleutel [::rio/opleidingscode false]
:toestemmingDeelnameSTAP [:consentParticipationSTAP true]
:voertaal [:teachingLanguage false]})

Expand Down Expand Up @@ -144,40 +142,40 @@
:validTo (:validTo %))
timelineOverrides)]
(fn [k] {:pre [(keyword? k)]}
(if (= k :opleidingseenheidSleutel)
opleidingscode
(if-let [[translation consumer] (mapping-course-program->aangeboden-opleiding k)]
(if (ooapi-mapping? (name k))
(rio-helper/ooapi-mapping (name k) (translation (if consumer rio-consumer course-program)))
(translation (if consumer rio-consumer course-program)))
(case k
;; Required field. If found in the resolve phase, will be added to the entity under the rioCode key,
;; otherwise use the eigen sleutel value (an UUID).
:aangebodenOpleidingCode (or rioCode id)
;; See opleidingseenheid for explanation of timelineOverrides and periods.
:begindatum (first (sort (conj (map :validFrom timelineOverrides) validFrom)))
:einddatum (last (sort (conj (map :validTo timelineOverrides) validTo)))
:ISCED (rio-helper/narrow-isced fieldsOfStudy)
:afwijkendeOpleidingsduur (when duration-map {:opleidingsduurEenheid (:eenheid duration-map)
:opleidingsduurOmvang (:omvang duration-map)})
:niveau (rio-helper/level-sector-mapping level sector)
:vorm (rio-helper/ooapi-mapping "vorm" modeOfStudy)

:cohorten (mapv #(course-program-offering-adapter %)
offerings)

;; See opleidingseenheid for explanation of timelineOverrides and periods.
:periodes (->> (conj periods course-program)
(mapv #(course-program-timeline-override-adapter %)))

;; These are in the xsd but ignored by us
:eigenAangebodenOpleidingSleutel (some-> id str/lower-case) ;; resolve to the ooapi id
:opleidingserkenningSleutel nil
:voVakerkenningSleutel nil))))))
(if-let [[translation consumer] (mapping-course-program->aangeboden-opleiding k)]
(if (ooapi-mapping? (name k))
(rio-helper/ooapi-mapping (name k) (translation (if consumer rio-consumer course-program)))
(translation (if consumer rio-consumer course-program)))
(case k
:opleidingseenheidSleutel opleidingscode
;; Required field. If found in the resolve phase, will be added to the entity under the rioCode key,
;; otherwise use the eigen sleutel value (an UUID).
:aangebodenOpleidingCode (or rioCode id)
;; See opleidingseenheid for explanation of timelineOverrides and periods.
:begindatum (first (sort (conj (map :validFrom timelineOverrides) validFrom)))
:einddatum (last (sort (conj (map :validTo timelineOverrides) validTo)))
:ISCED (rio-helper/narrow-isced fieldsOfStudy)
:afwijkendeOpleidingsduur (when duration-map {:opleidingsduurEenheid (:eenheid duration-map)
:opleidingsduurOmvang (:omvang duration-map)})
:niveau (rio-helper/level-sector-mapping level sector)
:vorm (rio-helper/ooapi-mapping "vorm" modeOfStudy)

:cohorten (mapv #(course-program-offering-adapter %)
offerings)

;; See opleidingseenheid for explanation of timelineOverrides and periods.
:periodes (->> (conj periods course-program)
(mapv #(course-program-timeline-override-adapter %)))

;; These are in the xsd but ignored by us
:eigenAangebodenOpleidingSleutel (some-> id str/lower-case) ;; resolve to the ooapi id
:opleidingserkenningSleutel nil
:voVakerkenningSleutel nil)))))

(defn ->aangeboden-opleiding
"Converts a program or course into the right kind of AangebodenOpleiding."
[course-program ooapi-type opleidingscode education-specification-type]
{:pre [(string? education-specification-type)]}
(-> (course-program-adapter course-program opleidingscode ooapi-type)
rio-helper/wrapper-periodes-cohorten
(rio-helper/->xml (education-specification-type-mapping education-specification-type))))
30 changes: 4 additions & 26 deletions src/nl/surf/eduhub_rio_mapper/rio/updated_handler.clj
Original file line number Diff line number Diff line change
Expand Up @@ -34,35 +34,13 @@
;; been deleted) and we only need the education-specification id if
;; the root entity is an education-specification.

(defn education-specification-id
[{:keys [::ooapi/entity ::ooapi/type ::ooapi/id]}]
(if (= type "education-specification")
id
(ooapi-base/education-specification-id entity)))

(defn wrap-resolver
"Get the RIO opleidingscode and aangeboden opleiding code for the given entity.

Inserts the codes in the request as ::rio/opleidingscode
and ::rio/aangeboden-opleiding-code (if entity is a course or
program)."
[f resolver]
(fn with-resolver [{:keys [institution-oin] ::ooapi/keys [type id] ::rio/keys [opleidingscode] :as request}]
(f (cond-> request
(#{"course" "program"} type)
(assoc ::rio/aangeboden-opleiding-code
(resolver type id institution-oin))

true
(assoc ::rio/opleidingscode
(or opleidingscode (resolver "education-specification" (education-specification-id request) institution-oin)))))))

(defn update-mutation
"Returned object conforms to ::Mutation/mutation-response."
[{:keys [institution-oin args]
::ooapi/keys [id entity type education-specification]
::ooapi/keys [id entity type education-specification-type]
::rio/keys [opleidingscode aangeboden-opleiding-code]}]
{:post [(s/valid? ::mutation/mutation-response %)]}
{:pre [(or (not= type "program") education-specification-type)]
:post [(s/valid? ::mutation/mutation-response %)]}
(assert institution-oin)
(if (and (not (#{"education-specification" "relation"} type))
(not opleidingscode))
Expand Down Expand Up @@ -98,7 +76,7 @@
{:action "aanleveren_aangebodenOpleiding"
:ooapi entity
:sender-oin institution-oin
:rio-sexp [(aangeboden-opl/->aangeboden-opleiding entity :program opleidingscode (:educationSpecificationType education-specification))]}
:rio-sexp [(aangeboden-opl/->aangeboden-opleiding entity :program opleidingscode education-specification-type)]}

"relation"
(let [[object-code valid-from valid-to] args]
Expand Down
11 changes: 8 additions & 3 deletions src/nl/surf/eduhub_rio_mapper/specs/program.clj
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
(:require [clojure.spec.alpha :as s]
[nl.surf.eduhub-rio-mapper.ooapi.enums :as enums]
[nl.surf.eduhub-rio-mapper.re-spec :refer [re-spec text-spec]]
[nl.surf.eduhub-rio-mapper.specs.common :as common]))
[nl.surf.eduhub-rio-mapper.specs.common :as common]
[nl.surf.eduhub-rio-mapper.specs.rio :as rio]))

(s/def ::abbreviation
(text-spec 1 40))
Expand All @@ -32,6 +33,8 @@
(s/def ::description ::common/LongLanguageTypedStrings)
(s/def ::educationLocationCode string?)
(s/def ::educationSpecification ::common/uuid)
(s/def ::educationUnitCode ::rio/OpleidingsEenheidID-v01)
(s/def ::jointProgram boolean?)
(s/def ::firstStartDate ::common/date)
(s/def ::foreignPartner string?)
(s/def ::foreignPartners (s/coll-of ::foreignPartner))
Expand Down Expand Up @@ -82,13 +85,13 @@
(s/def ::program
(s/keys :req-un [::programId
::consumers
::educationSpecification
::name
::validFrom]
:opt-un [::abbreviation
::children
::description
::common/duration
::educationSpecification
::link
::modeOfStudy
::parent
Expand All @@ -104,4 +107,6 @@

(s/def ::ProgramConsumerType
(s/keys :req-un [::propaedeuticPhase
::studyChoiceCheck]))
::studyChoiceCheck]
:opt-un [::educationUnitCode
::jointProgram]))
Loading