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<>());
}
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";
}
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);
}
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);
}
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);
}
Aggregations