Skip to content

Commit

Permalink
#600 support biocache as a user properties store
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Collins committed May 8, 2024
1 parent 6f6707b commit 1dc4025
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 10 deletions.
4 changes: 4 additions & 0 deletions grails-app/conf/plugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ alwaysshow.imagetab = false

facets.defaultSelected = "data_resource_uid,taxon_name,year,multimedia"

// User properties are stored by "userdetails" or "biocache".
// This is required when using AWS Cognito with userdetails (more or less).
userproperties.provider="userdetails"

mapdownloads {
baseLayers {
default_layer {
Expand Down
39 changes: 29 additions & 10 deletions grails-app/services/au/org/ala/biocache/hubs/UserDataService.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,33 @@
package au.org.ala.biocache.hubs

import grails.converters.JSON
import org.apache.http.entity.ContentType

class UserDataService {
def grailsApplication
def webService

final static String USERDETAILS = 'userdetails'
final static String BIOCACHE = 'biocache'

def get(userId, type) {

def data = [:]

if (userId && grailsApplication.config.userdetails.baseUrl) {
if (userId) {
try {
def resp = webService.get(grailsApplication.config.getProperty('userdetails.baseUrl') + '/property/getProperty' +
"?alaId=${userId}&name=${URLEncoder.encode(grailsApplication.config.getProperty('info.app.name') +'.'+ type, "UTF-8")}")
String url;
if (USERDETAILS.equals(grailsApplication.config.getProperty("userproperties.provider")) && grailsApplication.config.userdetails.baseUrl) {
url = grailsApplication.config.getProperty('userdetails.baseUrl') + '/property/getProperty';
} else if (BIOCACHE.equals(grailsApplication.config.getProperty("userproperties.provider")) && grailsApplication.config.biocache.baseUrl) {
url = grailsApplication.config.getProperty('biocache.baseUrl') + '/user/property'
}
if (url) {
def resp = webService.get( url + "?alaId=${userId}&name=${URLEncoder.encode(grailsApplication.config.getProperty('info.app.name') + '.' + type, "UTF-8")}")

if (resp?.resp && resp?.resp[0]?.value && resp?.resp[0]?.value) {
data = JSON.parse(resp?.resp[0]?.value)
if (resp?.resp && resp?.resp[0]?.value && resp?.resp[0]?.value) {
data = JSON.parse(resp?.resp[0]?.value)
}
}
} catch (err) {
//fail with only a log entry
Expand All @@ -44,11 +55,19 @@ class UserDataService {

// return value indicates if set succeeds
boolean set(userId, type, data) {
if (userId && grailsApplication.config.getProperty('userdetails.baseUrl')) {
def response = webService.post(grailsApplication.config.getProperty('userdetails.baseUrl') + '/property/saveProperty', null,
[alaId: userId, name: grailsApplication.config.getProperty('info.app.name') +'.'+ type, value: (data as JSON).toString()])

return response?.statusCode == 200
if (userId) {
String url;
if (USERDETAILS.equals(grailsApplication.config.getProperty("userproperties.provider")) && grailsApplication.config.userdetails.baseUrl) {
url = grailsApplication.config.getProperty('userdetails.baseUrl') + '/property/saveProperty';
} else if (BIOCACHE.equals(grailsApplication.config.getProperty("userproperties.provider")) && grailsApplication.config.biocache.baseUrl) {
url = grailsApplication.config.getProperty('biocache.baseUrl') + '/user/property'
}
if (url) {
def response = webService.post(url, null,
[alaId: userId, name: grailsApplication.config.getProperty('info.app.name') + '.' + type, value: (data as JSON).toString()],
ContentType.APPLICATION_JSON, true, false)
return response?.statusCode == 200
}
}
return false
}
Expand Down

0 comments on commit 1dc4025

Please sign in to comment.