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
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
Boris Kocherov
jio
Commits
52486182
Commit
52486182
authored
Jan 24, 2013
by
Sven Franck
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
indexStorage: REMOVE new API and qunit tests
parent
39f13bfd
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
252 additions
and
35 deletions
+252
-35
src/jio.storage/indexstorage.js
src/jio.storage/indexstorage.js
+113
-14
test/jiotests.js
test/jiotests.js
+139
-21
No files found.
src/jio.storage/indexstorage.js
View file @
52486182
...
@@ -155,6 +155,7 @@ jIO.addStorageType('indexed', function (spec, my) {
...
@@ -155,6 +155,7 @@ jIO.addStorageType('indexed', function (spec, my) {
index
.
reference
=
priv
.
indices
[
i
];
index
.
reference
=
priv
.
indices
[
i
];
index
.
name
=
index
.
reference
[
"
name
"
];
index
.
name
=
index
.
reference
[
"
name
"
];
index
.
size
=
priv
.
getObjectSize
(
indices
[
index
.
name
]);
index
.
size
=
priv
.
getObjectSize
(
indices
[
index
.
name
]);
index
.
result_array
;
if
(
index
.
size
>
0
)
{
if
(
index
.
size
>
0
)
{
if
(
priv
.
searchIndexByValue
(
indices
[
index
.
name
],
doc
.
_id
,
"
bool
"
))
{
if
(
priv
.
searchIndexByValue
(
indices
[
index
.
name
],
doc
.
_id
,
"
bool
"
))
{
...
@@ -164,6 +165,35 @@ jIO.addStorageType('indexed', function (spec, my) {
...
@@ -164,6 +165,35 @@ jIO.addStorageType('indexed', function (spec, my) {
}
}
return
false
;
return
false
;
}
}
priv
.
cleanIndices
=
function
(
indices
,
doc
)
{
var
i
,
j
,
k
,
index
,
key
,
obj
,
prop
,
l
=
priv
.
indices
.
length
,
docid
=
doc
.
_id
;
// loop indices (indexA, indexAB...)
for
(
i
=
0
;
i
<
l
;
i
+=
1
)
{
// index object (reference and current-iteration)
index
=
{};
index
.
reference
=
priv
.
indices
[
i
];
index
.
name
=
index
.
reference
[
"
name
"
];
index
.
current
=
indices
[
index
.
name
];
index
.
current_size
=
priv
.
getObjectSize
(
index
.
current
);
for
(
j
=
0
;
j
<
index
.
current_size
;
j
++
)
{
key
=
priv
.
searchIndexByValue
(
index
.
current
,
doc
.
_id
,
"
key
"
);
index
.
result_array
=
index
.
current
[
key
];
if
(
!!
key
)
{
// if there is more than one docid in the result array,
// just remove this one and not the whole array
if
(
index
.
result_array
.
length
>
1
)
{
index
.
result_array
.
splice
(
k
,
1
);
}
else
{
delete
index
.
current
[
key
];
}
}
}
}
return
indices
;
}
/**
/**
* Adds entries to indices
* Adds entries to indices
* @method createEmptyIndexArray
* @method createEmptyIndexArray
...
@@ -414,23 +444,92 @@ jIO.addStorageType('indexed', function (spec, my) {
...
@@ -414,23 +444,92 @@ jIO.addStorageType('indexed', function (spec, my) {
}
}
);
);
};
};
/**
* Removes a document.
/**
* Remove document or attachment - removing documents updates index!.
* @method remove
* @method remove
*//*
* @param {object} command The JIO command
*/
that
.
remove
=
function
(
command
)
{
that
.
remove
=
function
(
command
)
{
var success = function (val) {
var
f
=
{},
indices
,
doc
,
docid
,
option
;
priv.removeFile(command.getDocId());
priv.update();
doc
=
command
.
cloneDoc
();
that.success(val);
option
=
command
.
cloneOption
();
},
if
(
option
.
max_retry
===
0
)
{
error = function (err) {
option
.
max_retry
=
3
;
that.error(err);
}
};
that.addJob('remove', priv.sub_storage_spec, command.cloneDoc(),
f
.
removeDocument
=
function
(
type
)
{
command.cloneOption(), success, error);
if
(
type
===
'
doc
'
)
{
docid
=
command
.
getDocId
();
}
else
{
docid
=
command
.
getDocId
()
+
'
/
'
+
command
.
getAttachmentId
();
}
that
.
addJob
(
"
remove
"
,
priv
.
substorage
,
docid
,
option
,
function
(
response
)
{
that
.
success
(
response
);
},
function
(
err
)
{
that
.
error
({
"
status
"
:
409
,
"
statusText
"
:
"
Conflict
"
,
"
error
"
:
"
conflict
"
,
"
message
"
:
"
Document Update Conflict
"
,
"
reason
"
:
"
Could not delete document or attachment
"
});
}
);
};
f
.
getIndices
=
function
()
{
that
.
addJob
(
"
get
"
,
priv
.
substorage
,
priv
.
index_suffix
,
option
,
function
(
response
)
{
// if deleting an attachment
if
(
typeof
command
.
getAttachmentId
()
===
'
string
'
){
f
.
removeDocument
(
'
attachment
'
)
}
else
{
indices
=
priv
.
cleanIndices
(
response
,
doc
);
// store update index file
that
.
addJob
(
"
put
"
,
priv
.
substorage
,
indices
,
command
.
cloneOption
(),
function
()
{
// remove actual document
f
.
removeDocument
(
'
doc
'
);
},
function
(
err
)
{
// xxx do we try to delete the posted document ?
err
.
message
=
"
Cannot save index file
"
;
that
.
error
(
err
);
}
);
}
},
function
(
err
)
{
that
.
error
({
"
status
"
:
404
,
"
statusText
"
:
"
Not Found
"
,
"
error
"
:
"
not_found
"
,
"
message
"
:
"
Document index not found, please check document ID
"
,
"
reason
"
:
"
Incorrect document ID
"
});
return
;
}
);
};
f
.
getIndices
();
};
};
*//**
/**
* Gets a document list.
* Gets a document list.
* @method allDocs
* @method allDocs
*/
*/
...
...
test/jiotests.js
View file @
52486182
...
@@ -3027,34 +3027,152 @@ test ('Get document list', function () {
...
@@ -3027,34 +3027,152 @@ test ('Get document list', function () {
ok (false, 'no response / too much results');
ok (false, 'no response / too much results');
}
}
});
});
*/
test ('Remove document', function () {
test
(
"
Remove
"
,
function
(){
var o = {}; o.clock = this.sandbox.useFakeTimers();
o.clock.tick(base_tick);
o.sub_storage = {type:'dummyall3tries',username:'indexremove'}
o.storage_file_object_name = 'jio/indexed_file_object/'+
JSON.stringify (o.sub_storage);
o.jio = JIO.newJio({type:'indexed',storage:o.sub_storage});
// not sure these need to be run, because the index does not change
o.f = function (err,val) {
// and only small modifications have been made to handle putAttachment
if (err) {
// tests are from localStorage putAttachment
err = err.status;
var
o
=
generateTools
(
this
);
}
deepEqual (err || val,{ok:true,id:'file'},'document remove');
o
.
jio
=
JIO
.
newJio
({
"
type
"
:
"
indexed
"
,
"
indices
"
:
[
{
"
name
"
:
"
indexA
"
,
"
fields
"
:[
"
author
"
]},
{
"
name
"
:
"
indexAB
"
,
"
fields
"
:[
"
author
"
,
"
year
"
]}
],
"
sub_storage
"
:
{
"
type
"
:
"
local
"
,
"
username
"
:
"
irem
"
,
"
application_name
"
:
"
irem
"
}
});
// remove inexistent document
o
.
spy
(
o
,
"
status
"
,
404
,
"
Remove inexistent document
"
);
o
.
jio
.
remove
({
"
_id
"
:
"
remove1
"
},
o
.
f
);
o
.
tick
(
o
);
// remove inexistent document/attachment
o
.
spy
(
o
,
"
status
"
,
404
,
"
Remove inexistent document/attachment
"
);
o
.
jio
.
remove
({
"
_id
"
:
"
remove1/remove2
"
},
o
.
f
);
o
.
tick
(
o
);
// adding a document
o
.
jio
.
put
({
"
_id
"
:
"
remove1
"
,
"
title
"
:
"
myRemove1
"
,
"
author
"
:
"
Mr. President
"
,
"
year
"
:
"
2525
"
});
o
.
tick
(
o
);
// adding a 2nd document with same keywords
o
.
jio
.
put
({
"
_id
"
:
"
removeAlso
"
,
"
title
"
:
"
myRemove2
"
,
"
author
"
:
"
Martin Mustermann
"
,
"
year
"
:
"
2525
"
});
o
.
tick
(
o
);
// remove document
o
.
spy
(
o
,
"
value
"
,
{
"
ok
"
:
true
,
"
id
"
:
"
remove1
"
},
"
Remove document
"
);
o
.
jio
.
remove
({
"
_id
"
:
"
remove1
"
},
o
.
f
);
o
.
tick
(
o
);
// check index
o
.
fakeIndex
=
{
"
_id
"
:
"
irem_indices.json
"
,
"
indexA
"
:
{
"
Martin Mustermann
"
:
[
"
removeAlso
"
]},
"
indexAB
"
:
{
"
2525
"
:
[
"
removeAlso
"
],
"
Martin Mustermann
"
:
[
"
removeAlso
"
]}
};
};
this.spy(o,'f');
o
.
jio
.
get
(
"
irem_indices.json
"
,
function
(
err
,
response
){
o.jio.remove({_id:'file'},{max_retry:3},o.f);
o
.
actualIndex
=
response
;
o.clock.tick(2000);
deepEqual
(
o
.
actualIndex
,
o
.
fakeIndex
,
"
Check index file
"
);
if (!o.f.calledOnce){
});
ok (false, 'no response / too much results');
o
.
tick
(
o
);
}
o.tmp = LocalOrCookieStorage.getItem(o.storage_file_object_name) || {};
// check document
ok (!o.tmp.file,'File does not exists anymore');
o
.
spy
(
o
,
"
status
"
,
404
,
"
Check if document has been removed
"
);
o
.
jio
.
get
(
"
remove1
"
,
o
.
f
);
o
.
tick
(
o
);
// adding a new document
o
.
jio
.
put
({
"
_id
"
:
"
remove3
"
,
"
title
"
:
"
myRemove1
"
,
"
author
"
:
"
Mrs Sunshine
"
,
"
year
"
:
"
1234
"
});
o
.
tick
(
o
);
// adding an attachment
o
.
jio
.
putAttachment
({
"
id
"
:
"
remove3/removeAtt
"
,
"
mimetype
"
:
"
text/plain
"
,
"
content
"
:
"
hello
"
});
o
.
tick
(
o
);
// add another attachment
o
.
jio
.
putAttachment
({
"
id
"
:
"
remove3/removeAtt2
"
,
"
mimetype
"
:
"
text/plain
"
,
"
content
"
:
"
hello2
"
});
o
.
tick
(
o
);
// remove attachment
o
.
spy
(
o
,
"
value
"
,
{
"
ok
"
:
true
,
"
id
"
:
"
remove3/removeAtt2
"
},
"
Remove one of multiple attachment
"
);
o
.
jio
.
remove
({
"
_id
"
:
"
remove3/removeAtt2
"
},
o
.
f
);
o
.
tick
(
o
);
// check index
o
.
fakeIndex
=
{
"
_id
"
:
"
irem_indices.json
"
,
"
indexA
"
:
{
"
Martin Mustermann
"
:
[
"
removeAlso
"
],
"
Mrs Sunshine
"
:
[
"
remove3
"
]
},
"
indexAB
"
:
{
"
1234
"
:
[
"
remove3
"
],
"
2525
"
:
[
"
removeAlso
"
],
"
Martin Mustermann
"
:
[
"
removeAlso
"
],
"
Mrs Sunshine
"
:
[
"
remove3
"
]
}
};
o
.
jio
.
get
(
"
irem_indices.json
"
,
function
(
err
,
response
){
o
.
actualIndex
=
response
;
deepEqual
(
o
.
actualIndex
,
o
.
fakeIndex
,
"
Check index file
"
);
});
o
.
tick
(
o
);
// remove document and attachment together
o
.
spy
(
o
,
"
value
"
,
{
"
ok
"
:
true
,
"
id
"
:
"
remove3
"
},
"
Remove one document and attachment together
"
);
o
.
jio
.
remove
({
"
_id
"
:
"
remove3
"
},
o
.
f
);
o
.
tick
(
o
);
// check index
o
.
fakeIndex
=
{
"
_id
"
:
"
irem_indices.json
"
,
"
indexA
"
:
{
"
Martin Mustermann
"
:
[
"
removeAlso
"
]
},
"
indexAB
"
:
{
"
2525
"
:
[
"
removeAlso
"
],
"
Martin Mustermann
"
:
[
"
removeAlso
"
]
}
};
o
.
jio
.
get
(
"
irem_indices.json
"
,
function
(
err
,
response
){
o
.
actualIndex
=
response
;
deepEqual
(
o
.
actualIndex
,
o
.
fakeIndex
,
"
Check index file
"
);
});
o
.
tick
(
o
);
// check attachment
o
.
spy
(
o
,
"
status
"
,
404
,
"
Check if attachment has been removed
"
);
o
.
jio
.
get
(
"
remove3/removeAtt
"
,
o
.
f
);
o
.
tick
(
o
);
// check document
o
.
spy
(
o
,
"
status
"
,
404
,
"
Check if document has been removed
"
);
o
.
jio
.
get
(
"
remove3
"
,
o
.
f
);
o
.
tick
(
o
);
o
.
jio
.
stop
();
o
.
jio
.
stop
();
});
});
*/
/*
/*
module ('Jio CryptedStorage');
module ('Jio CryptedStorage');
...
...
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