@@ -9,7 +9,6 @@ import org.apache.commons.lang.StringUtils
9
9
import org.apache.http.client.methods.HttpGet
10
10
import org.apache.http.client.methods.HttpPost
11
11
import org.apache.http.entity.ContentType
12
- import org.jasig.cas.client.util.CommonUtils
13
12
import org.springframework.web.multipart.MultipartFile
14
13
import org.springframework.web.multipart.MultipartHttpServletRequest
15
14
@@ -378,19 +377,36 @@ class PortalController {
378
377
379
378
def r
380
379
if (grailsApplication. config. lists. useListWs) {
381
- // format input
382
- /*
383
- {
384
- "listName": name,
385
- "listItems": items,
386
- "description": description,
387
- "isPrivate": makePrivate,
388
- "listType": listType
389
- }
390
- */
391
- r = webService. post(" ${ url} /upload" , json, null , ContentType . APPLICATION_JSON , false , true )
380
+ // create tmp file
381
+ File tmpFile = File . createTempFile(" spatial-species-list-" ," .csv" )
382
+ BufferedWriter fw = new BufferedWriter (new FileWriter (tmpFile))
383
+ fw. writeLine(" taxonID" )
384
+ for (String item : json. listItems. split(" ," )) {
385
+ fw. writeLine(item)
386
+ }
387
+ fw. flush()
388
+ fw. close()
389
+
390
+ r = webService. postMultipart(" ${ url} /upload" , null , null , [file : tmpFile], ContentType . APPLICATION_JSON , false , true )
391
+
392
+ tmpFile. delete()
392
393
393
- r = webService. post(" ${ url} /ingest/${ speciesListID} " , json, null , ContentType . APPLICATION_JSON , false , true )
394
+ if (r. statusCode == 200 ) {
395
+ def metadata = [
396
+ file : r. resp. localFile,
397
+ title : json. listName,
398
+ description : json. description ?: json. listName,
399
+ listType : json. listType,
400
+ region : " AUS" , // TODO: replicate species-lists behaviour, depends on species-lists issue #83
401
+ licence : " CC-BY" , // TODO: replicate species-lists behaviour, depends on species-lists issue #83
402
+ isPrivate : json. isPrivate
403
+ ]
404
+
405
+ r = webService. post(" ${ url} /ingest" , metadata, [file : r. resp. localFile], ContentType . APPLICATION_JSON , false , true )
406
+
407
+ // backward compatible id field
408
+ r. resp. druid = r. resp. id
409
+ }
394
410
} else {
395
411
r = webService. post(" ${ url} /ws/speciesList/" , json)
396
412
}
0 commit comments