DATAREST-463 - Polishing.

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.
This commit is contained in:
Oliver Gierke
2015-02-22 15:23:46 +01:00
parent 8d47fab92c
commit 0a542564bc
8 changed files with 43 additions and 63 deletions

View File

@@ -337,13 +337,8 @@ public class RootResourceInformationToAlpsDescriptorConverter {
public void doWithAssociation(Association<? extends PersistentProperty<?>> 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;
}

View File

@@ -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<BeanPropertyDefinition> {
}
/**
* 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;
}

View File

@@ -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)) {

View File

@@ -138,5 +138,4 @@ public class AlpsControllerIntegrationTests extends AbstractControllerIntegratio
LinkDiscoverer discoverer = discoverers.getLinkDiscovererFor(MediaType.valueOf(response.getContentType()));
return discoverer.findLinkWithRel(rel, response.getContentAsString());
}
}

View File

@@ -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;

View File

@@ -19,7 +19,7 @@ import org.springframework.data.repository.CrudRepository;
/**
* @author Greg Turnquist
* @author Oliver Gierke
* @see DATAREST-463
*/
public interface ItemRepository extends CrudRepository<Item, Long> {
}
public interface ItemRepository extends CrudRepository<Item, Long> {}

View File

@@ -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;
}
}

View File

@@ -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<User, Long> {
}
interface UserRepository extends CrudRepository<User, Long> {}