Search in sources :

Example 41 with CypherQuery

use of org.eol.globi.util.CypherQuery in project eol-globi-data by jhpoelen.

the class ReportController method datasetQuery.

private CypherQuery datasetQuery(HttpServletRequest request, String searchKey, final String searchValue) {
    String searchMatch = searchKey + "={namespace}";
    if (StringUtils.isBlank(searchValue)) {
        searchMatch = "'" + searchKey + ":*'";
    }
    String cypherQuery = "START dataset = node:datasets(" + searchMatch + "), report = node:reports('sourceId:*') " + " WHERE ('globi:' + dataset.namespace) = report.sourceId " + " RETURN report.citation as " + ResultField.STUDY_CITATION + ", report.externalId as " + ResultField.STUDY_URL + ", report.doi as " + ResultField.STUDY_DOI + ", dataset.citation as " + ResultField.STUDY_SOURCE_CITATION + ", report.nInteractions as " + ResultField.NUMBER_OF_INTERACTIONS + ", report.nTaxa as " + ResultField.NUMBER_OF_DISTINCT_TAXA + ", report.nStudies as " + ResultField.NUMBER_OF_STUDIES + ", report.nSources as " + ResultField.NUMBER_OF_SOURCES + ", report.nTaxaNoMatch as " + ResultField.NUMBER_OF_DISTINCT_TAXA_NO_MATCH + ", report.sourceId as " + ResultField.STUDY_SOURCE_ID + ", dataset.doi as " + ResultField.STUDY_SOURCE_DOI + ", dataset.format as " + ResultField.STUDY_SOURCE_FORMAT + ", dataset.archiveURI as " + ResultField.STUDY_SOURCE_ARCHIVE_URI + ", dataset.lastSeenAt as " + ResultField.STUDY_SOURCE_LAST_SEEN_AT;
    Map<String, String> params = StringUtils.isBlank(searchValue) ? CypherQueryBuilder.EMPTY_PARAMS : new HashMap<String, String>() {

        {
            put("namespace", searchValue);
        }
    };
    return CypherQueryBuilder.createPagedQuery(request, new CypherQuery(cypherQuery, params, CypherUtil.CYPHER_VERSION_2_3));
}
Also used : CypherQuery(org.eol.globi.util.CypherQuery)

Example 42 with CypherQuery

use of org.eol.globi.util.CypherQuery in project eol-globi-data by jhpoelen.

the class ReportController method studies.

@RequestMapping(value = "/reports/studies", method = RequestMethod.GET)
@ResponseBody
public CypherQuery studies(@RequestParam(required = false) final String source, final HttpServletRequest request) throws IOException {
    String cypherQuery = "START report = node:reports(" + (StringUtils.isBlank(source) ? "'source:*'" : "source={source}") + ") " + " WHERE exists(report.title) " + " RETURN report.citation as " + ResultField.STUDY_CITATION + ", report.externalId as " + ResultField.STUDY_URL + ", report.doi as " + ResultField.STUDY_DOI + ", report.source as " + ResultField.STUDY_SOURCE_CITATION + ", report.nInteractions as " + ResultField.NUMBER_OF_INTERACTIONS + ", report.nTaxa as " + ResultField.NUMBER_OF_DISTINCT_TAXA + ", report.nStudies as " + ResultField.NUMBER_OF_STUDIES + ", report.nSources as " + ResultField.NUMBER_OF_SOURCES + ", report.nTaxaNoMatch as " + ResultField.NUMBER_OF_DISTINCT_TAXA_NO_MATCH;
    Map<String, String> params = StringUtils.isBlank(source) ? CypherQueryBuilder.EMPTY_PARAMS : new HashMap<String, String>() {

        {
            put("source", source);
        }
    };
    return CypherQueryBuilder.createPagedQuery(request, new CypherQuery(cypherQuery, params, CypherUtil.CYPHER_VERSION_2_3));
}
Also used : CypherQuery(org.eol.globi.util.CypherQuery) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 43 with CypherQuery

use of org.eol.globi.util.CypherQuery in project eol-globi-data by jhpoelen.

the class ReportController method sourceQuery.

