Permalink
Browse files

Added find-by-path multi-method (wrapper around FileFolderService.res…

…olveNamePath)
  • Loading branch information...
1 parent 6ffa3cd commit 689b57b158d6fe993b312b76af41c26a787a0fdd @pmonks pmonks committed Jul 21, 2014
Showing with 28 additions and 2 deletions.
  1. +28 −2 src/clojure/alfresco/filefolder.clj
@@ -14,8 +14,9 @@
; limitations under the License.
(ns alfresco.filefolder
- (:require [alfresco.core :as c]
- [alfresco.auth :as a])
+ (:require [clojure.string :as s]
+ [alfresco.core :as c]
+ [alfresco.nodes :as n])
(:import [org.alfresco.service.cmr.model FileFolderService
FileInfo]
[org.alfresco.model ContentModel]))
@@ -55,3 +56,28 @@
[source-node target-parent new-name]
{ :pre (exist? [source-node target-parent]) }
(.getNodeRef (.copy (file-folder-service) source-node target-parent new-name)))
+
+; N00B WARNING: Don't yet know how to express this inline as an anonymous fn...
@skuro

skuro Jul 23, 2014

You could do like:

(defmulti find-by-path (comp sequential? first list))
+(defn- first-sequential?
+ [& args]
+ (sequential? (first args)))
+
+(defmulti find-by-path
+ "Finds a node at the given path location, optionally providing a start-node (defaults to Company Home).
+ Returns nil if the path does not identify a node."
+ first-sequential?)
+
+(defmethod find-by-path true
+ ([path-elems] (find-by-path path-elems (n/company-home)))
+ ([path-elems start-node]
+ (let [file-info (.resolveNamePath (file-folder-service) start-node path-elems false)]
+ (if (nil? file-info)
+ nil
+ (.getNodeRef file-info)))))
+
+; This version of the multi-method converts the incoming path to a string, then splits it on "/". Naive, but useful...
+(defmethod find-by-path false
+ ([path] (find-by-path path (n/company-home)))
+ ([path start-node]
+ (find-by-path (filter #(< 0 (.length %)) (s/split (str path) #"/")) start-node)))
+

0 comments on commit 689b57b

Please sign in to comment.