Skip to content
This repository was archived by the owner on Apr 25, 2023. It is now read-only.

Commit fbacdf8

Browse files
committed
Corrected API for stored queries
1 parent 82e3ba2 commit fbacdf8

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

src/main/java/org/humanbrainproject/knowledgegraph/query/api/QueryAPI.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,9 @@ public ResponseEntity<Map> getQuerySpecification(@PathVariable(ORG) String org,
117117
authorizationContext.populateAuthorizationContext(authorizationToken);
118118

119119
Map queryPayload = query.getQueryPayload(new StoredQueryReference(new NexusSchemaReference(org, domain, schema, version), queryId), Map.class);
120+
JsonDocument doc = new JsonDocument(queryPayload).removeAllInternalKeys();
120121
if (queryPayload != null) {
121-
return ResponseEntity.ok(queryPayload);
122+
return ResponseEntity.ok(doc);
122123
} else {
123124
return ResponseEntity.notFound().build();
124125
}

src/main/java/org/humanbrainproject/knowledgegraph/query/boundary/ArangoQuery.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import org.humanbrainproject.knowledgegraph.commons.propertyGraph.arango.exceptions.StoredQueryNotFoundException;
1818
import org.humanbrainproject.knowledgegraph.commons.vocabulary.ArangoVocabulary;
1919
import org.humanbrainproject.knowledgegraph.commons.vocabulary.HBPVocabulary;
20+
import org.humanbrainproject.knowledgegraph.commons.vocabulary.SchemaOrgVocabulary;
2021
import org.humanbrainproject.knowledgegraph.indexing.entity.nexus.NexusInstanceReference;
2122
import org.humanbrainproject.knowledgegraph.indexing.entity.nexus.NexusSchemaReference;
2223
import org.humanbrainproject.knowledgegraph.query.control.FreemarkerTemplating;
@@ -161,10 +162,20 @@ public List<Map> getStoredQueriesBySchema(NexusSchemaReference schemaReference){
161162
List<Map> internalDocuments = arangoInternalRepository.getInternalDocuments(SPECIFICATION_QUERIES);
162163
List<Map> result = new ArrayList<>();
163164
for (Map internalDocument : internalDocuments) {
164-
String rootSchema = (String)((Map) internalDocument.get(GraphQueryKeys.GRAPH_QUERY_ROOT_SCHEMA)).get(JsonLdConsts.ID);
165-
NexusSchemaReference fromUrl = NexusSchemaReference.createFromUrl(rootSchema);
166-
if(schemaReference.getRelativeUrl().getUrl().equals(fromUrl.getRelativeUrl().getUrl())){
167-
result.add(internalDocument);
165+
if(internalDocument.containsKey(GraphQueryKeys.GRAPH_QUERY_ROOT_SCHEMA.getFieldName())){
166+
String rootSchema = (String)((Map) internalDocument.get(GraphQueryKeys.GRAPH_QUERY_ROOT_SCHEMA.getFieldName())).get(JsonLdConsts.ID);
167+
NexusSchemaReference fromUrl = NexusSchemaReference.createFromUrl(rootSchema);
168+
if(schemaReference.getRelativeUrl().getUrl().equals(fromUrl.getRelativeUrl().getUrl())){
169+
JsonDocument doc = new JsonDocument(internalDocument);
170+
if(doc.containsKey(SchemaOrgVocabulary.IDENTIFIER)){
171+
JsonDocument r = new JsonDocument();
172+
r.addToProperty(SchemaOrgVocabulary.IDENTIFIER, doc.get(SchemaOrgVocabulary.IDENTIFIER));
173+
r.addToProperty(HBPVocabulary.PROVENANCE_CREATED_BY, doc.get(ArangoVocabulary.CREATED_BY_USER));
174+
r.addToProperty(SchemaOrgVocabulary.NAME, doc.getOrDefault(SchemaOrgVocabulary.NAME, ""));
175+
r.addToProperty(SchemaOrgVocabulary.DESCRIPTION, doc.getOrDefault(SchemaOrgVocabulary.DESCRIPTION, ""));
176+
result.add(r);
177+
}
178+
}
168179
}
169180
}
170181
return result;
@@ -215,6 +226,7 @@ public void storeSpecificationInDb(String specification, StoredQueryReference qu
215226
String id = queryReference.getName();
216227
jsonObject.put(ArangoVocabulary.KEY, id);
217228
jsonObject.put(ArangoVocabulary.ID, id);
229+
jsonObject.put(SchemaOrgVocabulary.IDENTIFIER, queryReference.getSchemaReference().toString() + "/" +queryReference.getAlias());
218230
ArangoDocumentReference document = new ArangoDocumentReference(SPECIFICATION_QUERIES, id);
219231
arangoInternalRepository.insertOrUpdateDocument(document, jsonObject.toString());
220232
}

0 commit comments

Comments
 (0)