Skip to content

Commit

Permalink
Merge pull request #167 from charvolant/name-match-redesign
Browse files Browse the repository at this point in the history
Release version 1.4.1
  • Loading branch information
charvolant authored Dec 10, 2017
2 parents 52892a5 + e7af7a8 commit de29770
Show file tree
Hide file tree
Showing 29 changed files with 44,614 additions and 71 deletions.
5 changes: 3 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ buildscript {
}
}

version "1.4.1-SNAPSHOT"
version "1.4.1"
group "au.org.ala"

apply plugin:"eclipse"
Expand Down Expand Up @@ -52,6 +52,7 @@ dependencies {
testRuntime "org.seleniumhq.selenium:selenium-htmlunit-driver:2.47.1"
testRuntime "net.sourceforge.htmlunit:htmlunit:2.18"

compile "org.grails.plugins:ala-ws-security-plugin:2.0-SNAPSHOT"
compile 'com.github.davidmoten:rxjava-file:0.4'
compile 'io.reactivex:rxgroovy:1.0.3'
compile ('org.jasig.cas.client:cas-client-core:3.4.1') {
Expand All @@ -64,7 +65,7 @@ dependencies {
exclude group: 'com.google.guava', module: 'guava'
}
compile "com.google.guava:guava:19.0"
compile("au.org.ala:ala-name-matching:2.4.6-SNAPSHOT") {
compile("au.org.ala:ala-name-matching:2.4.6") {
exclude group: 'org.slf4j', module: 'slf4j-log4j12'
}
compile "org.jsoup:jsoup:1.8.3"
Expand Down
6 changes: 3 additions & 3 deletions grails-app/conf/logback.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ if (Environment.isDevelopmentMode()) {
'org.springframework',
],
(DEBUG): [
'org.apache.http.headers',
'org.apache.http.wire',
'org.hibernate.SQL',
//'org.apache.http.headers',
//'org.apache.http.wire',
//'org.hibernate.SQL',
'au.org.ala.bie'
],
(TRACE): []
Expand Down
91 changes: 54 additions & 37 deletions grails-app/controllers/au/org/ala/bie/ImportController.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

package au.org.ala.bie

import au.org.ala.bie.util.Job
import grails.converters.JSON
import org.apache.commons.lang.BooleanUtils
import au.org.ala.web.AlaSecured
Expand All @@ -24,6 +25,10 @@ class ImportController {

def importService, bieAuthService
def brokerMessagingTemplate
def jobService

Map<String, Job> jobStatus = [:]

/**
* Load import index page.
*/
Expand Down Expand Up @@ -66,16 +71,21 @@ class ImportController {
def dwcDir = params.dwca_dir

if(new File(dwcDir).exists()){
execute { importService.importDwcA(dwcDir, clearIndex) }
asJson ([success:true])
def job = execute("importDwca", "admin.button.importdwca", { importService.importDwcA(dwcDir, clearIndex) })
asJson (job.status())
} else {
asJson ([success: false, message: 'Supplied directory path is not accessible'])
}
}

def importAll(){
execute { importService.importAll() }
asJson([success: true])
def job = execute(
"importDwca,importCollectory,deleteDanglingSynonyms,importLayers,importLocalities,importRegions,importHabitats,importHabitats," +
"importWordPressPages,importOccurrences,importConsevationSpeciesLists,buildVernacularSpeciesLists,buildLinkIdentifiers" +
"denormaliseTaxa,loadImages,",
"admin.button.importall",
{ importService.importAll() })
asJson(job.status())
}

/**
Expand All @@ -85,16 +95,16 @@ class ImportController {
*/
def importAllDwcA() {
if(new File(grailsApplication.config..getProperty('import.taxonomy.dir')).exists()){
execute { importService.importAllDwcA() }
asJson ([success:true])
def job = execute("importDwca", "admin.button.importalldwca", { importService.importAllDwcA() })
asJson(job.status())
} else {
asJson ([success: false, message: 'Supplied directory path is not accessible'])
}
}

def deleteDanglingSynonyms(){
execute { importService.clearDanglingSynonyms() }
asJson([success: true])
def job = execute("deleteDanglingSynonyms", "admin.button.deletedanglingsynonyms", { importService.clearDanglingSynonyms() })
asJson(job.status())
}

/**
Expand All @@ -104,8 +114,8 @@ class ImportController {
*/
def importCollectory(){
if(grailsApplication.config.collectoryServicesUrl){
execute { importService.importCollectory() }
asJson([success:true])
def job = execute("importCollectory", "admin.button.importcollectory", { importService.importCollectory() })
asJson(job.status())
} else {
asJson([success: false, message: 'collectoryServicesUrl not configured'])
}
Expand All @@ -118,8 +128,8 @@ class ImportController {
*/
def importLayers(){
if(grailsApplication.config.layersServicesUrl){
execute { importService.importLayers() }
asJson([success:true])
def job = execute("importLayers", "admin.button.importlayer", { importService.importLayers() })
asJson(job.status())
} else {
asJson([success: false, message: 'layersServicesUrl not configured'])
}
Expand All @@ -132,8 +142,8 @@ class ImportController {
*/
def importLocalities(){
if(grailsApplication.config.layersServicesUrl && grailsApplication.config.gazetteerLayerId){
execute { importService.importLocalities() }
asJson([success:true])
def job = execute("importLocalities", "admin.button.importlocalities", { importService.importLocalities() })
asJson(job.status())
} else {
asJson([success: false, message: 'layersServicesUrl not configured or gazetteerLayerId not configured'])
}
Expand All @@ -146,8 +156,8 @@ class ImportController {
*/
def importRegions(){
if(grailsApplication.config.layersServicesUrl){
execute { importService.importRegions() }
asJson([success:true])
def job = execute("importRegions", "admin.button.importregions", { importService.importRegions() })
asJson(job.status())
} else {
asJson([success: false, message: 'layersServicesUrl not configured'])
}
Expand All @@ -159,8 +169,8 @@ class ImportController {
* @return
*/
def importHabitats(){
execute { importService.importHabitats() }
asJson([success:true])
def job = execute("importHabitats", "admin.button.importhabitats", { importService.importHabitats() })
asJson(job.status())
}

/**
Expand All @@ -169,8 +179,8 @@ class ImportController {
* @return
*/
def importWordPress(){
execute { importService.importWordPressPages() }
asJson([success:true])
def job = execute("importWordPressPages", "admin.button.loadwordpress", { importService.importWordPressPages() })
asJson(job.status())
}

/**
Expand All @@ -179,8 +189,8 @@ class ImportController {
* @return
*/
def importOccurrences(){
execute { importService.importOccurrenceData() }
asJson ([success:true] )
def job = execute("importOccurrences", "admin.button.loadoccurrence", { importService.importOccurrenceData() })
asJson (job.status())

}

Expand All @@ -190,8 +200,8 @@ class ImportController {
* @return
*/
def importConservationSpeciesLists(){
execute { importService.importConservationSpeciesLists() }
asJson ([success:true] )
def job = execute("importConsevationSpeciesLists", "admin.button.importlistconservatioon", { importService.importConservationSpeciesLists() })
asJson(job.status())
}

/**
Expand All @@ -200,22 +210,22 @@ class ImportController {
* @return
*/
def importVernacularSpeciesLists(){
execute { importService.importVernacularSpeciesLists() }
asJson ([success:true] )
def job = execute("buildVernacularSpeciesLists", "admin.button.importlistvernacular", { importService.importVernacularSpeciesLists() })
asJson (job.status())

}

def buildLinkIdentifiers() {
def online = BooleanUtils.toBooleanObject(params.online ?: "false")
execute { importService.buildLinkIdentifiers(online) }
asJson ([success:true] )
def job = execute("buildLinkIdentifiers", "admin.button.buildLinks", { importService.buildLinkIdentifiers(online) })
asJson (job.status())

}

def denormaliseTaxa() {
def online = BooleanUtils.toBooleanObject(params.online ?: "false")
execute { importService.denormaliseTaxa(online) }
asJson ([success:true] )
def job = execute("denormaliseTaxa", "admin.button.denormalise", { importService.denormaliseTaxa(online) })
asJson (job.status())

}

Expand All @@ -227,14 +237,14 @@ class ImportController {
*/
def loadPreferredImages() {
def online = BooleanUtils.toBooleanObject(params.online ?: "false")
execute { importService.loadPreferredImages(online) }
asJson ([success:true] )
def job = execute("loadImages", "admin.button.loadimagespref", { importService.loadPreferredImages(online) })
asJson (job.status())
}

def loadImages() {
def online = BooleanUtils.toBooleanObject(params.online ?: "false")
execute { importService.loadImages(online) }
asJson ([success:true] )
def job = execute("loadImages", "admin.bitton.loadimagesall", { importService.loadImages(online) })
asJson (job.status())
}

def ranks() {
Expand All @@ -247,16 +257,23 @@ class ImportController {
render (model as JSON)
}

private def execute = { Closure task ->
Thread.start {
private def execute(String type, String titleCode, Closure task) {
def title = message(code: titleCode)
def types = type.split(',') as Set
def job = jobService.existing(types)
if (job) {
return job
}
job = jobService.create(types, title, {
try {
brokerMessagingTemplate.convertAndSend "/topic/import-control", "STARTED"
task.call()
brokerMessagingTemplate.convertAndSend "/topic/import-control", "FINISHED"
} catch (Exception ex) {
log.error(ex.message, ex)
brokerMessagingTemplate.convertAndSend "/topic/import-control", "ERROR"
throw ex
}
}
})
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package au.org.ala.bie

import au.ala.org.ws.security.RequireApiKey
import grails.converters.JSON

/**
* A controller for managing imoort via web service rather than UI
*/
@RequireApiKey
class ImportServicesController {
def importService
def jobService

/**
* Import all
*/
def all() {
def job = execute(
"importDwca,importCollectory,deleteDanglingSynonyms,importLayers,importLocalities,importRegions,importHabitats,importHabitats," +
"importWordPressPages,importOccurrences,importConsevationSpeciesLists,buildVernacularSpeciesLists,buildLinkIdentifiers" +
"denormaliseTaxa,loadImages,",
"admin.button.importall",
{ importService.importAll() })
asJson(job.status())
}

/**
* Get a job status
*/
def status() {
def id = params.id
def status = jobService.get(id)?.status() ?: notFoundStatus(id)
asJson(status)
}

private def asJson = { model ->
response.setContentType("application/json;charset=UTF-8")
render (model as JSON)
}

private def execute(String type, String titleCode, Closure task) {
def title = message(code: titleCode)
def types = type.split(',') as Set
def job = jobService.existing(types)
if (job) {
return job
}
job = jobService.create(types, title, task)
}

private def notFoundStatus(id) {
return [success: false, active: false, id: id, lifecycle: 'ERROR', lastUpdated: new Date(), message: 'Not found']
}
}
65 changes: 65 additions & 0 deletions grails-app/controllers/au/org/ala/bie/JobController.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package au.org.ala.bie

import au.org.ala.web.AlaSecured
import grails.converters.JSON
import grails.converters.XML

@AlaSecured(value = "ROLE_ADMIN", redirectUri = "/")
class JobController {
def jobService

def index() {
def jobs = jobService.list().collect { it.status() }
withFormat {
html jobs: jobs
json { render jobs as JSON }
xml { render jobs as XML }
'*' jobs: jobs
}
}

def status() {
def id = params.id
def status = jobService.get(id)?.status() ?: notFoundStatus(id)
withFormat {
html job: status
json { render status as JSON }
xml { render status as XML }
'*' job: status
}
}

def panel() {
def id = params.id
def status = jobService.get(id)?.status() ?: notFoundStatus(id)
[job: status]
}

def cancel() {
def id = params.id
jobService.cancel(params.id)
def status = jobService.get(id)?.status() ?: notFoundStatus(id)
withFormat {
html { render view: 'status', model: [job: status] }
json { render status as JSON }
xml { render status as XML }
'*' { render view: 'status', model: [job: status] }
}
}

def remove() {
def id = params.id
def removed = jobService.remove(params.id)
def status = [success: removed]
withFormat {
html { redirect(action: 'index') }
json { render status as JSON }
xml { render status as XML }
'*' { redirect(action: 'index') }
}
}

private def notFoundStatus(id) {
return [success: false, active: false, id: id, lifecycle: 'ERROR', lastUpdated: new Date(), message: 'Not found']
}
}
Loading

0 comments on commit de29770

Please sign in to comment.