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

Truncate rio fields per rio max length #316

Closed
wants to merge 1 commit into from
Closed
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
4 changes: 2 additions & 2 deletions src/nl/surf/eduhub_rio_mapper/commands/dry_run.clj
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
{:begindatum (:validFrom current-period),
:naamLang (ooapi-utils/get-localized-value (:name current-period) dutch-locales),
:naamKort (:abbreviation current-period),
:internationaleNaam (ooapi-utils/get-localized-value (:name current-period)),
:internationaleNaam (ooapi-utils/get-localized-value (:name current-period) []),
:omschrijving (ooapi-utils/get-localized-value (:description current-period) dutch-locales),
:eigenOpleidingseenheidSleutel (:educationSpecificationId eduspec)}))

Expand All @@ -98,7 +98,7 @@
(ooapi-utils/get-localized-value dutch-locales))
:eigenNaamInternationaal (-> current-period
:name
(ooapi-utils/get-localized-value))
(ooapi-utils/get-localized-value []))
:eigenOmschrijving (-> current-period
:description
(ooapi-utils/get-localized-value dutch-locales))
Expand Down
16 changes: 8 additions & 8 deletions src/nl/surf/eduhub_rio_mapper/rio/aangeboden_opleiding.clj
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"privateProgram" "aangebodenParticuliereOpleiding"})

