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
Bryan Kaperick
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
Hide 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 @@
...
@@ -403,12 +403,26 @@
function
isSingleLocalRoles
(
parsed_query
)
{
function
isSingleLocalRoles
(
parsed_query
)
{
if
((
parsed_query
instanceof
SimpleQuery
)
&&
if
((
parsed_query
instanceof
SimpleQuery
)
&&
(
parsed_query
.
operator
===
undefined
)
&&
(
parsed_query
.
key
===
'
local_roles
'
))
{
(
parsed_query
.
key
===
'
local_roles
'
))
{
// local_roles:"Assignee"
// local_roles:"Assignee"
return
parsed_query
.
value
;
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
)
{
function
isMultipleLocalRoles
(
parsed_query
)
{
var
i
,
var
i
,
sub_query
,
sub_query
,
...
@@ -420,6 +434,7 @@
...
@@ -420,6 +434,7 @@
for
(
i
=
0
;
i
<
parsed_query
.
query_list
.
length
;
i
+=
1
)
{
for
(
i
=
0
;
i
<
parsed_query
.
query_list
.
length
;
i
+=
1
)
{
sub_query
=
parsed_query
.
query_list
[
i
];
sub_query
=
parsed_query
.
query_list
[
i
];
if
((
sub_query
instanceof
SimpleQuery
)
&&
if
((
sub_query
instanceof
SimpleQuery
)
&&
(
sub_query
.
key
!==
undefined
)
&&
(
sub_query
.
key
===
'
local_roles
'
))
{
(
sub_query
.
key
===
'
local_roles
'
))
{
local_role_list
.
push
(
sub_query
.
value
);
local_role_list
.
push
(
sub_query
.
value
);
}
else
{
}
else
{
...
@@ -443,49 +458,76 @@
...
@@ -443,49 +458,76 @@
.
push
(
function
(
site_hal
)
{
.
push
(
function
(
site_hal
)
{
var
query
=
options
.
query
,
var
query
=
options
.
query
,
i
,
i
,
key
,
parsed_query
,
parsed_query
,
sub_query
,
sub_query
,
result_list
,
result_list
,
local_roles
,
local_roles
,
local_role_found
=
false
,
selection_domain
,
sort_list
=
[];
sort_list
=
[];
if
(
options
.
query
)
{
if
(
options
.
query
)
{
parsed_query
=
jIO
.
QueryFactory
.
create
(
options
.
query
);
parsed_query
=
jIO
.
QueryFactory
.
create
(
options
.
query
);
result_list
=
isSingleLocalRoles
(
parsed_query
);
result_list
=
isSingleLocalRoles
(
parsed_query
);
if
(
result_list
)
{
if
(
result_list
)
{
query
=
undefined
;
query
=
undefined
;
local_roles
=
result_list
;
local_roles
=
result_list
;
}
else
{
}
else
{
result_list
=
isSingleDomain
(
parsed_query
);
result_list
=
isMultipleLocalRoles
(
parsed_query
);
if
(
result_list
)
{
if
(
result_list
)
{
query
=
undefined
;
query
=
undefined
;
local_roles
=
result_list
;
selection_domain
=
result_list
;
}
else
if
((
parsed_query
instanceof
ComplexQuery
)
&&
}
else
{
(
parsed_query
.
operator
===
'
AND
'
))
{
result_list
=
isMultipleLocalRoles
(
parsed_query
);
// portal_type:"Person" AND local_roles:"Assignee"
if
(
result_list
)
{
for
(
i
=
0
;
i
<
parsed_query
.
query_list
.
length
;
i
+=
1
)
{
query
=
undefined
;
sub_query
=
parsed_query
.
query_list
[
i
];
local_roles
=
result_list
;
}
else
if
((
parsed_query
instanceof
ComplexQuery
)
&&
result_list
=
isSingleLocalRoles
(
sub_query
);
(
parsed_query
.
operator
===
'
AND
'
))
{
if
(
result_list
)
{
local_roles
=
result_list
;
// portal_type:"Person" AND local_roles:"Assignee"
parsed_query
.
query_list
.
splice
(
i
,
1
);
// AND selection_domain_region:"europe/france"
query
=
jIO
.
Query
.
objectToSearchText
(
parsed_query
);
for
(
i
=
0
;
i
<
parsed_query
.
query_list
.
length
;
i
+=
1
)
{
i
=
parsed_query
.
query_list
.
length
;
sub_query
=
parsed_query
.
query_list
[
i
];
}
else
{
result_list
=
isMultipleLocalRoles
(
sub_query
);
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
);
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
);
local_role_found
=
true
;
}
}
}
result_list
=
isSingleDomain
(
sub_query
);
if
(
result_list
)
{
if
(
result_list
)
{
local_roles
=
result_list
;
parsed_query
.
query_list
.
splice
(
i
,
1
);
parsed_query
.
query_list
.
splice
(
i
,
1
);
query
=
jIO
.
Query
.
objectToSearchText
(
parsed_query
);
query
=
jIO
.
Query
.
objectToSearchText
(
parsed_query
);
i
=
parsed_query
.
query_list
.
length
;
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
;
}
}
}
}
}
}
}
}
}
}
}
}
...
@@ -495,6 +537,10 @@
...
@@ -495,6 +537,10 @@
}
}
}
}
if
(
selection_domain
)
{
selection_domain
=
JSON
.
stringify
(
selection_domain
);
}
return
jIO
.
util
.
ajax
({
return
jIO
.
util
.
ajax
({
"
type
"
:
"
GET
"
,
"
type
"
:
"
GET
"
,
"
url
"
:
UriTemplate
.
parse
(
site_hal
.
_links
.
raw_search
.
href
)
"
url
"
:
UriTemplate
.
parse
(
site_hal
.
_links
.
raw_search
.
href
)
...
@@ -504,7 +550,8 @@
...
@@ -504,7 +550,8 @@
select_list
:
options
.
select_list
||
[
"
title
"
,
"
reference
"
],
select_list
:
options
.
select_list
||
[
"
title
"
,
"
reference
"
],
limit
:
options
.
limit
,
limit
:
options
.
limit
,
sort_on
:
sort_list
,
sort_on
:
sort_list
,
local_roles
:
local_roles
local_roles
:
local_roles
,
selection_domain
:
selection_domain
}),
}),
"
xhrFields
"
:
{
"
xhrFields
"
:
{
withCredentials
:
true
withCredentials
:
true
...
...
test/jio.storage/erp5storage.tests.js
View file @
a06b3b4b
...
@@ -13,7 +13,7 @@
...
@@ -13,7 +13,7 @@
domain
=
"
https://example.org
"
,
domain
=
"
https://example.org
"
,
traverse_template
=
domain
+
"
?mode=traverse{&relative_url,view}
"
,
traverse_template
=
domain
+
"
?mode=traverse{&relative_url,view}
"
,
search_template
=
domain
+
"
?mode=search{&query,select_list*,limit*,
"
+
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
"
,
add_url
=
domain
+
"
lets?add=somedocument
"
,
root_hateoas
=
JSON
.
stringify
({
root_hateoas
=
JSON
.
stringify
({
"
_links
"
:
{
"
_links
"
:
{
...
@@ -1175,6 +1175,7 @@
...
@@ -1175,6 +1175,7 @@
});
});
});
});
// Local roles tests
test
(
"
extract simple single local_roles
"
,
function
()
{
test
(
"
extract simple single local_roles
"
,
function
()
{
var
search_url
=
domain
+
"
?mode=search&
"
+
var
search_url
=
domain
+
"
?mode=search&
"
+
"
select_list=destination&select_list=source&limit=5
"
+
"
select_list=destination&select_list=source&limit=5
"
+
...
@@ -1435,6 +1436,219 @@
...
@@ -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
// 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