CPS-235: Overview of (early) CPS Query
Resources
CPS-235: Spike: Create Overview of (early) CPS Query and Update ScenariosClosed
https://www.softwaretestinghelp.com/xpath-writing-cheat-sheet-tutorial-examples/
*Note when using online xpath testers, ensure that laves are expressed as xml attributes and not like other xml elements like json-to-xml convertors will do.
Incorrect | Correct | Bookstore XML extract for testing xPath Queries online |
---|---|---|
<categories>
<code>01</code>
<name>SciFi</name>
<books>
</books>
</categories> | <categories code=01 name='SciFi'>
<books>
</books>
</categories> | Bookstore <bookstore name="Chapters">
<bookstore-name>Chapters</bookstore-name>
<categories code="01" name="SciFi">
<books>
<book name="Feersum Endjinn"/>
<book name="Chapters"/>
</books>
</categories>
<categories code="02" name="kids" />
<categories code="03" name="Chapters" />
</bookstore> |
Open Issues & Decision
Slogan | Notes | Answer | |
---|---|---|---|
1 | Is there and xPath expression to 'include or exclude all descendants' | Alternatively client can pass an enum option | Need to use output option additional to the cpsPath (xpath) expression! Although xpath has many options to include or exclude children from filters (conditions) it does NOT control what is being returned. |
Queries
Scope of queries
The assumes scope for all below Queries is one Dataspace and oen Anchor.
It will be relatively easy to extend the scope to multiple anchors in a later user story.
There is no need to extend the scope beyond one Dataspace
xpath functions
Slogan | cpsPath | Jira | Notes | Priority / When do we need this? | |
---|---|---|---|---|---|
1 | get (list element) by xpath |
| CPS-71: VSE: Retrieve node by (fully qualified) cpsPath an anchorClosed | This is not really a query as code is the key attributes and this xpath is stored with the target fragment | Already implemented |
2 | filter list element by other (then key) leaf value |
| CPS-231: E2E - DataNode Query with AnchorName, xpath and leafname and valueClosed | Compare to #1, notice how from a cpsPath perspective it is not clear which is a get and which is a query. The customer might not know either! See issue #1 | Required for E2E Slicing see CPS-200 study |
3 | xpath ending (with possible refernce to list key) |
| Client ignore/does not care/does not know the preceding xpath | Investigate if needed for E2E Slicing. | |
4 | xpath ending combined with leafvalue filter |
| |||
5 | filter on leaf value without any path |
| This will return anything with that name, might be useful when working with small models | ||
6 | allow any element from list ie. find something under any possible list entry |
| Not obvious but since /categories is not indexed (no key defined using [@...] notation) it will return a book from any categories | ||
7 | partial xpath, wildcard in the middle of the path . Could be seen as combination of starts-with and end-with |
| using // in the middle of a path is like a wildcard for any containers or lists between /categories and /book | ||
8 | combining several leaf values (and, or etc.) Can bee seen too for composite list-keys and does work in scenario #1 above (but is order dependent) | just for illustration purposes | |||
9 | (string) leave value contains something |
| just for illustration purposes | ||
10 | get direct ancestor | //*[child::book[@name='Chapters']] //book[@name="Chapters"]/.. | |||
11 | get ancestor by type | <query>/ancestor::bookstore e.g //book[@name="Chapters"]/ancestor::bookstore | Required for end to end API call #1 |
Note 1. All cpsPath queries can be fulfilled by just 1 REST endpoint and Java API method (as agreed earlier). We just need to document the capabilities (xpath functions) support by our cpsPath...
Note 2. At the start the cpsPath can probably be examined using regular expression to distinguish between the queries. But at some stage we might need to write a more advanced parsing using tools like Antlr. There might also be existing utilities breaking down xpaths?