Skip to content

Commit 4ea9c2f

Browse files
committed
- added method to handle temp file via multipart post - refactored methods calling postMultipartWithOkhttp3
1 parent 2530a77 commit 4ea9c2f

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

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

+6
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,12 @@ class EcpWebService {
651651
postMultipart(url, params, fileBody, contentType, originalFilename, fileParamName, useToken, userToken)
652652
}
653653

654+
Map postMultipart(String url, Map params, File file, String contentType, String originalFilename, String fileParamName = 'files', boolean useToken = false, boolean userToken = false) {
655+
RequestBody fileBody = RequestBody.create(okhttp3.MediaType.parse(contentType), file)
656+
postMultipart(url, params, fileBody, contentType, originalFilename, fileParamName, useToken, userToken)
657+
}
658+
659+
654660
private void addTokenHeader(conn, boolean requireUser = false) {
655661
if (useJWT()) {
656662
conn.setRequestProperty("Authorization", getToken(requireUser))

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ class SpeciesListService {
404404

405405
try {
406406
String url = grailsApplication.config.getProperty('lists.baseURL') + UPLOAD_V2
407-
Map resp = ecpWebService.postMultipartWithOkhttp3(url, [:], file, "text/csv", "specieslist.csv", "file", true, true)
407+
Map resp = ecpWebService.postMultipart(url, [:], file, "text/csv", "specieslist.csv", "file", true, true)
408408
if (HttpStatus.resolve(resp.statusCode as int).is2xxSuccessful()) {
409409
Map apiResp = resp.content
410410
String tempFileName = apiResp.localFile

src/test/groovy/au/org/ala/ecodata/forms/SpeciesListServiceSpec.groovy

+3-3
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ class SpeciesListServiceSpec extends Specification implements ServiceUnitTest<Sp
360360
]
361361

362362
and: "mock exception during upload"
363-
webService.postMultipartWithOkhttp3(*_) >> { throw new IOException("Network error") }
363+
webService.postMultipart(*_) >> { throw new IOException("Network error") }
364364

365365
when:
366366
def result = service.uploadSpeciesListUsingV2(rows, "Test List", "Test Description", "CC-BY", "TEST_LIST")
@@ -381,7 +381,7 @@ class SpeciesListServiceSpec extends Specification implements ServiceUnitTest<Sp
381381
def dataResourceId = "dr-12345"
382382

383383
and: "mock successful upload and ingest but failed completion"
384-
webService.postMultipartWithOkhttp3(*_) >> [
384+
webService.postMultipart(*_) >> [
385385
statusCode: 200,
386386
content: [localFile: tempFileName]
387387
]
@@ -415,7 +415,7 @@ class SpeciesListServiceSpec extends Specification implements ServiceUnitTest<Sp
415415
def dataResourceId = "dr-12345"
416416

417417
and: "mock upload responses"
418-
webService.postMultipartWithOkhttp3(
418+
webService.postMultipart(
419419
{it.endsWith(service.UPLOAD_V2)},
420420
[:],
421421
_,

0 commit comments

Comments
 (0)