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:
@@ -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) {
|
||||
|
||||
@@ -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)).//
|
||||
|
||||
Reference in New Issue
Block a user