Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #61

Merged
merged 3 commits into from
May 25, 2024
Merged

Dev #61

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Weller
Weller is like Alfresco out-of-process extensions but in [Clojure](https://clojure.org).
Weller is like [Alfresco](https://docs.alfresco.com/content-services/latest/develop/oop-sdk/) out-of-process extensions but in [Clojure](https://clojure.org).

[![Clojars Version](https://img.shields.io/clojars/v/org.saidone/weller)](https://clojars.org/org.saidone/weller)
[![cljdoc badge](https://cljdoc.org/badge/org.saidone/weller)](https://cljdoc.org/d/org.saidone/weller)
Expand Down Expand Up @@ -41,17 +41,17 @@ and this one matches updated nodes with `cm:titled` **or** `cm:dublincore` aspec
(pred/node-aspect? cm/asp-dublincore)))
```
The built-in predicates are available [here](src/weller/predicates.clj) while the events [here](src/weller/events.clj).
### Create a function
A (processing) function is the piece of code deputed to take the (resource part of) message and do something with it.
The (node) resource is a map representing (usually) a node in Alfresco.
### Create functions for message processing
Functions are the pieces of code deputed to take the message and do something with it. The resource is a map
representing a node in Alfresco.

A simple function that prints the node name could be:
A function that prints the node name could be as simple as:
```clojure
(defn print-node-name
[resource]
(println (:name resource)))
```
a more useful function that make use of the [CRAL](https://github.com/saidone75/cral) library to update the node on
a more useful function that makes use of the [CRAL](https://github.com/saidone75/cral) library to update the node on
Alfresco:
```clojure
(defn add-aspect
Expand Down
6 changes: 3 additions & 3 deletions src/weller/pipe.clj
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@

(defn make-tap
"Return a filtered tap connected to the `mult` channel.
The returned tap is filtered by predicate `pred`."
The tap is filtered by predicate `pred`."
[mult pred]
(a/tap mult (a/chan 1 (filter pred))))

(defn add-filtered-tap
"Adds a filtered (by `pred`) tap to the pipe. Filtered messages are processed by function `f`."
"Add a filtered (by `pred`) tap to the pipe. Filtered messages are processed by function `f`."
[this pred f]
(if (:running this)
(do
Expand All @@ -71,7 +71,7 @@
(assoc this :taps [])))

(defn make-pipe
"Creates a pipe with a built-in ActiveMQ listener.
"Create a pipe with a built-in ActiveMQ listener.
If a predicate `pred` and a function `f` are provided, then also add a filtered tap to it and start the pipe."
([]
;; load configuration
Expand Down
38 changes: 19 additions & 19 deletions test/weller/test_utils.clj
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@

(defn- get-guest-home
[]
(get-in (nodes/get-node (get-in @c/config [:alfresco :ticket]) "-root-" (model/map->GetNodeQueryParams {:relative-path "/Guest Home"})) [:body :entry :id]))
(get-in (nodes/get-node (c/ticket) "-root-" (model/map->GetNodeQueryParams {:relative-path "/Guest Home"})) [:body :entry :id]))

(defn- create-folder
[]
(->> (model/map->CreateNodeBody {:name (.toString (UUID/randomUUID)) :node-type cm/type-folder})
(nodes/create-node (get-in @c/config [:alfresco :ticket]) (get-guest-home))
(nodes/create-node (c/ticket) (get-guest-home))
(#(get-in % [:body :entry :id]))))

(defn- create-node
Expand All @@ -46,26 +46,26 @@
(create-node name (get-guest-home)))
([name parent-id]
(->> (model/map->CreateNodeBody {:name name :node-type cm/type-content})
(nodes/create-node (get-in @c/config [:alfresco :ticket]) parent-id)
(nodes/create-node (c/ticket) parent-id)
(#(get-in % [:body :entry :id])))))

(defn- update-node
[node-id]
(->> (model/map->UpdateNodeBody {:properties {cm/prop-title (.toString (UUID/randomUUID))}})
(nodes/update-node (get-in @c/config [:alfresco :ticket]) node-id)
(nodes/update-node (c/ticket) node-id)
(#(get-in % [:body :entry :id]))))

(defn- update-node-content
[node-id]
(let [file-to-be-uploaded (File/createTempFile "tmp." ".txt")]
(spit file-to-be-uploaded (gen-str (rand-int (math/pow 2 16))))
(nodes/update-node-content (get-in @c/config [:alfresco :ticket]) node-id file-to-be-uploaded)
(nodes/update-node-content (c/ticket) node-id file-to-be-uploaded)
(io/delete-file file-to-be-uploaded)
node-id))

(defn- delete-node
[node-id]
(nodes/delete-node (get-in @c/config [:alfresco :ticket]) node-id {:permanent true}))
(nodes/delete-node (c/ticket) node-id {:permanent true}))

(defn create-then-update-then-delete-node
([]
Expand All @@ -82,15 +82,15 @@
(let [node-id (create-node)
folder-id (create-folder)]
(->> (model/map->MoveNodeBody {:target-parent-id folder-id})
(nodes/move-node (get-in @c/config [:alfresco :ticket]) node-id))
(nodes/move-node (c/ticket) node-id))
(delete-node node-id)
(delete-node folder-id)))

(defn change-type
[type]
(let [created-node-id (create-node)]
(->> (model/map->UpdateNodeBody {:node-type type})
(nodes/update-node (get-in @c/config [:alfresco :ticket]) created-node-id))
(nodes/update-node (c/ticket) created-node-id))
(delete-node created-node-id)))

(defn add-then-remove-property
Expand All @@ -99,9 +99,9 @@
([prop value]
(let [created-node-id (create-node)]
(->> (model/map->UpdateNodeBody {:properties {prop value}})
(nodes/update-node (get-in @c/config [:alfresco :ticket]) created-node-id))
(nodes/update-node (c/ticket) created-node-id))
(->> (model/map->UpdateNodeBody {:properties {prop nil}})
(nodes/update-node (get-in @c/config [:alfresco :ticket]) created-node-id))
(nodes/update-node (c/ticket) created-node-id))
(delete-node created-node-id))))

(defn change-property
Expand All @@ -110,35 +110,35 @@
([prop initial-value]
(let [created-node-id (create-node)]
(->> (model/map->UpdateNodeBody {:properties {prop initial-value}})
(nodes/update-node (get-in @c/config [:alfresco :ticket]) created-node-id))
(nodes/update-node (c/ticket) created-node-id))
(->> (model/map->UpdateNodeBody {:properties {prop (.toString (UUID/randomUUID))}})
(nodes/update-node (get-in @c/config [:alfresco :ticket]) created-node-id))
(nodes/update-node (c/ticket) created-node-id))
(delete-node created-node-id))))

(defn create-then-delete-child-assoc
[]
(let [parent-node-id (create-folder)
child-node-id (create-node)]
(->> [(model/map->CreateSecondaryChildBody {:child-id child-node-id :assoc-type cm/assoc-contains})]
(nodes/create-secondary-child (get-in @c/config [:alfresco :ticket]) parent-node-id))
(nodes/delete-secondary-child (get-in @c/config [:alfresco :ticket]) parent-node-id child-node-id)
(nodes/create-secondary-child (c/ticket) parent-node-id))
(nodes/delete-secondary-child (c/ticket) parent-node-id child-node-id)
(delete-node child-node-id)
(delete-node parent-node-id)))

(defn create-then-delete-peer-assoc
[]
(let [created-node-id (create-node)]
(->> (model/map->CreateNodeAssocsBody {:target-id created-node-id :assoc-type cm/assoc-contains})
(nodes/create-node-assocs (get-in @c/config [:alfresco :ticket]) (get-guest-home)))
(nodes/delete-node-assocs (get-in @c/config [:alfresco :ticket]) (get-guest-home) created-node-id)
(nodes/create-node-assocs (c/ticket) (get-guest-home)))
(nodes/delete-node-assocs (c/ticket) (get-guest-home) created-node-id)
(delete-node created-node-id)))

(defn add-then-remove-aspect
[aspect-name]
(let [created-node-id (create-node)
aspect-names (get-in (nodes/get-node (get-in @c/config [:alfresco :ticket]) created-node-id) [:body :entry :aspect-names])]
aspect-names (get-in (nodes/get-node (c/ticket) created-node-id) [:body :entry :aspect-names])]
(->> (model/map->UpdateNodeBody {:aspect-names (conj aspect-names aspect-name)})
(nodes/update-node (get-in @c/config [:alfresco :ticket]) created-node-id))
(nodes/update-node (c/ticket) created-node-id))
(->> (model/map->UpdateNodeBody {:aspect-names aspect-names})
(nodes/update-node (get-in @c/config [:alfresco :ticket]) created-node-id))
(nodes/update-node (c/ticket) created-node-id))
(delete-node created-node-id)))