Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
jio
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
amrani
jio
Commits
8a7f3c76
Commit
8a7f3c76
authored
Feb 18, 2015
by
Romain Courteaud
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Test drive to jio mapping.
parent
4428686a
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
1103 additions
and
42 deletions
+1103
-42
src/jio.storage/drivetojiomapping.js
src/jio.storage/drivetojiomapping.js
+41
-42
test/jio.storage/drivetojiomapping.tests.js
test/jio.storage/drivetojiomapping.tests.js
+1061
-0
test/tests.html
test/tests.html
+1
-0
No files found.
src/jio.storage/drivetojiomapping.js
View file @
8a7f3c76
/*jslint nomen: true
, maxlen: 200
*/
/*global
console,
RSVP, Blob*/
(
function
(
jIO
)
{
/*jslint nomen: true*/
/*global RSVP, Blob*/
(
function
(
jIO
,
RSVP
,
Blob
)
{
"
use strict
"
;
/**
...
...
@@ -11,10 +11,11 @@
*/
function
FileSystemBridgeStorage
(
spec
)
{
this
.
_sub_storage
=
jIO
.
createJIO
(
spec
.
sub_storage
);
this
.
_document_key
=
"
/.jio_documents/
"
;
this
.
_attachment_key
=
"
/.jio_attachments/
"
;
}
var
DOCUMENT_EXTENSION
=
"
.json
"
,
DOCUMENT_REGEXP
=
new
RegExp
(
"
^([
\\
w=]+)
"
+
DOCUMENT_EXTENSION
+
"
$
"
),
DOCUMENT_KEY
=
"
/.jio_documents/
"
,
ROOT
=
"
/
"
;
FileSystemBridgeStorage
.
prototype
.
get
=
function
(
param
)
{
...
...
@@ -28,21 +29,22 @@
.
push
(
function
()
{
// First get the document itself if it exists
return
context
.
_sub_storage
.
getAttachment
({
"
_id
"
:
context
.
_document_key
,
"
_id
"
:
DOCUMENT_KEY
,
"
_attachment
"
:
param
.
_id
+
DOCUMENT_EXTENSION
});
})
.
push
(
function
(
blob
)
{
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
return
jIO
.
util
.
readBlobAsText
(
blob
);
return
jIO
.
util
.
readBlobAsText
(
blob
.
data
);
})
.
push
(
function
(
text
)
{
explicit_document
=
true
;
return
JSON
.
parse
(
text
.
target
.
result
);
});
},
function
(
error
)
{
if
((
error
instanceof
jIO
.
util
.
jIOError
)
&&
(
error
.
status_code
===
404
))
{
if
((
error
instanceof
jIO
.
util
.
jIOError
)
&&
(
error
.
status_code
===
404
))
{
return
{};
}
throw
error
;
...
...
@@ -59,13 +61,15 @@
})
.
push
(
function
(
directory_document
)
{
if
(
directory_document
.
_attachments
.
hasOwnProperty
(
param
.
_id
))
{
if
((
directory_document
.
hasOwnProperty
(
"
_attachments
"
))
&&
(
directory_document
.
_attachments
.
hasOwnProperty
(
param
.
_id
)))
{
json_document
.
_attachments
=
{
enclosure
:
{}
};
}
else
{
if
(
!
explicit_document
)
{
throw
new
jIO
.
util
.
jIOError
(
"
Cannot find document
"
,
404
);
throw
new
jIO
.
util
.
jIOError
(
"
Cannot find document
"
+
param
.
_id
,
404
);
}
}
return
json_document
;
...
...
@@ -73,38 +77,28 @@
};
FileSystemBridgeStorage
.
prototype
.
post
=
function
(
param
)
{
var
doc_id
=
param
.
_id
;
if
(
doc_id
===
undefined
)
{
doc_id
=
jIO
.
util
.
generateUuid
();
}
param
.
_id
=
doc_id
;
return
this
.
put
(
param
);
};
FileSystemBridgeStorage
.
prototype
.
put
=
function
(
param
)
{
var
context
=
this
,
doc_id
=
param
.
_id
;
// XXX Handle conflict!
// XXX Put empty enclosure directly if json is empty
return
context
.
_sub_storage
.
putAttachment
({
"
_id
"
:
context
.
_document_key
,
"
_id
"
:
DOCUMENT_KEY
,
"
_attachment
"
:
doc_id
+
DOCUMENT_EXTENSION
,
"
_blob
"
:
new
Blob
([
JSON
.
stringify
(
param
)],
{
type
:
"
application/json
"
})
})
.
push
(
undefined
,
function
(
error
)
{
if
((
error
instanceof
jIO
.
util
.
jIOError
)
&&
(
error
.
status_code
===
404
))
{
if
((
error
instanceof
jIO
.
util
.
jIOError
)
&&
(
error
.
status_code
===
404
))
{
return
context
.
_sub_storage
.
put
({
"
_id
"
:
context
.
_document_key
"
_id
"
:
DOCUMENT_KEY
})
.
push
(
function
()
{
return
context
.
_sub_storage
.
putAttachment
({
"
_id
"
:
context
.
_document_key
,
"
_id
"
:
DOCUMENT_KEY
,
"
_attachment
"
:
doc_id
+
DOCUMENT_EXTENSION
,
"
_blob
"
:
new
Blob
([
JSON
.
stringify
(
param
)],
{
type
:
"
application/json
"
})
"
_blob
"
:
new
Blob
([
JSON
.
stringify
(
param
)],
{
type
:
"
application/json
"
})
});
});
}
...
...
@@ -131,7 +125,8 @@
})
.
push
(
undefined
,
function
(
error
)
{
if
((
error
instanceof
jIO
.
util
.
jIOError
)
&&
(
error
.
status_code
===
404
))
{
if
((
error
instanceof
jIO
.
util
.
jIOError
)
&&
(
error
.
status_code
===
404
))
{
got_error
=
true
;
return
;
}
...
...
@@ -141,14 +136,15 @@
// Second, try to remove explicit doc
.
push
(
function
()
{
return
context
.
_sub_storage
.
removeAttachment
({
"
_id
"
:
context
.
_document_key
,
"
_id
"
:
DOCUMENT_KEY
,
"
_attachment
"
:
doc_id
+
DOCUMENT_EXTENSION
});
})
.
push
(
undefined
,
function
(
error
)
{
if
((
!
got_error
)
&&
(
error
instanceof
jIO
.
util
.
jIOError
)
&&
(
error
.
status_code
===
404
))
{
return
;
if
((
!
got_error
)
&&
(
error
instanceof
jIO
.
util
.
jIOError
)
&&
(
error
.
status_code
===
404
))
{
return
doc_id
;
}
throw
error
;
});
...
...
@@ -156,10 +152,7 @@
};
FileSystemBridgeStorage
.
prototype
.
hasCapacity
=
function
(
capacity
)
{
if
(
capacity
===
"
list
"
)
{
return
true
;
}
return
false
;
return
(
capacity
===
"
list
"
);
};
FileSystemBridgeStorage
.
prototype
.
buildQuery
=
function
()
{
...
...
@@ -171,18 +164,21 @@
.
push
(
function
()
{
return
context
.
_sub_storage
.
get
({
"
_id
"
:
context
.
_document_key
"
_id
"
:
DOCUMENT_KEY
});
})
.
push
(
function
(
result
)
{
var
key
;
for
(
key
in
result
.
_attachments
)
{
if
(
result
.
_attachments
.
hasOwnProperty
(
key
))
{
result_dict
[
key
.
slice
(
0
,
key
.
length
-
DOCUMENT_EXTENSION
.
length
)]
=
null
;
if
(
DOCUMENT_REGEXP
.
test
(
key
))
{
result_dict
[
DOCUMENT_REGEXP
.
exec
(
key
)[
1
]]
=
null
;
}
}
}
},
function
(
error
)
{
if
((
error
instanceof
jIO
.
util
.
jIOError
)
&&
(
error
.
status_code
===
404
))
{
if
((
error
instanceof
jIO
.
util
.
jIOError
)
&&
(
error
.
status_code
===
404
))
{
return
;
}
throw
error
;
...
...
@@ -224,7 +220,8 @@
FileSystemBridgeStorage
.
prototype
.
getAttachment
=
function
(
param
)
{
if
(
param
.
_attachment
!==
"
enclosure
"
)
{
throw
new
Error
(
"
Only support 'enclosure' attachment
"
);
throw
new
jIO
.
util
.
jIOError
(
"
Only support 'enclosure' attachment
"
,
400
);
}
return
this
.
_sub_storage
.
getAttachment
({
...
...
@@ -235,7 +232,8 @@
FileSystemBridgeStorage
.
prototype
.
putAttachment
=
function
(
param
)
{
if
(
param
.
_attachment
!==
"
enclosure
"
)
{
throw
new
Error
(
"
Only support 'enclosure' attachment
"
);
throw
new
jIO
.
util
.
jIOError
(
"
Only support 'enclosure' attachment
"
,
400
);
}
return
this
.
_sub_storage
.
putAttachment
({
...
...
@@ -247,7 +245,8 @@
FileSystemBridgeStorage
.
prototype
.
removeAttachment
=
function
(
param
)
{
if
(
param
.
_attachment
!==
"
enclosure
"
)
{
throw
new
Error
(
"
Only support 'enclosure' attachment
"
);
throw
new
jIO
.
util
.
jIOError
(
"
Only support 'enclosure' attachment
"
,
400
);
}
return
this
.
_sub_storage
.
removeAttachment
({
...
...
@@ -258,4 +257,4 @@
jIO
.
addStorage
(
'
drivetojiomapping
'
,
FileSystemBridgeStorage
);
}(
jIO
));
}(
jIO
,
RSVP
,
Blob
));
test/jio.storage/drivetojiomapping.tests.js
0 → 100644
View file @
8a7f3c76
This diff is collapsed.
Click to expand it.
test/tests.html
View file @
8a7f3c76
...
...
@@ -30,6 +30,7 @@
<script
src=
"jio.storage/localstorage.tests.js"
></script>
<script
src=
"jio.storage/documentstorage.tests.js"
></script>
<script
src=
"jio.storage/davstorage.tests.js"
></script>
<script
src=
"jio.storage/drivetojiomapping.tests.js"
></script>
<!--script src="jio.storage/unionstorage.tests.js"></script-->
...
...
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