move logic from instance.db to instance.domain

neo4j-4
Josha von Gizycki 5 years ago
parent 61dbceb364
commit 4aa3a14ba2

@ -1,33 +1,9 @@
(ns wanijo.instance.db
(:require [clojure.spec.alpha :as spec]
[wanijo.specs :as specs]
[wanijo.infrastructure.neo4j :as neo4j]
[wanijo.schema.db :as domain-schema]
[wanijo.attribute.domain :as domain-attr]
[wanijo.tag.db :as db-tag]
[wanijo.link.db :as db-link]))
[wanijo.instance.domain :as domain-instance]
[wanijo.tag.db :as db-tag]))
(spec/def ::instance
(spec/keys :req-un [::neo4j/uuid
::specs/created_at
::specs/updated_at
::specs/name]))
(spec/def ::properties
(spec/coll-of
(spec/keys :req-un [::neo4j/uuid
::specs/created_at
::specs/updated_at
::domain-attr/attribute])))
(spec/def ::target ::instance)
(spec/def ::source ::instance)
(spec/def ::tags
(spec/coll-of ::db-tag/tag))
(spec/def ::contains-schema
(spec/keys :req-un [::domain-schema/schema]))
(spec/def ::instances-with-tags
(spec/coll-of (spec/merge ::instance
(spec/keys :req-un [::tags]))))
(neo4j/defquery findy-by-schema
"MATCH (i:instance)-[:of]->(s:schema)
WHERE s.uuid = {uuid}
@ -35,7 +11,7 @@
(i)-[:tagged_with]->(t:tag)
RETURN i, t")
(defn find-by-schema! [schema-uuid]
{:post [(spec/assert ::instances-with-tags %)]}
{:post [(spec/assert ::domain-instance/instances-with-tags %)]}
(->> (neo4j/exec-query! findy-by-schema
{:uuid schema-uuid})
(group-by :i)
@ -84,13 +60,11 @@
(concat [instance-tuple]
prop-tuples))))
(spec/def ::instance-with-schema
(spec/merge ::instance ::contains-schema))
(neo4j/defquery find-by-uuid
"MATCH (i:instance {uuid:{uuid}})-[:of]->(s:schema)
RETURN i, s")
(defn find-by-uuid! [uuid]
{:post [(spec/assert ::instance-with-schema %)]}
{:post [(spec/assert ::domain-instance/instance-with-schema %)]}
(->> (neo4j/exec-query! find-by-uuid
{:uuid uuid})
(map #(assoc (:i %)
@ -111,15 +85,6 @@
(neo4j/exec-query! find-properties
{:uuid uuid})))
(spec/def ::prop-tuple-values
(spec/keys :req-un [::neo4j/uuid
::specs/now
::value
::specs/instance_uuid
::specs/attribute_uuid]))
(spec/def ::prop-tuple
(spec/coll-of
(spec/tuple fn? ::prop-tuple-values)))
(neo4j/defquery edit-instance
"MATCH (i:instance {uuid:{uuid}})
SET i.name = {name},
@ -135,7 +100,7 @@
ON MATCH SET p.updated_at = {now},
p.value = {value}")
(defn instance->prop-tuples [instance]
{:post [(spec/assert ::prop-tuple %)]}
{:post [(spec/assert ::domain-instance/prop-tuple %)]}
(map (fn [prop]
(let [prop-uuid (:uuid prop)
uuid (if (empty? prop-uuid)
@ -192,12 +157,6 @@
#(-> % direction :name)
#(-> % direction :created_at)))))
(spec/def ::links-out
(spec/coll-of
(spec/keys :req-un [::db-link/link
::target
::domain-schema/schema
::tags])))
(neo4j/defquery outgoing-links
"MATCH (inst:instance {uuid:{uuid}}),
(inst)<-[:link_from]-(link:link),
@ -207,15 +166,9 @@
(target)-[:tagged_with]->(tag:tag)
RETURN link, target, schema, tag")
(defn outgoing-links! [uuid]
{:post [(spec/assert ::links-out %)]}
{:post [(spec/assert ::domain-instance/links-out %)]}
(group-by-link-and-assoc-tags uuid outgoing-links :target))
(spec/def ::links-in
(spec/coll-of
(spec/keys :req-un [::db-link/link
::source
::domain-schema/schema
::tags])))
(neo4j/defquery incoming-links
"MATCH (inst:instance {uuid:{uuid}}),
(inst)<-[:link_to]-(link:link),
@ -226,19 +179,11 @@
RETURN link, source, schema, tag
ORDER BY schema.name, source.name, source.created_at")
(defn incoming-links! [uuid]
{:post [(spec/assert ::links-in %)]}
{:post [(spec/assert ::domain-instance/links-in %)]}
(group-by-link-and-assoc-tags uuid incoming-links :source))
(spec/def ::contains-full-information
(spec/keys :req-un [::properties
::links-out
::links-in
::tags]))
(spec/def ::full-instance
(spec/merge ::instance-with-schema
::contains-full-information))
(defn full-instance-by-uuid! [uuid]
{:post [(spec/assert ::full-instance %)]}
{:post [(spec/assert ::domain-instance/full-instance %)]}
(assoc (find-by-uuid! uuid)
:properties
(find-properties! uuid)

@ -0,0 +1,65 @@
(ns wanijo.instance.domain
(:require [wanijo.specs :as specs]
[wanijo.attribute.domain :as domain-attr]
[wanijo.schema.db :as db-schema]
[wanijo.tag.db :as db-tag]
[wanijo.link.db :as db-link]
[clojure.spec.alpha :as spec]))
(spec/def ::instance
(spec/keys :req-un [::specs/uuid
::specs/created_at
::specs/updated_at
::specs/name]))
(spec/def ::properties
(spec/coll-of
(spec/keys :req-un [::specs/uuid
::specs/created_at
::specs/updated_at
::domain-attr/attribute])))
(spec/def ::target ::instance)
(spec/def ::source ::instance)
(spec/def ::tags
(spec/coll-of ::db-tag/tag))
(spec/def ::contains-schema
(spec/keys :req-un [::db-schema/schema]))
(spec/def ::instances-with-tags
(spec/coll-of (spec/merge ::instance
(spec/keys :req-un [::tags]))))
(spec/def ::instance-with-schema
(spec/merge ::instance ::contains-schema))
(spec/def ::prop-tuple-values
(spec/keys :req-un [::specs/uuid
::specs/now
::value
::specs/instance_uuid
::specs/attribute_uuid]))
(spec/def ::prop-tuple
(spec/coll-of
(spec/tuple fn? ::prop-tuple-values)))
(spec/def ::links-out
(spec/coll-of
(spec/keys :req-un [::db-link/link
::target
::db-schema/schema
::tags])))
(spec/def ::links-in
(spec/coll-of
(spec/keys :req-un [::db-link/link
::source
::db-schema/schema
::tags])))
(spec/def ::contains-full-information
(spec/keys :req-un [::properties
::links-out
::links-in
::tags]))
(spec/def ::full-instance
(spec/merge ::instance-with-schema
::contains-full-information))

@ -1,6 +1,5 @@
(ns wanijo.instance.forms
(:require [wanijo.specs :as specs]
[wanijo.instance.db :as domain]))
(:require [wanijo.specs :as specs]))
(def form
{:fields {:name {:label "Name"

@ -6,7 +6,6 @@
[markdown.core :as md]
[formulare.core :as form]
[wanijo.tag.view :as view-tag]
[wanijo.instance.db :as domain]
[wanijo.visualisation.viz :as viz]
[wanijo.infrastructure
[view :as view]

@ -6,7 +6,7 @@
[wanijo.schema.db :as domain-schema]
[wanijo.instance
[view :as view-instance]
[db :as domain-instance]]
[db :as db-instance]]
[wanijo.tag
[db :as domain]
[forms :as forms]]))
@ -22,7 +22,7 @@
(resp/redirect (path :instance-show
{:uuid instance-uuid})))
(view-instance/show!
(domain-instance/full-instance-by-uuid! instance-uuid)
(db-instance/full-instance-by-uuid! instance-uuid)
(domain-schema/accessible-schemas! user-uuid)
req))))

@ -1,7 +1,8 @@
(ns wanijo.visualisation.db
(:require [clojure.spec.alpha :as spec]
[wanijo.infrastructure.neo4j :as neo4j]
[wanijo.instance.db :as domain-instance]))
[wanijo.instance.db :as db-instance]
[wanijo.instance.domain :as domain-instance]))
(spec/def ::link-name
(spec/or :not-give nil?
@ -34,7 +35,7 @@
:links-out
(fn [links-in]
(map #(assoc
(domain-instance/full-instance-by-uuid!
(db-instance/full-instance-by-uuid!
(-> % :target :uuid))
:link-name
(-> % :label :name))
@ -42,9 +43,9 @@
(defn search! [term]
{:post [(spec/assert (spec/coll-of ::with-enriched-out-links) %)]}
(->> (neo4j/exec-query! search {:term (str ".*" term ".*")})
(map #(domain-instance/full-instance-by-uuid! (-> % :i :uuid)))
(map #(db-instance/full-instance-by-uuid! (-> % :i :uuid)))
(map enrich-links)))
(defn instance! [uuid]
{:post [(spec/assert ::with-enriched-out-links %)]}
(enrich-links (domain-instance/full-instance-by-uuid! uuid)))
(enrich-links (db-instance/full-instance-by-uuid! uuid)))

@ -1,10 +1,10 @@
(ns wanijo.visualisation.routes
(:require [compojure.core :refer [defroutes wrap-routes
GET POST DELETE]]
[ring.util.response :as resp]
[wanijo.infrastructure.routing :refer [register! path]]
[wanijo.infrastructure.view :as view]
[wanijo.instance.db :as domain-instance]
[wanijo.infrastructure
[routing :refer [register! path]]
[view :as view]]
[wanijo.instance.db :as db-instance]
[wanijo.schema.db :as domain-schema]
[wanijo.visualisation
[db :as vis-db]
@ -35,7 +35,7 @@
(defroutes routes
(GET (register! :vis-explore "/vis/explore/:instance-uuid")
[instance-uuid :as req]
(vis-view/index (domain-instance/find-by-uuid! instance-uuid)
(vis-view/index (db-instance/find-by-uuid! instance-uuid)
req))
(GET (register! :vis-all-instances "/vis/all-instances")
[:as req]

Loading…
Cancel
Save