Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
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
Roque
jio
Commits
a06b3b4b
Commit
a06b3b4b
authored
Mar 05, 2018
by
Romain Courteaud
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[erp5storage] Add selection_domain support
parent
fc0e7413
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
285 additions
and
24 deletions
+285
-24
src/jio.storage/erp5storage.js
src/jio.storage/erp5storage.js
+70
-23
test/jio.storage/erp5storage.tests.js
test/jio.storage/erp5storage.tests.js
+215
-1
No files found.
src/jio.storage/erp5storage.js
View file @
a06b3b4b
...
...
@@ -403,12 +403,26 @@
function
isSingleLocalRoles
(
parsed_query
)
{
if
((
parsed_query
instanceof
SimpleQuery
)
&&
(
parsed_query
.
operator
===
undefined
)
&&
(
parsed_query
.
key
===
'
local_roles
'
))
{
// local_roles:"Assignee"
return
parsed_query
.
value
;
}
}
function
isSingleDomain
(
parsed_query
)
{
if
((
parsed_query
instanceof
SimpleQuery
)
&&
(
parsed_query
.
operator
===
undefined
)
&&
(
parsed_query
.
key
!==
undefined
)
&&
(
parsed_query
.
key
.
indexOf
(
'
selection_domain_
'
)
===
0
))
{
// domain_region:"europe/france"
var
result
=
{};
result
[
parsed_query
.
key
.
slice
(
'
selection_domain_
'
.
length
)]
=
parsed_query
.
value
;
return
result
;
}
}
function
isMultipleLocalRoles
(
parsed_query
)
{
var
i
,
sub_query
,
...
...
@@ -420,6 +434,7 @@
for
(
i
=
0
;
i
<
parsed_query
.
query_list
.
length
;
i
+=
1
)
{
sub_query
=
parsed_query
.
query_list
[
i
];
if
((
sub_query
instanceof
SimpleQuery
)
&&
(
sub_query
.
key
!==
undefined
)
&&
(
sub_query
.
key
===
'
local_roles
'
))
{
local_role_list
.
push
(
sub_query
.
value
);
}
else
{
...
...
@@ -443,19 +458,26 @@
.
push
(
function
(
site_hal
)
{
var
query
=
options
.
query
,
i
,
key
,
parsed_query
,
sub_query
,
result_list
,
local_roles
,
local_role_found
=
false
,
selection_domain
,
sort_list
=
[];
if
(
options
.
query
)
{
parsed_query
=
jIO
.
QueryFactory
.
create
(
options
.
query
);
result_list
=
isSingleLocalRoles
(
parsed_query
);
if
(
result_list
)
{
query
=
undefined
;
local_roles
=
result_list
;
}
else
{
result_list
=
isSingleDomain
(
parsed_query
);
if
(
result_list
)
{
query
=
undefined
;
selection_domain
=
result_list
;
}
else
{
result_list
=
isMultipleLocalRoles
(
parsed_query
);
if
(
result_list
)
{
...
...
@@ -465,29 +487,49 @@
(
parsed_query
.
operator
===
'
AND
'
))
{
// portal_type:"Person" AND local_roles:"Assignee"
// AND selection_domain_region:"europe/france"
for
(
i
=
0
;
i
<
parsed_query
.
query_list
.
length
;
i
+=
1
)
{
sub_query
=
parsed_query
.
query_list
[
i
];
if
(
!
local_role_found
)
{
result_list
=
isSingleLocalRoles
(
sub_query
);
if
(
result_list
)
{
local_roles
=
result_list
;
parsed_query
.
query_list
.
splice
(
i
,
1
);
query
=
jIO
.
Query
.
objectToSearchText
(
parsed_query
);
i
=
parsed_query
.
query_list
.
length
;
local_role_found
=
true
;
}
else
{
result_list
=
isMultipleLocalRoles
(
sub_query
);
if
(
result_list
)
{
local_roles
=
result_list
;
parsed_query
.
query_list
.
splice
(
i
,
1
);
query
=
jIO
.
Query
.
objectToSearchText
(
parsed_query
);
i
=
parsed_query
.
query_list
.
length
;
local_role_found
=
true
;
}
}
}
result_list
=
isSingleDomain
(
sub_query
);
if
(
result_list
)
{
parsed_query
.
query_list
.
splice
(
i
,
1
);
query
=
jIO
.
Query
.
objectToSearchText
(
parsed_query
);
if
(
selection_domain
)
{
for
(
key
in
result_list
)
{
if
(
result_list
.
hasOwnProperty
(
key
))
{
selection_domain
[
key
]
=
result_list
[
key
];
}
}
}
else
{
selection_domain
=
result_list
;
}
i
-=
1
;
}
}
}
}
}
}
if
(
options
.
sort_on
)
{
for
(
i
=
0
;
i
<
options
.
sort_on
.
length
;
i
+=
1
)
{
...
...
@@ -495,6 +537,10 @@
}
}
if
(
selection_domain
)
{
selection_domain
=
JSON
.
stringify
(
selection_domain
);
}
return
jIO
.
util
.
ajax
({
"
type
"
:
"
GET
"
,
"
url
"
:
UriTemplate
.
parse
(
site_hal
.
_links
.
raw_search
.
href
)
...
...
@@ -504,7 +550,8 @@
select_list
:
options
.
select_list
||
[
"
title
"
,
"
reference
"
],
limit
:
options
.
limit
,
sort_on
:
sort_list
,
local_roles
:
local_roles
local_roles
:
local_roles
,
selection_domain
:
selection_domain
}),
"
xhrFields
"
:
{
withCredentials
:
true
...
...
test/jio.storage/erp5storage.tests.js
View file @
a06b3b4b
...
...
@@ -13,7 +13,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*}
"
,
"
sort_on*,local_roles*
,selection_domain*
}
"
,
add_url
=
domain
+
"
lets?add=somedocument
"
,
root_hateoas
=
JSON
.
stringify
({
"
_links
"
:
{
...
...
@@ -1175,6 +1175,7 @@
});
});
// Local roles tests
test
(
"
extract simple single local_roles
"
,
function
()
{
var
search_url
=
domain
+
"
?mode=search&
"
+
"
select_list=destination&select_list=source&limit=5
"
+
...
...
@@ -1435,6 +1436,219 @@
});
});
// Selection Domain tests
test
(
"
extract simple single domain
"
,
function
()
{
var
search_url
=
domain
+
"
?mode=search&
"
+
"
select_list=destination&select_list=source&limit=5
"
+
"
&selection_domain=%7B%22region%22%3A%22foo%2Fbar%22%7D
"
,
search_hateoas
=
JSON
.
stringify
({
"
_embedded
"
:
{
"
contents
"
:
[]
}
}),
server
=
this
.
server
;
this
.
server
.
respondWith
(
"
GET
"
,
domain
,
[
200
,
{
"
Content-Type
"
:
"
application/hal+json
"
},
root_hateoas
]);
this
.
server
.
respondWith
(
"
GET
"
,
search_url
,
[
200
,
{
"
Content-Type
"
:
"
application/hal+json
"
},
search_hateoas
]);
stop
();
expect
(
10
);
this
.
jio
.
allDocs
({
limit
:
[
5
],
select_list
:
[
"
destination
"
,
"
source
"
],
query
:
'
selection_domain_region:"foo/bar"
'
})
.
then
(
function
(
result
)
{
deepEqual
(
result
,
{
data
:
{
rows
:
[],
total_rows
:
0
}
},
"
Check document
"
);
equal
(
server
.
requests
.
length
,
2
);
equal
(
server
.
requests
[
0
].
method
,
"
GET
"
);
equal
(
server
.
requests
[
0
].
url
,
domain
);
equal
(
server
.
requests
[
0
].
requestBody
,
undefined
);
equal
(
server
.
requests
[
0
].
withCredentials
,
true
);
equal
(
server
.
requests
[
1
].
method
,
"
GET
"
);
equal
(
server
.
requests
[
1
].
url
,
search_url
);
equal
(
server
.
requests
[
1
].
requestBody
,
undefined
);
equal
(
server
.
requests
[
1
].
withCredentials
,
true
);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
test
(
"
extract complex AND single domains
"
,
function
()
{
var
search_url
=
domain
+
"
?mode=search&
"
+
"
query=%28%20portal_type%3A%20%20%22Person%22%20%29&
"
+
"
select_list=destination&select_list=source&limit=5&
"
+
"
selection_domain=%7B%22group%22%3A%22bar%2Ffoo%22%7D
"
,
search_hateoas
=
JSON
.
stringify
({
"
_embedded
"
:
{
"
contents
"
:
[]
}
}),
server
=
this
.
server
;
this
.
server
.
respondWith
(
"
GET
"
,
domain
,
[
200
,
{
"
Content-Type
"
:
"
application/hal+json
"
},
root_hateoas
]);
this
.
server
.
respondWith
(
"
GET
"
,
search_url
,
[
200
,
{
"
Content-Type
"
:
"
application/hal+json
"
},
search_hateoas
]);
stop
();
expect
(
10
);
this
.
jio
.
allDocs
({
limit
:
[
5
],
select_list
:
[
"
destination
"
,
"
source
"
],
query
:
'
portal_type:"Person" AND selection_domain_group:"bar/foo"
'
})
.
then
(
function
(
result
)
{
deepEqual
(
result
,
{
data
:
{
rows
:
[],
total_rows
:
0
}
},
"
Check document
"
);
equal
(
server
.
requests
.
length
,
2
);
equal
(
server
.
requests
[
0
].
method
,
"
GET
"
);
equal
(
server
.
requests
[
0
].
url
,
domain
);
equal
(
server
.
requests
[
0
].
requestBody
,
undefined
);
equal
(
server
.
requests
[
0
].
withCredentials
,
true
);
equal
(
server
.
requests
[
1
].
method
,
"
GET
"
);
equal
(
server
.
requests
[
1
].
url
,
search_url
);
equal
(
server
.
requests
[
1
].
requestBody
,
undefined
);
equal
(
server
.
requests
[
1
].
withCredentials
,
true
);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
test
(
"
extract complex OR single domains
"
,
function
()
{
var
search_url
=
domain
+
"
?mode=search&
"
+
"
query=portal_type%3A%22Person%22%20OR%20
"
+
"
selection_domain_group%3A%22bar%2Ffoo%22&
"
+
"
select_list=destination&select_list=source&limit=5
"
,
search_hateoas
=
JSON
.
stringify
({
"
_embedded
"
:
{
"
contents
"
:
[]
}
}),
server
=
this
.
server
;
this
.
server
.
respondWith
(
"
GET
"
,
domain
,
[
200
,
{
"
Content-Type
"
:
"
application/hal+json
"
},
root_hateoas
]);
this
.
server
.
respondWith
(
"
GET
"
,
search_url
,
[
200
,
{
"
Content-Type
"
:
"
application/hal+json
"
},
search_hateoas
]);
stop
();
expect
(
10
);
this
.
jio
.
allDocs
({
limit
:
[
5
],
select_list
:
[
"
destination
"
,
"
source
"
],
query
:
'
portal_type:"Person" OR selection_domain_group:"bar/foo"
'
})
.
then
(
function
(
result
)
{
deepEqual
(
result
,
{
data
:
{
rows
:
[],
total_rows
:
0
}
},
"
Check document
"
);
equal
(
server
.
requests
.
length
,
2
);
equal
(
server
.
requests
[
0
].
method
,
"
GET
"
);
equal
(
server
.
requests
[
0
].
url
,
domain
);
equal
(
server
.
requests
[
0
].
requestBody
,
undefined
);
equal
(
server
.
requests
[
0
].
withCredentials
,
true
);
equal
(
server
.
requests
[
1
].
method
,
"
GET
"
);
equal
(
server
.
requests
[
1
].
url
,
search_url
);
equal
(
server
.
requests
[
1
].
requestBody
,
undefined
);
equal
(
server
.
requests
[
1
].
withCredentials
,
true
);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
test
(
"
extract sub multiple domains
"
,
function
()
{
var
search_url
=
domain
+
"
?mode=search&
"
+
"
query=%28%20portal_type%3A%20%20%22Person%22%20AND%20
"
+
"
title%3A%20%20%22atitle%22%20%29&
"
+
"
select_list=destination&select_list=source&limit=5&
"
+
"
local_roles=Assignee&
"
+
"
selection_domain=%7B%22group%22%3A%22bar%2Ffoo%22%2C
"
+
"
%22region%22%3A%22foo%2Fbar%22%7D
"
,
search_hateoas
=
JSON
.
stringify
({
"
_embedded
"
:
{
"
contents
"
:
[]
}
}),
server
=
this
.
server
;
this
.
server
.
respondWith
(
"
GET
"
,
domain
,
[
200
,
{
"
Content-Type
"
:
"
application/hal+json
"
},
root_hateoas
]);
this
.
server
.
respondWith
(
"
GET
"
,
search_url
,
[
200
,
{
"
Content-Type
"
:
"
application/hal+json
"
},
search_hateoas
]);
stop
();
expect
(
10
);
this
.
jio
.
allDocs
({
limit
:
[
5
],
select_list
:
[
"
destination
"
,
"
source
"
],
query
:
'
portal_type:"Person" AND selection_domain_group:"bar/foo" AND
'
+
'
selection_domain_region:"foo/bar" AND
'
+
'
local_roles:"Assignee" AND title:"atitle"
'
})
.
then
(
function
(
result
)
{
deepEqual
(
result
,
{
data
:
{
rows
:
[],
total_rows
:
0
}
},
"
Check document
"
);
equal
(
server
.
requests
.
length
,
2
);
equal
(
server
.
requests
[
0
].
method
,
"
GET
"
);
equal
(
server
.
requests
[
0
].
url
,
domain
);
equal
(
server
.
requests
[
0
].
requestBody
,
undefined
);
equal
(
server
.
requests
[
0
].
withCredentials
,
true
);
equal
(
server
.
requests
[
1
].
method
,
"
GET
"
);
equal
(
server
.
requests
[
1
].
url
,
search_url
);
equal
(
server
.
requests
[
1
].
requestBody
,
undefined
);
equal
(
server
.
requests
[
1
].
withCredentials
,
true
);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
/////////////////////////////////////////////////////////////////
// erp5Storage.put
/////////////////////////////////////////////////////////////////
...
...
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