Skip to content

Commit

Permalink
#1570 add doPost case
Browse files Browse the repository at this point in the history
  • Loading branch information
schoicsiro committed Nov 21, 2023
1 parent 471cfa7 commit 6f7ba11
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -248,14 +248,14 @@ class MetadataService {
def facetConfig = webService.getJson(grailsApplication.config.ecodata.service.url + "/metadata/getGeographicFacetConfig")
facetConfig.grouped.each { k, v ->
v.each { name, fid ->
def objects = webService.getJson(grailsApplication.config.spatial.baseURL + '/ws/objects/'+fid, null, true, false, true)
def objects = webService.getJson(grailsApplication.config.spatial.baseURL + '/ws/objects/'+fid, null, false, false, true)
results[k] << [(objects[0].fieldname):objects[0]] // Using the fieldname instead of the name for grouped facets is a temp workaround for the GER.
}

}

facetConfig.contextual.each { name, fid ->
def objects = webService.getJson(grailsApplication.config.spatial.baseURL + '/ws/objects/'+fid, null, true, false, true)
def objects = webService.getJson(grailsApplication.config.spatial.baseURL + '/ws/objects/'+fid, null, false, false, true)
objects.each {
results[name] << [(it.name):it]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,11 @@ class SiteService {
def baseUrl = "${grailsApplication.config.spatial.layersUrl}/shape/upload/shp"
def userId = userService.getUser().userId

def site = [name:name, description: description, user_id:userId, api_key:grailsApplication.config.api_key]
def site = [name:name, description: description, user_id:userId]

def url = "${baseUrl}/${shapeFileId}/${siteId}"

def result = webService.doPost(url, site)
def result = webService.doPost(url, site, true)

String error
if (!result?.resp?.id) {
Expand Down
21 changes: 14 additions & 7 deletions grails-app/services/au/org/ala/biocollect/merit/WebService.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,13 @@ class WebService {
try {
conn = configureConnection(url, includeUserId, timeout)
if (includeApiKey) {
if (useToken) {
conn.setRequestProperty("Authorization", getAuthHeader())
} else {
conn.setRequestProperty("Authorization", grailsApplication.config.getProperty("api_key"))
}
conn.setRequestProperty("Authorization", grailsApplication.config.getProperty("api_key"))
}

if (useToken) {
conn.setRequestProperty("Authorization", getAuthHeader())
}

conn.setRequestProperty(ACCEPT, MediaType.APPLICATION_JSON_VALUE)
def json = responseText(conn)
def result = JSON.parse(json)
Expand Down Expand Up @@ -285,14 +286,20 @@ class WebService {
}
}

def doPost(String url, Map postBody) {
def doPost(String url, Map postBody, boolean useToken = false) {
def conn = null
def charEncoding = 'utf-8'
try {
conn = new URL(url).openConnection()
conn.setDoOutput(true)
conn.setRequestProperty("Content-Type", "application/json;charset=${charEncoding}")
conn.setRequestProperty("Authorization", grailsApplication.config.getProperty("api_key"))

if (useToken) {
conn.setRequestProperty("Authorization", getAuthHeader())
} else {
conn.setRequestProperty("Authorization", grailsApplication.config.getProperty("api_key"))
}

addHubUrlPath(conn)

def user = getUserService().getUser()
Expand Down

0 comments on commit 6f7ba11

Please sign in to comment.