Skip to content

Commit

Permalink
Fix problem with returning empty sets in hal+json.
Browse files Browse the repository at this point in the history
When fetching the list of studies with HTTP header
'Accept: application/hal+json', the application returned code 
406 'Not acceptable' if the set of studies was empty.
  • Loading branch information
gijskant committed Sep 10, 2015
1 parent f74161d commit 00df0c0
Showing 1 changed file with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,14 @@

package org.transmartproject.rest

import org.transmartproject.core.ontology.StudiesResource
import grails.rest.Link

import javax.annotation.Resource

import org.transmartproject.core.ontology.StudiesResource
import org.transmartproject.core.ontology.Study
import org.transmartproject.rest.marshallers.ContainerResponseWrapper

class StudyController {

static responseFormats = ['json', 'hal']
Expand All @@ -40,7 +44,7 @@ class StudyController {
* This will return the list of studies, where each study will be rendered in its short format
*/
def index() {
respond studiesResourceService.studySet
respond wrapStudies(studiesResourceService.studySet)
}

/** GET request on /studies/${id}
Expand All @@ -51,4 +55,18 @@ class StudyController {
def show(String id) {
respond studiesResourceService.getStudyById(id)
}

private def wrapStudies(Object source) {

new ContainerResponseWrapper(
container: source,
componentType: Study,
links: [
new Link(grails.rest.render.util.AbstractLinkingRenderer.RELATIONSHIP_SELF,
"/studies"
)
]
)
}

}

0 comments on commit 00df0c0

Please # to comment.