Commit 31e65d17 authored by Sven Franck's avatar Sven Franck

added revision management, POST working, PUT partially

parent 2c7d952d
......@@ -238,6 +238,7 @@ var command = function (method) {
log ('revision: '+ other.revision);
log ('content: '+ other.content);
log ('mimetype: '+ other.mimetype);
break;
case 'post':
case 'put':
doc = JSON.parse ($('#metadata').attr('value'));
......
......@@ -18,12 +18,47 @@
return o;
};
// Fake revisions
var fakeCount = 0;
var generateRevision = function(command, action, reset){
var that = {},
priv = {},
fakeRevision = "",
fakeCount = reset === true ? 0 : fakeCount,
now = Date.now();
that.makeHash = function(){
return that.hashCode('' + command.getDocId() + ' ' + now + '');
};
that.hashCode = function (string) {
return hex_sha256(string);
};
that.generateNextRev = function (previous_revision, string) {
return (parseInt(previous_revision.split('-')[0],10)+1) + '-' +
priv.hashCode(previous_revision + string);
};
if ( fakeRevision === "" && fakeCount === 0 ){
fakeRevision = '1-'+that.makeHash();
} else {
if( action !== "post"){
fakeRevision = that.generateNextRev( fakeRev, that.makeHash );
}
}
return fakeRevision;
};
that.post = function (command) {
setTimeout (function () {
that.success ({
that.success({
ok:true,
id:command.getDocId()
id:command.getDocId(),
rev:generateRevision(command, "post", true)
});
}, 100);
}; // end post
......@@ -32,7 +67,8 @@
setTimeout (function () {
that.success ({
ok:true,
id:command.getDocId()
id:command.getDocId(),
rev:generateRevision(command, "put", true)
});
}, 100); // 100 ms, for jiotests simple job waiting
}; // end put
......
This diff is collapsed.
......@@ -23,9 +23,13 @@ var command = function(spec, my) {
priv.doc = spec.doc || {};
priv.doc._id = priv.doc._id || generateUuid();
priv.docid = spec.docid || '';
priv.content = typeof spec.content === 'string'?
spec.content:
undefined;
// xxx fixed spec.content to spec.doc.content for PUTATTACHMENT
// xxx need extra check for GET, otherwise spec.doc is undefined
priv.content = spec.doc === undefined ? undefined :
typeof spec.doc.content === 'string'?
spec.doc.content:
undefined;
priv.option = spec.options || {};
priv.callbacks = spec.callbacks || {};
priv.success = priv.callbacks.success || function (){};
......
......@@ -11,7 +11,7 @@ var putAttachmentCommand = function(spec, my) {
that.executeOn = function (storage) {
storage.putAttachment (that);
};
that.validateState = function () {
if (typeof that.getContent() !== 'string') {
that.error({
......
......@@ -194,6 +194,7 @@
[options, success, error],
{max_retry:0}
);
priv.addJob(postCommand,{
doc:doc,
options:param.options,
......@@ -223,6 +224,7 @@
[options, success, error],
{max_retry:0}
);
priv.addJob(putCommand,{
doc:doc,
options:param.options,
......@@ -253,6 +255,7 @@
[options,success,error],
{max_retry:3}
);
priv.addJob(getCommand,{
docid:id,
options:param.options,
......@@ -282,6 +285,7 @@
[options,success,callback],
{max_retry:0}
);
priv.addJob(removeCommand,{
doc:doc,
options:param.options,
......@@ -311,6 +315,7 @@
[options,success.error],
{max_retry: 3}
);
priv.addJob(allDocsCommand,{
options:param.options,
callbacks:{success:param.success,error:param.error}
......@@ -342,8 +347,9 @@
[options, success, error],
{max_retry: 0}
);
priv.addJob(putAttachmentCommand,{
doc:{_id:id,content:doc},
priv.addJob(putAttachmentCommand,{
doc:{_id:id,content:doc,_rev:rev,mimetype:mimetype},
options:param.options,
callbacks:{success:param.success,error:param.error}
});
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment