Commit d814b55c authored by Romain Courteaud's avatar Romain Courteaud

[erp5storage] Allow to query the catalog with the group_by parameter

parent 2f890873
......@@ -474,6 +474,7 @@
if (context.hasCapacity("list") &&
((options.query === undefined) || context.hasCapacity("query")) &&
((options.sort_on === undefined) || context.hasCapacity("sort")) &&
((options.group_by === undefined) || context.hasCapacity("group")) &&
((options.select_list === undefined) ||
context.hasCapacity("select")) &&
((options.include_docs === undefined) ||
......
......@@ -419,7 +419,7 @@
ERP5Storage.prototype.hasCapacity = function (name) {
return ((name === "list") || (name === "query") ||
(name === "select") || (name === "limit") ||
(name === "sort"));
(name === "sort") || (name === "group"));
};
function isSingleLocalRoles(parsed_query) {
......@@ -487,7 +487,8 @@
local_roles,
local_role_found = false,
selection_domain,
sort_list = [];
sort_list = [],
group_list = [];
if (options.query) {
parsed_query = jIO.QueryFactory.create(options.query);
result_list = isSingleLocalRoles(parsed_query);
......@@ -559,6 +560,10 @@
}
}
if (options.group_by) {
group_list = options.group_by;
}
if (selection_domain) {
selection_domain = JSON.stringify(selection_domain);
}
......@@ -572,6 +577,7 @@
select_list: options.select_list || ["title", "reference"],
limit: options.limit,
sort_on: sort_list,
group_by: group_list,
local_roles: local_roles,
selection_domain: selection_domain
})
......
......@@ -32,7 +32,7 @@
domain = "https://example.org",
traverse_template = domain + "?mode=traverse{&relative_url,view}",
search_template = domain + "?mode=search{&query,select_list*,limit*," +
"sort_on*,local_roles*,selection_domain*}",
"sort_on*,group_by*,local_roles*,selection_domain*}",
add_url = domain + "lets?add=somedocument",
root_hateoas = JSON.stringify({
"_links": {
......@@ -1289,6 +1289,7 @@
ok(this.jio.hasCapacity("query"));
ok(this.jio.hasCapacity("select"));
ok(this.jio.hasCapacity("limit"));
ok(this.jio.hasCapacity("group"));
});
/////////////////////////////////////////////////////////////////
......@@ -1481,7 +1482,9 @@
var search_url = domain + "?mode=search&query=title%3A%20%22two%22&" +
"select_list=destination&select_list=source&limit=5&" +
"sort_on=%5B%22title%22%2C%22descending%22%5D&" +
"sort_on=%5B%22id%22%2C%22descending%22%5D",
"sort_on=%5B%22id%22%2C%22descending%22%5D&" +
"group_by=a_foo_grouping&" +
"group_by=a_bar_grouping",
search_hateoas = JSON.stringify({
"_embedded": {
......@@ -1522,7 +1525,8 @@
limit: [5],
select_list: ["destination", "source"],
query: 'title: "two"',
sort_on: [["title", "descending"], ["id", "descending"]]
sort_on: [["title", "descending"], ["id", "descending"]],
group_by: ["a_foo_grouping", "a_bar_grouping"]
})
.then(function (result) {
deepEqual(result, {
......
......@@ -964,6 +964,44 @@
start();
});
});
test("group_by is not handled", function () {
stop();
expect(3);
function StorageGroupCapacity() {
return this;
}
StorageGroupCapacity.prototype.hasCapacity = function (capacity) {
return ((capacity === "list") || (capacity === "group"));
};
jIO.addStorage('querystoragegroupcapacity', StorageGroupCapacity);
var jio = jIO.createJIO({
type: "query",
sub_storage: {
type: "querystoragegroupcapacity"
}
});
jio.allDocs({
group_by: ["title"]
})
.then(function () {
ok(false, 'Must fail as group is not handled');
})
.fail(function (error) {
ok(error instanceof jIO.util.jIOError);
equal(error.status_code, 501);
equal(error.message,
"Capacity 'group' is not implemented on 'query'");
})
.always(function () {
start();
});
});
/////////////////////////////////////////////////////////////////
// queryStorage.repair
/////////////////////////////////////////////////////////////////
......
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