#1980 - RepositoryEntityLinks now overrides ….linkForItemResource(…).
This commit is contained in:
@@ -18,7 +18,6 @@ package org.springframework.data.rest.webmvc.support;
|
|||||||
import static org.assertj.core.api.Assertions.*;
|
import static org.assertj.core.api.Assertions.*;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.domain.PageRequest;
|
import org.springframework.data.domain.PageRequest;
|
||||||
import org.springframework.data.domain.Sort;
|
import org.springframework.data.domain.Sort;
|
||||||
@@ -157,4 +156,12 @@ public class RepositoryEntityLinksIntegrationTests extends AbstractControllerInt
|
|||||||
assertThat(link.getVariableNames()).contains("projection");
|
assertThat(link.getVariableNames()).contains("projection");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test // #1980
|
||||||
|
public void considersIdConverterInLinkForItemResource() {
|
||||||
|
|
||||||
|
Link link = entityLinks.linkForItemResource(Book.class, 7L).withSelfRel();
|
||||||
|
|
||||||
|
assertThat(link.getHref()).endsWith("/books/7-7-7-7-7-7-7");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -156,13 +156,26 @@ public class RepositoryEntityLinks extends AbstractEntityLinks {
|
|||||||
Assert.isInstanceOf(Serializable.class, id, "Id must be assignable to Serializable!");
|
Assert.isInstanceOf(Serializable.class, id, "Id must be assignable to Serializable!");
|
||||||
|
|
||||||
ResourceMetadata metadata = mappings.getMetadataFor(type);
|
ResourceMetadata metadata = mappings.getMetadataFor(type);
|
||||||
|
Link link = linkForItemResource(type, id).withRel(metadata.getItemResourceRel());
|
||||||
|
|
||||||
|
return Link.of(UriTemplate.of(link.getHref()).with(getProjectionVariable(type)).toString(),
|
||||||
|
metadata.getItemResourceRel());
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.hateoas.server.core.AbstractEntityLinks#linkForItemResource(java.lang.Class, java.lang.Object)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public LinkBuilder linkForItemResource(Class<?> type, Object id) {
|
||||||
|
|
||||||
|
Assert.isInstanceOf(Serializable.class, id, "Id must be assignable to Serializable!");
|
||||||
|
|
||||||
String mappedId = idConverters.getPluginFor(type)//
|
String mappedId = idConverters.getPluginFor(type)//
|
||||||
.orElse(DefaultIdConverter.INSTANCE)//
|
.orElse(DefaultIdConverter.INSTANCE)//
|
||||||
.toRequestId((Serializable) id, type);
|
.toRequestId((Serializable) id, type);
|
||||||
|
|
||||||
Link link = linkFor(type).slash(mappedId).withRel(metadata.getItemResourceRel());
|
return linkFor(type).slash(mappedId);
|
||||||
return Link.of(UriTemplate.of(link.getHref()).with(getProjectionVariable(type)).toString(),
|
|
||||||
metadata.getItemResourceRel());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user