Jira Ref: - CPS-1377Getting issue details... STATUS
Requirement :
we need to search over data across multiple anchors for a given dataspace. for this requirement below changes are proposed
Issues & Decisions
# | Issue | Notes | Decision |
---|---|---|---|
1 | Exact respons format | would like to be able to determine which dat is from which anchor See 3 alternatives below |
Endpoint Definition
New endpoint : GET http://localhost:8883/cps/api/v2/dataspaces/{dataspace-name}/nodes/query
parameters:
parameter name | in | isRequired |
---|---|---|
dataspace-name | path | yes |
cps-path | query | yes |
Response Definition
we can have below responses
# | scenario | Body Structures | Response Body Example |
---|---|---|---|
1 | without anchor name | [{data-tree1},..,{data-tree-n}] | |
2 | anchor name per data node | example [ { "test:bookstore": { "bookstore-name": "Chapters", "categories": [ { "code": 1, "name": "SciFi" }, { "code": 2, "name": "kids" } ] }, "anchorName": "anchor01" }, { "test:bookstore2": { "bookstore-name": "Chapters2", "categories": [ { "code": 10, "name": "SciFi" }, { "code": 20, "name": "kids" } ] }, "anchorName": "anchor02" } ] | |
3 | list of data nodes per anchor |
Required Code Changes
file | |
---|---|
openapi.yml | add new endpoint: New endpoint /v2/dataspaces/{dataspace-name}/nodes/query: $ref: 'cpsQueryV2.yml#/nodesByDataspaceAndCpsPath' |
cpsQueryV2.yml | |
FragmentRepositoryCpsPathQueryImpl.java | FragmentRepositoryCpsPathQueryImpl.java @Override @Transactional public List<FragmentEntity> findByCpsPath(final CpsPathQuery cpsPathQuery) { final StringBuilder sqlStringBuilder = new StringBuilder("SELECT * FROM FRAGMENT"); final Map<String, Object> queryParameters = new HashMap<>(); sqlStringBuilder.append(" WHERE xpath ~ :xpathRegex"); final String xpathRegex = getXpathSqlRegex(cpsPathQuery); queryParameters.put("xpathRegex", xpathRegex); if (cpsPathQuery.hasLeafConditions()) { sqlStringBuilder.append(" AND attributes @> :leafDataAsJson\\:\\:jsonb"); queryParameters.put("leafDataAsJson", jsonObjectMapper.asJsonString( cpsPathQuery.getLeavesData())); } addTextFunctionCondition(cpsPathQuery, sqlStringBuilder, queryParameters); final Query query = entityManager.createNativeQuery(sqlStringBuilder.toString(), FragmentEntity.class); setQueryParameters(query, queryParameters); final List<FragmentEntity> fragmentEntities = query.getResultList(); log.debug("Fetched {} fragment entities by anchor and cps path.", fragmentEntities.size()); return fragmentEntities; } |