Commit 5163b15b authored by Romain Courteaud's avatar Romain Courteaud

Release version 3.1.0

parent e4e18e6c
......@@ -5636,6 +5636,7 @@ Query.searchTextToRegExp = searchTextToRegExp;
return argument_list[0];
});
declareMethod(JioProxyStorage, "get", checkId);
declareMethod(JioProxyStorage, "bulk");
declareMethod(JioProxyStorage, "remove", checkId, function (argument_list) {
return argument_list[0];
});
......@@ -5781,7 +5782,11 @@ Query.searchTextToRegExp = searchTextToRegExp;
};
JioProxyStorage.prototype.hasCapacity = function (name) {
var storage_method = this.__storage.hasCapacity;
var storage_method = this.__storage.hasCapacity,
capacity_method = this.__storage[name];
if (capacity_method !== undefined) {
return true;
}
if ((storage_method === undefined) ||
!storage_method.apply(this.__storage, arguments)) {
throw new jIO.util.jIOError(
......@@ -6475,7 +6480,8 @@ Query.searchTextToRegExp = searchTextToRegExp;
});
}
function checkLocalCreation(queue, source, destination, id, options) {
function checkLocalCreation(queue, source, destination, id, options,
getMethod) {
var remote_doc;
queue
.push(function () {
......@@ -6495,7 +6501,7 @@ Query.searchTextToRegExp = searchTextToRegExp;
.push(function () {
// This document was never synced.
// Push it to the remote storage and store sync information
return source.get(id);
return getMethod(id);
})
.push(function (doc) {
var local_hash = generateHash(JSON.stringify(doc)),
......@@ -6521,6 +6527,34 @@ Query.searchTextToRegExp = searchTextToRegExp;
});
}
function checkBulkLocalCreation(queue, source, destination, id_list,
options) {
queue
.push(function () {
return source.bulk(id_list);
})
.push(function (result_list) {
var i,
sub_queue = new RSVP.Queue();
function getResult(j) {
return function (id) {
if (id !== id_list[j].parameter_list[0]) {
throw new Error("Does not access expected ID " + id);
}
return result_list[j];
};
}
for (i = 0; i < result_list.length; i += 1) {
checkLocalCreation(sub_queue, source, destination,
id_list[i].parameter_list[0],
options, getResult(i));
}
return sub_queue;
});
}
function checkLocalDeletion(queue, destination, id, source) {
var status_hash;
queue
......@@ -6620,6 +6654,7 @@ Query.searchTextToRegExp = searchTextToRegExp;
.push(function (result_list) {
var i,
local_dict = {},
new_list = [],
signature_dict = {},
key;
for (i = 0; i < result_list[0].data.total_rows; i += 1) {
......@@ -6636,13 +6671,26 @@ Query.searchTextToRegExp = searchTextToRegExp;
signature_dict[result_list[1].data.rows[i].id] = i;
}
}
if (options.check_creation === true) {
for (key in local_dict) {
if (local_dict.hasOwnProperty(key)) {
if (!signature_dict.hasOwnProperty(key)) {
checkLocalCreation(queue, source, destination, key, options);
if (options.use_bulk_get === true) {
new_list.push({
method: "get",
parameter_list: [key]
});
} else {
checkLocalCreation(queue, source, destination, key,
options, source.get.bind(source));
}
}
}
}
if ((options.use_bulk_get === true) && (new_list.length !== 0)) {
checkBulkLocalCreation(queue, source, destination, new_list,
options);
}
}
for (key in signature_dict) {
......@@ -6712,11 +6760,23 @@ Query.searchTextToRegExp = searchTextToRegExp;
}
})
.push(function () {
// Autoactivate bulk if substorage implements it
// Keep it like this until the bulk API is stabilized
var use_bulk_get = false;
try {
use_bulk_get = context._remote_sub_storage.hasCapacity("bulk");
} catch (error) {
if (!((error instanceof jIO.util.jIOError) &&
(error.status_code === 501))) {
throw error;
}
}
if (context._check_remote_modification ||
context._check_remote_creation ||
context._check_remote_deletion) {
return pushStorage(context._remote_sub_storage,
context._local_sub_storage, {
use_bulk_get: use_bulk_get,
check_modification: context._check_remote_modification,
check_creation: context._check_remote_creation,
check_deletion: context._check_remote_deletion
......@@ -7738,15 +7798,9 @@ Query.searchTextToRegExp = searchTextToRegExp;
"TextAreaField": null
};
function extractPropertyFromForm(context, id) {
return context.getAttachment(id, "view")
.push(function (blob) {
return jIO.util.readBlobAsText(blob);
})
.push(function (evt) {
return JSON.parse(evt.target.result);
})
.push(function (json) {
function extractPropertyFromFormJSON(json) {
return new RSVP.Queue()
.push(function () {
var form = json._embedded._view,
converted_json = {
portal_type: json.portal_type
......@@ -7784,6 +7838,19 @@ Query.searchTextToRegExp = searchTextToRegExp;
});
}
function extractPropertyFromForm(context, id) {
return context.getAttachment(id, "view")
.push(function (blob) {
return jIO.util.readBlobAsText(blob);
})
.push(function (evt) {
return JSON.parse(evt.target.result);
})
.push(function (json) {
return extractPropertyFromFormJSON(json);
});
}
// XXX docstring
function ERP5Storage(spec) {
if (typeof spec.url !== "string" || !spec.url) {
......@@ -7794,11 +7861,9 @@ Query.searchTextToRegExp = searchTextToRegExp;
this._default_view_reference = spec.default_view_reference;
}
ERP5Storage.prototype.get = function (id) {
return extractPropertyFromForm(this, id)
.push(function (result) {
var key;
result = result.data;
function convertJSONToGet(json) {
var key,
result = json.data;
// Remove all ERP5 hateoas links / convert them into jIO ID
for (key in result) {
if (result.hasOwnProperty(key)) {
......@@ -7808,6 +7873,63 @@ Query.searchTextToRegExp = searchTextToRegExp;
}
}
return result;
}
ERP5Storage.prototype.get = function (id) {
return extractPropertyFromForm(this, id)
.push(function (result) {
return convertJSONToGet(result);
});
};
ERP5Storage.prototype.bulk = function (request_list) {
var i,
storage = this,
bulk_list = [];
for (i = 0; i < request_list.length; i += 1) {
if (request_list[i].method !== "get") {
throw new Error("ERP5Storage: not supported " +
request_list[i].method + " in bulk");
}
bulk_list.push({
relative_url: request_list[i].parameter_list[0],
view: storage._default_view_reference
});
}
return getSiteDocument(storage)
.push(function (site_hal) {
var form_data = new FormData();
form_data.append("bulk_list", JSON.stringify(bulk_list));
return jIO.util.ajax({
"type": "POST",
"url": site_hal._actions.bulk.href,
"data": form_data,
// "headers": {
// "Content-Type": "application/json"
// },
"xhrFields": {
withCredentials: true
}
});
})
.push(function (response) {
var result_list = [],
hateoas = JSON.parse(response.target.responseText);
function pushResult(json) {
json.portal_type = json._links.type.name;
return extractPropertyFromFormJSON(json)
.push(function (json2) {
return convertJSONToGet(json2);
});
}
for (i = 0; i < hateoas.result_list.length; i += 1) {
result_list.push(pushResult(hateoas.result_list[i]));
}
return RSVP.all(result_list);
});
};
......
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
{
"name": "jio",
"version": "v3.0.0",
"version": "v3.1.0",
"license": "LGPLv3",
"author": "Nexedi SA",
"contributors": [
......
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