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

Changed System.out to logger. #701

Merged
merged 1 commit into from
Jul 15, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import org.apache.solr.client.solrj.response.FacetField.Count;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.common.SolrDocument;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
Expand All @@ -34,6 +36,7 @@

import org.springframework.web.bind.annotation.RestController;
import uk.ac.ebi.spot.ols.repository.Validation;
import uk.ac.ebi.spot.ols.repository.neo4j.OlsNeo4jClient;
import uk.ac.ebi.spot.ols.repository.solr.OlsSolrClient;
import uk.ac.ebi.spot.ols.repository.transforms.LocalizationTransform;
import uk.ac.ebi.spot.ols.repository.transforms.RemoveLiteralDatatypesTransform;
Expand All @@ -59,6 +62,8 @@ public class V1SearchController {
private OlsSolrClient solrClient;


private static final Logger logger = LoggerFactory.getLogger(V1SearchController.class);

@RequestMapping(path = "/api/search", produces = {MediaType.APPLICATION_JSON_VALUE}, method = RequestMethod.GET)
public void search(
@RequestParam("q") String query,
Expand All @@ -81,8 +86,6 @@ public void search(
@RequestParam(value = "lang", defaultValue = "en") String lang,
HttpServletResponse response
) throws IOException, SolrServerException {
System.out.println("fieldList 1 = " + fieldList);
System.out.println("type = " + types);

final SolrQuery solrQuery = new SolrQuery(); // 1

Expand Down Expand Up @@ -208,15 +211,13 @@ public void search(
* Fix: End
*/
solrQuery.add("wt", format);
System.out.println("fieldList 2 = " + fieldList);

System.out.println("solrQuery=" + solrQuery.jsonStr());
logger.debug("search: ()", solrQuery.toQueryString());

QueryResponse qr = solrClient.dispatchSearch(solrQuery, "ols4_entities");

List<Object> docs = new ArrayList<>();
for(SolrDocument res : qr.getResults()) {
System.out.println("res = " + res.toString());
String _json = (String)res.get("_json");
if(_json == null) {
throw new RuntimeException("_json was null");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import org.apache.solr.client.solrj.impl.HttpSolrClient;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.common.SolrDocument;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
Expand All @@ -17,6 +19,7 @@
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import uk.ac.ebi.spot.ols.repository.Validation;
import uk.ac.ebi.spot.ols.repository.neo4j.OlsNeo4jClient;
import uk.ac.ebi.spot.ols.repository.solr.OlsSolrClient;
import uk.ac.ebi.spot.ols.repository.transforms.LocalizationTransform;
import uk.ac.ebi.spot.ols.repository.transforms.RemoveLiteralDatatypesTransform;
Expand All @@ -42,6 +45,8 @@ public class V1SelectController {
@Autowired
private OlsSolrClient solrClient;

private static final Logger logger = LoggerFactory.getLogger(V1SelectController.class);

@RequestMapping(path = "/api/select", produces = {MediaType.APPLICATION_JSON_VALUE}, method = RequestMethod.GET)
public void select(
@RequestParam("q") String query,
Expand Down Expand Up @@ -118,7 +123,7 @@ public void select(
solrQuery.addHighlightField("whitespace_edge_synonym");
solrQuery.addHighlightField("synonym");

System.out.println("select: " + solrQuery.toQueryString());
logger.debug("select: ()", solrQuery.toQueryString());

QueryResponse qr = solrClient.dispatchSearch(solrQuery, "ols4_entities");

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package uk.ac.ebi.spot.ols.repository.neo4j;

import com.google.gson.JsonElement;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Component;
import uk.ac.ebi.spot.ols.repository.solr.OlsSolrClient;
import uk.ac.ebi.spot.ols.service.Neo4jClient;

import java.util.List;
Expand All @@ -19,6 +22,8 @@ public class OlsNeo4jClient {
@Autowired
Neo4jClient neo4jClient;

private static final Logger logger = LoggerFactory.getLogger(OlsNeo4jClient.class);

public Page<JsonElement> getAll(String type, Map<String,String> properties, Pageable pageable) {

String query = "MATCH (a:" + type + ")";
Expand Down Expand Up @@ -71,40 +76,40 @@ private String makeEdgePropsClause(Map<String,String> edgeProps) {

public Page<JsonElement> traverseOutgoingEdges(String type, String id, List<String> edgeIRIs, Map<String,String> edgeProps, Pageable pageable) {

String edge = makeEdgesList(edgeIRIs, edgeProps);
String edge = makeEdgesList(edgeIRIs, edgeProps);

// TODO fix injection
// TODO fix injection

String query =
"MATCH (a:" + type+ ")-[edge:" + edge + "]->(b) "
+ "WHERE a.id = $id " + makeEdgePropsClause(edgeProps)
+ "RETURN distinct b";
String query =
"MATCH (a:" + type+ ")-[edge:" + edge + "]->(b) "
+ "WHERE a.id = $id " + makeEdgePropsClause(edgeProps)
+ "RETURN distinct b";

String countQuery =
"MATCH (a:" + type + ")-[edge:" + edge + "]->(b) "
+ "WHERE a.id = $id " + makeEdgePropsClause(edgeProps)
+ "RETURN count(distinct b)";
String countQuery =
"MATCH (a:" + type + ")-[edge:" + edge + "]->(b) "
+ "WHERE a.id = $id " + makeEdgePropsClause(edgeProps)
+ "RETURN count(distinct b)";

System.out.println(query);
logger.trace(query);

return neo4jClient.queryPaginated(query, "b", countQuery, parameters("type", type, "id", id), pageable);
}

public Page<JsonElement> traverseIncomingEdges(String type, String id, List<String> edgeIRIs, Map<String,String> edgeProps, Pageable pageable) {

String edge = makeEdgesList(edgeIRIs, Map.of());
String edge = makeEdgesList(edgeIRIs, Map.of());

String query =
"MATCH (a:" + type + ")<-[edge:" + edge + "]-(b) "
+ "WHERE a.id = $id "
+ "RETURN distinct b";
String query =
"MATCH (a:" + type + ")<-[edge:" + edge + "]-(b) "
+ "WHERE a.id = $id "
+ "RETURN distinct b";

String countQuery =
"MATCH (a:" + type + ")<-[edge:" + edge + "]-(b) "
+ "WHERE a.id = $id "
+ "RETURN count(distinct b)";
String countQuery =
"MATCH (a:" + type + ")<-[edge:" + edge + "]-(b) "
+ "WHERE a.id = $id "
+ "RETURN count(distinct b)";

return neo4jClient.queryPaginated(query, "b", countQuery, parameters("type", type, "id", id), pageable);
return neo4jClient.queryPaginated(query, "b", countQuery, parameters("type", type, "id", id), pageable);
}

public Page<JsonElement> recursivelyTraverseOutgoingEdges(String type, String id, List<String> edgeIRIs, Map<String,String> edgeProps, Pageable pageable) {
Expand All @@ -128,21 +133,21 @@ public Page<JsonElement> recursivelyTraverseOutgoingEdges(String type, String id

public Page<JsonElement> recursivelyTraverseIncomingEdges(String type, String id, List<String> edgeIRIs, Map<String,String> edgeProps, Pageable pageable) {

String edge = makeEdgesList(edgeIRIs, Map.of());
String edge = makeEdgesList(edgeIRIs, Map.of());

String query =
"MATCH (a:" + type + ") WHERE a.id = $id "
+ "WITH a "
+ "OPTIONAL MATCH (a)<-[edge:" + edge + " *]-(descendant) "
+ "RETURN DISTINCT descendant AS c";
String query =
"MATCH (a:" + type + ") WHERE a.id = $id "
+ "WITH a "
+ "OPTIONAL MATCH (a)<-[edge:" + edge + " *]-(descendant) "
+ "RETURN DISTINCT descendant AS c";

String countQuery =
"MATCH (a:" + type + ") WHERE a.id = $id "
+ "WITH a "
+ "OPTIONAL MATCH (a)<-[edge:" + edge + " *]-(descendant) "
+ "RETURN count(DISTINCT descendant)";
String countQuery =
"MATCH (a:" + type + ") WHERE a.id = $id "
+ "WITH a "
+ "OPTIONAL MATCH (a)<-[edge:" + edge + " *]-(descendant) "
+ "RETURN count(DISTINCT descendant)";

return neo4jClient.queryPaginated(query, "c", countQuery, parameters("id", id), pageable);
return neo4jClient.queryPaginated(query, "c", countQuery, parameters("id", id), pageable);
}


Expand Down
20 changes: 11 additions & 9 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 @@ -12,29 +12,31 @@
import org.neo4j.driver.*;
import org.neo4j.driver.Record;
import org.neo4j.driver.exceptions.NoSuchRecordException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Component;
import org.springframework.data.rest.webmvc.ResourceNotFoundException;
import uk.ac.ebi.spot.ols.repository.neo4j.OlsNeo4jClient;

import javax.validation.constraints.NotNull;

@Component
public class Neo4jClient {


@NotNull
@org.springframework.beans.factory.annotation.Value("${ols.neo4j.host:bolt://localhost:7687}")
private String host;



private Gson gson = new Gson();

private Driver driver;

private static final Logger logger = LoggerFactory.getLogger(Neo4jClient.class);

public Driver getDriver() {

if(driver == null) {
Expand Down Expand Up @@ -106,20 +108,20 @@ public Page<JsonElement> queryPaginated(String query, String resVar, String coun
queryToRun = query;
}

System.out.println(queryToRun);
System.out.println(gson.toJson(parameters.asMap()));
logger.debug(queryToRun);
logger.trace(gson.toJson(parameters.asMap()));

Stopwatch timer = Stopwatch.createStarted();
Result result = session.run(
queryToRun,

parameters
);
System.out.println("Neo4j run paginated query: " + timer.stop());
logger.info("Neo4j run paginated query: " + timer.stop());

Stopwatch timer2 = Stopwatch.createStarted();
Result countResult = session.run(countQuery, parameters);
System.out.println("Neo4j run paginated count: " + timer2.stop());
logger.info("Neo4j run paginated count: " + timer2.stop());

Record countRecord = countResult.single();
int count = countRecord.get(0).asInt();
Expand All @@ -142,11 +144,11 @@ public JsonElement queryOne(String query, String resVar, Value parameters) {

Session session = getSession();

System.out.println(query);
logger.debug(query);

Stopwatch timer = Stopwatch.createStarted();
Result result = session.run(query, parameters);
System.out.println("Neo4j run query " + query + ": " + timer.stop());
logger.info("Neo4j run query " + query + ": " + timer.stop());

Value v = null;

Expand Down
2 changes: 1 addition & 1 deletion backend/src/main/resources/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</encoder>
</appender>

<logger name="uk.ac.ebi.spot.ols" level="trace"/>
<logger name="uk.ac.ebi.spot.ols" level="info"/>
<root level="error">
<appender-ref ref="STDOUT" />
</root>
Expand Down
Loading