Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search returning all fields including private and internal fields #195

Merged
merged 2 commits into from
Dec 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion java/apitest/src/test/java/e2e/registry/StudentRequest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"name": "abc",
"gender": "male",
"contact": "1237",
"email": "[email protected]"
"email": "[email protected]",
"favoriteSubject": "Maths"
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "Student7",
"schema": "{\n \"$schema\": \"http://json-schema.org/draft-07/schema\",\n \"type\": \"object\",\n \"properties\": {\n \"Student\": {\n \"$ref\": \"#/definitions/Student\"\n }\n },\n \"required\": [\n \"Student\"\n ],\n \"title\": \"Student\",\n \"definitions\": {\n \"Student\": {\n \"$id\": \"#/properties/Student\",\n \"type\": \"object\",\n \"title\": \"The Student Schema\",\n \"required\": [\n \"name\",\n \"gender\",\n \"contact\",\n \"email\"\n ],\n \"properties\": {\n \"name\": {\n \"type\": \"string\"\n },\n \"gender\": {\n \"type\": \"string\"\n },\n \"contact\": {\n \"type\": \"string\"\n },\n \"email\": {\n \"type\": \"string\"\n }\n }\n }\n },\n \"_osConfig\": {\n \"uniqueIndexFields\": [],\n \"ownershipAttributes\": [{\n \"email\": \"/email\",\n \"mobile\": \"/contact\",\n \"userId\": \"/contact\"\n }],\n \"roles\": [],\n \"inviteRoles\": [\n \"anonymous\"\n ]\n }\n}",
"schema": "{\n \"$schema\": \"http://json-schema.org/draft-07/schema\",\n \"type\": \"object\",\n \"properties\": {\n \"Student\": {\n \"$ref\": \"#/definitions/Student\"\n }\n },\n \"required\": [\n \"Student\"\n ],\n \"title\": \"Student\",\n \"definitions\": {\n \"Student\": {\n \"$id\": \"#/properties/Student\",\n \"type\": \"object\",\n \"title\": \"The Student Schema\",\n \"required\": [\n \"name\",\n \"gender\",\n \"contact\",\n \"email\"\n, \n \"favoriteSubject\" ],\n \"properties\": {\n \"name\": {\n \"type\": \"string\"\n },\n \"gender\": {\n \"type\": \"string\"\n },\n \"contact\": {\n \"type\": \"string\"\n },\n \"email\": {\n \"type\": \"string\"\n }\n }\n }\n },\n \"_osConfig\": {\n\"privateFields\": [\"contact\"], \n\"internalFields\": [\"favoriteSubject\"],\n \"uniqueIndexFields\": [],\n \"ownershipAttributes\": [{\n \"email\": \"/email\",\n \"mobile\": \"/contact\",\n \"userId\": \"/contact\"\n }],\n \"roles\": [],\n \"inviteRoles\": [\n \"anonymous\"\n ]\n }\n}",
"status": "PUBLISHED"
}
11 changes: 11 additions & 0 deletions java/apitest/src/test/java/e2e/registry/registry.feature
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,16 @@ Feature: Registry api tests
When method get
Then status 200
And response[0].name == "xyz"
# get student
Given url registryUrl
And path 'api/v1/Student/search'
And request {"filters":{}}
When method post
Then status 200
* print response
And response.length == 1
And match response[0].contact == '#notpresent'
And match response[0].favoriteSubject == '#notpresent'
# delete student info
Given url registryUrl
And path 'api/v1/Student/' + studentOsid
Expand Down Expand Up @@ -220,6 +230,7 @@ Feature: Registry api tests
Then status 200
* print response
And response.length == 1
And response[0].contact == '#notpresent'

Scenario: Create Board and invite institutes
# get admin token
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,7 @@ public JsonNode search(JsonNode inputQueryNode) throws IOException {
String prefix = shard.getShardLabel() + RecordIdentifier.getSeparator();
JSONUtil.addPrefix((ObjectNode) shardResult, prefix, new ArrayList<>(Arrays.asList(uuidPropertyName)));
}

result.add(shardResult);
removeNonPublicFields(result, searchQuery, shardResult);
transaction.add(tx.hashCode());
}
} catch (Exception e) {
Expand All @@ -144,20 +143,16 @@ public JsonNode search(JsonNode inputQueryNode) throws IOException {

return buildResultNode(searchQuery, result);
}

/**
* combines all the nodes for an entity
* @param entity
* @param allShardResult
* @return
*/
private ArrayNode getEntityAttibute(String entity, ArrayNode allShardResult) {
ArrayNode resultArray = JsonNodeFactory.instance.arrayNode();
for (int i = 0; i < allShardResult.size(); i++) {
resultArray.addAll((ArrayNode) allShardResult.get(i).get(entity));

private void removeNonPublicFields(ArrayNode result, SearchQuery searchQuery, ObjectNode shardResult) throws Exception {
for(String entityType: searchQuery.getEntityTypes()) {
ArrayNode arrayNode = (ArrayNode) shardResult.get(entityType);
for(JsonNode node : arrayNode) {
result.add(JSONUtil.removeNodesByPath(node, definitionsManager.getExcludingFieldsForEntity(entityType)));
}
}
return resultArray;
}

/**
* Builds result node from given array of shard nodes
* @param searchQuery
Expand All @@ -167,8 +162,7 @@ private ArrayNode getEntityAttibute(String entity, ArrayNode allShardResult) {
private JsonNode buildResultNode(SearchQuery searchQuery, ArrayNode allShardResult) {
ObjectNode resultNode = JsonNodeFactory.instance.objectNode();
for (String entity : searchQuery.getEntityTypes()) {
ArrayNode entityResult = getEntityAttibute(entity, allShardResult);
resultNode.set(entity, entityResult);
resultNode.set(entity, allShardResult);
}
return resultNode;
}
Expand Down