(def ^:private mapping-course-program->aangeboden-opleiding
{:buitenlandsePartner [:foreignPartners true]
{:buitenlandsePartner [#(ooapi-utils/truncate (:foreignPartners %) 250) true]
:eersteInstroomDatum [:firstStartDate false]
:onderwijsaanbiedercode [:educationOffererCode true]
:onderwijslocatiecode [:educationLocationCode true]
Expand All @@ -67,7 +67,7 @@
:deelnemersplaatsen :maxNumberStudents
:einddatum :endDate
:eindeAanmeldperiode :enrollEndDate
:toelichtingVereisteToestemming :explanationRequiredPermission})
:toelichtingVereisteToestemming #(-> % :explanationRequiredPermission (ooapi-utils/truncate 3000))})

(defn- course-program-timeline-override-adapter
[{:keys [name description validFrom abbreviation link consumers] :as _periode}]
Expand All @@ -76,14 +76,14 @@
(fn [pk]
(case pk
:begindatum validFrom
:buitenlandsePartner foreignPartners
:buitenlandsePartner (ooapi-utils/truncate foreignPartners 250)
:deficientie (rio-helper/ooapi-mapping "deficientie" deficiency)
:eigenNaamAangebodenOpleiding (ooapi-utils/get-localized-value name ["nl-NL" "nl"])
:eigenNaamInternationaal (ooapi-utils/get-localized-value-exclusive name ["en"])
:eigenNaamKort abbreviation
:eigenOmschrijving (ooapi-utils/get-localized-value description ["nl-NL" "nl"])
:eigenNaamAangebodenOpleiding (ooapi-utils/get-localized-value name ["nl-NL" "nl"] :maxlen 225)
:eigenNaamInternationaal (ooapi-utils/get-localized-value-exclusive name ["en"] :maxlen 225)
:eigenNaamKort (ooapi-utils/truncate abbreviation 40)
:eigenOmschrijving (ooapi-utils/get-localized-value description ["nl-NL" "nl"] :maxlen 3000)
:eisenWerkzaamheden (rio-helper/ooapi-mapping "eisenWerkzaamheden" requirementsActivities)
:internationaleNaamDuits (ooapi-utils/get-localized-value-exclusive name ["de"])
:internationaleNaamDuits (ooapi-utils/get-localized-value-exclusive name ["de"] :maxlen 225)
:propedeutischeFase (rio-helper/ooapi-mapping "propedeutischeFase" propaedeuticPhase)
:samenwerkendeOnderwijsaanbiedercode jointPartnerCodes
:studiekeuzecheck (rio-helper/ooapi-mapping "studiekeuzecheck" studyChoiceCheck)
Expand Down
8 changes: 4 additions & 4 deletions src/nl/surf/eduhub_rio_mapper/rio/opleidingseenheid.clj
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@
(fn [pk]
(case pk
:begindatum validFrom
:internationaleNaam (ooapi-utils/get-localized-value-exclusive name ["en"])
:naamKort abbreviation
:naamLang (ooapi-utils/get-localized-value name ["nl-NL" "nl"])
:omschrijving (ooapi-utils/get-localized-value description ["nl-NL" "nl"])
:internationaleNaam (ooapi-utils/get-localized-value-exclusive name ["en"] :maxlen 225)
:naamKort (ooapi-utils/truncate abbreviation 40)
:naamLang (ooapi-utils/get-localized-value name ["nl-NL" "nl"] :maxlen 225)
:omschrijving (ooapi-utils/get-localized-value description ["nl-NL" "nl"] :maxlen 3000)
:studielast (if (= "VARIANT" (soort-mapping eduspec)) nil (:value studyLoad))
:studielasteenheid (rio-helper/ooapi-mapping "studielasteenheid" (:studyLoadUnit studyLoad))
:waardedocumentsoort (rio-helper/ooapi-mapping "waardedocumentsoort" formalDocument))))
Expand Down
19 changes: 16 additions & 3 deletions src/nl/surf/eduhub_rio_mapper/utils/ooapi.clj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
true
(catch IllegalArgumentException _ false)))

(defn truncate [s n]
{:pre [(and (integer? n) (pos? n))]}
(if (string? s)
(subs s 0 (min (count s) n))
s))

(defn level-sector-map-to-rio?
"True if we can map the given level and sector to RIO."
[{:keys [level sector educationSpecificationType]}]
Expand All @@ -22,23 +28,30 @@
"Get localized value from LanguageTypedString.

The provided locales are tried in order. There is no fallback"
[attr & [locales]]
([attr locales]
(->> locales
(keep (fn [locale]
(some #(when (string/starts-with? (% :language) locale)
(% :value))
attr)))
first))
([attr locales key value]
{:pre [(= key :maxlen)]}
(-> (get-localized-value-exclusive attr locales)
(truncate value))))

(defn get-localized-value
"Get localized value from LanguageTypedString.

The provided locales are tried in order. If none found, fall back to
English (international). If still none found take the first."
[attr & [locales]]
(or
([attr locales] (or
(get-localized-value-exclusive attr (concat locales ["en"]))
(-> attr first :value)))
([attr locales key value]
{:pre [(= key :maxlen)]}
(-> (get-localized-value attr locales)
(truncate value))))

(defn ooapi-to-periods [{:keys [timelineOverrides] :as ooapi} entity-key]
(as-> timelineOverrides $
Expand Down
14 changes: 1 addition & 13 deletions test/nl/surf/eduhub_rio_mapper/rio_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@
[nl.surf.eduhub-rio-mapper.utils.keystore :as keystore]
[nl.surf.eduhub-rio-mapper.utils.soap :as soap]
[nl.surf.eduhub-rio-mapper.utils.xml-utils :as xml-utils])
(:import clojure.lang.ExceptionInfo
java.io.PushbackReader))
(:import java.io.PushbackReader))

(deftest canonicalization-and-digestion
(let [canonicalizer (fn [id] (str "<wsa:Action "
Expand Down Expand Up @@ -102,17 +101,6 @@
::ooapi/type "course"
:client-id "rio-mapper-dev.jomco.nl"}))

;; eigenNaamInternationaal max 225 chars
(deftest test-and-validate-program-4-invalid
(let [request (test-handler {::ooapi/id "29990000-0000-0000-0000-000000000000"
::ooapi/type "program"
:client-id "rio-mapper-dev.jomco.nl"})]
(is (thrown? ExceptionInfo
(-> request
prep-body
(soap/guard-valid-sexp mutator/validator)))
"guard should throw an exception")))

(defn collect-paths
"If leaf-node, add current path (and node if include-leaves is true) to acc.
Otherwise, call recursively for each child with name of child appended to the path."
Expand Down