Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
jio-main
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Hardik Juneja
jio-main
Commits
98871f94
Commit
98871f94
authored
Jan 17, 2013
by
Sven Franck
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
webDav Storage ALLDOCS new API and unit tests
parent
4ccd05a0
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
98 additions
and
161 deletions
+98
-161
src/jio.storage/davstorage.js
src/jio.storage/davstorage.js
+52
-65
test/jiotests.js
test/jiotests.js
+43
-93
test/responsexml/davlist
test/responsexml/davlist
+3
-3
No files found.
src/jio.storage/davstorage.js
View file @
98871f94
...
...
@@ -61,18 +61,6 @@ jIO.addStorageType('dav', function (spec, my) {
return
o
;
};
/**
* If some other parameters is needed, it returns an error message.
* @method validateState
* @return {string} '' -> ok, 'message' -> error
*/
that
.
validateState
=
function
()
{
if
(
priv
.
secured_username
&&
priv
.
url
)
{
return
''
;
}
return
'
Need at least 2 parameters: "username" and "url".
'
;
};
priv
.
newAsyncModule
=
function
()
{
var
async
=
{};
async
.
call
=
function
(
obj
,
function_name
,
arglist
)
{
...
...
@@ -765,59 +753,74 @@ jIO.addStorageType('dav', function (spec, my) {
};
/**
* Gets a document list from a distant dav storage
.
* Gets a document list from a distant dav storage
* @method allDocs
* @param {object} command The JIO command
*/
//{
// "total_rows": 4,
// "rows": [
// {
// "id": "otherdoc",
// "key": "otherdoc",
// "value": {
// "rev": "1-3753476B70A49EA4D8C9039E7B04254C"
// }
// },{...}
// ]
//}
that
.
allDocs
=
function
(
command
)
{
var
rows
=
[],
var
rows
=
[],
url
,
am
=
priv
.
newAsyncModule
(),
o
=
{};
o
.
getContent
=
function
(
file
)
{
$
.
ajax
({
url
:
priv
.
url
+
'
/
'
+
priv
.
secured_username
+
'
/
'
+
priv
.
secured_application_name
+
'
/
'
+
priv
.
secureDocId
(
file
.
id
)
+
'
?_=
'
+
Date
.
now
(),
type
:
"
GET
"
,
url
:
priv
.
url
+
'
/
'
+
priv
.
secureDocId
(
file
.
id
)
+
'
?_=
'
+
Date
.
now
(),
type
:
'
GET
'
,
async
:
true
,
dataType
:
'
text
'
,
// TODO : is it necessary ?
dataType
:
'
text
'
,
headers
:
{
'
Authorization
'
:
'
Basic
'
+
Base64
.
encode
(
priv
.
username
+
'
:
'
+
priv
.
password
)
'
Authorization
'
:
'
Basic
'
+
Base64
.
encode
(
priv
.
username
+
'
:
'
+
priv
.
password
)
},
success
:
function
(
content
)
{
file
.
value
.
content
=
content
;
// WARNING : files can be disordered because
// of asynchronous action
rows
.
push
(
file
);
am
.
call
(
o
,
'
success
'
);
},
error
:
function
(
type
)
{
type
.
error
=
type
.
statusText
;
// TODO : to lower case
type
.
reason
=
'
Cannot get a document
'
+
'
content from DAVStorage
'
;
type
.
message
=
type
.
message
+
'
.
'
;
that
.
error
({
"
status
"
:
404
,
"
statusText
"
:
"
Not Found
"
,
"
error
"
:
"
not_found
"
,
"
message
"
:
"
Cannot find the document
"
,
"
reason
"
:
"
Cannot get a document from DAVStorage
"
});
am
.
call
(
o
,
'
error
'
,
[
type
]);
}
});
};
o
.
getDocumentList
=
function
()
{
url
=
priv
.
url
+
'
/
'
;
$
.
ajax
({
url
:
priv
.
url
+
'
/
'
+
priv
.
secured_username
+
'
/
'
+
priv
.
secured_application_name
+
'
/
'
+
'
?_=
'
+
Date
.
now
(),
async
:
true
,
url
:
url
+
'
?_=
'
+
Date
.
now
(),
type
:
'
PROPFIND
'
,
async
:
true
,
dataType
:
'
xml
'
,
headers
:
{
'
Authorization
'
:
'
Basic
'
+
Base64
.
encode
(
crossdomain
:
true
,
headers
:
{
Authorization
:
'
Basic
'
+
Base64
.
encode
(
priv
.
username
+
'
:
'
+
priv
.
password
),
Depth
:
'
1
'
},
// xhrFields: {withCredentials: 'true'}, // cross domain
success
:
function
(
xmlData
)
{
var
response
=
$
(
xmlData
).
find
(
'
D
\\
:response, response
'
),
len
=
response
.
length
;
if
(
len
===
1
)
{
return
am
.
call
(
o
,
'
success
'
);
}
...
...
@@ -833,24 +836,10 @@ jIO.addStorageType('dav', function (spec, my) {
file
.
id
=
priv
.
restoreSlashes
(
file
.
id
);
file
.
key
=
file
.
id
;
});
if
(
file
.
id
===
'
.htaccess
'
||
file
.
id
===
'
.htpasswd
'
)
{
return
;
}
$
(
data
).
find
(
'
lp1
\\
:getlastmodified, getlastmodified
'
).
each
(
function
()
{
file
.
value
.
_last_modified
=
new
Date
(
$
(
this
).
text
()
).
getTime
();
}
);
$
(
data
).
find
(
'
lp1
\\
:creationdate, creationdate
'
).
each
(
function
()
{
file
.
value
.
_creation_date
=
new
Date
(
$
(
this
).
text
()
).
getTime
();
}
);
if
(
!
command
.
getOption
(
'
metadata_only
'
))
{
// this should probably also filter for the "." in case
// there is a title.revision. Then we could fill value in
// allDocs, too!
if
(
command
.
getOption
(
'
include_content
'
))
{
am
.
call
(
o
,
'
getContent
'
,
[
file
]);
}
else
{
rows
.
push
(
file
);
...
...
@@ -860,18 +849,15 @@ jIO.addStorageType('dav', function (spec, my) {
});
},
error
:
function
(
type
)
{
if
(
type
.
status
===
404
)
{
type
.
error
=
'
not_found
'
;
type
.
reason
=
'
missing
'
;
am
.
call
(
o
,
'
error
'
,
[
type
]);
}
else
{
type
.
error
=
type
.
statusText
;
// TODO : to lower case
type
.
reason
=
'
Cannot get a document list from DAVStorage
'
;
type
.
message
=
type
.
reason
+
'
.
'
;
that
.
error
({
"
status
"
:
404
,
"
statusText
"
:
"
Not Found
"
,
"
error
"
:
"
not_found
"
,
"
message
"
:
"
Cannot find the document
"
,
"
reason
"
:
"
Cannot get a document list from DAVStorage
"
});
am
.
call
(
o
,
'
retry
'
,
[
type
]);
}
}
});
};
o
.
retry
=
function
(
error
)
{
...
...
@@ -895,8 +881,9 @@ jIO.addStorageType('dav', function (spec, my) {
rows
:
rows
});
};
// first get the XML list
am
.
call
(
o
,
'
getDocumentList
'
);
};
// end allDocs
};
return
that
;
});
\ No newline at end of file
test/jiotests.js
View file @
98871f94
...
...
@@ -142,16 +142,8 @@ basicTickFunction = function (obj) {
}
},
getXML
=
function
(
url
)
{
var
tmp
=
''
;
$
.
ajax
({
url
:
url
,
async
:
false
,
dataType
:
'
text
'
,
success
:
function
(
xml
)
{
tmp
=
xml
;
}
});
return
tmp
;
var
xml
=
$
.
ajax
({
url
:
url
,
async
:
false
});
return
xml
.
responseText
;
},
objectifyDocumentArray
=
function
(
array
)
{
var
obj
=
{},
k
;
...
...
@@ -165,6 +157,10 @@ getLastJob = function (id) {
},
generateTools
=
function
(
sinon
)
{
var
o
=
{};
// need to make server requests before activating fakeServer
o
.
davlist
=
getXML
(
'
responsexml/davlist
'
);
o
.
t
=
sinon
;
o
.
server
=
o
.
t
.
sandbox
.
useFakeServer
();
o
.
clock
=
o
.
t
.
sandbox
.
useFakeTimers
();
...
...
@@ -239,7 +235,6 @@ generateTools = function (sinon) {
o
.
addFakeServerResponse
=
function
(
method
,
path
,
status
,
response
)
{
var
url
=
new
RegExp
(
'
https:
\\
/
\\
/ca-davstorage:8080
\\
/
'
+
path
+
'
(
\\
?.*|$)
'
);
// console.log("adding response for: "+method+" "+url );
o
.
server
.
respondWith
(
method
,
url
,
[
status
,
{
"
Content-Type
"
:
'
application/xml
'
},
response
]
);
...
...
@@ -258,7 +253,6 @@ isUuid = function (uuid) {
return
uuid
.
match
(
"
^
"
+
x
+
x
+
"
-
"
+
x
+
"
-
"
+
x
+
"
-
"
+
x
+
"
-
"
+
x
+
x
+
x
+
"
$
"
)
===
null
?
false
:
true
;
};
//// QUnit Tests ////
module
(
'
Jio Global tests
'
);
...
...
@@ -2322,91 +2316,47 @@ test ("Remove", function(){
// check for credentials in sinon
});
test
(
"
AllDocs
"
,
function
()
{
/*
var
o
=
generateTools
(
this
);
test ('Get Document List', function () {
// Test if DavStorage can get a list a document.
o
.
jio
=
JIO
.
newJio
({
"
type
"
:
"
dav
"
,
"
username
"
:
"
davall
"
,
"
password
"
:
"
checkpwd
"
,
"
url
"
:
"
https://ca-davstorage:8080
"
});
var o = {};
o.davlist = getXML('responsexml/davlist');
o.clock = this.sandbox.useFakeTimers();
o.clock.tick(base_tick);
o.t = this;
o.mytest = function (message,metadata_only,value,errnoprop) {
var server = o.t.sandbox.useFakeServer();
server.respondWith (
"PROPFIND",
/https:\/\/ca-davstorage:8080\/davlist\/jiotests\/(\?.*|$)/,
[errnoprop,{'Content-Type':'text/xml; charset="utf-8"'},
o.davlist]);
server.respondWith (
"GET",
/https:\/\/ca-davstorage:8080\/davlist\/jiotests\/file(\?.*|$)/,
[200,{},'content']);
server.respondWith (
"GET",
/https:\/\/ca-davstorage:8080\/davlist\/jiotests\/memo(\?.*|$)/,
[200,{},'content2']);
o.f = function (err,val) {
if (err) {
result = undefined;
} else {
deepEqual (objectifyDocumentArray(val.rows),
objectifyDocumentArray(value),message);
return;
// get allDocs, no content
o
.
addFakeServerResponse
(
"
PROPFIND
"
,
""
,
200
,
o
.
davlist
);
o
.
thisShouldBeTheAnswer
=
{
"
rows
"
:
[
{
"
id
"
:
"
alldocs1
"
,
"
key
"
:
"
alldocs1
"
,
"
value
"
:
{}},
{
"
id
"
:
"
alldocs2
"
,
"
key
"
:
"
alldocs2
"
,
"
value
"
:
{}}
],
"
total_rows
"
:
2
}
deepEqual (result, value, message);
};
o.t.spy(o,'f');
o.jio.allDocs({metadata_only:metadata_only},o.f);
o.clock.tick(1000);
server.respond();
if (!o.f.calledOnce) {
if (o.f.called) {
ok(false, 'too much results');
} else {
ok(false, 'no response');
}
}
};
o.jio = JIO.newJio({type:'dav',username:'davlist',
password:'checkpwd',
url:'https://ca-davstorage:8080',
application_name:'jiotests'});
o.mytest('fail to get list',true,undefined,404);
o.mytest('getting list',true,[{
id:'file',key:'file',
value:{
_creation_date:1335962911000,
_last_modified:1335962907000
}
},{
id:'memo',key:'memo',
value:{
_creation_date:1335894073000,
_last_modified:1335955713000
}
}],207);
o.mytest('getting list',false,[{
id:'file',key:'file',
value:{
content:'content',
_creation_date:1335962911000,
_last_modified:1335962907000
}
},{
id:'memo',key:'memo',
value:{
content:'content2',
_creation_date:1335894073000,
_last_modified:1335955713000
}
}],207);
o
.
spy
(
o
,
"
value
"
,
o
.
thisShouldBeTheAnswer
,
"
allDocs (no content)
"
);
o
.
jio
.
allDocs
(
o
.
f
);
o
.
clock
.
tick
(
5000
);
o
.
server
.
respond
();
// allDocs with option include
o
.
all1
=
JSON
.
stringify
({
"
_id
"
:
"
allDocs1
"
,
"
title
"
:
"
a doc title
"
});
o
.
all2
=
JSON
.
stringify
({
"
_id
"
:
"
allDocs2
"
,
"
title
"
:
"
another doc title
"
});
o
.
addFakeServerResponse
(
"
GET
"
,
"
alldocs1
"
,
200
,
o
.
all1
);
o
.
addFakeServerResponse
(
"
GET
"
,
"
alldocs2
"
,
200
,
o
.
all2
);
o
.
spy
(
o
,
"
value
"
,
o
.
thisShouldBeTheAnswer
,
"
allDocs (include_docs)
"
);
o
.
jio
.
allDocs
({
"
include_docs
"
:
true
},
o
.
f
);
o
.
clock
.
tick
(
5000
);
o
.
server
.
respond
();
// do the same tests live webDav-Server/simulate CORS
// check for credentials in sinon
o
.
jio
.
stop
();
});
*/
/*
module ('Jio ReplicateStorage');
...
...
test/responsexml/davlist
View file @
98871f94
<?xml version="1.0" encoding="utf-8"?>
<D:multistatus
xmlns:D=
"DAV:"
>
<D:response
xmlns:lp1=
"DAV:"
xmlns:lp2=
"http://apache.org/dav/props/"
>
<D:href>
/
davgetlist/jiotests
/
</D:href>
<D:href>
/
some/path
/
</D:href>
<D:propstat>
<D:prop>
<lp1:resourcetype><D:collection/></lp1:resourcetype>
...
...
@@ -25,7 +25,7 @@
</D:propstat>
</D:response>
<D:response
xmlns:lp1=
"DAV:"
xmlns:lp2=
"http://apache.org/dav/props/"
>
<D:href>
/
davgetlist/jiotests/file
</D:href>
<D:href>
/
some/path/alldocs1
</D:href>
<D:propstat>
<D:prop>
<lp1:resourcetype/>
...
...
@@ -50,7 +50,7 @@
</D:propstat>
</D:response>
<D:response
xmlns:lp1=
"DAV:"
xmlns:lp2=
"http://apache.org/dav/props/"
>
<D:href>
/
davgetlist/jiotests/memo
</D:href>
<D:href>
/
some/path/alldocs2
</D:href>
<D:propstat>
<D:prop>
<lp1:resourcetype/>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment