Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
list-file now returns a single DavResource
assoc-props now takes If header
  • Loading branch information
clayton committed Aug 6, 2017
1 parent e495ea3 commit 543b659
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 36 deletions.
2 changes: 1 addition & 1 deletion project.clj
@@ -1,4 +1,4 @@
(defproject de.mpg.shh/util-webdav "0.0.2"
(defproject de.mpg.shh/util-webdav "0.0.3"
:description "LIMS for ssh"
:url "http://www.shh.mpg.de/"
:license {:name "Eclipse Public License"
Expand Down
6 changes: 3 additions & 3 deletions src/main/clojure/de/mpg/shh/util_webdav/client.clj
Expand Up @@ -106,7 +106,7 @@
file-path]
(let [url (str/join "/" [base-url file-path])]
(try
(map extract-dav-resource (-> sardine (.list url 0)))
(first (map extract-dav-resource (-> sardine (.list url 0))))
(catch SardineException se
(throw (ex-info "Failed to list file" {:cause (.getMessage se)}))))))

Expand Down Expand Up @@ -182,11 +182,11 @@
base-url :base-url}
file-path
props
lock-token]
if-header]
(let [url (str/join "/" [base-url file-path])
sardine-props (reduce prop->sardine [] props)]
(try
(map extract-dav-resource (-> sardine (.patchTx url sardine-props (Collections/emptyList) lock-token)))
(map extract-dav-resource (-> sardine (.patchTx url sardine-props (Collections/emptyList) if-header)))
(catch SardineException se
(throw (ex-info "Failed to add props" {:cause (.getMessage se)})))))))

Expand Down
Expand Up @@ -30,11 +30,11 @@ public class SardineImplWithTransaction extends SardineImpl {

public SardineImplWithTransaction(String username, String password) { super(username, password); }

public List<DavResource> patchTx(String url, List<Element> setProps, List<QName> removeProps, String lockToken) throws IOException
public List<DavResource> patchTx(String url, List<Element> setProps, List<QName> removeProps, String ifHeader) throws IOException
{
HttpPropPatch entity = new HttpPropPatch(url);
if ( lockToken != null ) {
entity.setHeader("If", "(<" + lockToken + ">)");
if ( ifHeader != null ) {
entity.setHeader("If", ifHeader);
}
// Build WebDAV <code>PROPPATCH</code> entity.
Propertyupdate body = new Propertyupdate();
Expand Down
58 changes: 29 additions & 29 deletions src/test/clojure/util_webdav/client_test.clj
Expand Up @@ -132,18 +132,18 @@
i-stream (io/input-stream (io/resource file-name))
_ (client/put-stream conn i-stream file-name)
result (try
(vec (client/list-file conn file-name))
(client/list-file conn file-name)
(catch Exception e
(error "caught exception e: " e)
(ex-data e)))
_ (client/delete-file conn file-name)
expected [{:file-name "foo.txt"
:path (str "/" dav-prefix "foo.txt")
:dir? false
:content-type "text/plain"
:content-length 12
:properties {:apache.org.dav.props/executable false}}]]
(is (= (vec (sort-by :file-name expected)) (vec (sort-by :file-name (map simple-dav-map result)))))))
expected {:file-name "foo.txt"
:path (str "/" dav-prefix "foo.txt")
:dir? false
:content-type "text/plain"
:content-length 12
:properties {:apache.org.dav.props/executable false}}]
(is (= expected (simple-dav-map result)))))

(deftest delete-test
(let [conn (client/conn default-opts)
Expand All @@ -169,17 +169,17 @@
(catch Exception e
(error "caught exception e: " e)
(ex-data e)))
result (vec (client/list-file conn file-name))
result (client/list-file conn file-name)
_ (client/delete-file conn "foo.txt")
expected [{:file-name "foo.txt"
:path (str "/" dav-prefix "foo.txt")
:dir? false
:content-type "text/plain"
:content-length 12
:properties {:apache.org.dav.props/executable false
:huricane/katrina true
:huricane/bob false}}]]
(is (= expected (vec (map simple-dav-map result))))))
expected {:file-name "foo.txt"
:path (str "/" dav-prefix "foo.txt")
:dir? false
:content-type "text/plain"
:content-length 12
:properties {:apache.org.dav.props/executable false
:huricane/katrina true
:huricane/bob false}}]
(is (= expected (simple-dav-map result)))))

(deftest dissoc-props-test
(let [conn (client/conn default-opts)
Expand All @@ -199,19 +199,19 @@
(error "caught exception e: " e)
(ex-data e)))
result (try
(vec (client/list-file conn file-name))
(client/list-file conn file-name)
(catch Exception e
(error "caught exception e: " e)
(ex-data e)))
_ (client/delete-file conn "foo.txt")
expected [{:file-name "foo.txt"
:path (str "/" dav-prefix "foo.txt")
:dir? false
:content-type "text/plain"
:content-length 12
:properties {:apache.org.dav.props/executable false
:huricane/bob true}}]]
(is (= expected (vec (map simple-dav-map result))))))
expected {:file-name "foo.txt"
:path (str "/" dav-prefix "foo.txt")
:dir? false
:content-type "text/plain"
:content-length 12
:properties {:apache.org.dav.props/executable false
:huricane/bob true}}]
(is (= expected (simple-dav-map result)))))

(deftest locktest
(let [conn (client/conn default-opts)
Expand All @@ -229,7 +229,7 @@
(client/lock conn file-name)
(catch Exception e
(ex-data e)))
_ (client/assoc-props conn file-name {:count 1} lock-token)
_ (client/assoc-props conn file-name {:count 1} (str "(<" lock-token ">)"))
result-no-token (try
(client/assoc-props conn file-name {:count 2})
(catch Exception e
Expand All @@ -250,4 +250,4 @@
(is (= (:cause already-locked) "Unexpected response (423 Locked)"))
(is (= (:cause result-no-token) "Unexpected response (423 Locked)"))
(is (nil? result-unlock))
(is (= (-> result-props first :properties :count) 1)))))
(is (= (-> result-props :properties :count) 1)))))

0 comments on commit 543b659

Please sign in to comment.