|
|
|
@ -23,16 +23,6 @@
|
|
|
|
|
::name]))
|
|
|
|
|
(spec/def ::target ::instance)
|
|
|
|
|
(spec/def ::source ::instance)
|
|
|
|
|
(spec/def ::links-out
|
|
|
|
|
(spec/coll-of
|
|
|
|
|
(spec/keys :req-un [::link
|
|
|
|
|
::target
|
|
|
|
|
::domain-schema/schema])))
|
|
|
|
|
(spec/def ::links-in
|
|
|
|
|
(spec/coll-of
|
|
|
|
|
(spec/keys :req-un [::link
|
|
|
|
|
::source
|
|
|
|
|
::domain-schema/schema])))
|
|
|
|
|
(spec/def ::tags
|
|
|
|
|
(spec/coll-of ::domain-tag/tag))
|
|
|
|
|
(spec/def ::contains-schema
|
|
|
|
@ -212,37 +202,57 @@
|
|
|
|
|
(:to link))]
|
|
|
|
|
(apply neo4j/exec-queries! tuples)))
|
|
|
|
|
|
|
|
|
|
(defn grouped-links-by-tag [uuid query direction]
|
|
|
|
|
(->> (neo4j/exec-query! query
|
|
|
|
|
{:uuid uuid})
|
|
|
|
|
(group-by
|
|
|
|
|
(fn [{:keys [link schema] :as row}]
|
|
|
|
|
{:link link
|
|
|
|
|
direction (direction row)
|
|
|
|
|
:schema schema}))
|
|
|
|
|
(map (fn [[link tags]]
|
|
|
|
|
(assoc link
|
|
|
|
|
:tags
|
|
|
|
|
(filter some?
|
|
|
|
|
(map :tag tags)))))))
|
|
|
|
|
|
|
|
|
|
(spec/def ::links-out
|
|
|
|
|
(spec/coll-of
|
|
|
|
|
(spec/keys :req-un [::link
|
|
|
|
|
::target
|
|
|
|
|
::domain-schema/schema
|
|
|
|
|
::tags])))
|
|
|
|
|
(neo4j/defquery outgoing-links
|
|
|
|
|
"MATCH (i:instance {uuid:{uuid}}),
|
|
|
|
|
(i)<-[:link_from]-(l:link),
|
|
|
|
|
(l)-[:link_to]->(t:instance),
|
|
|
|
|
(t)-[:of]->(s:schema)
|
|
|
|
|
RETURN i, l, t, s
|
|
|
|
|
ORDER BY s.name, t.name, t.created_at")
|
|
|
|
|
"MATCH (inst:instance {uuid:{uuid}}),
|
|
|
|
|
(inst)<-[:link_from]-(link:link),
|
|
|
|
|
(link)-[:link_to]->(target:instance),
|
|
|
|
|
(target)-[:of]->(schema:schema)
|
|
|
|
|
OPTIONAL MATCH
|
|
|
|
|
(target)-[:tagged_with]->(tag:tag)
|
|
|
|
|
RETURN link, target, schema, tag
|
|
|
|
|
ORDER BY schema.name, target.name, target.created_at")
|
|
|
|
|
(defn outgoing-links! [uuid]
|
|
|
|
|
{:post [(spec/assert ::links-out %)]}
|
|
|
|
|
(map (fn [row]
|
|
|
|
|
{:link (:l row)
|
|
|
|
|
:target (:t row)
|
|
|
|
|
:schema (:s row)})
|
|
|
|
|
(neo4j/exec-query! outgoing-links
|
|
|
|
|
{:uuid uuid})))
|
|
|
|
|
(grouped-links-by-tag uuid outgoing-links :target))
|
|
|
|
|
|
|
|
|
|
(spec/def ::links-in
|
|
|
|
|
(spec/coll-of
|
|
|
|
|
(spec/keys :req-un [::link
|
|
|
|
|
::source
|
|
|
|
|
::domain-schema/schema
|
|
|
|
|
::tags])))
|
|
|
|
|
(neo4j/defquery incoming-links
|
|
|
|
|
"MATCH (i:instance {uuid:{uuid}}),
|
|
|
|
|
(i)<-[:link_to]-(l:link),
|
|
|
|
|
(l)-[:link_from]->(source:instance),
|
|
|
|
|
"MATCH (inst:instance {uuid:{uuid}}),
|
|
|
|
|
(inst)<-[:link_to]-(link:link),
|
|
|
|
|
(link)-[:link_from]->(source:instance),
|
|
|
|
|
(source)-[:of]->(schema:schema)
|
|
|
|
|
RETURN i, l, source, schema
|
|
|
|
|
OPTIONAL MATCH
|
|
|
|
|
(source)-[:tagged_with]->(tag:tag)
|
|
|
|
|
RETURN link, source, schema, tag
|
|
|
|
|
ORDER BY schema.name, source.name, source.created_at")
|
|
|
|
|
(defn incoming-links! [uuid]
|
|
|
|
|
{:post [(spec/assert ::links-in %)]}
|
|
|
|
|
(map (fn [row]
|
|
|
|
|
{:link (:l row)
|
|
|
|
|
:source (:source row)
|
|
|
|
|
:schema (:schema row)})
|
|
|
|
|
(neo4j/exec-query! incoming-links
|
|
|
|
|
{:uuid uuid})))
|
|
|
|
|
(grouped-links-by-tag uuid incoming-links :source))
|
|
|
|
|
|
|
|
|
|
(neo4j/defquery delete-link
|
|
|
|
|
"MATCH (l:link {uuid:{uuid}}),
|
|
|
|
|