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

Commit 927c7a5

Browse files
committed
Added not found exception when deleting stored queries
1 parent 9ff32f4 commit 927c7a5

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/main/java/org/humanbrainproject/knowledgegraph/commons/propertyGraph/arango/control/ArangoInternalRepository.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@
1212
import org.humanbrainproject.knowledgegraph.commons.propertyGraph.arango.control.query.ArangoQueryFactory;
1313
import org.humanbrainproject.knowledgegraph.commons.propertyGraph.arango.entity.ArangoCollectionReference;
1414
import org.humanbrainproject.knowledgegraph.commons.propertyGraph.arango.entity.ArangoDocumentReference;
15+
import org.humanbrainproject.knowledgegraph.commons.propertyGraph.arango.exceptions.StoredQueryNotFoundException;
1516
import org.humanbrainproject.knowledgegraph.commons.vocabulary.ArangoVocabulary;
1617
import org.slf4j.Logger;
1718
import org.slf4j.LoggerFactory;
1819
import org.springframework.beans.factory.annotation.Autowired;
1920
import org.springframework.stereotype.Component;
2021

22+
import javax.ws.rs.NotFoundException;
2123
import java.util.List;
2224
import java.util.Map;
2325

@@ -127,15 +129,17 @@ public boolean doesDocumentExist(ArangoCollectionReference collectionReference,
127129
return false;
128130
}
129131

130-
public void removeInternalDocument(ArangoDocumentReference document) throws IllegalAccessException {
132+
public void removeInternalDocument(ArangoDocumentReference document) throws IllegalAccessException, StoredQueryNotFoundException {
131133
String userId = authorizationContext.getUserId();
132134
if(userId==null){
133135
throw new IllegalAccessException("You have to be authenticated if you want to execute this operation");
134136
}
135137
ArangoDatabase db = getDB();
136138
ArangoCollection collection = db.collection(document.getCollection().getName());
137-
if (collection.documentExists(document.getKey())) {
139+
if ( collection.exists() && collection.documentExists(document.getKey())) {
138140
collection.deleteDocument(document.getKey());
141+
} else {
142+
throw new StoredQueryNotFoundException("Query not found");
139143
}
140144
}
141145
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,8 @@ public ResponseEntity<String> removeSpecificationToDB(@PathVariable(ORG) String
332332
authorizationContext.populateAuthorizationContext(authorization);
333333
query.removeSpecificationInDb(new StoredQueryReference(new NexusSchemaReference(org, domain, schema, version), id));
334334
return ResponseEntity.ok("Deleted specification from database");
335+
} catch (StoredQueryNotFoundException e){
336+
return ResponseEntity.notFound().build();
335337
} catch (HttpClientErrorException e) {
336338
return ResponseEntity.status(e.getStatusCode()).build();
337339
} catch (IllegalAccessException e){

0 commit comments

Comments
 (0)