DATAREST-37: Display entities inline when accessing relationship links.

This commit is contained in:
Jon Brisbin
2012-08-13 09:31:55 -05:00
committed by Jon Brisbin
parent 17c97eb423
commit 3393780e65
21 changed files with 420 additions and 250 deletions

View File

@@ -1,12 +1,12 @@
package org.springframework.data.rest.repository;
import org.codehaus.jackson.annotate.JsonProperty;
import org.springframework.data.rest.core.Resources;
import org.springframework.data.rest.core.ResourceSet;
/**
* @author Jon Brisbin
*/
public class PageableResources extends Resources {
public class PageableResourceSet extends ResourceSet {
protected long resourceCount = 0;
@JsonProperty("page")
@@ -16,7 +16,7 @@ public class PageableResources extends Resources {
return resourceCount;
}
public PageableResources setResourceCount(long resourceCount) {
public PageableResourceSet setResourceCount(long resourceCount) {
this.resourceCount = resourceCount;
return this;
}
@@ -25,7 +25,7 @@ public class PageableResources extends Resources {
return paging;
}
public PageableResources setPaging(PagingMetadata paging) {
public PageableResourceSet setPaging(PagingMetadata paging) {
this.paging = paging;
return this;
}

View File

@@ -8,7 +8,7 @@ import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.ApplicationListener;
import org.springframework.data.rest.core.Resource;
import org.springframework.data.rest.core.Resources;
import org.springframework.data.rest.core.ResourceSet;
import org.springframework.data.rest.repository.RepositoryExporter;
import org.springframework.data.rest.repository.RepositoryExporterSupport;
import org.springframework.data.rest.repository.RepositoryMetadata;
@@ -143,7 +143,7 @@ public abstract class AbstractRepositoryEventListener<T extends AbstractReposito
*/
protected void onBeforeRenderResources(ServerHttpRequest request,
RepositoryMetadata repositoryMetadata,
Resources resources) {
ResourceSet resources) {
}
/**

View File

@@ -1,7 +1,7 @@
package org.springframework.data.rest.repository.context;
import org.springframework.data.rest.core.Resource;
import org.springframework.data.rest.core.Resources;
import org.springframework.data.rest.core.ResourceSet;
import org.springframework.data.rest.repository.RepositoryMetadata;
import org.springframework.http.server.ServerHttpRequest;
import org.springframework.util.Assert;
@@ -17,10 +17,11 @@ public abstract class RenderEvent extends RepositoryEvent {
public RenderEvent(ServerHttpRequest request, RepositoryMetadata repoMeta, Object source) {
super(source);
Assert.isTrue(source instanceof Resource || source instanceof Resources);
Assert.isTrue(source instanceof Resource || source instanceof ResourceSet,
"Event source must be of type 'Resource' or 'ResourceSet'");
this.request = request;
this.repositoryMetadata = repoMeta;
this.topLevelResource = (source instanceof Resources);
this.topLevelResource = (source instanceof ResourceSet);
}
public ServerHttpRequest getRequest() {
@@ -39,9 +40,9 @@ public abstract class RenderEvent extends RepositoryEvent {
}
}
public Resources getResources() {
if(getSource() instanceof Resources) {
return (Resources)getSource();
public ResourceSet getResources() {
if(getSource() instanceof ResourceSet) {
return (ResourceSet)getSource();
} else {
throw new IllegalStateException("Source of event is not a Resources, it's " + source);
}

View File

@@ -5,8 +5,8 @@ import org.springframework.context.ApplicationContext
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.data.rest.core.Resource
import org.springframework.data.rest.core.Resources
import org.springframework.data.rest.core.SimpleLink
import org.springframework.data.rest.core.ResourceSet
import org.springframework.data.rest.core.ResourceLink
import org.springframework.data.rest.repository.RepositoryExporter
import org.springframework.data.rest.repository.RepositoryMetadata
import org.springframework.data.rest.repository.annotation.HandleAfterDelete
@@ -76,8 +76,8 @@ class ExtensionsSpec extends Specification {
def request = Mock(ServerHttpRequest)
def p = new Person("John Doe")
def selfLink = new SimpleLink("self", new URI("http://localhost:8080/people/1"))
def resources = new Resources()
def selfLink = new ResourceLink("self", new URI("http://localhost:8080/people/1"))
def resources = new ResourceSet()
resources.links << selfLink
def resource = new Resource(p)
resource.links << selfLink
@@ -154,14 +154,14 @@ class PersonRenderHandler {
@HandleBeforeRenderResources void handleBeforeRenderResources(ServerHttpRequest request,
RepositoryMetadata repoMeta,
Resources resources) {
resources.links << new SimpleLink("linkAddedByHandler", new URI("http://localhost:8080/linkAddedByHandler"))
ResourceSet resources) {
resources.links << new ResourceLink("linkAddedByHandler", new URI("http://localhost:8080/linkAddedByHandler"))
}
@HandleBeforeRenderResource void handleBeforeRenderResource(ServerHttpRequest request,
RepositoryMetadata repoMeta,
Resource resource) {
resource.links << new SimpleLink("linkAddedByHandler", new URI("http://localhost:8080/linkAddedByHandler"))
resource.links << new ResourceLink("linkAddedByHandler", new URI("http://localhost:8080/linkAddedByHandler"))
}
}