Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Romain Courteaud
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
*/
/*jslint nomen: true*/
/*global
console,
RSVP, Blob*/
/*global RSVP, Blob*/
(
function
(
jIO
)
{
(
function
(
jIO
,
RSVP
,
Blob
)
{
"
use strict
"
;
"
use strict
"
;
/**
/**
...
@@ -11,10 +11,11 @@
...
@@ -11,10 +11,11 @@
*/
*/
function
FileSystemBridgeStorage
(
spec
)
{
function
FileSystemBridgeStorage
(
spec
)
{
this
.
_sub_storage
=
jIO
.
createJIO
(
spec
.
sub_storage
);
this
.
_sub_storage
=
jIO
.
createJIO
(
spec
.
sub_storage
);
this
.
_document_key
=
"
/.jio_documents/
"
;
this
.
_attachment_key
=
"
/.jio_attachments/
"
;
}
}
var
DOCUMENT_EXTENSION
=
"
.json
"
,
var
DOCUMENT_EXTENSION
=
"
.json
"
,
DOCUMENT_REGEXP
=
new
RegExp
(
"
^([
\\
w=]+)
"
+
DOCUMENT_EXTENSION
+
"
$
"
),
DOCUMENT_KEY
=
"
/.jio_documents/
"
,
ROOT
=
"
/
"
;
ROOT
=
"
/
"
;
FileSystemBridgeStorage
.
prototype
.
get
=
function
(
param
)
{
FileSystemBridgeStorage
.
prototype
.
get
=
function
(
param
)
{
...
@@ -28,21 +29,22 @@
...
@@ -28,21 +29,22 @@
.
push
(
function
()
{
.
push
(
function
()
{
// First get the document itself if it exists
// First get the document itself if it exists
return
context
.
_sub_storage
.
getAttachment
({
return
context
.
_sub_storage
.
getAttachment
({
"
_id
"
:
context
.
_document_key
,
"
_id
"
:
DOCUMENT_KEY
,
"
_attachment
"
:
param
.
_id
+
DOCUMENT_EXTENSION
"
_attachment
"
:
param
.
_id
+
DOCUMENT_EXTENSION
});
});
})
})
.
push
(
function
(
blob
)
{
.
push
(
function
(
blob
)
{
return
new
RSVP
.
Queue
()
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
.
push
(
function
()
{
return
jIO
.
util
.
readBlobAsText
(
blob
);
return
jIO
.
util
.
readBlobAsText
(
blob
.
data
);
})
})
.
push
(
function
(
text
)
{
.
push
(
function
(
text
)
{
explicit_document
=
true
;
explicit_document
=
true
;
return
JSON
.
parse
(
text
.
target
.
result
);
return
JSON
.
parse
(
text
.
target
.
result
);
});
});
},
function
(
error
)
{
},
function
(
error
)
{
if
((
error
instanceof
jIO
.
util
.
jIOError
)
&&
(
error
.
status_code
===
404
))
{
if
((
error
instanceof
jIO
.
util
.
jIOError
)
&&
(
error
.
status_code
===
404
))
{
return
{};
return
{};
}
}
throw
error
;
throw
error
;
...
@@ -59,13 +61,15 @@
...
@@ -59,13 +61,15 @@
})
})
.
push
(
function
(
directory_document
)
{
.
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
=
{
json_document
.
_attachments
=
{
enclosure
:
{}
enclosure
:
{}
};
};
}
else
{
}
else
{
if
(
!
explicit_document
)
{
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
;
return
json_document
;
...
@@ -73,38 +77,28 @@
...
@@ -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
)
{
FileSystemBridgeStorage
.
prototype
.
put
=
function
(
param
)
{
var
context
=
this
,
var
context
=
this
,
doc_id
=
param
.
_id
;
doc_id
=
param
.
_id
;
// XXX Handle conflict!
// XXX Handle conflict!
// XXX Put empty enclosure directly if json is empty
return
context
.
_sub_storage
.
putAttachment
({
return
context
.
_sub_storage
.
putAttachment
({
"
_id
"
:
context
.
_document_key
,
"
_id
"
:
DOCUMENT_KEY
,
"
_attachment
"
:
doc_id
+
DOCUMENT_EXTENSION
,
"
_attachment
"
:
doc_id
+
DOCUMENT_EXTENSION
,
"
_blob
"
:
new
Blob
([
JSON
.
stringify
(
param
)],
{
type
:
"
application/json
"
})
"
_blob
"
:
new
Blob
([
JSON
.
stringify
(
param
)],
{
type
:
"
application/json
"
})
})
})
.
push
(
undefined
,
function
(
error
)
{
.
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
({
return
context
.
_sub_storage
.
put
({
"
_id
"
:
context
.
_document_key
"
_id
"
:
DOCUMENT_KEY
})
})
.
push
(
function
()
{
.
push
(
function
()
{
return
context
.
_sub_storage
.
putAttachment
({
return
context
.
_sub_storage
.
putAttachment
({
"
_id
"
:
context
.
_document_key
,
"
_id
"
:
DOCUMENT_KEY
,
"
_attachment
"
:
doc_id
+
DOCUMENT_EXTENSION
,
"
_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 @@
...
@@ -131,7 +125,8 @@
})
})
.
push
(
undefined
,
function
(
error
)
{
.
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
;
got_error
=
true
;
return
;
return
;
}
}
...
@@ -141,14 +136,15 @@
...
@@ -141,14 +136,15 @@
// Second, try to remove explicit doc
// Second, try to remove explicit doc
.
push
(
function
()
{
.
push
(
function
()
{
return
context
.
_sub_storage
.
removeAttachment
({
return
context
.
_sub_storage
.
removeAttachment
({
"
_id
"
:
context
.
_document_key
,
"
_id
"
:
DOCUMENT_KEY
,
"
_attachment
"
:
doc_id
+
DOCUMENT_EXTENSION
"
_attachment
"
:
doc_id
+
DOCUMENT_EXTENSION
});
});
})
})
.
push
(
undefined
,
function
(
error
)
{
.
push
(
undefined
,
function
(
error
)
{
if
((
!
got_error
)
&&
(
error
instanceof
jIO
.
util
.
jIOError
)
&&
(
error
.
status_code
===
404
))
{
if
((
!
got_error
)
&&
(
error
instanceof
jIO
.
util
.
jIOError
)
&&
return
;
(
error
.
status_code
===
404
))
{
return
doc_id
;
}
}
throw
error
;
throw
error
;
});
});
...
@@ -156,10 +152,7 @@
...
@@ -156,10 +152,7 @@
};
};
FileSystemBridgeStorage
.
prototype
.
hasCapacity
=
function
(
capacity
)
{
FileSystemBridgeStorage
.
prototype
.
hasCapacity
=
function
(
capacity
)
{
if
(
capacity
===
"
list
"
)
{
return
(
capacity
===
"
list
"
);
return
true
;
}
return
false
;
};
};
FileSystemBridgeStorage
.
prototype
.
buildQuery
=
function
()
{
FileSystemBridgeStorage
.
prototype
.
buildQuery
=
function
()
{
...
@@ -171,18 +164,21 @@
...
@@ -171,18 +164,21 @@
.
push
(
function
()
{
.
push
(
function
()
{
return
context
.
_sub_storage
.
get
({
return
context
.
_sub_storage
.
get
({
"
_id
"
:
context
.
_document_key
"
_id
"
:
DOCUMENT_KEY
});
});
})
})
.
push
(
function
(
result
)
{
.
push
(
function
(
result
)
{
var
key
;
var
key
;
for
(
key
in
result
.
_attachments
)
{
for
(
key
in
result
.
_attachments
)
{
if
(
result
.
_attachments
.
hasOwnProperty
(
key
))
{
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
)
{
},
function
(
error
)
{
if
((
error
instanceof
jIO
.
util
.
jIOError
)
&&
(
error
.
status_code
===
404
))
{
if
((
error
instanceof
jIO
.
util
.
jIOError
)
&&
(
error
.
status_code
===
404
))
{
return
;
return
;
}
}
throw
error
;
throw
error
;
...
@@ -224,7 +220,8 @@
...
@@ -224,7 +220,8 @@
FileSystemBridgeStorage
.
prototype
.
getAttachment
=
function
(
param
)
{
FileSystemBridgeStorage
.
prototype
.
getAttachment
=
function
(
param
)
{
if
(
param
.
_attachment
!==
"
enclosure
"
)
{
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
({
return
this
.
_sub_storage
.
getAttachment
({
...
@@ -235,7 +232,8 @@
...
@@ -235,7 +232,8 @@
FileSystemBridgeStorage
.
prototype
.
putAttachment
=
function
(
param
)
{
FileSystemBridgeStorage
.
prototype
.
putAttachment
=
function
(
param
)
{
if
(
param
.
_attachment
!==
"
enclosure
"
)
{
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
({
return
this
.
_sub_storage
.
putAttachment
({
...
@@ -247,7 +245,8 @@
...
@@ -247,7 +245,8 @@
FileSystemBridgeStorage
.
prototype
.
removeAttachment
=
function
(
param
)
{
FileSystemBridgeStorage
.
prototype
.
removeAttachment
=
function
(
param
)
{
if
(
param
.
_attachment
!==
"
enclosure
"
)
{
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
({
return
this
.
_sub_storage
.
removeAttachment
({
...
@@ -258,4 +257,4 @@
...
@@ -258,4 +257,4 @@
jIO
.
addStorage
(
'
drivetojiomapping
'
,
FileSystemBridgeStorage
);
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 @@
...
@@ -30,6 +30,7 @@
<script
src=
"jio.storage/localstorage.tests.js"
></script>
<script
src=
"jio.storage/localstorage.tests.js"
></script>
<script
src=
"jio.storage/documentstorage.tests.js"
></script>
<script
src=
"jio.storage/documentstorage.tests.js"
></script>
<script
src=
"jio.storage/davstorage.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-->
<!--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