Skip to content

Commit e7ff2d7

Browse files
author
Adam Collins
committed
Fix custom_facets
1 parent 028f683 commit e7ff2d7

File tree

3 files changed

+85
-5
lines changed

3 files changed

+85
-5
lines changed

Diff for: grails-app/controllers/au/org/ala/spatial/portal/PortalController.groovy

+77-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ class PortalController {
111111
userDetails: authService.userDetails(),
112112
sessionId : sessionService.newId(userId),
113113
messagesAge: messageService.messagesAge,
114-
hub : hub])
114+
hub : hub,
115+
custom_facets: toMapOfLists(config.biocacheService.custom_facets)])
115116
} else if (!authDisabled && userId == null) {
116117
login()
117118
} else {
@@ -378,6 +379,7 @@ class PortalController {
378379
def header = [:]
379380
if (Holders.config.security.oidc.enabled) {
380381
header.put("userId", userId)
382+
header.put("X-ALA-userId", userId)
381383
header.put("apiKey", grailsApplication.config.api_key)
382384
//header.put('Cookie', 'ALA-Auth=' + URLEncoder.encode(authService.email, 'UTF-8'))
383385
}
@@ -631,4 +633,78 @@ class PortalController {
631633
def embedExample() {
632634
render(view: 'embedExample')
633635
}
636+
637+
private def toList(Object o) {
638+
if (o == null || org.apache.commons.lang3.StringUtils.isEmpty(o.toString())) {
639+
return []
640+
} else if (o instanceof List) {
641+
return o
642+
} else if (o.toString().startsWith("[")) {
643+
// JSON list
644+
return JSON.parse(o.toString())
645+
} else {
646+
// comma delimited
647+
return Arrays.asList(o.toString().split(","))
648+
}
649+
}
650+
651+
private def toListOfMaps(Object o) {
652+
if (o == null || o.toString().isEmpty()) {
653+
return new ArrayList()
654+
}
655+
656+
def listOfMaps = toList(o)
657+
658+
for (def i = 0; i < listOfMaps.size(); i++) {
659+
listOfMaps.set(i, toMap(listOfMaps.get(i)))
660+
}
661+
662+
return listOfMaps
663+
}
664+
665+
private def toMap(Object o) {
666+
if (o == null || o.toString().isEmpty()) {
667+
return new HashMap()
668+
}
669+
670+
def map = o
671+
672+
if (!(map instanceof Map)) {
673+
map = JSON.parse(map.toString())
674+
}
675+
676+
return map
677+
}
678+
679+
private def toMapOfMaps(Object o) {
680+
if (o == null || o.toString().isEmpty()) {
681+
return new HashMap()
682+
}
683+
684+
def mapOfMaps = toMap(o)
685+
686+
for (def key : mapOfMaps.keySet) {
687+
mapOfMaps[key] = toMap(mapOfMaps[key])
688+
}
689+
690+
return mapOfMaps
691+
}
692+
693+
private def toMapOfLists(Object o) {
694+
if (o == null || o.toString().isEmpty()) {
695+
return new HashMap()
696+
}
697+
698+
def mapOfLists = toMap(o)
699+
700+
def result = [:]
701+
mapOfLists.each { k, v ->
702+
if (!k.contains('[')) { // exclude odd artifacts
703+
result[k] = toList(v)
704+
}
705+
}
706+
707+
708+
return result
709+
}
634710
}

Diff for: grails-app/init/au/org/ala/spatial/portal/BootStrap.groovy

+7-3
Original file line numberDiff line numberDiff line change
@@ -243,10 +243,14 @@ class BootStrap {
243243

244244
def mapOfLists = toMap(o)
245245

246-
for (def key : mapOfLists.keySet) {
247-
mapOfLists[key] = toList(mapOfLists[key])
246+
def result = [:]
247+
mapOfLists.each { k, v ->
248+
if (!k.contains('[')) { // exclude odd artifacts
249+
result[k] = toList(v)
250+
}
248251
}
249252

250-
return mapOfLists
253+
254+
return result
251255
}
252256
}

Diff for: grails-app/views/portal/index.gsp

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
biocacheUrl: '${config.biocache.url}',
3535
biocacheServiceUrl: '${config.biocacheService.url}',
3636
default_facets_ignored: '${config.biocacheService.default_facets_ignored}',
37-
custom_facets: ${(config.biocacheService.custom_facets as grails.converters.JSON).toString().encodeAsRaw()},
37+
custom_facets: ${(custom_facets as grails.converters.JSON).toString().encodeAsRaw()},
3838
bieUrl: '${config.bie.baseURL}',
3939
bieServiceUrl: '${config.bieService.baseURL}',
4040
layersServiceUrl: '${config.layersService.url}',

0 commit comments

Comments
 (0)