Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP AVRO versions of CSV exports #156

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 115 additions & 2 deletions grails-app/controllers/au/org/ala/images/WebServiceController.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -1747,6 +1747,26 @@ class WebServiceController {
bos.close()
}

@ApiOperation(
value = "Export Avro of entire image catalogue",
nickname = "exportAvro",
produces = "application/octet-stream",
consumes = "application/json",
httpMethod = "GET",
tags = ["Export"]
)
@ApiResponses([
@ApiResponse(code = 200, message = "OK"),
@ApiResponse(code = 405, message = "Method Not Allowed. Only GET is allowed")]
)
def exportAvro(){
response.setHeader("Content-disposition", "attachment;filename=images-export.avro")
response.contentType = "application/octet-stream"
def os = response.outputStream
imageService.exportAvro(os)
os.flush()
}

@ApiOperation(
value = "Export CSV of URL to imageIdentifier mappings",
nickname = "exportMapping",
Expand All @@ -1769,6 +1789,26 @@ class WebServiceController {
bos.close()
}

@ApiOperation(
value = "Export Avro of URL to imageIdentifier mappings",
nickname = "exportMappingAvro",
produces = "application/octet-stream",
consumes = "application/json",
httpMethod = "GET",
tags = ["Export"]
)
@ApiResponses([
@ApiResponse(code = 200, message = "OK"),
@ApiResponse(code = 405, message = "Method Not Allowed. Only GET is allowed")]
)
def exportMappingAvro(){
response.setHeader("Content-disposition", "attachment;filename=image-mapping.avro")
response.contentType = "application/octet-stream"
def os = response.outputStream
imageService.exportMappingAvro(os)
os.flush()
}

@ApiOperation(
value = "Export CSV of URL to imageIdentifier mappings",
nickname = "exportDatasetMapping/{dataResourceUid}",
Expand All @@ -1788,7 +1828,7 @@ class WebServiceController {
])
def exportDatasetMapping(){
if (!params.id){
renderResults([success: false, message: "Failed to store image!"], 400)
renderResults([success: false, message: "id param is missing"], 400)
} else {
response.setHeader("Content-disposition", "attachment;filename=image-mapping-${params.id}.csv.gz")
response.contentType = "application/gzip"
Expand All @@ -1799,6 +1839,34 @@ class WebServiceController {
}
}

@ApiOperation(
value = "Export Avro of URL to imageIdentifier mappings",
nickname = "exportDatasetMappingAvro/{dataResourceUid}",
produces = "application/octet-stream",
consumes = "application/json",
httpMethod = "GET",
tags = ["Export"]
)
@ApiResponses([
@ApiResponse(code = 200, message = "OK"),
@ApiResponse(code = 400, message = "Missing dataResourceUid parameter"),
@ApiResponse(code = 405, message = "Method Not Allowed. Only GET is allowed")]
)
@ApiImplicitParams([
@ApiImplicitParam(name = "dataResourceUid", paramType = "path", required = true, value = "Data resource UID", dataType = "string")
])
def exportDatasetMappingAvro(){
if (!params.id){
renderResults([success: false, message: "id param is missing"], 400)
} else {
response.setHeader("Content-disposition", "attachment;filename=image-mapping-${params.id}.avro")
response.contentType = "application/octet-stream"
def os = response.outputStream
imageService.exportDatasetMappingAvro(params.id, os)
os.flush()
}
}

@ApiOperation(
value = "Export CSV of URL to imageIdentifier mappings",
notes = """Exports the following fields in CSV:
Expand Down Expand Up @@ -1835,7 +1903,7 @@ class WebServiceController {
])
def exportDataset(){
if (!params.id){
renderResults([success: false, message: "Failed to store image!"], 400)
renderResults([success: false, message: "id param is missing"], 400)
} else {
response.setHeader("Content-disposition", "attachment;filename=image-export-${params.id}.csv.gz")
response.contentType = "application/gzip"
Expand All @@ -1845,4 +1913,49 @@ class WebServiceController {
bos.close()
}
}

@ApiOperation(
value = "Export Avro of URL to imageIdentifier mappings",
notes = """Exports the following fields in Avro:
image_identifier as "imageID"
identifier
audience
contributor
created
creator
description
format
license
publisher
references
rightsHolder
source
title
type
""",
nickname = "exportDatasetAvro/{dataResourceUid}",
produces = "application/octet-stream",
consumes = "application/json",
httpMethod = "GET",
tags = ["Export"]
)
@ApiResponses([
@ApiResponse(code = 200, message = "OK"),
@ApiResponse(code = 400, message = "Missing dataResourceUid parameter"),
@ApiResponse(code = 405, message = "Method Not Allowed. Only GET is allowed")]
)
@ApiImplicitParams([
@ApiImplicitParam(name = "dataResourceUid", paramType = "path", required = true, value = "Data resource UID", dataType = "string")
])
def exportDatasetAvro(){
if (!params.id){
renderResults([success: false, message: "id param is missing"], 400)
} else {
response.setHeader("Content-disposition", "attachment;filename=image-export-${params.id}.avro")
response.contentType = "application/octet-stream"
def os = response.outputStream
imageService.exportDatasetAvro(params.id, os)
os.flush()
}
}
}
Loading