Skip to content

Commit

Permalink
Merge pull request #131 from charvolant/master
Browse files Browse the repository at this point in the history
Handle changes to EoL API
  • Loading branch information
charvolant committed Dec 11, 2018
2 parents 58fc347 + 5dd563b commit 5f0e78e
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 39 deletions.
6 changes: 3 additions & 3 deletions grails-app/assets/javascripts/species.show.js
Original file line number Diff line number Diff line change
Expand Up @@ -350,9 +350,9 @@ function loadExternalSources(){
$.ajax({url: SHOW_CONF.eolUrl}).done(function ( data ) {
//console.log(data);
//clone a description template...
if(data.dataObjects){
//console.log('Loading EOL content - ' + data.dataObjects.length);
$.each(data.dataObjects, function(idx, dataObject){
if(data.taxonConcept && data.taxonConcept.dataObjects){
//console.log('Loading EOL content - ' + data.taxonConcept.dataObjects.length);
$.each(data.taxonConcept.dataObjects, function(idx, dataObject){
//console.log('Loading EOL content -> ' + dataObject.description);
if(dataObject.language == SHOW_CONF.eolLanguage || !dataObject.language){
var $description = $('#descriptionTemplate').clone();
Expand Down
11 changes: 11 additions & 0 deletions grails-app/conf/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,14 @@ grails:
endpoints:
jmx:
unique-names: true
---
external:
eol:
search:
# {0}= name to search for, {1} = filter string
# service: https://eol.org/api/search/1.0.json?q={0}&page=1&exact=true&filter_by_string={1}&cache_ttl=
service: https://eol.org/api/search/1.0.json?q={0}&page=1&exact=true&cache_ttl=
page:
# {0} = page id
service: https://eol.org/api/pages/1.0/{0,number,#0}.json?images_per_page=0&videos_per_page=0&sounds_per_page=0&maps_per_page=0&texts_per_page=30&subjects=overview&licenses=all&details=true&references=true&vetted=0&cache_ttl=

24 changes: 13 additions & 11 deletions grails-app/controllers/au/org/ala/bie/ExternalSiteController.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import org.jsoup.Jsoup
import org.jsoup.nodes.Document
import org.jsoup.select.Elements

import java.text.MessageFormat

/**
* Controller that proxies external webservice calls to get around cross domain issues
* and to make consumption of services easier from javascript.
Expand All @@ -27,22 +29,22 @@ class ExternalSiteController {
def index() {}

def eol = {
def searchString = params.s
def filterString = java.net.URLEncoder.encode(params.f?:"", "UTF-8")
def nameEncoded = java.net.URLEncoder.encode(searchString, "UTF-8")
def searchURL = "http://eol.org/api/search/1.0.json?q=${nameEncoded}&page=1&exact=true&filter_by_taxon_concept_id=&filter_by_hierarchy_entry_id=&filter_by_string=${filterString}&cache_ttl="
log.debug "Initial EOL url = ${searchURL}"
def nameEncoded = URLEncoder.encode(params.s, 'UTF-8')
def filterString = URLEncoder.encode(params.f ?: '', 'UTF-8')
String search = grailsApplication.config.external.eol.search.service
search = MessageFormat.format(search, nameEncoded, filterString)
log.debug "Initial EOL url = ${search}"
def js = new JsonSlurper()
def jsonText = new java.net.URL(searchURL).text

def json = js.parseText(jsonText)
def jsonText = new URL(search).text
def json = js.parseText(jsonText ?: '{}')

//get first pageId
if(json.results){
def pageId = json.results[0].id
def pageUrl = "http://eol.org/api/pages/1.0/${pageId}.json?images=00&videos=0&sounds=0&maps=0&text=2&iucn=false&subjects=overview&licenses=all&details=true&references=true&vetted=0&cache_ttl="
log.debug(pageUrl)
def pageText = new java.net.URL(pageUrl).text
String page = grailsApplication.config.external.eol.page.service
page = MessageFormat.format(page, pageId)
log.debug("EOL page url = ${page}")
def pageText = new URL(page).text ?: '{}'
response.setContentType("application/json")
render pageText
} else {
Expand Down
48 changes: 23 additions & 25 deletions grails-app/views/species/_classification.gsp
Original file line number Diff line number Diff line change
Expand Up @@ -57,35 +57,33 @@
</g:each>
<dl class="child-taxa">
<g:set var="currentRank" value=""/>
<g:each in="${childConcepts.toSorted { a, b -> a.rankID <=> b.rankID }}" var="child" status="i">
<g:each in="${childConcepts}" var="child" status="i"><!-- Rely on web service for correct order -->
<g:set var="currentRank" value="${child.rank}"/>
<g:if test="${child.rankID - tc.taxonConcept.rankID < 2001}"><%-- Fix for issue https://github.com/AtlasOfLivingAustralia/bie-plugin/issues/121 --%>
<dt>${child.rank}</dt>
<g:set var="taxonLabel"><bie:formatSciName rankId="${child.rankID}"
nameFormatted="${child.nameFormatted}"
nameComplete="${child.nameComplete}"
taxonomicStatus="name"
name="${child.name}"/><g:if
test="${child.commonNameSingle}">: ${child.commonNameSingle}</g:if></g:set>
<dd><a href="${request?.contextPath}/species/${child.guid}#classification">${raw(taxonLabel.trim())}</a>&nbsp;
<span>
<g:if test="${child.isAustralian}">
<img src="${grailsApplication.config.ala.baseURL}/wp-content/themes/ala2011/images/status_native-sm.png"
alt="Recorded in Australia" title="Recorded in Australia" width="21"
height="21">
<dt>${child.rank}</dt>
<g:set var="taxonLabel"><bie:formatSciName rankId="${child.rankID}"
nameFormatted="${child.nameFormatted}"
nameComplete="${child.nameComplete}"
taxonomicStatus="name"
name="${child.name}"/><g:if
test="${child.commonNameSingle}">: ${child.commonNameSingle}</g:if></g:set>
<dd><a href="${request?.contextPath}/species/${child.guid}#classification">${raw(taxonLabel.trim())}</a>&nbsp;
<span>
<g:if test="${child.isAustralian}">
<img src="${grailsApplication.config.ala.baseURL}/wp-content/themes/ala2011/images/status_native-sm.png"
alt="Recorded in Australia" title="Recorded in Australia" width="21"
height="21">
</g:if>
<g:else>
<g:if test="${child.guid?.startsWith('urn:lsid:catalogueoflife.org:taxon')}">
<span class="inferredPlacement"
title="Not recorded in Australia">[inferred placement]</span>
</g:if>
<g:else>
<g:if test="${child.guid?.startsWith('urn:lsid:catalogueoflife.org:taxon')}">
<span class="inferredPlacement"
title="Not recorded in Australia">[inferred placement]</span>
</g:if>
<g:else>
<span class="inferredPlacement" title="Not recorded in Australia"></span>
</g:else>
<span class="inferredPlacement" title="Not recorded in Australia"></span>
</g:else>
</span>
</dd>
</g:if>
</g:else>
</span>
</dd>
</g:each>
</dl>
<g:each in="${taxonHierarchy}" var="taxon">
Expand Down

0 comments on commit 5f0e78e

Please sign in to comment.