Skip to content

Commit 2dc3aca

Browse files
committed
Merge remote-tracking branch 'origin/dev' into feature/biocollect-1586
2 parents 300f36a + 912a780 commit 2dc3aca

File tree

4 files changed

+31
-33
lines changed

4 files changed

+31
-33
lines changed

grails-app/services/au/org/ala/ecodata/forms/EcpWebService.groovy

+27-12
Original file line numberDiff line numberDiff line change
@@ -615,19 +615,22 @@ class EcpWebService {
615615

616616
// Execute request
617617
try (Response response = client.newCall(requestBuilder.build()).execute()) {
618-
okhttp3.MediaType respContentType = response.body().contentType()
619-
String subType = respContentType.subtype()?.toLowerCase()
618+
619+
ResponseBody responseBody = response.body()
620+
okhttp3.MediaType respContentType = responseBody.contentType()
621+
String mediaType = respContentType.toString()?.toLowerCase()
620622
def responseData
621-
String responseBody = response.body().string()
622-
switch (subType) {
623-
case "json":
623+
if (isTextBased(mediaType)) {
624+
responseData = responseBody.string()
625+
if (mediaType.contains('json')) {
624626
ObjectMapper objectMapper = new ObjectMapper()
625-
responseData = objectMapper.readValue(responseBody, Object)
626-
break
627-
case "text":
628-
default:
629-
responseData = responseBody
630-
break
627+
responseData = objectMapper.readValue(responseData, Object)
628+
}
629+
} else {
630+
// This is only used for the /document/createThumbnail endpoint. Because the thumbnail is small we
631+
// can get away with reading the entire response into memory. If dealing with large files
632+
// we might have to remove the try with resources and handle the stream manually.
633+
responseData = responseBody.bytes()
631634
}
632635

633636
result.statusCode = result.status = response.code()
@@ -641,6 +644,18 @@ class EcpWebService {
641644
return result
642645
}
643646

647+
private static boolean isTextBased(String contentType) {
648+
if (!contentType) {
649+
log.error("Missing content type")
650+
return false
651+
}
652+
String contentTypeLower = contentType.toLowerCase()
653+
return contentTypeLower.contains('json') ||
654+
contentTypeLower.contains('text') ||
655+
contentTypeLower.contains('xml') ||
656+
contentTypeLower.contains('graphql')
657+
}
658+
644659
/**
645660
* Forwards a HTTP multipart/form-data request to ecodata.
646661
* @param url the URL to forward to.
@@ -660,7 +675,7 @@ class EcpWebService {
660675
}
661676

662677
Map postMultipart(String url, Map params, File file, String contentType, String originalFilename, String fileParamName = 'files', boolean useToken = false, boolean userToken = false) {
663-
RequestBody fileBody = RequestBody.create(okhttp3.MediaType.parse(contentType), file)
678+
RequestBody fileBody = RequestBody.create(file, okhttp3.MediaType.parse(contentType))
664679
postMultipart(url, params, fileBody, contentType, originalFilename, fileParamName, useToken, userToken)
665680
}
666681

grails-app/services/au/org/ala/ecodata/forms/SpeciesListService.groovy

+2-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class SpeciesListService {
2828
static final String UPLOAD_V2 = "/upload"
2929
public static final String INGEST_V2 = "/ingest"
3030
public static final String PROGRESS_V2 = "/progress"
31+
public static final String ENCODING = 'UTF-8'
3132

3233
GrailsApplication grailsApplication
3334
EcpWebService ecpWebService
@@ -245,7 +246,7 @@ class SpeciesListService {
245246
if (!listId) {
246247
return null
247248
}
248-
String url = grailsApplication.config.getProperty('lists.baseURL') + SPECIES_LIST_ITEMS_PATH_V2 + '/' + listId
249+
String url = grailsApplication.config.getProperty('lists.baseURL') + SPECIES_LIST_ITEMS_PATH_V2 + '/' + URLEncoder.encode(listId, ENCODING)
249250
Map params = [pageSize: pageSize, page: page]
250251
if (query) {
251252
params.q = query

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main/groovy/au/org/ala/ecodata/forms/IntegrationTestConfiguration.java

-18
This file was deleted.

0 commit comments

Comments
 (0)