Skip to content

Commit 435aaaa

Browse files
committed
DATACMNS-1470 - Adapt to package refactorings in Spring HATEOAS.
1 parent 06cb767 commit 435aaaa

9 files changed

+88
-83
lines changed

src/main/java/org/springframework/data/domain/jaxb/SpringDataJaxb.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
import org.springframework.data.domain.Sort;
3636
import org.springframework.data.domain.Sort.Direction;
3737
import org.springframework.data.domain.Sort.Order;
38-
import org.springframework.hateoas.ResourceSupport;
38+
import org.springframework.hateoas.RepresentationModel;
3939
import org.springframework.lang.Nullable;
4040
import org.springframework.util.Assert;
4141

@@ -96,7 +96,7 @@ public static class OrderDto {
9696
*/
9797
@XmlRootElement(name = "page", namespace = NAMESPACE)
9898
@XmlAccessorType(XmlAccessType.FIELD)
99-
public static class PageDto extends ResourceSupport {
99+
public static class PageDto extends RepresentationModel {
100100

101101
@Nullable @XmlAnyElement @XmlElementWrapper(name = "content") List<Object> content;
102102
}

src/main/java/org/springframework/data/web/HateoasPageableHandlerMethodArgumentResolver.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import org.springframework.hateoas.TemplateVariable;
2727
import org.springframework.hateoas.TemplateVariable.VariableType;
2828
import org.springframework.hateoas.TemplateVariables;
29-
import org.springframework.hateoas.mvc.UriComponentsContributor;
29+
import org.springframework.hateoas.server.mvc.UriComponentsContributor;
3030
import org.springframework.lang.Nullable;
3131
import org.springframework.util.Assert;
3232
import org.springframework.util.MultiValueMap;
@@ -100,7 +100,7 @@ public TemplateVariables getPaginationTemplateVariables(MethodParameter paramete
100100

101101
/*
102102
* (non-Javadoc)
103-
* @see org.springframework.hateoas.mvc.UriComponentsContributor#enhance(org.springframework.web.util.UriComponentsBuilder, org.springframework.core.MethodParameter, java.lang.Object)
103+
* @see org.springframework.hateoas.server.mvc.UriComponentsContributor#enhance(org.springframework.web.util.UriComponentsBuilder, org.springframework.core.MethodParameter, java.lang.Object)
104104
*/
105105
@Override
106106
public void enhance(UriComponentsBuilder builder, @Nullable MethodParameter parameter, Object value) {

src/main/java/org/springframework/data/web/HateoasSortHandlerMethodArgumentResolver.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import org.springframework.hateoas.TemplateVariable;
2323
import org.springframework.hateoas.TemplateVariable.VariableType;
2424
import org.springframework.hateoas.TemplateVariables;
25-
import org.springframework.hateoas.mvc.UriComponentsContributor;
25+
import org.springframework.hateoas.server.mvc.UriComponentsContributor;
2626
import org.springframework.util.MultiValueMap;
2727
import org.springframework.web.util.UriComponents;
2828
import org.springframework.web.util.UriComponentsBuilder;
@@ -64,7 +64,7 @@ public TemplateVariables getSortTemplateVariables(MethodParameter parameter, Uri
6464

6565
/*
6666
* (non-Javadoc)
67-
* @see org.springframework.hateoas.mvc.UriComponentsContributor#enhance(org.springframework.web.util.UriComponentsBuilder, org.springframework.core.MethodParameter, java.lang.Object)
67+
* @see org.springframework.hateoas.server.mvc.UriComponentsContributor#enhance(org.springframework.web.util.UriComponentsBuilder, org.springframework.core.MethodParameter, java.lang.Object)
6868
*/
6969
@Override
7070
public void enhance(UriComponentsBuilder builder, MethodParameter parameter, Object value) {

src/main/java/org/springframework/data/web/PagedResourcesAssembler.java

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,17 @@
2626
import org.springframework.data.domain.Page;
2727
import org.springframework.data.domain.PageRequest;
2828
import org.springframework.data.domain.Pageable;
29+
import org.springframework.hateoas.EntityModel;
2930
import org.springframework.hateoas.IanaLinkRelations;
3031
import org.springframework.hateoas.Link;
3132
import org.springframework.hateoas.LinkRelation;
32-
import org.springframework.hateoas.PagedResources;
33-
import org.springframework.hateoas.PagedResources.PageMetadata;
34-
import org.springframework.hateoas.Resource;
35-
import org.springframework.hateoas.ResourceAssembler;
36-
import org.springframework.hateoas.ResourceSupport;
33+
import org.springframework.hateoas.PagedModel;
34+
import org.springframework.hateoas.PagedModel.PageMetadata;
35+
import org.springframework.hateoas.RepresentationModel;
3736
import org.springframework.hateoas.UriTemplate;
38-
import org.springframework.hateoas.core.EmbeddedWrapper;
39-
import org.springframework.hateoas.core.EmbeddedWrappers;
37+
import org.springframework.hateoas.server.RepresentationModelAssembler;
38+
import org.springframework.hateoas.server.core.EmbeddedWrapper;
39+
import org.springframework.hateoas.server.core.EmbeddedWrappers;
4040
import org.springframework.lang.Nullable;
4141
import org.springframework.util.Assert;
4242
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
@@ -51,7 +51,7 @@
5151
* @author Nick Williams
5252
* @author Marcel Overdijk
5353
*/
54-
public class PagedResourcesAssembler<T> implements ResourceAssembler<Page<T>, PagedResources<Resource<T>>> {
54+
public class PagedResourcesAssembler<T> implements RepresentationModelAssembler<Page<T>, PagedModel<EntityModel<T>>> {
5555

5656
private final HateoasPageableHandlerMethodArgumentResolver pageableResolver;
5757
private final Optional<UriComponents> baseUri;
@@ -62,7 +62,7 @@ public class PagedResourcesAssembler<T> implements ResourceAssembler<Page<T>, Pa
6262
/**
6363
* Creates a new {@link PagedResourcesAssembler} using the given {@link PageableHandlerMethodArgumentResolver} and
6464
* base URI. If the former is {@literal null}, a default one will be created. If the latter is {@literal null}, calls
65-
* to {@link #toResource(Page)} will use the current request's URI to build the relevant previous and next links.
65+
* to {@link #toModel(Page)} will use the current request's URI to build the relevant previous and next links.
6666
*
6767
* @param resolver can be {@literal null}.
6868
* @param baseUri can be {@literal null}.
@@ -89,12 +89,12 @@ public void setForceFirstAndLastRels(boolean forceFirstAndLastRels) {
8989

9090
/*
9191
* (non-Javadoc)
92-
* @see org.springframework.hateoas.ResourceAssembler#toResource(java.lang.Object)
92+
* @see org.springframework.hateoas.server.RepresentationModelAssembler#toModel(java.lang.Object)
9393
*/
9494
@Override
9595
@SuppressWarnings("null")
96-
public PagedResources<Resource<T>> toResource(Page<T> entity) {
97-
return toResource(entity, it -> new Resource<>(it));
96+
public PagedModel<EntityModel<T>> toModel(Page<T> entity) {
97+
return toModel(entity, it -> new EntityModel<>(it));
9898
}
9999

100100
/**
@@ -106,8 +106,8 @@ public PagedResources<Resource<T>> toResource(Page<T> entity) {
106106
* @param selfLink must not be {@literal null}.
107107
* @return
108108
*/
109-
public PagedResources<Resource<T>> toResource(Page<T> page, Link selfLink) {
110-
return toResource(page, it -> new Resource<>(it), selfLink);
109+
public PagedModel<EntityModel<T>> toModel(Page<T> page, Link selfLink) {
110+
return toModel(page, it -> new EntityModel<>(it), selfLink);
111111
}
112112

113113
/**
@@ -118,8 +118,9 @@ public PagedResources<Resource<T>> toResource(Page<T> page, Link selfLink) {
118118
* @param assembler must not be {@literal null}.
119119
* @return
120120
*/
121-
public <R extends ResourceSupport> PagedResources<R> toResource(Page<T> page, ResourceAssembler<T, R> assembler) {
122-
return createResource(page, assembler, Optional.empty());
121+
public <R extends RepresentationModel<?>> PagedModel<R> toModel(Page<T> page,
122+
RepresentationModelAssembler<T, R> assembler) {
123+
return createModel(page, assembler, Optional.empty());
123124
}
124125

125126
/**
@@ -132,12 +133,12 @@ public <R extends ResourceSupport> PagedResources<R> toResource(Page<T> page, Re
132133
* @param link must not be {@literal null}.
133134
* @return
134135
*/
135-
public <R extends ResourceSupport> PagedResources<R> toResource(Page<T> page, ResourceAssembler<T, R> assembler,
136-
Link link) {
136+
public <R extends RepresentationModel<?>> PagedModel<R> toModel(Page<T> page,
137+
RepresentationModelAssembler<T, R> assembler, Link link) {
137138

138139
Assert.notNull(link, "Link must not be null!");
139140

140-
return createResource(page, assembler, Optional.of(link));
141+
return createModel(page, assembler, Optional.of(link));
141142
}
142143

143144
/**
@@ -148,8 +149,8 @@ public <R extends ResourceSupport> PagedResources<R> toResource(Page<T> page, Re
148149
* @return
149150
* @since 2.0
150151
*/
151-
public PagedResources<?> toEmptyResource(Page<?> page, Class<?> type) {
152-
return toEmptyResource(page, type, Optional.empty());
152+
public PagedModel<?> toEmptyModel(Page<?> page, Class<?> type) {
153+
return toEmptyModel(page, type, Optional.empty());
153154
}
154155

155156
/**
@@ -161,11 +162,11 @@ public PagedResources<?> toEmptyResource(Page<?> page, Class<?> type) {
161162
* @return
162163
* @since 1.11
163164
*/
164-
public PagedResources<?> toEmptyResource(Page<?> page, Class<?> type, Link link) {
165-
return toEmptyResource(page, type, Optional.of(link));
165+
public PagedModel<?> toEmptyModel(Page<?> page, Class<?> type, Link link) {
166+
return toEmptyModel(page, type, Optional.of(link));
166167
}
167168

168-
private PagedResources<?> toEmptyResource(Page<?> page, Class<?> type, Optional<Link> link) {
169+
private PagedModel<?> toEmptyModel(Page<?> page, Class<?> type, Optional<Link> link) {
169170

170171
Assert.notNull(page, "Page must must not be null!");
171172
Assert.isTrue(!page.hasContent(), "Page must not have any content!");
@@ -177,7 +178,7 @@ private PagedResources<?> toEmptyResource(Page<?> page, Class<?> type, Optional<
177178
EmbeddedWrapper wrapper = wrappers.emptyCollectionOf(type);
178179
List<EmbeddedWrapper> embedded = Collections.singletonList(wrapper);
179180

180-
return addPaginationLinks(new PagedResources<>(embedded, metadata), page, link);
181+
return addPaginationLinks(new PagedModel<>(embedded, metadata), page, link);
181182
}
182183

183184
/**
@@ -188,34 +189,34 @@ private PagedResources<?> toEmptyResource(Page<?> page, Class<?> type, Optional<
188189
* @param page the original page handed to the assembler, must not be {@literal null}.
189190
* @return must not be {@literal null}.
190191
*/
191-
protected <R extends ResourceSupport, S> PagedResources<R> createPagedResource(List<R> resources,
192+
protected <R extends RepresentationModel<?>, S> PagedModel<R> createPagedModel(List<R> resources,
192193
PageMetadata metadata, Page<S> page) {
193194

194195
Assert.notNull(resources, "Content resources must not be null!");
195196
Assert.notNull(metadata, "PageMetadata must not be null!");
196197
Assert.notNull(page, "Page must not be null!");
197198

198-
return new PagedResources<>(resources, metadata);
199+
return new PagedModel<>(resources, metadata);
199200
}
200201

201-
private <S, R extends ResourceSupport> PagedResources<R> createResource(Page<S> page,
202-
ResourceAssembler<S, R> assembler, Optional<Link> link) {
202+
private <S, R extends RepresentationModel<?>> PagedModel<R> createModel(Page<S> page,
203+
RepresentationModelAssembler<S, R> assembler, Optional<Link> link) {
203204

204205
Assert.notNull(page, "Page must not be null!");
205206
Assert.notNull(assembler, "ResourceAssembler must not be null!");
206207

207208
List<R> resources = new ArrayList<>(page.getNumberOfElements());
208209

209210
for (S element : page) {
210-
resources.add(assembler.toResource(element));
211+
resources.add(assembler.toModel(element));
211212
}
212213

213-
PagedResources<R> resource = createPagedResource(resources, asPageMetadata(page), page);
214+
PagedModel<R> resource = createPagedModel(resources, asPageMetadata(page), page);
214215

215216
return addPaginationLinks(resource, page, link);
216217
}
217218

218-
private <R> PagedResources<R> addPaginationLinks(PagedResources<R> resources, Page<?> page, Optional<Link> link) {
219+
private <R> PagedModel<R> addPaginationLinks(PagedModel<R> resources, Page<?> page, Optional<Link> link) {
219220

220221
UriTemplate base = getUriTemplate(link);
221222

src/main/java/org/springframework/data/web/PagedResourcesAssemblerArgumentResolver.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
import org.springframework.core.MethodParameter;
2626
import org.springframework.data.domain.Pageable;
2727
import org.springframework.hateoas.Link;
28-
import org.springframework.hateoas.MethodLinkBuilderFactory;
29-
import org.springframework.hateoas.core.MethodParameters;
30-
import org.springframework.hateoas.mvc.ControllerLinkBuilderFactory;
28+
import org.springframework.hateoas.server.MethodLinkBuilderFactory;
29+
import org.springframework.hateoas.server.core.MethodParameters;
30+
import org.springframework.hateoas.server.mvc.WebMvcLinkBuilderFactory;
3131
import org.springframework.lang.Nullable;
3232
import org.springframework.web.bind.support.WebDataBinderFactory;
3333
import org.springframework.web.context.request.NativeWebRequest;
@@ -60,13 +60,13 @@ public class PagedResourcesAssemblerArgumentResolver implements HandlerMethodArg
6060
* {@link PageableHandlerMethodArgumentResolver} and {@link MethodLinkBuilderFactory}.
6161
*
6262
* @param resolver can be {@literal null}.
63-
* @param linkBuilderFactory can be {@literal null}, will be defaulted to a {@link ControllerLinkBuilderFactory}.
63+
* @param linkBuilderFactory can be {@literal null}, will be defaulted to a {@link WebMvcLinkBuilderFactory}.
6464
*/
6565
public PagedResourcesAssemblerArgumentResolver(HateoasPageableHandlerMethodArgumentResolver resolver,
6666
@Nullable MethodLinkBuilderFactory<?> linkBuilderFactory) {
6767

6868
this.resolver = resolver;
69-
this.linkBuilderFactory = linkBuilderFactory == null ? new ControllerLinkBuilderFactory() : linkBuilderFactory;
69+
this.linkBuilderFactory = linkBuilderFactory == null ? new WebMvcLinkBuilderFactory() : linkBuilderFactory;
7070
}
7171

7272
/*

src/test/java/org/springframework/data/web/HateoasPageableHandlerMethodArgumentResolverUnitTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import org.springframework.core.MethodParameter;
2424
import org.springframework.data.domain.PageRequest;
2525
import org.springframework.data.domain.Pageable;
26-
import org.springframework.hateoas.mvc.UriComponentsContributor;
26+
import org.springframework.hateoas.server.mvc.UriComponentsContributor;
2727
import org.springframework.util.MultiValueMap;
2828
import org.springframework.web.util.UriComponents;
2929
import org.springframework.web.util.UriComponentsBuilder;

0 commit comments

Comments
 (0)