diff --git a/.gitattribute b/.gitattribute deleted file mode 100644 index 590a9c5b6..000000000 --- a/.gitattribute +++ /dev/null @@ -1 +0,0 @@ -web-app/bootstrap linguist-vendored diff --git a/.gitignore b/.gitignore index e89ed3981..f33ace278 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,12 @@ -out -target/* -.idea/* -*.iml -wrapper/* -.slcache/* -build/* -.gradle/* +Thumbs.db .DS_Store +.gradle +build/ +out/ +.idea +*.iml +*.ipr +*.iws +.project +.settings +.classpath diff --git a/.travis/trigger-travis.sh b/.travis/trigger-travis.sh deleted file mode 100644 index c3947676d..000000000 --- a/.travis/trigger-travis.sh +++ /dev/null @@ -1,69 +0,0 @@ -#!/bin/sh -f - -# Trigger a new Travis-CI job. - -# Usage: -# trigger-travis.sh [--pro] [--branch BRANCH] GITHUBID GITHUBPROJECT TRAVIS_ACCESS_TOKEN [MESSAGE] -# For example: -# trigger-travis.sh typetools checker-framework `cat ~/private/.travis-access-token` "Trigger for testing" - -# For full documentation, see -# https://github.com/plume-lib/trigger-travis/ - - -if [ "$#" -lt 3 ] || [ "$#" -ge 7 ]; then - echo "Wrong number of arguments $# to trigger-travis.sh; run like:" - echo " trigger-travis.sh [--pro] [--branch BRANCH] GITHUBID GITHUBPROJECT TRAVIS_ACCESS_TOKEN [MESSAGE]" >&2 - exit 1 -fi - -# always use travis-ci.com -TRAVIS_URL=travis-ci.com - -if [ "$1" = "--branch" ] ; then - shift - BRANCH="$1" - shift -else - BRANCH=master -fi - -USER=$1 -REPO=$2 -TOKEN=$3 -if [ $# -eq 4 ] ; then - MESSAGE=",\"message\": \"$4\"" -elif [ -n "$TRAVIS_REPO_SLUG" ] ; then - MESSAGE=",\"message\": \"Triggered by upstream build of $TRAVIS_REPO_SLUG commit "`git log --oneline -n 1 HEAD`"\"" -else - MESSAGE="" -fi -## For debugging: -# echo "USER=$USER" -# echo "REPO=$REPO" -# echo "TOKEN=$TOKEN" -# echo "MESSAGE=$MESSAGE" - -body="{ -\"request\": { - \"branch\":\"$BRANCH\" - $MESSAGE -}}" - -# "%2F" creates a literal "/" in the URL, that is not interpreted as a -# segment or directory separator. -curl -s -X POST \ - -H "Content-Type: application/json" \ - -H "Accept: application/json" \ - -H "Travis-API-Version: 3" \ - -H "Authorization: token ${TOKEN}" \ - -d "$body" \ - https://api.${TRAVIS_URL}/repo/${USER}%2F${REPO}/requests \ - | tee /tmp/travis-request-output.$$.txt - -if grep -q '"@type": "error"' /tmp/travis-request-output.$$.txt; then - exit 1 -fi -if grep -q 'access denied' /tmp/travis-request-output.$$.txt; then - exit 1 -fi diff --git a/README.md b/README.md index 95736dc59..ef1ece257 100644 --- a/README.md +++ b/README.md @@ -42,4 +42,6 @@ Use these as reference: * https://github.com/AtlasOfLivingAustralia/ala-hub/blob/77ad912b6007afb21e5ee9d46cd068ba2040eb9f/grails-app/assets/stylesheets/alaBs.css#L11 * https://github.com/AtlasOfLivingAustralia/ala-hub/blob/c6c999d7e87de985bfc65e1fe6fe5cd13396212f/grails-app/assets/javascripts/alaBs.js#L11 +## Grails 4 +Starting with version 3.4.0, biocache-hubs has been migrated to run on Grails 4 diff --git a/build.gradle b/build.gradle index 5085bb12c..f03b32617 100644 --- a/build.gradle +++ b/build.gradle @@ -1,69 +1,93 @@ buildscript { repositories { mavenLocal() - maven { url "https://nexus.ala.org.au/content/groups/public/" } maven { url "https://repo.grails.org/grails/core" } + maven { url "https://nexus.ala.org.au/content/groups/public/" } } dependencies { classpath "org.grails:grails-gradle-plugin:$grailsVersion" - classpath "com.bertramlabs.plugins:asset-pipeline-gradle:2.14.2" + //classpath "org.grails.plugins:hibernate5:7.0.5" + classpath "gradle.plugin.com.github.erdi.webdriver-binaries:webdriver-binaries-gradle-plugin:2.0" + classpath "com.bertramlabs.plugins:asset-pipeline-gradle:3.2.4" } } -version "3.0.6-SNAPSHOT" +version "3.4.0-SNAPSHOT" group "au.org.ala.plugins.grails" apply plugin:"eclipse" apply plugin:"idea" -apply plugin:"org.grails.grails-plugin" -apply plugin:"org.grails.grails-plugin-publish" +apply plugin:"org.grails.grails-web" +apply plugin:"com.github.erdi.webdriver-binaries" +apply plugin:"com.bertramlabs.asset-pipeline" apply plugin:"org.grails.grails-gsp" -apply plugin:"asset-pipeline" apply plugin:"maven-publish" -sourceCompatibility = 1.8 -targetCompatibility = 1.8 - repositories { mavenLocal() - maven { url "https://nexus.ala.org.au/content/groups/public/" } + maven { url "https://nexus.ala.org.au/content/groups/public/" } maven { url "https://repo.grails.org/grails/core" } } -configurations.all { - resolutionStrategy.cacheChangingModulesFor 1, 'minutes' +configurations { + developmentOnly + runtimeClasspath { + extendsFrom developmentOnly + } } -// Inplace plugin config - -// Set to true it needed only for development -boolean inplace = false -// Inplace plugins ala-charts-plugin and images-client-plugin are defined in ala-hub configuration - dependencies { - def noCache = { - exclude group: 'org.grails.plugins', module: 'cache' - exclude group: 'org.ehcache', module: 'ehcache' - } - + developmentOnly("org.springframework.boot:spring-boot-devtools") compile "org.springframework.boot:spring-boot-starter-logging" compile "org.springframework.boot:spring-boot-autoconfigure" compile "org.grails:grails-core" compile "org.springframework.boot:spring-boot-starter-actuator" compile "org.springframework.boot:spring-boot-starter-tomcat" - compile "org.grails:grails-dependencies" compile "org.grails:grails-web-boot" + compile "org.grails:grails-logging" + compile "org.grails:grails-plugin-rest" + compile "org.grails:grails-plugin-databinding" + compile "org.grails:grails-plugin-i18n" + compile "org.grails:grails-plugin-services" + compile "org.grails:grails-plugin-url-mappings" + compile "org.grails:grails-plugin-interceptors" compile "org.grails.plugins:cache" + compile "org.grails.plugins:async" compile "org.grails.plugins:scaffolding" + compile "org.grails.plugins:events" + compile "org.grails.plugins:hibernate5" + compile "org.hibernate:hibernate-core:5.4.18.Final" + compile "org.grails.plugins:gsp" + compileOnly "io.micronaut:micronaut-inject-groovy" console "org.grails:grails-console" - profile "org.grails.profiles:web-plugin" - provided "org.grails:grails-plugin-services" - provided "org.grails:grails-plugin-domain-class" - runtime "com.bertramlabs.plugins:asset-pipeline-grails:2.14.2" - testCompile "org.grails:grails-plugin-testing" + profile "org.grails.profiles:web" + runtime "org.glassfish.web:el-impl:2.1.2-b03" + runtime "com.h2database:h2" + runtime "org.apache.tomcat:tomcat-jdbc" + runtime "javax.xml.bind:jaxb-api:2.3.1" + runtime "com.bertramlabs.plugins:asset-pipeline-grails:3.2.4" + testCompile "io.micronaut:micronaut-inject-groovy" + testCompile "org.grails:grails-gorm-testing-support" + testCompile "org.mockito:mockito-core" + testCompile "org.grails:grails-web-testing-support" testCompile "org.grails.plugins:geb" - testRuntime "org.seleniumhq.selenium:selenium-htmlunit-driver:2.47.1" - testRuntime "net.sourceforge.htmlunit:htmlunit:2.18" + testCompile "org.seleniumhq.selenium:selenium-remote-driver:3.14.0" + testCompile "org.seleniumhq.selenium:selenium-api:3.14.0" + testCompile "org.seleniumhq.selenium:selenium-support:3.14.0" + testRuntime "org.seleniumhq.selenium:selenium-chrome-driver:3.14.0" + testRuntime "org.seleniumhq.selenium:selenium-firefox-driver:3.14.0" + + testImplementation group: 'org.spockframework', name: 'spock-spring', version: '1.3-groovy-2.5' + implementation group: 'org.ehcache', name: 'ehcache', version: '3.1.0' + testImplementation group: 'xml-apis', name: 'xml-apis', version: '1.4.01' + //compile 'org.grails:grails-validation:3.1.14' + + // testCompile "org.grails:grails-test-mixins:3.3.0" + + def noCache = { + exclude group: 'org.grails.plugins', module: 'cache' + exclude group: 'org.ehcache', module: 'ehcache' + } //jars compile "org.apache.httpcomponents:httpclient:4.5.6" @@ -81,46 +105,49 @@ dependencies { //plugins //compile 'org.grails.plugins:cache-ehcache:3.0.0.M1' compile 'org.grails.plugins:http-builder-helper:1.0.2.ALA' - compile "org.grails.plugins:ala-admin-plugin:2.2", noCache - compile "org.grails.plugins:ala-auth:3.2.3", noCache - - if(!inplace) { - compile "au.org.ala.plugins.grails:images-client-plugin:1.2", noCache - compile "au.org.ala.plugins.grails:ala-charts-plugin:2.0.1", noCache - } + compile "org.grails.plugins:ala-admin-plugin:2.2" + compile "org.grails.plugins:ala-auth:3.2.3" + compile "au.org.ala.plugins.grails:images-client-plugin:1.4-SNAPSHOT" + compile "au.org.ala.plugins.grails:ala-charts-plugin:2.2" + compile "au.org.ala:userdetails-service-client:1.5.0" + compile 'commons-fileupload:commons-fileupload:1.4' } bootRun { - jvmArgs('-Dspring.output.ansi.enabled=always') - addResources = true + ignoreExitValue true + jvmArgs( + '-Dspring.output.ansi.enabled=always', + '-noverify', + '-XX:TieredStopAtLevel=1', + '-Xmx1024m') + sourceResources sourceSets.main + String springProfilesActive = 'spring.profiles.active' + systemProperty springProfilesActive, System.getProperty(springProfilesActive) } -// enable if you wish to package this plugin as a standalone application -bootRepackage.enabled = false -grailsPublish { - // TODO: Provide values here -// user = 'user' -// key = 'key' - - githubSlug = 'AtlasOfLivingAustralia/biocache-hubs' - websiteUrl = 'https://github.com/AtlasOfLivingAustralia/biocache-hubs' - license { - name = 'MPL-1.1' + +tasks.withType(GroovyCompile) { + configure(groovyOptions) { + forkOptions.jvmArgs = ['-Xmx1024m'] } - issueTrackerUrl = 'https://github.com/AtlasOfLivingAustralia/biocache-hubs/issues' - vcsUrl = 'https://github.com/AtlasOfLivingAustralia/biocache-hubs' - title = "Biocache Hubs Plugin" - desc = '''\ -A Grails plugin to provide the core functionality for searching and displaying biodiversity data from -biocache web services. Data access is via JSON REST web services -from the ALA biocache-service app (no local DB is required for this app). -''' - developers = [:] +} + +webdriverBinaries { + chromedriver '2.45.0' + geckodriver '0.24.0' +} + +tasks.withType(Test) { + systemProperty "geb.env", System.getProperty('geb.env') + systemProperty "geb.build.reportsDir", reporting.file("geb/integrationTest") + systemProperty "webdriver.chrome.driver", System.getProperty('webdriver.chrome.driver') + systemProperty "webdriver.gecko.driver", System.getProperty('webdriver.gecko.driver') } assets { - packagePlugin = true + minifyJs = true + minifyCss = true } publishing { @@ -134,4 +161,23 @@ publishing { } } } + + publications { + mavenJar(org.gradle.api.publish.maven.MavenPublication) { + pom.withXml { + def pomNode = asNode() + pomNode.dependencyManagement.replaceNode {} + + // simply remove dependencies without a version + // version-less dependencies are handled with dependencyManagement + // see https://github.com/spring-gradle-plugins/dependency-management-plugin/issues/8 for more complete solutions + pomNode.dependencies.dependency.findAll { + it.version.text().isEmpty() + }.each { + it.replaceNode {} + } + } + from components.java + } + } } diff --git a/gradle.properties b/gradle.properties index 64f2d4f99..83e8a142f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ -#Mon May 18 05:26:56 AEST 2020 -grailsVersion=3.2.11 -grailsWrapperVersion=1.0.0 -gormVersion=6.1.12.RELEASE -gradleWrapperVersion=3.4.1 +grailsVersion=4.0.12 +gorm.version=7.0.8.RELEASE +org.gradle.daemon=true +org.gradle.parallel=true +org.gradle.jvmargs=-Dfile.encoding=UTF-8 -Xmx1024M diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index deedc7fa5..87b738cbd 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 39d56185c..5028f28f8 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,5 @@ -#Thu Aug 31 10:01:36 AEST 2017 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-3.4.1-all.zip diff --git a/gradlew b/gradlew index 9d82f7891..af6708ff2 100755 --- a/gradlew +++ b/gradlew @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +#!/usr/bin/env sh ############################################################################## ## @@ -6,20 +6,38 @@ ## ############################################################################## -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS="" +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null APP_NAME="Gradle" APP_BASE_NAME=`basename "$0"` +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m"' + # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD="maximum" -warn ( ) { +warn () { echo "$*" } -die ( ) { +die () { echo echo "$*" echo @@ -30,6 +48,7 @@ die ( ) { cygwin=false msys=false darwin=false +nonstop=false case "`uname`" in CYGWIN* ) cygwin=true @@ -40,26 +59,11 @@ case "`uname`" in MINGW* ) msys=true ;; + NONSTOP* ) + nonstop=true + ;; esac -# Attempt to set APP_HOME -# Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi -done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >/dev/null -APP_HOME="`pwd -P`" -cd "$SAVED" >/dev/null - CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar # Determine the Java command to use to start the JVM. @@ -85,7 +89,7 @@ location of your Java installation." fi # Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then MAX_FD_LIMIT=`ulimit -H -n` if [ $? -eq 0 ] ; then if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then @@ -150,11 +154,19 @@ if $cygwin ; then esac fi -# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules -function splitJvmOpts() { - JVM_OPTS=("$@") +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " } -eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS -JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" +APP_ARGS=$(save "$@") + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong +if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then + cd "$(dirname "$0")" +fi -exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat index aec99730b..0f8d5937c 100755 --- a/gradlew.bat +++ b/gradlew.bat @@ -8,14 +8,14 @@ @rem Set local scope for the variables with windows NT shell if "%OS%"=="Windows_NT" setlocal -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS= - set DIRNAME=%~dp0 if "%DIRNAME%" == "" set DIRNAME=. set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" + @rem Find java.exe if defined JAVA_HOME goto findJavaFromJavaHome @@ -46,10 +46,9 @@ echo location of your Java installation. goto fail :init -@rem Get command-line arguments, handling Windowz variants +@rem Get command-line arguments, handling Windows variants if not "%OS%" == "Windows_NT" goto win9xME_args -if "%@eval[2+2]" == "4" goto 4NT_args :win9xME_args @rem Slurp the command line arguments. @@ -60,11 +59,6 @@ set _SKIP=2 if "x%~1" == "x" goto execute set CMD_LINE_ARGS=%* -goto execute - -:4NT_args -@rem Get arguments from the 4NT Shell from JP Software -set CMD_LINE_ARGS=%$ :execute @rem Setup the command line diff --git a/grails-app/conf/application.yml b/grails-app/conf/application.yml index bee0c1e61..b51abea0e 100644 --- a/grails-app/conf/application.yml +++ b/grails-app/conf/application.yml @@ -15,3 +15,20 @@ info: version: '@info.app.version@' grailsVersion: '@info.app.grailsVersion@' +security: + cas: + casServerName: 'https://auth.ala.org.au' + loginUrl: 'https://auth.ala.org.au/cas/login' + logoutUrl: 'https://auth.ala.org.au/cas/logout' + casServerUrlPrefix: 'https://auth.ala.org.au/cas' + + bypass: false # set to true for non-ALA deployment + gateway: false + uriExclusionFilterPattern: '/assets.*,/images.*,/css.*,/js.*,/less.*,' + uriFilterPattern: '/alaAdmin.*' + #if false, ticket params always proceed + #true, only processes urls listed in authenticateOnlyIfLoggedInFilterPattern + applyUriFiltersToTicketValidation: false + authenticateOnlyIfLoggedInFilterPattern: '/master,/master/.*,/manageLayers,/manageLayers/.*,/admin,/admin/.*,/layers/view/more/.*,/layer/download/.*,/workflow.*' + disableCAS: false + appServerName: "" diff --git a/grails-app/controllers/au/org/ala/biocache/hubs/ProxyController.groovy b/grails-app/controllers/au/org/ala/biocache/hubs/ProxyController.groovy index 7acfa2d1b..8cf8c5916 100644 --- a/grails-app/controllers/au/org/ala/biocache/hubs/ProxyController.groovy +++ b/grails-app/controllers/au/org/ala/biocache/hubs/ProxyController.groovy @@ -266,8 +266,7 @@ class ProxyController { String stringStatusCode = Integer.toString(intProxyResponseCode); String stringLocation = httpMethodProxyRequest.getResponseHeader(STRING_LOCATION_HEADER).getValue(); if(stringLocation == null) { - throw new ServletException("Recieved status code: " + stringStatusCode - + " but no " + STRING_LOCATION_HEADER + " header was found in the response"); + throw new ServletException("Recieved status code: " + stringStatusCode + " but no " + STRING_LOCATION_HEADER + " header was found in the response"); } // Modify the redirect to go to this proxy servlet rather that the proxied host String stringMyHostName = httpServletRequest.getServerName(); diff --git a/grails-app/services/au/org/ala/biocache/hubs/WebServicesService.groovy b/grails-app/services/au/org/ala/biocache/hubs/WebServicesService.groovy index 434f3f53e..965586418 100644 --- a/grails-app/services/au/org/ala/biocache/hubs/WebServicesService.groovy +++ b/grails-app/services/au/org/ala/biocache/hubs/WebServicesService.groovy @@ -158,7 +158,7 @@ class WebServicesService { getJsonElements(url) } - @Cacheable(value="longTermCache", key = "#root.method.name") + //@Cacheable(value="longTermCache", key = "#root.method.name") def Map getGroupedFacets() { log.info "Getting grouped facets with key: #root.methodName" def url = "${grailsApplication.config.biocache.baseUrl}/search/grouped/facets" diff --git a/grails-wrapper.jar b/grails-wrapper.jar index bc85146c1..6b6da64fe 100644 Binary files a/grails-wrapper.jar and b/grails-wrapper.jar differ diff --git a/grailsw b/grailsw index c2c921c29..8d0cc123e 100755 --- a/grailsw +++ b/grailsw @@ -102,6 +102,7 @@ fi if $cygwin ; then APP_HOME=`cygpath --path --mixed "$APP_HOME"` JAVACMD=`cygpath --unix "$JAVACMD"` + JAR_PATH=`cygpath --path --mixed "$JAR_PATH"` # We build the pattern for arguments to be converted via cygpath ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` diff --git a/src/test/groovy/au/org/ala/biocache/hubs/OccurrenceTagLibSpec.groovy b/src/test/groovy/au/org/ala/biocache/hubs/OccurrenceTagLibSpec.groovy deleted file mode 100644 index 220bdfcda..000000000 --- a/src/test/groovy/au/org/ala/biocache/hubs/OccurrenceTagLibSpec.groovy +++ /dev/null @@ -1,199 +0,0 @@ -/* - * Copyright (C) 2018 Atlas of Living Australia - * All Rights Reserved. - * The contents of this file are subject to the Mozilla Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/MPL/ - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - */ - -package au.org.ala.biocache.hubs - -import au.org.ala.dataquality.model.QualityCategory -import au.org.ala.dataquality.model.QualityFilter -import grails.test.mixin.TestFor -import grails.util.Holders -import spock.lang.Specification -import spock.lang.Unroll - -/** - * Unit tests for {@link au.org.ala.biocache.hubs.OccurrenceTagLib} - * - * @author "Nick dos Remedios " - */ -@TestFor(OccurrenceTagLib) -class OccurrenceTagLibSpec extends Specification { - - def setup() { - Holders.grailsApplication.config.dataResourceUuid.alaSightings = "dr364" - Holders.grailsApplication.config.dataResourceUuid.iNaturalist = "dr1411" - Holders.grailsApplication.config.dataResourceUuid.flickr = "dr360" - } - - static doWithConfig(config) { - config.dataquality.enabled = 'true' - } - - void "test sanitizeBodyText plain text"() { - given: - def text = "Australian Plant Image Index (APII)" - when: - def html = tagLib.sanitizeBodyText(text) - then: - html == text - } - - void "test sanitizeBodyText LSID text"() { - given: - def text = "urn:lsid:biocol.org:col:34978" - when: - def html = tagLib.sanitizeBodyText(text) - then: - html == text - } - - void "test sanitizeBodyText suspect text"() { - given: - def text = "Australian Plant Image Index (APII) " - when: - def html = tagLib.sanitizeBodyText(text) - then: - html == "Australian Plant Image Index (APII) " - } - - void "test sanitizeBodyText html no target attr"() { - // taken from record ID c31644ae-cb2b-4111-9966-afa8cac42f01 - given: - def text = "Taken at Loughnan Nature Reserve NSW, Australian Plant Image Index (APII) Photo: dig1975" - when: - def html = tagLib.sanitizeBodyText(text, false) - then: - html == "Taken at Loughnan Nature Reserve NSW, Australian Plant Image Index (APII) Photo: dig1975" - } - - void "test sanitizeBodyText html text"() { - // taken from record ID c31644ae-cb2b-4111-9966-afa8cac42f01 - given: - def text = "Taken at Loughnan Nature Reserve NSW, Australian Plant Image Index (APII) Photo: dig1975" - when: - def html = tagLib.sanitizeBodyText(text) - then: - html == "Taken at Loughnan Nature Reserve NSW, Australian Plant Image Index (APII) Photo: dig1975" - } - - - void "test sanitizeBodyText ALA generated html text"() { - // taken from record ID df9c78e6-6908-4ae4-8b72-09b22ef9c9ff - given: - def text = "source specimen NMV:Ichthyology:A30460-29" - when: - def html = tagLib.sanitizeBodyText(text) - then: - html == "source specimen NMV:Ichthyology:A30460-29" - } - - void "test sanitizeBodyText ALA generated html text 2"() { - // taken from record ID df9c78e6-6908-4ae4-8b72-09b22ef9c9ff - given: - def text = "Collectors were identical
Occurrence was compared without day
Coordinates were identical
" - when: - def html = tagLib.sanitizeBodyText(text) - then: - html == "Collectors were identical
Occurrence was compared without day
Coordinates were identical
" - } - - void "test sanitizeBodyText ALA generated html text 3"() { - // taken from record ID df9c78e6-6908-4ae4-8b72-09b22ef9c9ff - given: - def text = " Museums Victoria
Supplied institution code \"NMV\"" - when: - def html = tagLib.sanitizeBodyText(text) - then: - html == " Museums Victoria
Supplied institution code "NMV"" - } - - void "test sanitizeBodyText for taxa search span from biocache-service"() { - // taken from acacia search - https://biocache-ws.ala.org.au/ws/occurrences/search?q=taxa:acacia - given: - def text = "GENUS: Acacia" - when: - def html = tagLib.sanitizeBodyText(text) - then: - html == "GENUS: Acacia" - } - - void "test sanitizeBodyText XSS test 1"() { - // for issue AtlasOfLivingAustralia/biocache-hubs/issues/327 - // - given: - def text = "" - when: - def html = tagLib.sanitizeBodyText(text) - then: - html == "" - } - - void "test sanitizeBodyText HTML test 4"() { - // div - given: - def text = "
acacia
" - when: - def html = tagLib.sanitizeBodyText(text) - then: - html == "acacia" - } - - void "test Biocollect sightings user link via getLinkForUserId() tag"() { - // taken from record ID 04eacba3-cec1-4d6b-8822-78444655081d - given: - grailsApplication.config.sightings.baseUrl = "https://sightings.ala.org.au" - when: - def html = tagLib.getLinkForUserId(userName:"David Sando", userId: "1267", dataResourceUid: "dr364") - then: - html == "David Sando" - - } - - void "test iNaturalist user page link via getLinkForUserId() tag"() { - // taken from record ID 94f19c5b-1065-4ac1-9b77-2abf4c2bcbc4 - given: - grailsApplication.config.iNaturalist.baseUrl = "https://inaturlist.ala.org.au" - when: - def html = tagLib.getLinkForUserId(userName:"peggydnew", dataResourceUid: "dr1411") - then: - html == "peggydnew" - } - - void "test Flickr user page link via getLinkForUserId() tag"() { - // taken from record ID 674aa318-8f9a-4218-a43f-6c47f0070c82 - when: - def html = tagLib.getLinkForUserId(userName:"Donald Hobern", dataResourceUid: "dr360", occurrenceId: "https://www.flickr.com/photos/dhobern/5466675452/") - then: - html == "Donald Hobern" - } - - @Unroll - void 'test linkQualityCategory enable: #enable expand #expand'(boolean enable, boolean expand, Map searchParams, String result) { - given: - QualityCategory category = new QualityCategory(name: 'asdf', label: 'asdf', qualityFilters: [new QualityFilter(filter: 'a:b', enabled: true), new QualityFilter(filter: 'c:d', enabled: true), new QualityFilter(filter: 'e:f', enabled: false)]) - params.q = '*:*' - params.putAll(searchParams) - - when: - def html = applyTemplate('FOO', [category: category]) - - then: - html == result - - where: - enable || expand || searchParams || result - true | true | [fq: ['a:z', 'c:d'], disableQualityFilter: ['qwerty', 'asdf']] | 'FOO' - true | false | [fq: ['a:z', 'c:d'], disableQualityFilter: ['qwerty', 'asdf']] | 'FOO' - false | true | [fq: ['x:y', 'y:z'], disableQualityFilter: ['qwerty']] | 'FOO' - false | false | [fq: ['x:y', 'y:z'], disableQualityFilter: 'qwerty'] | 'FOO' - } -} diff --git a/src/test/groovy/au/org/ala/biocache/hubs/PostProcessingServiceSpec.groovy b/src/test/groovy/au/org/ala/biocache/hubs/PostProcessingServiceSpec.groovy deleted file mode 100644 index 46f4eb170..000000000 --- a/src/test/groovy/au/org/ala/biocache/hubs/PostProcessingServiceSpec.groovy +++ /dev/null @@ -1,115 +0,0 @@ -package au.org.ala.biocache.hubs - -import grails.converters.JSON -import grails.test.mixin.TestFor -import groovy.json.JsonSlurper -import org.grails.web.json.JSONObject -import spock.lang.IgnoreRest -import spock.lang.Specification - -/** - * See the API for {@link grails.test.mixin.services.ServiceUnitTestMixin} for usage instructions - */ -@TestFor(PostProcessingService) -class PostProcessingServiceSpec extends Specification { - - def setup() { - grailsApplication.config.facets = [ - include:"dataHubUid,day,modified,left,right", - exclude:"establishment_means,user_assertions,assertion_user_id,name_match_metric", - hide:"taxon_name,common_name", - customOrder:"" - ] - grailsApplication.config.stateConservationListPath = [ - NewSouthWales: "/speciesListItem/list/dr650", - AustralianCapitalTerritory: "/speciesListItem/list/dr649", - Queensland: "/speciesListItem/list/dr652", - Victoria: "/speciesListItem/list/dr655", - WesternAustralia: "/speciesListItem/list/dr2201", - SouthAustralia: "/speciesListItem/list/dr653", - NorthernTerritory: "/speciesListItem/list/dr651", - Tasmania: "/speciesListItem/list/dr654" - ] - grailsApplication.config.speciesList.baseURL = "https://lists.ala.org.au" - service.grailsApplication = grailsApplication - } - - def cleanup() { - } - - //@IgnoreRest - void "test resultsHaveImages"() { - setup: - def json1 = '''{"query":"?q=lsid%3Aurn%3Alsid%3Abiodiversity.org.au%3Aafd.taxon%3A682e1228-5b3c-45ff-833b-550efd40c399&fq=multimedia%3A%22None%22","status":"OK","sort":"score","pageSize":0,"dir":"asc","occurrences":[],"totalRecords":779882,"facetResults":[{"fieldName":"multimedia","fieldResult":[{"count":779882,"label":"None"}]}],"startIndex":0,"urlParameters":"?q=lsid%3Aurn%3Alsid%3Abiodiversity.org.au%3Aafd.taxon%3A682e1228-5b3c-45ff-833b-550efd40c399&fq=multimedia%3A%22None%22","queryTitle":"CLASS: REPTILIA","activeFacetMap":{"multimedia":{"name":"multimedia","value":"\\"None\\"","displayName":"Multimedia:None"}}}''' - def json2 = '''{"query":"?q=lsid%3Aurn%3Alsid%3Abiodiversity.org.au%3Aafd.taxon%3A682e1228-5b3c-45ff-833b-550efd40c399&fq=multimedia%3A%22Image%22","status":"OK","sort":"score","pageSize":0,"dir":"asc","occurrences":[],"totalRecords":1719,"facetResults":[{"fieldName":"multimedia","fieldResult":[{"count":1719,"label":"Image"}]}],"startIndex":0,"urlParameters":"?q=lsid%3Aurn%3Alsid%3Abiodiversity.org.au%3Aafd.taxon%3A682e1228-5b3c-45ff-833b-550efd40c399&fq=multimedia%3A%22Image%22","queryTitle":"CLASS: REPTILIA","activeFacetMap":{"multimedia":{"name":"multimedia","value":"\\"Image\\"","displayName":"Multimedia:Image"}}}''' - JSONObject sr1 = new JsonSlurper().parseText(json1) - JSONObject sr2 = new JsonSlurper().parseText(json2) - - expect: - service.resultsHaveImages(sr1) == false - service.resultsHaveImages(sr2) == true - } - - //@IgnoreRest - void "test getListFromGroupedFacets"() { - setup: - def ds1 = [Taxon:["taxon_name", "raw_taxon_name", "subspecies_name", "species", "genus", "family", "order", "class", "phylum", "kingdom", "rank", "name_match_metric", "species_group", "common_name", "species_subgroup" ], Location:["country", "state", "cl2079", "cl2078", "cl925", "cl901", "cl958", "cl1048", "cl1049", "cl21"]] - def ds2 = ["taxon_name", "raw_taxon_name", "subspecies_name", "species", "genus", "family", "order", "class", "phylum", "kingdom", "rank", "name_match_metric", "species_group", "common_name", "species_subgroup", "country", "state", "cl2079", "cl2078", "cl925", "cl901", "cl958", "cl1048", "cl1049", "cl21"] - def ds3 = [foo:"bar", bash:"bam"] - expect: - service.getListFromGroupedFacets(ds1).getClass().name == "java.util.ArrayList" - service.getListFromGroupedFacets(ds1).size() == 25 - service.getListFromGroupedFacets(ds1) == ds2 - service.getListFromGroupedFacets(ds3).size() == 2 - service.getListFromGroupedFacets(ds3) == ["bar","bam"] - } - - //@IgnoreRest - void "test getAllFacets"() { - setup: - def ds1 = ["taxon_name", "raw_taxon_name", "subspecies_name", "species", "genus", "family", "order", "class", "phylum", "kingdom", "rank", "name_match_metric", "species_group", "common_name", "species_subgroup", "country", "state", "cl2079", "cl2078", "cl925", "cl901", "cl958", "cl1048", "cl1049", "cl21"] - def ds2 = [taxon_name:false, raw_taxon_name:true, subspecies_name:true, species:true, genus:true, family:true, order:true, class:true, phylum:true, kingdom:true, rank:true, species_group:true, common_name:false, species_subgroup:true, country:true, state:true, cl2079:true, cl2078:true, cl925:true, cl901:true, cl958:true, cl1048:true, cl1049:true, cl21:true, dataHubUid:true, day:true, modified:true, left:true, right:true] - expect: - service.getAllFacets(ds1).getClass().name == "java.util.LinkedHashMap" - service.getAllFacets(ds1).size() == 29 - service.getAllFacets(ds1) == ds2 - } - - //@IgnoreRest - void "test augmentRecord"() { - setup: - def json1 = '''{"Measurement":[],"Attribution":[{"raw":"","processed":"co49","name":"collectionUid"},{"raw":"","processed":"Queensland Herbarium Records","name":"dataResourceName"},{"raw":"","processed":"in42","name":"institutionUid"},{"raw":"","processed":"[\\"dh2\\",\\"dh9\\"]","name":"dataHubUid"},{"raw":"","processed":"Queensland Herbarium","name":"collectionName"},{"raw":"","processed":"dp36","name":"dataProviderUid"},{"raw":"","processed":"Department of Science, Information Technology and Innovation","name":"institutionName"},{"raw":"","processed":"CC BY","name":"license"},{"raw":"dr2287","processed":"","name":"dataResourceUid"},{"raw":"","processed":"Australia's Virtual Herbarium","name":"dataProviderName"}],"Classification":[{"raw":"","processed":"wellformed","name":"nameParseType"},{"raw":"","processed":"Verticordia cunninghamii","name":"species"},{"raw":"","processed":"exactMatch","name":"nameMatchMetric"},{"raw":"Verticordia cunninghamii Schauer","processed":"Verticordia cunninghamii","name":"scientificName"},{"raw":"","processed":"Equisetopsida","name":"classs"},{"raw":"","processed":"http://id.biodiversity.org.au/node/apni/7910992","name":"genusID"},{"raw":"","processed":"http://id.biodiversity.org.au/node/apni/2887513","name":"taxonConceptID"},{"raw":"","processed":"http://id.biodiversity.org.au/node/apni/8807563","name":"kingdomID"},{"raw":"","processed":"498741","name":"left"},{"raw":"","processed":"Charophyta","name":"phylum"},{"raw":"","processed":"Plantae","name":"kingdom"},{"raw":"","processed":"http://id.biodiversity.org.au/node/apni/8807565","name":"classID"},{"raw":"Verticordia","processed":"Verticordia","name":"genus"},{"raw":"","processed":"http://id.biodiversity.org.au/node/apni/8807562","name":"phylumID"},{"raw":"","processed":"Myrtales","name":"order"},{"raw":"species","processed":"species","name":"taxonRank"},{"raw":"cunninghamii","processed":"","name":"specificEpithet"},{"raw":"","processed":"http://id.biodiversity.org.au/node/apni/8774852","name":"orderID"},{"raw":"","processed":"[\\"noIssue\\"]","name":"taxonomicIssue"},{"raw":"","processed":"http://id.biodiversity.org.au/node/apni/2887513","name":"speciesID"},{"raw":"","processed":"http://id.biodiversity.org.au/node/apni/8774750","name":"familyID"},{"raw":"Myrtaceae","processed":"Myrtaceae","name":"family"},{"raw":"","processed":"7000","name":"taxonRankID"},{"raw":"Schauer","processed":"","name":"scientificNameAuthorship"},{"raw":"ICBN","processed":"","name":"nomenclaturalCode"},{"raw":"","processed":"498741","name":"right"}],"Event":[],"Location":[{"raw":"AGD66","processed":"","name":"verbatimSRS"},{"raw":"1.0e-05","processed":"","name":"coordinatePrecision"},{"raw":"-17.9166666667","processed":"-17.9152833666","name":"decimalLatitude"},{"raw":"compiler","processed":"","name":"georeferencedBy"},{"raw":"","processed":"Burke (S)","name":"lga"},{"raw":"16000.00","processed":"16000.0","name":"coordinateUncertaintyInMeters"},{"raw":"Australia","processed":"Australia","name":"country"},{"raw":"Oceania","processed":"","name":"continent"},{"raw":"Burke","processed":"","name":"county"},{"raw":"unknown","processed":"","name":"georeferenceProtocol"},{"raw":"Queensland","processed":"Queensland","name":"stateProvince"},{"raw":"138.2500000000","processed":"138.2509257211","name":"decimalLongitude"},{"raw":"","processed":"Terrestrial","name":"biome"},{"raw":"NICHOLSON RIVER","processed":"","name":"locality"},{"raw":"AGD66","processed":"EPSG:4326","name":"geodeticDatum"},{"raw":"AU","processed":"","name":"countryCode"},{"raw":"decimal degrees","processed":"","name":"verbatimCoordinateSystem"},{"raw":"138.25","processed":"","name":"verbatimLongitude"},{"raw":"-17.9166666667","processed":"","name":"verbatimLatitude"}],"Identification":[{"raw":"","processed":"Not provided","name":"abcdIdentificationQualifier"},{"raw":"1988-06","processed":"","name":"dateIdentified"},{"raw":"","processed":"Not provided","name":"identificationQualifier"},{"raw":"1988-06-00","processed":"","name":"verbatimDateIdentified"},{"raw":"det.","processed":"","name":"identifierRole"},{"raw":"2651.00","processed":"","name":"identificationID"},{"raw":"George, A.S.","processed":"","name":"identifiedBy"}],"Occurrence":[{"raw":"urn:catalog:BRI:Herbrecs:AQ0045921","processed":"","name":"occurrenceID"},{"raw":"native","processed":"","name":"naturalOccurrence"},{"raw":"","processed":"Least concern wildlife,Least concern wildlife","name":"stateConservation"},{"raw":"PreservedSpecimen","processed":"PreservedSpecimen","name":"basisOfRecord"},{"raw":"Anonymous","processed":"UNKNOWN OR ANONYMOUS","name":"recordedBy"},{"raw":"2017-01-13 14:37:40","processed":"2017-01-13","name":"modified"},{"raw":"native","processed":"native","name":"establishmentMeans"},{"raw":"BRI","processed":"","name":"institutionCode"},{"raw":"Nicholson River.","processed":"","name":"occurrenceRemarks"},{"raw":"present","processed":"present","name":"occurrenceStatus"},{"raw":"flowers","processed":"","name":"reproductiveCondition"},{"raw":"not cultivated","processed":"","name":"cultivated"},{"raw":"sheet","processed":"","name":"preparations"},{"raw":"BRI AQ0045921","processed":"","name":"catalogNumber"},{"raw":"Herbrecs","processed":"","name":"collectionCode"}]}''' - def json2 = '''{"Measurement":[],"Attribution":[{"raw":"","processed":"co12","name":"collectionUid"},{"raw":"","processed":"Australia's Virtual Herbarium","name":"dataResourceName"},{"raw":"","processed":"in5","name":"institutionUid"},{"raw":"","processed":"[\\"dh2\\",\\"dh9\\"]","name":"dataHubUid"},{"raw":"","processed":"Australian National Herbarium","name":"collectionName"},{"raw":"","processed":"dp36","name":"dataProviderUid"},{"raw":"","processed":"Centre for Australian National Biodiversity Research","name":"institutionName"},{"raw":"","processed":"CC BY","name":"license"},{"raw":"","processed":"Published dataset","name":"provenance"},{"raw":"dr376","processed":"","name":"dataResourceUid"},{"raw":"","processed":"Australia's Virtual Herbarium","name":"dataProviderName"}],"Classification":[{"raw":"","processed":"wellformed","name":"nameParseType"},{"raw":"","processed":"Pterostylis oreophila","name":"species"},{"raw":"","processed":"exactMatch","name":"nameMatchMetric"},{"raw":"Pterostylis oreophila Clemesha","processed":"Pterostylis oreophila","name":"scientificName"},{"raw":"","processed":"http://id.biodiversity.org.au/name/apni/75185","name":"taxonConceptID"},{"raw":"","processed":"http://id.biodiversity.org.au/node/apni/8807563","name":"kingdomID"},{"raw":"","processed":"587392","name":"left"},{"raw":"","processed":"Plantae","name":"kingdom"},{"raw":"Pterostylis","processed":"","name":"genus"},{"raw":"","processed":"species","name":"taxonRank"},{"raw":"oreophila","processed":"","name":"specificEpithet"},{"raw":"","processed":"[\\"noIssue\\"]","name":"taxonomicIssue"},{"raw":"","processed":"http://id.biodiversity.org.au/name/apni/75185","name":"speciesID"},{"raw":"Orchidaceae","processed":"","name":"family"},{"raw":"","processed":"7000","name":"taxonRankID"},{"raw":"Clemesha","processed":"","name":"scientificNameAuthorship"},{"raw":"ICBN","processed":"","name":"nomenclaturalCode"},{"raw":"","processed":"587392","name":"right"}],"Event":[{"raw":"1990-01-22","processed":"","name":"eventDate"},{"raw":"","processed":"1990","name":"year"},{"raw":"","processed":"01","name":"month"}],"Location":[{"raw":"-35.6","processed":"-35.6","name":"decimalLatitude"},{"raw":"","processed":"Tumut Shire (A)","name":"lga"},{"raw":"1000","processed":"11000.0","name":"coordinateUncertaintyInMeters"},{"raw":"Australia","processed":"Australia","name":"country"},{"raw":"not available","processed":"","name":"generalisedLocality"},{"raw":"Gentle slope. Black, wet, peaty soil under {Leptospermum langigerum}.","processed":"Gentle slope. Black, wet, peaty soil under {Leptospermum langigerum}.","name":"habitat"},{"raw":"unknown","processed":"","name":"georeferenceProtocol"},{"raw":"Australian Capital Territory","processed":"New South Wales","name":"stateProvince"},{"raw":"148.8","processed":"148.8","name":"decimalLongitude"},{"raw":"","processed":"Terrestrial","name":"biome"},{"raw":"","processed":"EPSG:4326","name":"geodeticDatum"},{"raw":"AU","processed":"","name":"countryCode"}],"Identification":[{"raw":"","processed":"Not provided","name":"abcdIdentificationQualifier"},{"raw":"2005-05","processed":"","name":"dateIdentified"},{"raw":"","processed":"Not provided","name":"identificationQualifier"},{"raw":"det.","processed":"","name":"identifierRole"},{"raw":"Jones, D.L.","processed":"","name":"identifiedBy"}],"Occurrence":[{"raw":"Unknown","processed":"","name":"naturalOccurrence"},{"raw":"","processed":"Critically Endangered,Critically Endangered","name":"stateConservation"},{"raw":"PreservedSpecimen","processed":"PreservedSpecimen","name":"basisOfRecord"},{"raw":"","processed":"Location in New South Wales, Australia generalised to 0.1 degrees. \\nSensitive in NSW, Name: New South Wales, Zone: STATE [NSW Category 2 Conservation Protected, NSW OEH]","name":"dataGeneralizations"},{"raw":"Jones, D.L.","processed":"Jones, D.L.","name":"recordedBy"},{"raw":"Jones, T.D.","processed":"","name":"secondaryCollectors"},{"raw":"2016-01-27 15:17:26","processed":"2016-01-27","name":"modified"},{"raw":"5630","processed":"","name":"fieldNumber"},{"raw":"5630","processed":"","name":"recordNumber"},{"raw":"","processed":"03fee6b0-38cf-4e80-bc17-2586443322b2|9eab97d3-344b-4bd2-9d6e-92c0e9f696cc","name":"associatedOccurrences"},{"raw":"Unknown","processed":"unknown","name":"establishmentMeans"},{"raw":"CANB","processed":"","name":"institutionCode"},{"raw":"Deciduous terrestrial orchid; stems smooth. Common.","processed":"","name":"occurrenceRemarks"},{"raw":"","processed":"present","name":"occurrenceStatus"},{"raw":"","processed":"R","name":"duplicationStatus"},{"raw":"sheet","processed":"","name":"preparations"},{"raw":"CBG 9004654.1","processed":"","name":"catalogNumber"},{"raw":"CBG","processed":"","name":"collectionCode"}]}''' - def json3 = '''{"Measurement":[],"Attribution":[{"raw":"","processed":"co12","name":"collectionUid"},{"raw":"","processed":"Australia's Virtual Herbarium","name":"dataResourceName"},{"raw":"","processed":"in5","name":"institutionUid"},{"raw":"","processed":"[\\"dh2\\",\\"dh9\\"]","name":"dataHubUid"},{"raw":"","processed":"Australian National Herbarium","name":"collectionName"},{"raw":"","processed":"dp36","name":"dataProviderUid"},{"raw":"","processed":"Centre for Australian National Biodiversity Research","name":"institutionName"},{"raw":"","processed":"CC BY","name":"license"},{"raw":"","processed":"Published dataset","name":"provenance"},{"raw":"dr376","processed":"","name":"dataResourceUid"},{"raw":"","processed":"Australia's Virtual Herbarium","name":"dataProviderName"}],"Classification":[{"raw":"","processed":"wellformed","name":"nameParseType"},{"raw":"","processed":"Pterostylis oreophila","name":"species"},{"raw":"","processed":"exactMatch","name":"nameMatchMetric"},{"raw":"Pterostylis oreophila Clemesha","processed":"Pterostylis oreophila","name":"scientificName"},{"raw":"","processed":"http://id.biodiversity.org.au/name/apni/75185","name":"taxonConceptID"},{"raw":"","processed":"http://id.biodiversity.org.au/node/apni/8807563","name":"kingdomID"},{"raw":"","processed":"587392","name":"left"},{"raw":"","processed":"Plantae","name":"kingdom"},{"raw":"Pterostylis","processed":"","name":"genus"},{"raw":"","processed":"species","name":"taxonRank"},{"raw":"oreophila","processed":"","name":"specificEpithet"},{"raw":"","processed":"[\\"noIssue\\"]","name":"taxonomicIssue"},{"raw":"","processed":"http://id.biodiversity.org.au/name/apni/75185","name":"speciesID"},{"raw":"Orchidaceae","processed":"","name":"family"},{"raw":"","processed":"7000","name":"taxonRankID"},{"raw":"Clemesha","processed":"","name":"scientificNameAuthorship"},{"raw":"ICBN","processed":"","name":"nomenclaturalCode"},{"raw":"","processed":"587392","name":"right"}],"Event":[{"raw":"1990-01-22","processed":"","name":"eventDate"},{"raw":"","processed":"1990","name":"year"},{"raw":"","processed":"01","name":"month"}],"Location":[{"raw":"-35.6","processed":"-35.6","name":"decimalLatitude"},{"raw":"","processed":"Tumut Shire (A)","name":"lga"},{"raw":"1000","processed":"11000.0","name":"coordinateUncertaintyInMeters"},{"raw":"Australia","processed":"Australia","name":"country"},{"raw":"not available","processed":"","name":"generalisedLocality"},{"raw":"Gentle slope. Black, wet, peaty soil under {Leptospermum langigerum}.","processed":"Gentle slope. Black, wet, peaty soil under {Leptospermum langigerum}.","name":"habitat"},{"raw":"unknown","processed":"","name":"georeferenceProtocol"},{"raw":"Australian Capital Territory","processed":"Van Demon's Land","name":"stateProvince"},{"raw":"148.8","processed":"148.8","name":"decimalLongitude"},{"raw":"","processed":"Terrestrial","name":"biome"},{"raw":"","processed":"EPSG:4326","name":"geodeticDatum"},{"raw":"AU","processed":"","name":"countryCode"}],"Identification":[{"raw":"","processed":"Not provided","name":"abcdIdentificationQualifier"},{"raw":"2005-05","processed":"","name":"dateIdentified"},{"raw":"","processed":"Not provided","name":"identificationQualifier"},{"raw":"det.","processed":"","name":"identifierRole"},{"raw":"Jones, D.L.","processed":"","name":"identifiedBy"}],"Occurrence":[{"raw":"Unknown","processed":"","name":"naturalOccurrence"},{"raw":"","processed":"Critically Endangered,Critically Endangered","name":"stateConservation"},{"raw":"PreservedSpecimen","processed":"PreservedSpecimen","name":"basisOfRecord"},{"raw":"","processed":"Location in New South Wales, Australia generalised to 0.1 degrees. \\nSensitive in NSW, Name: New South Wales, Zone: STATE [NSW Category 2 Conservation Protected, NSW OEH]","name":"dataGeneralizations"},{"raw":"Jones, D.L.","processed":"Jones, D.L.","name":"recordedBy"},{"raw":"Jones, T.D.","processed":"","name":"secondaryCollectors"},{"raw":"2016-01-27 15:17:26","processed":"2016-01-27","name":"modified"},{"raw":"5630","processed":"","name":"fieldNumber"},{"raw":"5630","processed":"","name":"recordNumber"},{"raw":"","processed":"03fee6b0-38cf-4e80-bc17-2586443322b2|9eab97d3-344b-4bd2-9d6e-92c0e9f696cc","name":"associatedOccurrences"},{"raw":"Unknown","processed":"unknown","name":"establishmentMeans"},{"raw":"CANB","processed":"","name":"institutionCode"},{"raw":"Deciduous terrestrial orchid; stems smooth. Common.","processed":"","name":"occurrenceRemarks"},{"raw":"","processed":"present","name":"occurrenceStatus"},{"raw":"","processed":"R","name":"duplicationStatus"},{"raw":"sheet","processed":"","name":"preparations"},{"raw":"CBG 9004654.1","processed":"","name":"catalogNumber"},{"raw":"CBG","processed":"","name":"collectionCode"}]}''' - JSONObject rec1 = JSON.parse(json1) - JSONObject rec2 = JSON.parse(json2) - JSONObject rec3 = JSON.parse(json3) - expect: - extractStateConservationValue(rec1) != extractStateConservationValue(service.augmentRecord(rec1)) - extractStateConservationValue(service.augmentRecord(rec1)) == '''Queensland: Least concern wildlife''' - extractStateConservationValue(rec2) != extractStateConservationValue(service.augmentRecord(rec2)) - extractStateConservationValue(service.augmentRecord(rec2)) == '''New South Wales: Critically Endangered''' - extractStateConservationValue(rec3) == extractStateConservationValue(service.augmentRecord(rec3)) - } - - String extractStateConservationValue(JSONObject rec) { - rec.get("Occurrence").find{ it.name == "stateConservation" }.get("processed") - } - - void "test getListOfLayerIds via data table"() { - expect: - service.getListOfLayerIds(new SpatialSearchRequestParams(q:q, fq:fq)) == ids - - where: - q | fq | ids - "cl10955:*" | [] | ["cl10955"] - "cl10955:*" | ["el123:foo"] | ["cl10955","el123"] - "element" | ["cl10955:*"] | ["cl10955"] - "el123a:*" | ["el1234:*"] | ["el1234"] - "" | ["dl1234:*"] | [] - "" | ["-cl1234:*"] | ["cl1234"] - "dl1234:*" | [] | [] - "dl1234:*" | ["cl456:[* TO *]"] | ["cl456"] - "*:*" | ["el123:*","cl456:*"] | ["el123","cl456"] - } -}