From 0a542564bc32adf5b96b796077b32a7912287aaa Mon Sep 17 00:00:00 2001 From: Oliver Gierke Date: Sun, 22 Feb 2015 15:23:46 +0100 Subject: [PATCH] DATAREST-463 - Polishing. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Collapsed if clauses leading to the very same return in RootResourceinformationToAlpsDescriptorConverter. Renamed isExportableProperty(…) to isExportable(…) in JacksonMetadata. Removed commented out code in AssociationLinks. Cleanups in test code. Original pull request: #160. --- ...eInformationToAlpsDescriptorConverter.java | 7 +-- .../rest/webmvc/json/JacksonMetadata.java | 9 +-- .../rest/webmvc/mapping/AssociationLinks.java | 1 - .../alps/AlpsControllerIntegrationTests.java | 1 - .../data/rest/webmvc/jpa/Item.java | 17 ++---- .../data/rest/webmvc/jpa/ItemRepository.java | 4 +- .../data/rest/webmvc/jpa/User.java | 61 +++++++++---------- .../data/rest/webmvc/jpa/UserRepository.java | 6 +- 8 files changed, 43 insertions(+), 63 deletions(-) diff --git a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/alps/RootResourceInformationToAlpsDescriptorConverter.java b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/alps/RootResourceInformationToAlpsDescriptorConverter.java index ab5b3edc4..361e0f127 100644 --- a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/alps/RootResourceInformationToAlpsDescriptorConverter.java +++ b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/alps/RootResourceInformationToAlpsDescriptorConverter.java @@ -337,13 +337,8 @@ public class RootResourceInformationToAlpsDescriptorConverter { public void doWithAssociation(Association> association) { PersistentProperty property = association.getInverse(); - final Class propertyType = property.getType(); - if (!jackson.isExportableProperty(property)) { - return; - } - - if (!associationLinks.isLinkableAssociation(property)) { + if (!jackson.isExported(property) || !associationLinks.isLinkableAssociation(property)) { return; } diff --git a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/JacksonMetadata.java b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/JacksonMetadata.java index bd5f264c3..51200c7c5 100644 --- a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/JacksonMetadata.java +++ b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/JacksonMetadata.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 the original author or authors. + * Copyright 2014-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -76,11 +76,12 @@ public class JacksonMetadata implements Iterable { } /** - * Check if a given property for a type is avaiaable to be exported, i.e. serialized via Jackson - * @param property + * Check if a given property for a type is available to be exported, i.e. serialized via Jackson. + * + * @param property must not be {@literal null}. * @return */ - public boolean isExportableProperty(PersistentProperty property) { + public boolean isExported(PersistentProperty property) { return getDefinitionFor(property) != null; } diff --git a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/mapping/AssociationLinks.java b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/mapping/AssociationLinks.java index d23309c6c..dff8c6462 100644 --- a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/mapping/AssociationLinks.java +++ b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/mapping/AssociationLinks.java @@ -91,7 +91,6 @@ public class AssociationLinks { return false; } -// ResourceMetadata metadata = mappings.getMappingFor(property.getActualType()); ResourceMetadata metadata = mappings.getMappingFor(property.getOwner().getType()); if (metadata != null && !metadata.isExported(property)) { diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/alps/AlpsControllerIntegrationTests.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/alps/AlpsControllerIntegrationTests.java index d55d1af7a..6c89a4153 100644 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/alps/AlpsControllerIntegrationTests.java +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/alps/AlpsControllerIntegrationTests.java @@ -138,5 +138,4 @@ public class AlpsControllerIntegrationTests extends AbstractControllerIntegratio LinkDiscoverer discoverer = discoverers.getLinkDiscovererFor(MediaType.valueOf(response.getContentType())); return discoverer.findLinkWithRel(rel, response.getContentAsString()); } - } diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/jpa/Item.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/jpa/Item.java index c7b479ce6..d2cd28f02 100644 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/jpa/Item.java +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/jpa/Item.java @@ -24,25 +24,16 @@ import com.fasterxml.jackson.annotation.JsonIgnore; /** * @author Greg Turnquist + * @author Oliver Gierke * @see DATAREST-463 */ @Entity public class Item { - @Id @GeneratedValue - private Long id; - + private @Id @GeneratedValue Long id; private String name; - - @JsonIgnore - @OneToOne - private User owner; - - @OneToOne - private User manager; - - @OneToOne - private User curator; + private @JsonIgnore @OneToOne User owner; + private @OneToOne User manager, curator; public Long getId() { return id; diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/jpa/ItemRepository.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/jpa/ItemRepository.java index 5ae29bfd2..5e11e12ed 100644 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/jpa/ItemRepository.java +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/jpa/ItemRepository.java @@ -19,7 +19,7 @@ import org.springframework.data.repository.CrudRepository; /** * @author Greg Turnquist + * @author Oliver Gierke * @see DATAREST-463 */ -public interface ItemRepository extends CrudRepository { -} +public interface ItemRepository extends CrudRepository {} diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/jpa/User.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/jpa/User.java index 2a3f24fe7..f184abceb 100644 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/jpa/User.java +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/jpa/User.java @@ -23,50 +23,47 @@ import com.fasterxml.jackson.annotation.JsonIgnore; /** * @author Greg Turnquist + * @author Oliver Gierke * @see DATAREST-463 */ @Entity public class User { - @Id @GeneratedValue - private Long id; + private @Id @GeneratedValue Long id; + private String name; + private @JsonIgnore String password; - private String name; + private String[] roles; - @JsonIgnore - private String password; + public Long getId() { + return id; + } - private String[] roles; + public void setId(Long id) { + this.id = id; + } - public Long getId() { - return id; - } + public String getName() { + return name; + } - public void setId(Long id) { - this.id = id; - } + public void setName(String name) { + this.name = name; + } - public String getName() { - return name; - } + public String getPassword() { + return password; + } - public void setName(String name) { - this.name = name; - } + public void setPassword(String password) { + this.password = password; + } - public String getPassword() { - return password; - } + public String[] getRoles() { + return roles; + } - public void setPassword(String password) { - this.password = password; - } - - public String[] getRoles() { - return roles; - } - - public void setRoles(String... roles) { - this.roles = roles; - } + public void setRoles(String... roles) { + this.roles = roles; + } } diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/jpa/UserRepository.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/jpa/UserRepository.java index 7771c47eb..d03ae4b15 100644 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/jpa/UserRepository.java +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/jpa/UserRepository.java @@ -16,12 +16,10 @@ package org.springframework.data.rest.webmvc.jpa; import org.springframework.data.repository.CrudRepository; -import org.springframework.data.rest.core.annotation.RepositoryRestResource; /** * @author Greg Turnquist + * @author Oliver Gierke * @see DATAREST-463 */ -@RepositoryRestResource(exported = false) -public interface UserRepository extends CrudRepository { -} +interface UserRepository extends CrudRepository {}