Skip to content

Commit

Permalink
Fix Neo4j exception.
Browse files Browse the repository at this point in the history
  • Loading branch information
henrietteharmse committed Oct 18, 2023
1 parent ee62657 commit f0886a6
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions backend/src/main/java/uk/ac/ebi/spot/ols/service/Neo4jClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,10 @@ public List<Map<String,Object>> rawQuery(String query) {

Result result = session.run(query);

session.close();
List<Map<String,Object>> list = result.stream().map(r -> r.asMap()).collect(Collectors.toList());

return result.stream().map(r -> r.asMap()).collect(Collectors.toList());
session.close();
return list;
}

public List<JsonElement> query(String query, String resVar) {
Expand All @@ -70,12 +71,14 @@ public List<JsonElement> query(String query, String resVar) {

Result result = session.run(query);


List<JsonElement> list = result.list().stream()
.map(r -> r.get(resVar).get("_json").asString())
.map(JsonParser::parseString)
.collect(Collectors.toList());
session.close();

return result.list().stream()
.map(r -> r.get(resVar).get("_json").asString())
.map(JsonParser::parseString)
.collect(Collectors.toList());
return list;
}

public Page<JsonElement> queryPaginated(String query, String resVar, String countQuery, Value parameters, Pageable pageable) {
Expand Down Expand Up @@ -118,19 +121,21 @@ public Page<JsonElement> queryPaginated(String query, String resVar, String coun
Result countResult = session.run(countQuery, parameters);
System.out.println("Neo4j run paginated count: " + timer2.stop());

session.close();
Record countRecord = countResult.single();
int count = countRecord.get(0).asInt();

if(!result.hasNext() || result.peek().values().get(0).isNull()) {
return new PageImpl<>(List.of(), pageable, count);
}

return new PageImpl<>(
Page<JsonElement> page = new PageImpl<>(
result.list().stream()
.map(r -> JsonParser.parseString(r.get(resVar).get("_json").asString()))
.collect(Collectors.toList()),
pageable, count);

session.close();
return page;
}

public JsonElement queryOne(String query, String resVar, Value parameters) {
Expand All @@ -143,7 +148,6 @@ public JsonElement queryOne(String query, String resVar, Value parameters) {
Result result = session.run(query, parameters);
System.out.println("Neo4j run query " + query + ": " + timer.stop());

session.close();
Value v = null;

try {
Expand All @@ -152,10 +156,8 @@ public JsonElement queryOne(String query, String resVar, Value parameters) {
throw new ResourceNotFoundException();
}

session.close();
return JsonParser.parseString(v.asString());
}



}

0 comments on commit f0886a6

Please sign in to comment.