From 23b68288f15bedfb3efc81ec3fb4f48e3f272508 Mon Sep 17 00:00:00 2001 From: Manuel Luypaert Date: Fri, 6 Nov 2020 08:45:37 +0000 Subject: [PATCH] Changed gene/*/update-other-names endpoints to use "other-names" key in data input structure (UI compatibility, #304) --- src/wormbase/names/entity.clj | 9 ++++++--- src/wormbase/names/util.clj | 8 ++++++++ src/wormbase/specs/gene.clj | 2 +- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/wormbase/names/entity.clj b/src/wormbase/names/entity.clj index 5e8f5836..10178b19 100644 --- a/src/wormbase/names/entity.clj +++ b/src/wormbase/names/entity.clj @@ -204,16 +204,19 @@ (fn handle-multi-card [request identifier] (let [{conn :conn payload :body-params} request ent-ns (namespace uiident) - data (some-> payload :data) + unqualified-attr (wnu/unqualify-keyword attr ent-ns) + update-elements (some-> payload + :data + unqualified-attr) [lur entity] (identify-fn request identifier)] - (when (and entity data) + (when (and entity update-elements) (let [build-tx (fn [id attr ^String val] (vec [dt-transact-fn id attr val])) ;;retriev db-id to add values to db-id (:db/id entity) ;;retrieve provenance prov (wnp/assoc-provenance request payload event) ;;build transaction statements to make - txes (map #(build-tx db-id attr %) data) + txes (map #(build-tx db-id attr %) update-elements) ;;transact data to datomic tx-result @(d/transact-async conn (conj txes prov))] (when-let [db-after (:db-after tx-result)] diff --git a/src/wormbase/names/util.clj b/src/wormbase/names/util.clj index 72bb8a40..a1df0523 100644 --- a/src/wormbase/names/util.clj +++ b/src/wormbase/names/util.clj @@ -199,6 +199,14 @@ {} mapping)) +(defn unqualify-keyword + "Transform `keyword` such that it gets unqualified if it contains namespace `entity-type`." + [kw entity-type] + (if (and (qualified-keyword? kw) + (= (namespace kw) entity-type)) + (-> kw name keyword) + kw)) + (defn transform-ident-ref [k m kw-ns] (update m k (fn [old] (keyword kw-ns (if (keyword old) diff --git a/src/wormbase/specs/gene.clj b/src/wormbase/specs/gene.clj index 6a2ef94e..f5b94f15 100644 --- a/src/wormbase/specs/gene.clj +++ b/src/wormbase/specs/gene.clj @@ -96,7 +96,7 @@ (s/def ::updated (stc/spec {:spec (s/keys :req-un [:gene/id]) :description "The response data from updating a Gene."})) -(s/def ::update-other-names (stc/spec {:spec :gene/other-names +(s/def ::update-other-names (stc/spec {:spec (s/keys :req-un [:gene/other-names]) :description "A collection of other names."})) (s/def ::merge (stc/spec {:spec (s/keys :req-un [:gene/biotype])