DATAREST-45 Using the wrong base URI to build links to the "self" and properties of entities. Needed to add two lines of code to generate a proper self link and use that as the base URI for generating property links.

This commit is contained in:
Jon Brisbin
2012-08-31 09:39:41 -05:00
committed by Jon Brisbin
parent e4d43278f7
commit 18616d9c89
2 changed files with 8 additions and 3 deletions

View File

@@ -2,6 +2,7 @@ package org.springframework.data.rest.webmvc;
import static org.springframework.data.rest.core.util.UriUtils.*;
import java.io.Serializable;
import java.net.URI;
import java.util.HashMap;
import java.util.HashSet;
@@ -39,13 +40,16 @@ public class EntityToResourceConverter implements Converter<Object, Resource> {
}
URI baseUri = RepositoryRestController.BASE_URI.get();
Serializable id = (Serializable)repositoryMetadata.entityMetadata().idAttribute().get(source);
URI selfUri = buildUri(baseUri, repositoryMetadata.name(), id.toString());
Set<Link> links = new HashSet<Link>();
for(Object attrName : entityMetadata.linkedAttributes().keySet()) {
URI uri = buildUri(baseUri, attrName.toString());
URI uri = buildUri(selfUri, attrName.toString());
String rel = repositoryMetadata.rel() + "." + source.getClass().getSimpleName() + "." + attrName;
links.add(new Link(uri.toString(), rel));
}
links.add(new Link(baseUri.toString(), "self"));
links.add(new Link(selfUri.toString(), "self"));
Map<String, Object> entityDto = new HashMap<String, Object>();
for(Map.Entry<String, AttributeMetadata> attrMeta : ((Map<String, AttributeMetadata>)entityMetadata.embeddedAttributes())

View File

@@ -469,7 +469,8 @@ public class RepositoryRestController
Object o = allEntities.next();
if(shouldReturnLinks(request.getServletRequest().getHeader("Accept"))) {
Serializable id = (Serializable)repoMeta.entityMetadata().idAttribute().get(o);
links.add(new Link(buildUri(baseUri, repository, id.toString()).toString(),
URI selfUri = buildUri(baseUri, repository, id.toString());
links.add(new Link(selfUri.toString(),
repoMeta.rel() + "." + o.getClass().getSimpleName()));
} else {
allResources.add(o);