diff --git a/.gitignore b/.gitignore index 91333ce..0903fd2 100644 --- a/.gitignore +++ b/.gitignore @@ -17,5 +17,4 @@ resources/public/js/out .rebel_readline_history /elm-stuff *.*~ -*# -.#* +*#* diff --git a/project.clj b/project.clj index 086eeef..1974219 100644 --- a/project.clj +++ b/project.clj @@ -7,12 +7,12 @@ :dependencies [;;clojure core [org.clojure/clojure "1.10.1"] - [nrepl "0.7.0"] + [nrepl "0.8.3"] ;; static site - [compojure "1.6.1"] + [compojure "1.6.2"] [ring/ring-defaults "0.3.2"] - [ring/ring-jetty-adapter "1.8.0" + [ring/ring-jetty-adapter "1.8.2" :exclusions [ring/ring-core ring/ring-codec commons-io @@ -24,29 +24,32 @@ ;; compojure uses old transitive dependencies of ring ;; specifiy them here explicitly so newer versions ;; will be used - [ring/ring-core "1.8.0"] + [ring/ring-core "1.8.2"] [ring/ring-codec "1.1.2"] ;; neo4j - [gorillalabs/neo4j-clj "2.0.1" - :exclusions [com.github.ben-manes.caffeine/caffeine]] - ;; neo4j-clj 2.0.1 uses version 1.7.2 of neo4j-java-driver - ;; this seems to be too old because there's a class - ;; missing, so we use a newer version of the - ;; transitive dependency - [org.neo4j.driver/neo4j-java-driver "4.2.0"] + [gorillalabs/neo4j-clj "4.1.0"] + [org.neo4j.test/neo4j-harness "4.2.1" + :exclusions + [com.fasterxml.jackson.core/jackson-core + commons-codec]] ;; additional server side libs - [buddy/buddy-hashers "1.4.0" - :exclusions [commons-codec]] + [buddy/buddy-hashers "1.7.0" + :exclusions + [com.fasterxml.jackson.dataformat/jackson-dataformat-smile + com.fasterxml.jackson.dataformat/jackson-dataformat-cbor + com.fasterxml.jackson.core/jackson-core + org.bouncycastle/bcprov-jdk15on + org.bouncycastle/bcpkix-jdk15on + commons-codec + cheshire + tigris]] [clj-time "0.15.2"] - [markdown-clj "1.10.1"] + [markdown-clj "1.10.5"] [dorothy "0.0.7"]] - :profiles {:dev {:plugins [;; neo4j db - [joshavg/lein-neo4j "0.5.0"] - - ;; web stuff + :profiles {:dev {:plugins [;; web stuff [lein-less "1.7.5"] ;; code quality diff --git a/src/wanijo/attribute/db.clj b/src/wanijo/attribute/db.clj index 9b43faa..8d30796 100644 --- a/src/wanijo/attribute/db.clj +++ b/src/wanijo/attribute/db.clj @@ -3,7 +3,7 @@ (neo4j/defquery findy-by-schema "MATCH (a:attribute)-->(s:schema) - WHERE s.uuid = {uuid} + WHERE s.uuid = $uuid RETURN a ORDER BY a.name") (defn find-by-schema! [schema-uuid] @@ -14,8 +14,8 @@ (neo4j/defquery with-name-in-schema "MATCH (a:attribute)-[:of]->(s:schema) - WHERE a.name = {name} - AND s.uuid = {schema_uuid} + WHERE a.name = $name + AND s.uuid = $schema_uuid RETURN a") (defn with-name-in-schema! [matching-name schema-uuid] (-> (neo4j/exec-query! with-name-in-schema @@ -25,16 +25,16 @@ :a)) (neo4j/defquery create-new - "MATCH (s:schema {uuid:{schema_uuid}}), - (u:user {uuid:{user_uuid}}) + "MATCH (s:schema {uuid: $schema_uuid}), + (u:user {uuid: $user_uuid}) CREATE (a:attribute) CREATE (a)-[:created_by]->(u) CREATE (a)-[:of]->(s) - SET a.type = {type} - SET a.name = {name} - SET a.uuid = {attribute_uuid} - SET a.required = {required} - SET a.created_at = {created_at}") + SET a.type = $type + SET a.name = $name + SET a.uuid = $attribute_uuid + SET a.required = $required + SET a.created_at = $created_at") (defn create-new! [attr schema-uuid user-uuid] (neo4j/exec-query! create-new @@ -46,10 +46,10 @@ (neo4j/defquery edit "MATCH (a:attribute) - WHERE a.uuid = {uuid} - SET a.type = {type} - SET a.name = {name} - SET a.required = {required}") + WHERE a.uuid = $uuid + SET a.type = $type + SET a.name = $name + SET a.required = $required") (defn edit! [attr] (neo4j/exec-query! edit @@ -57,7 +57,7 @@ (neo4j/defquery delete-by-uuid "MATCH (a:attribute)-[c]-() - WHERE a.uuid = {uuid} + WHERE a.uuid = $uuid DELETE c, a") (defn delete-by-uuid! [uuid] (neo4j/exec-query! @@ -65,7 +65,7 @@ {:uuid uuid})) (neo4j/defquery required - "MATCH (a:attribute)-[:of]->(s:schema {uuid:{schema_uuid}}) + "MATCH (a:attribute)-[:of]->(s:schema {uuid: $schema_uuid}) WHERE a.required = 1 RETURN a ORDER BY a.name") @@ -84,7 +84,7 @@ first)) (neo4j/defquery find-by-instance - "MATCH (i:instance {uuid:{instance_uuid}}), + "MATCH (i:instance {uuid: $instance_uuid}), (i)-[:of]->(s:schema), (a:attribute)-[:of]->(s) RETURN a diff --git a/src/wanijo/infrastructure/neo4j.clj b/src/wanijo/infrastructure/neo4j.clj index 5724640..fdac842 100644 --- a/src/wanijo/infrastructure/neo4j.clj +++ b/src/wanijo/infrastructure/neo4j.clj @@ -1,5 +1,6 @@ (ns wanijo.infrastructure.neo4j (:require [neo4j-clj.core :as db] + [neo4j-clj.in-memory :as db-inm] [wanijo.infrastructure.devmode :as devmode] [clj-time.format :as time-format] [clj-time.local :as time-local] @@ -43,6 +44,9 @@ ([port host user pass] (reset! conn (create-conn! port host user pass)))) +(defn in-memory-conn! [] + (reset! conn (db-inm/create-in-memory-connection))) + (defmacro defquery [& args] `(db/defquery ~@args)) (defn uuid [] @@ -58,14 +62,17 @@ (cljs/join \newline))) (defn exec-query! [qry params] - (let [live-conn (if (nil? @conn) - (reset-conn!) - @conn)] + (let [live-conn (or @conn (reset-conn!))] (with-open [session (db/get-session live-conn)] (devmode/send-to-bar (str (butiful-query qry) "
---Params---
" params)) + ;; neo4j-clj returns lazy lists, but when we leave with-open, + ;; the ResultSet (?) is already closed, so the list cannot + ;; be processed + ;; doall to the rescue to force the list to be evaluated + ;; eagerly (doall (qry session params))))) (spec/def ::tuple-query-list diff --git a/src/wanijo/infrastructure/repl.clj b/src/wanijo/infrastructure/repl.clj index 9888461..040fa19 100644 --- a/src/wanijo/infrastructure/repl.clj +++ b/src/wanijo/infrastructure/repl.clj @@ -5,9 +5,9 @@ (neo4j/defquery create-user "CREATE (n:user) - SET n.ident = {ident} - SET n.pw = {pw} - SET n.uuid = {uuid}") + SET n.ident = $ident + SET n.pw = $pw + SET n.uuid = $uuid") (defn create-user! [ident pw] (neo4j/exec-query! @@ -19,13 +19,13 @@ (neo4j/defquery init-config "MERGE (c:dbconfig) ON CREATE SET - c.installed_at = {now}, + c.installed_at = $now, c.db_version = 0, c.last_migration = ''") (neo4j/defquery merge-config "MATCH (c:dbconfig) - SET c.last_migration = {now}, + SET c.last_migration = $now, c.db_version = {version}") (neo4j/defquery config @@ -114,8 +114,13 @@ (main/start-server-dev!) (println "Started server at http://localhost:8080")) +(defn setup-in-memory! [] + (neo4j/in-memory-conn!) + (create-user! "admin" "admin")) + (comment (dev-server!) + (setup-in-memory!) (neo4j/reset-conn! "7688" "mokoscha" neo4j/standard-user diff --git a/src/wanijo/instance/db.clj b/src/wanijo/instance/db.clj index f9ba9bf..f09af34 100644 --- a/src/wanijo/instance/db.clj +++ b/src/wanijo/instance/db.clj @@ -6,7 +6,7 @@ (neo4j/defquery findy-by-schema "MATCH (i:instance)-[:of]->(s:schema) - WHERE s.uuid = {uuid} + WHERE s.uuid = $uuid OPTIONAL MATCH (i)-[:tagged_with]->(t:tag) OPTIONAL MATCH @@ -34,21 +34,21 @@ (sort-by :name))) (neo4j/defquery create-instance - "MATCH (s:schema {uuid:{schema_uuid}}), - (u:user {uuid:{user_uuid}}) - CREATE (i:instance {uuid:{uuid}})-[:of]->(s), + "MATCH (s:schema {uuid: $schema_uuid}), + (u:user {uuid: $user_uuid}) + CREATE (i:instance {uuid: $uuid})-[:of]->(s), (i)-[:created_by]->(u) - SET i.name = {name}, - i.created_at = {created_at}, - i.updated_at = {created_at}") + SET i.name = $name, + i.created_at = $created_at, + i.updated_at = $created_at") (neo4j/defquery create-property - "MATCH (i:instance {uuid:{uuid}}), - (a:attribute {uuid:{attr_uuid}}) - CREATE (p:property {uuid:{prop_uuid}})-[:of]->(i), + "MATCH (i:instance {uuid: $uuid}), + (a:attribute {uuid: $attr_uuid}) + CREATE (p:property {uuid: $prop_uuid})-[:of]->(i), (p)-[:of]->(a) - SET p.value = {value}, - p.created_at = {created_at}, - p.updated_at = {updated_at}") + SET p.value = $value, + p.created_at = $created_at, + p.updated_at = $updated_at") (defn create! [user-uuid schema-uuid {:keys [name properties]}] @@ -73,7 +73,7 @@ prop-tuples)))) (neo4j/defquery find-by-uuid - "MATCH (i:instance {uuid:{uuid}})-[:of]->(s:schema) + "MATCH (i:instance {uuid: $uuid})-[:of]->(s:schema) RETURN i, s") (defn find-by-uuid! [uuid] {:post [(spec/assert ::domain-instance/instance-with-schema %)]} @@ -85,7 +85,7 @@ first)) (neo4j/defquery find-properties - "MATCH (i:instance {uuid:{uuid}}), + "MATCH (i:instance {uuid: $uuid}), (p:property)-[:of]->(i), (p)-[:of]->(a:attribute) RETURN p, a @@ -98,19 +98,19 @@ {:uuid uuid}))) (neo4j/defquery edit-instance - "MATCH (i:instance {uuid:{uuid}}) - SET i.name = {name}, - i.updated_at = {updated_at}") + "MATCH (i:instance {uuid: $uuid}) + SET i.name = $name, + i.updated_at = $updated_at") (neo4j/defquery edit-property - "MATCH (i:instance {uuid:{instance_uuid}}), - (a:attribute {uuid:{attribute_uuid}}) - MERGE (p:property {uuid:{uuid}})-[:of]->(i) + "MATCH (i:instance {uuid: $instance_uuid}), + (a:attribute {uuid: $attribute_uuid}) + MERGE (p:property {uuid: $uuid})-[:of]->(i) MERGE (p)-[:of]->(a) - ON CREATE SET p.created_at = {now}, - p.updated_at = {now}, - p.value = {value} - ON MATCH SET p.updated_at = {now}, - p.value = {value}") + ON CREATE SET p.created_at = $now, + p.updated_at = $now, + p.value = $value + ON MATCH SET p.updated_at = $now, + p.value = $value") (defn instance->prop-tuples [instance] {:post [(spec/assert ::domain-instance/prop-tuple %)]} (map (fn [prop] @@ -135,7 +135,7 @@ prop-tuples)))) (neo4j/defquery delete - "MATCH (i:instance {uuid:{uuid}}), + "MATCH (i:instance {uuid: $uuid}), (i)-[ic:of]->(s:schema), (i)-[cb:created_by]->(:user) OPTIONAL MATCH @@ -164,7 +164,7 @@ #(-> % direction :created_at))))) (neo4j/defquery outgoing-links - "MATCH (inst:instance {uuid:{uuid}}), + "MATCH (inst:instance {uuid: $uuid}), (inst)-[link:link]->(target:instance), (target)-[:of]->(schema:schema) OPTIONAL MATCH @@ -175,7 +175,7 @@ (group-by-link-and-assoc-tags uuid outgoing-links :target)) (neo4j/defquery incoming-links - "MATCH (inst:instance {uuid:{uuid}}), + "MATCH (inst:instance {uuid: $uuid}), (inst)<-[link:link]-(source:instance), (source)-[:of]->(schema:schema) OPTIONAL MATCH @@ -199,8 +199,8 @@ (db-tag/tags-by-instance! uuid))) (neo4j/defquery is-starred - "MATCH (u:user {uuid:{user_uuid}}), - (i:instance {uuid:{uuid}}) + "MATCH (u:user {uuid: $user_uuid}), + (i:instance {uuid: $uuid}) RETURN EXISTS((i)-[:starred_by]->(u)) AS starred") (defn is-starred! [uuid user-uuid] (-> (neo4j/exec-query! is-starred @@ -210,11 +210,11 @@ :starred)) (neo4j/defquery mark-starred - "MATCH (i:instance {uuid:{uuid}}), - (u:user {uuid:{user_uuid}}) + "MATCH (i:instance {uuid: $uuid}), + (u:user {uuid: $user_uuid}) MERGE (i)-[s:starred_by]->(u) ON CREATE - SET s.created_at = {now}") + SET s.created_at = $now") (defn mark-starred! [uuid user-uuid] (neo4j/exec-query! mark-starred {:uuid uuid @@ -222,9 +222,9 @@ :now (neo4j/now-str)})) (neo4j/defquery remove-starred - "MATCH (:instance {uuid:{uuid}}) + "MATCH (:instance {uuid: $uuid}) -[s:starred_by]-> - (:user {uuid:{user_uuid}}) + (:user {uuid: $user_uuid}) DELETE s") (defn remove-starred! [uuid user-uuid] (neo4j/exec-query! remove-starred @@ -232,7 +232,7 @@ :user_uuid user-uuid})) (neo4j/defquery starred-by-user - "MATCH (u:user {uuid:{user_uuid}}) + "MATCH (u:user {uuid: $user_uuid}) <-[s:starred_by]- (i:instance) RETURN i, s diff --git a/src/wanijo/instance/routes.clj b/src/wanijo/instance/routes.clj index 367fb1f..53295f2 100644 --- a/src/wanijo/instance/routes.clj +++ b/src/wanijo/instance/routes.clj @@ -140,10 +140,10 @@ (let [names (-> req :params :name) instances (-> req :params :instances) source-uuid (-> req :params :source-uuid)] - (clojure.pprint/pprint names) - (clojure.pprint/pprint instances) - (clojure.pprint/pprint source-uuid) - (clojure.pprint/pprint +; (clojure.pprint/pprint names) +; (clojure.pprint/pprint instances) +; (clojure.pprint/pprint source-uuid) +#_ (clojure.pprint/pprint (map (fn [[target-schema target-instances]] {:link-name (get names target-schema) :instances target-instances}) diff --git a/src/wanijo/link/db.clj b/src/wanijo/link/db.clj index 9b5ca2a..3f73841 100644 --- a/src/wanijo/link/db.clj +++ b/src/wanijo/link/db.clj @@ -9,13 +9,13 @@ ::name])) (neo4j/defquery create - "MATCH (i:instance {uuid:{from}}), - (t:instance {uuid:{target}}) + "MATCH (i:instance {uuid: $from}), + (t:instance {uuid: $target}) CREATE (i)-[l:link]->(t) - SET l.created_at = {created_at}, - l.name = {name}, - l.created_by = {by}, - l.uuid = {uuid}") + SET l.created_at = $created_at, + l.name = $name, + l.created_by = $by, + l.uuid = $uuid") (defn create! [{:keys [from name to by]}] (let [tuples (map (fn [target-uuid] [create diff --git a/src/wanijo/schema/db.clj b/src/wanijo/schema/db.clj index ebe793d..86e8b34 100644 --- a/src/wanijo/schema/db.clj +++ b/src/wanijo/schema/db.clj @@ -5,7 +5,7 @@ (neo4j/defquery all-created-by "MATCH (s:schema)-[:created_by]->(u:user) - WHERE u.uuid = {uuid} + WHERE u.uuid = $uuid RETURN s ORDER BY s.name") (defn all-created-by! [user-uuid] @@ -24,11 +24,11 @@ (neo4j/defquery create-new "MATCH (u:user) - WHERE u.uuid = {u_uuid} + WHERE u.uuid = $u_uuid CREATE (s:schema)-[:created_by]->(u) - SET s.name = {name} - SET s.uuid = {s_uuid} - SET s.created_at = {created_at} + SET s.name = $name + SET s.uuid = $s_uuid + SET s.created_at = $created_at RETURN s") (defn create-new! [schema-name user-uuid] (->> @@ -43,7 +43,7 @@ (neo4j/defquery find-by-uuid "MATCH (s:schema) - WHERE s.uuid = {uuid} + WHERE s.uuid = $uuid OPTIONAL MATCH (s)<-[:of]-(a:attribute) WHERE a.required = 1 @@ -60,13 +60,13 @@ :req-attrs (map :a result))))) (neo4j/defquery schema-permissions - "MATCH (s:schema {uuid:{schema_uuid}}) + "MATCH (s:schema {uuid: $schema_uuid}) RETURN - EXISTS((:user {uuid:{user_uuid}}) - -[:permission {type:{type}}]- + EXISTS((:user {uuid: $user_uuid}) + -[:permission {type: $type}]- (s)) AS user_has_permission, NOT EXISTS((:user) - -[:permission {type:{type}}]- + -[:permission {type: $type}]- (s)) AS is_public") (defn has-user-permission? [perm-type schema-uuid user-uuid] (let [perms (first @@ -82,7 +82,7 @@ (neo4j/defquery accessible-schemas "MATCH (s:schema), - (u:user {uuid:{user_uuid}}) + (u:user {uuid: $user_uuid}) WHERE EXISTS((u)-[:permission {type:'read'}]->(s)) OR NOT EXISTS((:user)-[:permission {type:'read'}]->(s)) WITH s @@ -100,7 +100,7 @@ {:user_uuid user-uuid}))) (neo4j/defquery delete - "MATCH (s:schema {uuid:{uuid}}) + "MATCH (s:schema {uuid: $uuid}) WITH s OPTIONAL MATCH (s)--(a:attribute)-[cb:created_by]-(:user) DELETE cb, a @@ -114,8 +114,8 @@ (neo4j/defquery edit "MATCH (s:schema) - WHERE s.uuid = {uuid} - SET s.name = {name}") + WHERE s.uuid = $uuid + SET s.name = $name") (defn edit! [schema] (neo4j/exec-query! edit @@ -123,7 +123,7 @@ (neo4j/defquery assigned-users "MATCH (s:schema)-[p:permission]-(u:user) - WHERE s.uuid = {uuid} + WHERE s.uuid = $uuid RETURN u, p ORDER BY u.ident") (defn assigned-users! [uuid] @@ -133,7 +133,7 @@ (neo4j/defquery assigned-schemas "MATCH (s1:schema)-[p:permission]-(s2:schema) - WHERE s1.uuid = {uuid} + WHERE s1.uuid = $uuid RETURN s2 ORDER BY s2.name") (defn assigned-schemas! [uuid] @@ -157,14 +157,14 @@ (neo4j/defquery remove-assignments "MATCH (s:schema)-[c:permission]-(:user) - WHERE s.uuid = {uuid} - AND c.type = {permtype} + WHERE s.uuid = $uuid + AND c.type = $permtype DELETE c") (neo4j/defquery create-assignments "MATCH (s:schema), (u:user) - WHERE s.uuid = {uuid} - AND u.uuid IN {users} - CREATE (s)<-[:permission{type:{permtype}}]-(u)") + WHERE s.uuid = $uuid + AND u.uuid IN $users + CREATE (s)<-[:permission{type: $permtype}]-(u)") (defn assign-users! [uuid users permission] (neo4j/exec-queries! [remove-assignments @@ -177,12 +177,12 @@ (neo4j/defquery remove-schema-assignments "MATCH (s1:schema)-[p:permission]-(s2:schema) - WHERE s1.uuid = {uuid} + WHERE s1.uuid = $uuid DELETE p") (neo4j/defquery create-schema-assignments "MATCH (s1:schema), (s2:schema) - WHERE s1.uuid = {uuid} - AND s2.uuid IN {schemas} + WHERE s1.uuid = $uuid + AND s2.uuid IN $schemas CREATE (s1)-[:permission]->(s2)") (defn assign-schemas! [uuid schemas] (neo4j/exec-queries! @@ -192,7 +192,7 @@ {:uuid uuid :schemas schemas}])) (neo4j/defquery find-by-instance - "MATCH (i:instance {uuid:{uuid}})-[:of]->(s:schema) + "MATCH (i:instance {uuid: $uuid})-[:of]->(s:schema) RETURN s") (defn find-by-instance! [uuid] (-> find-by-instance diff --git a/src/wanijo/tag/db.clj b/src/wanijo/tag/db.clj index e26a1ee..cef3bd8 100644 --- a/src/wanijo/tag/db.clj +++ b/src/wanijo/tag/db.clj @@ -12,7 +12,7 @@ ::name])) (neo4j/defquery tags-by-instance - "MATCH (i:instance {uuid:{uuid}})-[:tagged_with]->(t:tag) + "MATCH (i:instance {uuid: $uuid})-[:tagged_with]->(t:tag) RETURN t ORDER BY t.name") (defn tags-by-instance! [instance-uuid] @@ -22,11 +22,11 @@ {:uuid instance-uuid}))) (neo4j/defquery merge-tag - "MATCH (i:instance {uuid:{instance_uuid}}), - (u:user {uuid:{user_uuid}}) - MERGE (t:tag {name:{name}})-[:created_by]->(u) - ON CREATE SET t.uuid = {uuid}, - t.created_at = {now} + "MATCH (i:instance {uuid: $instance_uuid}), + (u:user {uuid: $user_uuid}) + MERGE (t:tag {name: $name})-[:created_by]->(u) + ON CREATE SET t.uuid = $uuid, + t.created_at = $now MERGE (i)-[:tagged_with]->(t)") (spec/def ::merge-tag-tuple (spec/keys :req-un [::specs/instance_uuid @@ -59,9 +59,9 @@ (merge-tag-tuples tags instance-uuid user-uuid))) (neo4j/defquery remove-tag - "MATCH (i:instance {uuid:{instance_uuid}}) + "MATCH (i:instance {uuid: $instance_uuid}) -[c:tagged_with]-> - (t:tag {uuid:{uuid}}) + (t:tag {uuid: $uuid}) DELETE c") (defn remove-tag! [uuid instance-uuid] (neo4j/exec-query! remove-tag diff --git a/src/wanijo/user/db.clj b/src/wanijo/user/db.clj index c5a728e..31b6338 100644 --- a/src/wanijo/user/db.clj +++ b/src/wanijo/user/db.clj @@ -13,7 +13,7 @@ (neo4j/defquery find-user "MATCH (n:user) - WHERE n.ident = {ident} + WHERE n.ident = $ident RETURN n") (defn find! [ident] @@ -24,6 +24,20 @@ first :n)) +(comment + (macroexpand '(db/defquery test-find-user + "MATCH (u:user) WHERE u.ident = $ident RETURN u")) + (macroexpand '(neo4j/defquery + find-user + "MATCH (n:user) WHERE n.ident = $ident RETURN n")) + + (require '[neo4j-clj.core :as db]) + (db/defquery test-find-user + "MATCH (u:user) WHERE u.ident = $ident RETURN u") + (with-open [s (db/get-session @neo4j/conn)] + (test-find-user s {:ident "admin"})) + (neo4j/exec-query! test-find-user {:ident "admin"})) + (neo4j/defquery all "MATCH (u:user) diff --git a/src/wanijo/visualisation/db.clj b/src/wanijo/visualisation/db.clj index ccf0cfd..1418108 100644 --- a/src/wanijo/visualisation/db.clj +++ b/src/wanijo/visualisation/db.clj @@ -27,7 +27,7 @@ (neo4j/defquery search "MATCH (i:instance) - WHERE i.name =~ {term} + WHERE i.name =~ $term RETURN i LIMIT 10") (defn enrich-links [instance]