DATAREST-516 - Fixed link to ALPS representation descriptors of associations.

Previously the link pointing to representation descriptors of associations neither pointed to the ALPS controller nor to the representation descriptor.
This commit is contained in:
Oliver Gierke
2015-04-13 12:18:24 +02:00
parent 7c3b93fffd
commit 47d369608b
2 changed files with 28 additions and 4 deletions

View File

@@ -148,7 +148,7 @@ public class RootResourceInformationToAlpsDescriptorConverter {
ResourceMetadata metadata = mappings.getMetadataFor(type);
return descriptor().//
id(metadata.getItemResourceRel().concat("-representation")).//
id(getRepresentationDescriptorId(metadata)).//
href(entityLinks.linkFor(type).slash("schema").toString()).//
doc(getDocFor(metadata.getItemResourceDescription())).//
descriptors(buildPropertyDescriptors(type, metadata.getItemResourceRel())).//
@@ -347,9 +347,11 @@ public class RootResourceInformationToAlpsDescriptorConverter {
DescriptorBuilder builder = descriptor().//
name(mapping.getRel()).doc(getDocFor(mapping.getDescription()));
ResourceMetadata targetTypeMapping = mappings.getMetadataFor(property.getActualType());
String localPath = targetTypeMapping.getRel().concat("#").concat(targetTypeMapping.getItemResourceRel());
Link link = ControllerLinkBuilder.linkTo(AlpsController.class).slash(localPath).withSelfRel();
ResourceMetadata targetTypeMetadata = mappings.getMetadataFor(property.getActualType());
String localPath = targetTypeMetadata.getRel().concat("#")
.concat(getRepresentationDescriptorId(targetTypeMetadata));
Link link = ControllerLinkBuilder.linkTo(AlpsController.class).slash(AlpsController.ALPS_ROOT_MAPPING)
.slash(localPath).withSelfRel();
builder.//
type(Type.SAFE).//
@@ -414,6 +416,10 @@ public class RootResourceInformationToAlpsDescriptorConverter {
}
}
private static String getRepresentationDescriptorId(ResourceMetadata metadata) {
return metadata.getItemResourceRel().concat("-representation");
}
private static String prefix(HttpMethod method) {
switch (method) {

View File

@@ -141,6 +141,24 @@ public class AlpsControllerIntegrationTests extends AbstractControllerIntegratio
andExpect(jsonPath("$.descriptors[?(@.id == 'item-representation')].href", is(notNullValue())));
}
/**
* @see DATAREST-516
*/
@Test
public void referenceToAssociatedEntityDesciptorPointsToRepresentationDescriptor() throws Exception {
Link profileLink = discoverUnique("/", "profile");
Link usersLink = discoverUnique(profileLink.getHref(), "people");
String jsonPath = "$."; // Root
jsonPath += "descriptors[?(@.id == 'person-representation')]."; // Representation descriptor
jsonPath += "descriptors[?(@.name == 'father')][0]."; // First father descriptor
jsonPath += "rt"; // Return type
mvc.perform(get(usersLink.getHref())).andExpect(
jsonPath(jsonPath, allOf(containsString("alps"), endsWith("-representation"))));
}
private Link discoverUnique(String href, String rel) throws Exception {
MockHttpServletResponse response = mvc.perform(get(href)).//