Skip to content

Commit e8e6e0e

Browse files
committed
get 1.0.3 downgrade fns from SQL LRS
1 parent 719cbf5 commit e8e6e0e

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

src/lib/com/yetanalytics/xapipe/xapi.clj

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
(ns com.yetanalytics.xapipe.xapi
22
(:require [clojure.spec.alpha :as s]
33
[clojure.spec.gen.alpha :as sgen]
4+
[clojure.string :as cs]
45
[clojure.tools.logging :as log]
56
[com.yetanalytics.xapipe.client :as client]
67
[com.yetanalytics.xapipe.client.multipart-mixed :as multipart]
@@ -168,3 +169,40 @@
168169
(log/warnf "Extra attachments for shas %s, cleaning..." (pr-str (keys leftover)))
169170
(multipart/clean-tempfiles! (mapcat identity (vals leftover))))
170171
source-statements))
172+
173+
;; Statement version downgrade (from SQL LRS)
174+
175+
(s/fdef ensure-103-timestamp
176+
:args (s/cat :timestamp (s/with-gen
177+
string?
178+
(fn []
179+
(binding [xs/*xapi-version* "2.0.0"]
180+
(s/gen ::xs/timestamp)))))
181+
:ret ::xs/timestamp)
182+
183+
(defn ensure-103-timestamp
184+
"Ensure the timestamp is in the 1.0.3 format."
185+
[timestamp]
186+
(if (cs/includes? timestamp " ")
187+
(cs/replace-first timestamp " " "T")
188+
timestamp))
189+
190+
(s/fdef convert-200-to-103
191+
:args (s/cat :statement
192+
(s/with-gen
193+
map?
194+
(fn []
195+
(binding [xs/*xapi-version* "2.0.0"]
196+
(s/gen ::xs/statement))))))
197+
198+
(defn convert-200-to-103
199+
"Convert a Statement from xAPI 2.0.0 to 1.0.3 by removing properties not in
200+
the 1.0.3 spec and normalizing timestamp."
201+
[statement]
202+
(if (= "2.0.0" (get statement "version"))
203+
(-> statement
204+
(assoc "version" "1.0.0")
205+
(update "timestamp" ensure-103-timestamp)
206+
(cond-> (get statement "context")
207+
(update "context" dissoc "contextAgents" "contextGroups")))
208+
statement))

0 commit comments

Comments
 (0)