|
1 | 1 | (ns com.yetanalytics.xapipe.xapi |
2 | 2 | (:require [clojure.spec.alpha :as s] |
3 | 3 | [clojure.spec.gen.alpha :as sgen] |
| 4 | + [clojure.string :as cs] |
4 | 5 | [clojure.tools.logging :as log] |
5 | 6 | [com.yetanalytics.xapipe.client :as client] |
6 | 7 | [com.yetanalytics.xapipe.client.multipart-mixed :as multipart] |
|
168 | 169 | (log/warnf "Extra attachments for shas %s, cleaning..." (pr-str (keys leftover))) |
169 | 170 | (multipart/clean-tempfiles! (mapcat identity (vals leftover)))) |
170 | 171 | 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