Skip to content

Commit

Permalink
get-shared-link-content
Browse files Browse the repository at this point in the history
  • Loading branch information
saidone75 committed Mar 31, 2024
1 parent e193e65 commit f2f4ae7
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 7 deletions.
18 changes: 16 additions & 2 deletions src/cral/alfresco/core/shared_links.clj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
[cral.utils.utils :as utils])
(:import (clojure.lang PersistentHashMap)
(cral.alfresco.model.auth Ticket)
(cral.alfresco.model.core CreateSharedLinkBody CreateSharedLinkQueryParams ListSharedLinksQueryParams)))
(cral.alfresco.model.core CreateSharedLinkBody CreateSharedLinkQueryParams GetSharedLinkContentQueryParams ListSharedLinksQueryParams)))

(defn create-shared-link
"Create a shared link to the file **node-id** in the request body. Also, an optional expiry date could be set,
Expand Down Expand Up @@ -63,4 +63,18 @@
(format "%s/shared-links/%s" (config/get-url 'core) shared-id)
ticket
{}
opts))
opts))

(defn get-shared-link-content
"Gets the content of the file with shared link identifier **shared-id**.
**Note:** No authentication is required to call this endpoint.
More info [here](https://api-explorer.alfresco.com/api-explorer/?urls.primaryName=Core%20API#/shared-links/getSharedLinkContent)."
([^String shared-id]
(get-shared-link-content shared-id nil nil {:return-headers true}))
([^String shared-id ^GetSharedLinkContentQueryParams query-params & [^PersistentHashMap opts]]
(utils/call-rest
client/get
(format "%s/shared-links/%s/content" (config/get-url 'core) shared-id)
nil
{:query-params query-params :as :byte-array}
opts)))
3 changes: 3 additions & 0 deletions src/cral/alfresco/model/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,9 @@
(defrecord GetSharedLinkQueryParams
[^PersistentVector include])

(defrecord GetSharedLinkContentQueryParams
[^Boolean attachment])

;; sites
(defrecord ListSiteMembershipRequestsQueryParams
[^Integer skip-count
Expand Down
22 changes: 17 additions & 5 deletions test/cral/shared_links_test.clj
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
(ns cral.shared-links-test
(:require [clojure.test :refer :all])
(:require [clojure.test :refer :all]
(:require [clojure.java.io :as io]
[clojure.test :refer :all]
[clojure.test :refer :all]
[cral.alfresco.auth :as auth]
[cral.alfresco.core.shared-links :as shared-links]
[cral.alfresco.core.nodes :as nodes]
[cral.alfresco.core.shared-links :as shared-links]
[cral.alfresco.model.core]
[cral.alfresco.model.core :as model]
[cral.test-utils :as tu])
(:import (java.util UUID)))
(:import (java.io File)
(java.util UUID)))

(def user "admin")
(def password "admin")

(deftest create-then-list-then-get-then-delete-shared-link
(deftest create-then-list-then-get-then-get-content-then-delete-shared-link
(let [ticket (get-in (auth/create-ticket user password) [:body :entry])
parent-id (:id (tu/get-guest-home ticket))
;; create a node
Expand All @@ -30,6 +32,16 @@
(recur (shared-links/list-shared-links ticket))))
;; get shared link
(is (= (:status (shared-links/get-shared-link (get-in create-shared-link-response [:body :entry :id]))) 200))
;; update node content
(let [file-to-be-uploaded (File/createTempFile "tmp." ".txt")
file-content (.toString (UUID/randomUUID))]
(spit file-to-be-uploaded file-content)
(nodes/update-node-content ticket (get-in create-node-response [:body :entry :id]) file-to-be-uploaded)
;; get shared link content
(let [content (shared-links/get-shared-link-content (get-in create-shared-link-response [:body :entry :id]))]
(is (= (apply str (map char (:body content))) file-content)))
;; delete temp file
(io/delete-file file-to-be-uploaded))
;; delete shared link
(is (= (:status (shared-links/delete-shared-link ticket (get-in create-shared-link-response [:body :entry :id]))) 204)))
;; clean up
Expand Down

0 comments on commit f2f4ae7

Please sign in to comment.