DATAREST-754 - Polishing.

Upgraded to Groovy 2.4.4. Polished sample domain types and repositories. Removed obsolete format registration in test cases for schema creation. Keep inlined null checks to make sure the IDE doesn't create unnecessary can-be-null warnings.

Original pull request: #206.
This commit is contained in:
Oliver Gierke
2016-01-25 17:46:25 +01:00
parent 18cc22738c
commit 12d08bf159
8 changed files with 26 additions and 47 deletions

View File

@@ -20,7 +20,7 @@
<cassandra.version>2.0.9</cassandra.version>
<cassandraunit.version>2.0.2.1</cassandraunit.version>
<spring-security.version>4.0.1.RELEASE</spring-security.version>
<groovy.version>2.3.7</groovy.version>
<groovy.version>2.4.4</groovy.version>
</properties>
<dependencies>

View File

@@ -188,25 +188,23 @@ public class PersistentEntityToJsonSchemaConverter implements ConditionalGeneric
}
}
boolean isPersistentPropertyNull = persistentProperty == null;
AnnotatedMember primaryMember = definition.getPrimaryMember();
if (primaryMember == null) { // Ignore bean definitions with neither a getter nor a setter
if (primaryMember == null) {
continue;
}
TypeInformation<?> propertyType = isPersistentPropertyNull
? ClassTypeInformation.from(primaryMember.getRawType())
: persistentProperty.getTypeInformation();
TypeInformation<?> propertyType = persistentProperty == null
? ClassTypeInformation.from(primaryMember.getRawType()) : persistentProperty.getTypeInformation();
TypeInformation<?> actualPropertyType = propertyType.getActualType();
Class<?> rawPropertyType = propertyType.getType();
JsonSchemaFormat format = configuration.getMetadataConfiguration().getSchemaFormatFor(rawPropertyType);
ResourceDescription description = isPersistentPropertyNull
ResourceDescription description = persistentProperty == null
? jackson.getFallbackDescription(metadata, definition) : getDescriptionFor(persistentProperty, metadata);
JsonSchemaProperty property = getSchemaProperty(definition, propertyType, description);
boolean isSyntheticProperty = isPersistentPropertyNull;
boolean isSyntheticProperty = persistentProperty == null;
boolean isNotWritable = !isSyntheticProperty && !persistentProperty.isWritable();
boolean isJacksonReadOnly = !isSyntheticProperty && jackson.isReadOnly(persistentProperty);
@@ -233,7 +231,7 @@ public class PersistentEntityToJsonSchemaConverter implements ConditionalGeneric
continue;
}
if (isPersistentPropertyNull) {
if (persistentProperty == null) {
registrar.register(property, actualPropertyType);
continue;
}

View File

@@ -17,7 +17,6 @@ package org.springframework.data.rest.webmvc.alps;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
import org.junit.After;
@@ -209,11 +208,10 @@ public class AlpsControllerIntegrationTests extends AbstractControllerIntegratio
Link profileLink = client.discoverUnique("profile");
Link groovyDomainObjectLink = client.discoverUnique(profileLink, "simulatedGroovyDomainClasses");
client.follow(groovyDomainObjectLink)//
.andExpect(jsonPath(
"$.alps.descriptors[?(@.id == 'simulatedGroovyDomainClass-representation')][0].descriptors[0].name",
is("name")
));
is("name")));
}
}

View File

@@ -15,26 +15,24 @@
*/
package org.springframework.data.rest.webmvc.jpa.groovy;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import groovy.lang.GroovyObject;
import groovy.lang.MetaClass;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
/**
* Simulates a Groovy domain object by extending {@link GroovyObject}.
*
* @author Greg Turnquist
* @author Oliver Gierke
* @see DATAREST-754
*/
@Entity
public class SimulatedGroovyDomainClass implements GroovyObject {
@Id @GeneratedValue private Long id;
private @Id @GeneratedValue Long id;
private String name;
public Long getId() {
@@ -53,8 +51,6 @@ public class SimulatedGroovyDomainClass implements GroovyObject {
this.name = name;
}
protected SimulatedGroovyDomainClass() {}
//
// The following fields don't actually have to be implemented since the test cases don't
// make any Groovy calls. This just simulates the structure of a Groovy object to
@@ -72,9 +68,7 @@ public class SimulatedGroovyDomainClass implements GroovyObject {
}
@Override
public void setProperty(String s, Object o) {
}
public void setProperty(String s, Object o) {}
@Override
public MetaClass getMetaClass() {
@@ -82,7 +76,5 @@ public class SimulatedGroovyDomainClass implements GroovyObject {
}
@Override
public void setMetaClass(MetaClass metaClass) {
}
public void setMetaClass(MetaClass metaClass) {}
}

View File

@@ -23,6 +23,4 @@ import org.springframework.data.repository.CrudRepository;
* @author Greg Turnquist
* @see DATAREST-754
*/
public interface SimulatedGroovyDomainClassRepository extends CrudRepository<SimulatedGroovyDomainClass, Long> {
}
public interface SimulatedGroovyDomainClassRepository extends CrudRepository<SimulatedGroovyDomainClass, Long> {}

View File

@@ -74,7 +74,6 @@ public class PersistentEntityToJsonSchemaConverterUnitTests {
config.getMetadataConfiguration().registerJsonSchemaFormat(JsonSchemaFormat.EMAIL, EmailAddress.class);
config.getMetadataConfiguration().registerFormattingPatternFor("[A-Z]+", TypeWithPattern.class);
config.getMetadataConfiguration().registerJsonSchemaFormat(JsonSchemaFormat.EMAIL);
config.exposeIdsFor(Profile.class);
}

View File

@@ -15,22 +15,22 @@
*/
package org.springframework.data.rest.webmvc.mongodb.groovy;
import org.springframework.data.mongodb.core.mapping.Document;
import groovy.lang.GroovyObject;
import groovy.lang.MetaClass;
import org.springframework.data.mongodb.core.mapping.Document;
/**
* Simulates a Groovy domain object by extending {@link GroovyObject}.
*
* @author Greg Turnquist
* @author Oliver Gierke
* @see DATAREST-754
*/
@Document
public class SimulatedGroovyDomainClass implements GroovyObject {
private String id;
private String name;
private String id, name;
public String getId() {
return id;
@@ -65,9 +65,7 @@ public class SimulatedGroovyDomainClass implements GroovyObject {
}
@Override
public void setProperty(String s, Object o) {
}
public void setProperty(String s, Object o) {}
@Override
public MetaClass getMetaClass() {
@@ -75,7 +73,5 @@ public class SimulatedGroovyDomainClass implements GroovyObject {
}
@Override
public void setMetaClass(MetaClass metaClass) {
}
public void setMetaClass(MetaClass metaClass) {}
}

View File

@@ -23,6 +23,4 @@ import org.springframework.data.repository.CrudRepository;
* @author Greg Turnquist
* @see DATAREST-754
*/
public interface SimulatedGroovyDomainClassRepository extends CrudRepository<SimulatedGroovyDomainClass, String> {
}
public interface SimulatedGroovyDomainClassRepository extends CrudRepository<SimulatedGroovyDomainClass, String> {}