private CypherQuery sourceQuery(HttpServletRequest request, final String sourceId) {
    String searchMatch = "sourceId" + "={sourceId}";
    if (StringUtils.isBlank(sourceId)) {
        searchMatch = "'" + "sourceId" + ":*'";
    }
    String cypherQuery = "START report = node:reports(" + searchMatch + ") " + " RETURN report.citation as " + ResultField.STUDY_CITATION + ", report.externalId as " + ResultField.STUDY_URL + ", report.doi as " + ResultField.STUDY_DOI + ", null as " + ResultField.STUDY_SOURCE_CITATION + ", report.nInteractions as " + ResultField.NUMBER_OF_INTERACTIONS + ", report.nTaxa as " + ResultField.NUMBER_OF_DISTINCT_TAXA + ", report.nStudies as " + ResultField.NUMBER_OF_STUDIES + ", report.nSources as " + ResultField.NUMBER_OF_SOURCES + ", report.nTaxaNoMatch as " + ResultField.NUMBER_OF_DISTINCT_TAXA_NO_MATCH + ", report.sourceId as " + ResultField.STUDY_SOURCE_ID;
    String sourceIdActual = StringUtils.countMatches(sourceId, ":") > 0 ? sourceId : "globi:" + sourceId;
    Map<String, String> params = StringUtils.isBlank(sourceId) ? CypherQueryBuilder.EMPTY_PARAMS : new HashMap<String, String>() {

        {
            put("sourceId", sourceIdActual);
        }
    };
    return CypherQueryBuilder.createPagedQuery(request, new CypherQuery(cypherQuery, params, CypherUtil.CYPHER_VERSION_2_3));
}
Also used : CypherQuery(org.eol.globi.util.CypherQuery)

Example 44 with CypherQuery

use of org.eol.globi.util.CypherQuery in project eol-globi-data by jhpoelen.

the class TaxonSearchUtil method linksForTaxonName.

public static Collection<String> linksForTaxonName(@PathVariable("taxonPath") String taxonPath, HttpServletRequest request, LinkMapper linkMapper) throws IOException {
    final CypherQuery pagedQuery = createPagedQuery(taxonPath, request);
    final String response = CypherUtil.executeRemote(pagedQuery);
    JsonNode rowsAndMetas = RequestHelper.getRowsAndMetas(response);
    Collection<String> links = new HashSet<>();
    if (rowsAndMetas != null) {
        for (JsonNode rowAndMeta : rowsAndMetas) {
            addLinksFromNode(links, RequestHelper.getRow(rowAndMeta), linkMapper);
        }
    }
    return links;
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) CypherQuery(org.eol.globi.util.CypherQuery) HashSet(java.util.HashSet)

Example 45 with CypherQuery

use of org.eol.globi.util.CypherQuery in project eol-globi-data by jhpoelen.

the class ReportControllerTest method distinctSourceRoot.

@Test
public void distinctSourceRoot() throws IOException {
    CypherQuery source = new ReportController().sourceRoot(null);
    assertThat(source.getVersionedQuery(), is(CYPHER_VERSION + "START dataset = node:datasets('namespace:*'), report = node:reports('sourceId:*') " + "WHERE ('globi:' + dataset.namespace) = report.sourceId " + "RETURN report.citation as study_citation, " + "report.externalId as study_url, " + "report.doi as study_doi, " + "dataset.citation as study_source_citation, " + "report.nInteractions as number_of_interactions, " + "report.nTaxa as number_of_distinct_taxa, " + "report.nStudies as number_of_studies, " + "report.nSources as number_of_sources, " + "report.nTaxaNoMatch as number_of_distinct_taxa_no_match, " + "report.sourceId as study_source_id, " + "dataset.doi as study_source_doi, " + "dataset.format as study_source_format, " + "dataset.archiveURI as study_source_archive_uri, " + "dataset.lastSeenAt as study_source_last_seen_at " + "SKIP 0 " + "LIMIT 1024"));
    assertThat(source.getParams().size(), is(0));
    validate(source);
}
Also used : CypherQuery(org.eol.globi.util.CypherQuery) Test(org.junit.Test)

Aggregations

CypherQuery (org.eol.globi.util.CypherQuery)109 Test (org.junit.Test)92 HashMap (java.util.HashMap)66 Matchers.containsString (org.hamcrest.Matchers.containsString)13 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)7 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)7 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 Map (java.util.Map)4 ResultField (org.eol.globi.server.util.ResultField)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 TreeMap (java.util.TreeMap)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 JsonNode (org.codehaus.jackson.JsonNode)1 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)1 InteractionTypeExternal (org.eol.globi.server.util.InteractionTypeExternal)1 ResultFormatterCSV (org.eol.globi.server.util.ResultFormatterCSV)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1 StringContains.containsString (org.hamcrest.core.StringContains.containsString)1