Search in sources :

Example 96 with CypherQuery

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

the class CypherQueryBuilder method createDistinctTaxaInLocationQuery.

public static CypherQuery createDistinctTaxaInLocationQuery(Map<String, String[]> params) {
    StringBuilder builder = new StringBuilder();
    List<String> interactionTypes = collectParamValues(params, ParamName.INTERACTION_TYPE);
    if (RequestHelper.isSpatialSearch(params)) {
        appendSpatialStartWhereWith(params, builder);
    } else {
        builder.append("START taxon = node:taxons('*:*') ");
    }
    if (RequestHelper.isSpatialSearch(params)) {
        builder.append("MATCH taxon<-[:CLASSIFIED_AS]-specimen-[:COLLECTED_AT]->loc");
        if (!interactionTypes.isEmpty()) {
            builder.append(", taxon-[:");
            builder.append(createInteractionTypeSelector(interactionTypes));
            builder.append("]->otherTaxon ");
        } else {
            builder.append(" ");
        }
    } else {
        if (!interactionTypes.isEmpty()) {
            builder.append("MATCH taxon-[:");
            builder.append(createInteractionTypeSelector(interactionTypes));
            builder.append("]->otherTaxon ");
        }
    }
    List<String> fields = collectRequestedFields(params);
    List<ResultField> returnFields = CypherReturnClauseBuilder.actualReturnFields(fields, TAXON_FIELDS, TAXON_FIELDS);
    for (int i = 0; i < returnFields.size(); i++) {
        ResultField fieldName = returnFields.get(i);
        if (i == 0) {
            builder.append("RETURN distinct(").append(FIELD_MAP.get(fieldName)).append(") as ").append(fieldName);
        } else {
            builder.append(", ").append(FIELD_MAP.get(fieldName)).append(" as ").append(fieldName);
        }
    }
    return new CypherQuery(builder.toString(), new HashMap<>());
}
Also used : CypherQuery(org.eol.globi.util.CypherQuery) ResultField(org.eol.globi.server.util.ResultField)

Example 97 with CypherQuery

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

the class InteractionController method atLeastOneInteraction.

@RequestMapping(value = "/exists", method = { RequestMethod.GET, RequestMethod.HEAD })
@ResponseBody
protected String atLeastOneInteraction(HttpServletRequest request) throws IOException {
    // see https://github.com/globalbioticinteractions/globalbioticinteractions/issues/401
    Map parameterMap = getParamMap(request);
    CypherQuery query = CypherQueryBuilder.buildInteractionQuery(parameterMap, QueryType.forParams(parameterMap));
    CypherQuery pagedQuery = CypherQueryBuilder.createPagedQuery(query, 0, 1);
    String s = CypherUtil.executeRemote(pagedQuery);
    if (RequestHelper.emptyData(s)) {
        throw new ResourceNotFoundException("no results for query with params: " + parameterMap);
    }
    return "OK";
}
Also used : CypherQuery(org.eol.globi.util.CypherQuery) Map(java.util.Map) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 98 with CypherQuery

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

the class InteractionController method findInteractions.

@RequestMapping(value = "/interaction", method = { RequestMethod.GET })
@ResponseBody
protected CypherQuery findInteractions(HttpServletRequest request) {
    Map parameterMap = getParamMap(request);
    CypherQuery query = CypherQueryBuilder.buildInteractionQuery(parameterMap, QueryType.forParams(parameterMap));
    return CypherQueryBuilder.createPagedQuery(request, query);
}
Also used : CypherQuery(org.eol.globi.util.CypherQuery) Map(java.util.Map) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 99 with CypherQuery

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

the class InteractionController method findInteractions.

@RequestMapping(value = "/taxon/{sourceTaxonName}/{interactionType}/{targetTaxonName}", method = RequestMethod.GET)
@ResponseBody
public CypherQuery findInteractions(HttpServletRequest request, @PathVariable("sourceTaxonName") String sourceTaxonName, @PathVariable("interactionType") String interactionType, @PathVariable("targetTaxonName") String targetTaxonName) throws IOException {
    Map parameterMap = request == null ? null : getParamMap(request);
    CypherQuery query = createQuery(sourceTaxonName, interactionType, targetTaxonName, parameterMap);
    return CypherQueryBuilder.createPagedQuery(request, query);
}
Also used : CypherQuery(org.eol.globi.util.CypherQuery) Map(java.util.Map) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 100 with CypherQuery

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

the class SchemaController method getInteractionTypes.

@RequestMapping(value = "/interactionTypes", method = RequestMethod.GET)
@ResponseBody
public String getInteractionTypes(HttpServletRequest request) throws IOException {
    Collection<InteractionTypeExternal> availableTypes = Arrays.asList(InteractionTypeExternal.values());
    if (request != null) {
        if (StringUtils.isNotBlank(request.getParameter(ParamName.TAXON.getName()))) {
            CypherQuery cypherQuery = CypherQueryBuilder.buildInteractionTypeQuery(request.getParameterMap());
            String interactionTypes = new ResultFormatterCSV().format(CypherUtil.executeRemote(cypherQuery));
            String[] interactionType = StringUtils.replace(interactionTypes, "\"", "").split("\n");
            availableTypes = new HashSet<>();
            for (String type : interactionType) {
                InteractionTypeExternal value = CypherQueryBuilder.INTERACTION_TYPE_INTERNAL_EXTERNAL_MAP.get(type);
                if (value != null) {
                    availableTypes.add(value);
                }
            }
        }
    }
    return "csv".equals(getRequestType(request)) ? interactionMapCsv(availableTypes) : interactionMapJson(availableTypes);
}
Also used : ResultFormatterCSV(org.eol.globi.server.util.ResultFormatterCSV) InteractionTypeExternal(org.eol.globi.server.util.InteractionTypeExternal) CypherQuery(org.eol.globi.util.CypherQuery) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

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