Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b9957d1

Browse files
DATAREST-1008 - Adapt to API changes in Spring Data Commons, Java 8 upgrades and Mockito 2.7.
1 parent 272dc17 commit b9957d1

File tree

159 files changed

+2179
-2169
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

159 files changed

+2179
-2169
lines changed

‎spring-data-rest-core/pom.xml‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@
5757
<version>${jackson}</version>
5858
</dependency>
5959

60+
<dependency>
61+
<groupId>com.fasterxml.jackson.datatype</groupId>
62+
<artifactId>jackson-datatype-jdk8</artifactId>
63+
<version>${jackson}</version>
64+
</dependency>
65+
6066
<dependency>
6167
<groupId>com.google.guava</groupId>
6268
<artifactId>guava</artifactId>
@@ -73,4 +79,19 @@
7379

7480
</dependencies>
7581

82+
<build>
83+
84+
<plugins>
85+
<plugin>
86+
<groupId>org.apache.maven.plugins</groupId>
87+
<artifactId>maven-compiler-plugin</artifactId>
88+
<configuration>
89+
<source>${source.level}</source>
90+
<target>${source.level}</target>
91+
<compilerArgument>-parameters</compilerArgument>
92+
</configuration>
93+
</plugin>
94+
</plugins>
95+
</build>
96+
7697
</project>

‎spring-data-rest-core/src/main/java/org/springframework/data/rest/core/UriToEntityConverter.java‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@
1818
import java.net.URI;
1919
import java.util.Collections;
2020
import java.util.HashSet;
21+
import java.util.Optional;
2122
import java.util.Set;
2223

2324
import org.springframework.core.convert.ConversionFailedException;
2425
import org.springframework.core.convert.TypeDescriptor;
2526
import org.springframework.core.convert.converter.ConditionalGenericConverter;
2627
import org.springframework.core.convert.converter.GenericConverter;
2728
import org.springframework.data.mapping.PersistentEntity;
29+
import org.springframework.data.mapping.PersistentProperty;
2830
import org.springframework.data.mapping.context.PersistentEntities;
2931
import org.springframework.data.repository.support.Repositories;
3032
import org.springframework.data.repository.support.RepositoryInvokerFactory;
@@ -66,9 +68,9 @@ public UriToEntityConverter(PersistentEntities entities, RepositoryInvokerFactor
6668
for (TypeInformation<?> domainType : entities.getManagedTypes()) {
6769

6870
Class<?> rawType = domainType.getType();
69-
PersistentEntity<?, ?> entity = entities.getPersistentEntity(rawType);
71+
Optional<PersistentEntity<?, ?extendsPersistentProperty<?>>> entity = entities.getPersistentEntity(rawType);
7072

71-
if (entity != null && entity.hasIdProperty()) {
73+
if (entity.map(it -> it.hasIdProperty()).orElse(false)) {
7274
convertiblePairs.add(new ConvertiblePair(URI.class, domainType.getType()));
7375
}
7476
}
@@ -86,7 +88,7 @@ public UriToEntityConverter(PersistentEntities entities, RepositoryInvokerFactor
8688
@Override
8789
public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) {
8890
return !sourceType.equals(URI_TYPE) ? false
89-
: repositories.getRepositoryInformationFor(targetType.getType()) != null;
91+
: repositories.getRepositoryInformationFor(targetType.getType()).isPresent();
9092
}
9193

9294
/*
@@ -105,9 +107,10 @@ public Set<ConvertiblePair> getConvertibleTypes() {
105107
@Override
106108
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
107109

108-
PersistentEntity<?, ?> entity = entities.getPersistentEntity(targetType.getType());
110+
Optional<PersistentEntity<?, ? extends PersistentProperty<?>>> entity = entities
111+
.getPersistentEntity(targetType.getType());
109112

110-
if (entity == null) {
113+
if (!entity.isPresent()) {
111114
throw new ConversionFailedException(sourceType, targetType, source,
112115
new IllegalArgumentException("No PersistentEntity information available for " + targetType.getType()));
113116
}
@@ -120,6 +123,6 @@ public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor t
120123
"Cannot resolve URI " + uri + ". Is it local or remote? Only local URIs are resolvable."));
121124
}
122125

123-
return invokerFactory.getInvokerFor(targetType.getType()).invokeFindOne(parts[parts.length - 1]);
126+
return invokerFactory.getInvokerFor(targetType.getType()).invokeFindOne(parts[parts.length - 1]).orElse(null);
124127
}
125128
}

‎spring-data-rest-core/src/main/java/org/springframework/data/rest/core/ValidationErrors.java‎

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import java.util.Arrays;
1919
import java.util.Collection;
2020
import java.util.Iterator;
21+
import java.util.Optional;
2122

2223
import org.springframework.beans.BeansException;
2324
import org.springframework.beans.ConfigurablePropertyAccessor;
@@ -83,17 +84,11 @@ public Object getPropertyValue(String propertyName) throws BeansException {
8384
do {
8485

8586
String segment = iterator.next();
86-
PersistentEntity<?, ?> entity = entities.getPersistentEntity(value.getClass());
87-
PersistentProperty<?> property = entity.getPersistentProperty(PropertyAccessorUtils.getPropertyName(segment));
8887

89-
if (property == null) {
90-
throw new NotReadablePropertyException(source.getClass(), propertyName);
91-
}
88+
Optional<? extends PersistentProperty<?>> property = entities.getPersistentEntity(value.getClass())//
89+
.flatMap(it -> it.getPersistentProperty(PropertyAccessorUtils.getPropertyName(segment)));
9290

93-
ConfigurablePropertyAccessor accessor = property.usePropertyAccess()
94-
? PropertyAccessorFactory.forBeanPropertyAccess(value)
95-
: PropertyAccessorFactory.forDirectFieldAccess(value);
96-
value = accessor.getPropertyValue(segment);
91+
value = getValue(value, property, segment, propertyName);
9792

9893
} while (iterator.hasNext());
9994

@@ -110,4 +105,18 @@ public Object getPropertyValue(String propertyName) throws BeansException {
110105
public Object getTarget() {
111106
return source;
112107
}
108+
109+
private static Object getValue(Object source, Optional<? extends PersistentProperty<?>> property, String segment,
110+
String name) {
111+
112+
return property.map(it -> {
113+
114+
ConfigurablePropertyAccessor accessor = it.usePropertyAccess()
115+
? PropertyAccessorFactory.forBeanPropertyAccess(source)
116+
: PropertyAccessorFactory.forDirectFieldAccess(source);
117+
118+
return accessor.getPropertyValue(segment);
119+
120+
}).orElseThrow(() -> new NotReadablePropertyException(source.getClass(), name));
121+
}
113122
}

‎spring-data-rest-core/src/main/java/org/springframework/data/rest/core/config/EntityLookupConfiguration.java‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.io.Serializable;
2323
import java.util.ArrayList;
2424
import java.util.List;
25+
import java.util.Optional;
2526

2627
import org.springframework.core.convert.converter.Converter;
2728
import org.springframework.data.repository.Repository;
@@ -188,11 +189,15 @@ public RepositoriesEntityLookup(Repositories repositories,
188189
Assert.notNull(repositories, "Repositories must not be null!");
189190
Assert.notNull(lookupInformation, "LookupInformation must not be null!");
190191

191-
RepositoryInformation information = repositories.getRepositoryInformation(lookupInformation.repositoryType);
192+
RepositoryInformation information = repositories.getRepositoryInformation(lookupInformation.repositoryType)//
193+
.orElseThrow(() -> new IllegalStateException(
194+
"No repository found for type " + lookupInformation.repositoryType.getName() + "!"));
192195

193-
this.repository = (Repository<? extends T, ?>) repositories.getRepositoryFor(information.getDomainType());
194196
this.domainType = information.getDomainType();
195197
this.lookupInfo = lookupInformation;
198+
this.repository = (Repository<? extends T, ?>) repositories.getRepositoryFor(information.getDomainType())//
199+
.orElseThrow(() -> new IllegalStateException(
200+
"No repository found for type " + information.getDomainType().getName() + "!"));
196201
}
197202

198203
/*
@@ -209,8 +214,8 @@ public Serializable getResourceIdentifier(T entity) {
209214
* @see org.springframework.data.rest.core.support.EntityLookup#lookupEntity(java.io.Serializable)
210215
*/
211216
@Override
212-
public Object lookupEntity(Serializable id) {
213-
return lookupInfo.getLookup().lookup(repository, id);
217+
public Optional<Object> lookupEntity(Serializable id) {
218+
return Optional.ofNullable(lookupInfo.getLookup().lookup(repository, id));
214219
}
215220

216221
/*

‎spring-data-rest-core/src/main/java/org/springframework/data/rest/core/config/RepositoryRestConfiguration.java‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ public class RepositoryRestConfiguration {
6464
private final ProjectionDefinitionConfiguration projectionConfiguration;
6565
private final MetadataConfiguration metadataConfiguration;
6666
private final EntityLookupConfiguration entityLookupConfiguration;
67-
private final List<Class<?>> valueTypes = new ArrayList<Class<?>>();
6867

6968
private final EnumTranslationConfiguration enumTranslationConfiguration;
7069
private boolean enableEnumTranslation = false;

‎spring-data-rest-core/src/main/java/org/springframework/data/rest/core/mapping/CrudMethodsSupportedHttpMethods.java‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.lang.reflect.Method;
2525
import java.util.Collections;
2626
import java.util.HashSet;
27+
import java.util.Optional;
2728
import java.util.Set;
2829

2930
import org.springframework.core.annotation.AnnotationUtils;
@@ -179,14 +180,14 @@ public boolean exposesFindAll() {
179180
return exposes(crudMethods.getFindAllMethod());
180181
}
181182

182-
private static boolean exposes(Method method) {
183+
private static boolean exposes(Optional<Method> method) {
183184

184-
if (method == null) {
185-
return false;
186-
}
185+
return method.map(it -> {
187186

188-
RestResource annotation = AnnotationUtils.findAnnotation(method, RestResource.class);
189-
return annotation == null ? true : annotation.exported();
187+
RestResource annotation = AnnotationUtils.findAnnotation(it, RestResource.class);
188+
return annotation == null ? true : annotation.exported();
189+
190+
}).orElse(false);
190191
}
191192
}
192193

‎spring-data-rest-core/src/main/java/org/springframework/data/rest/core/mapping/MappingResourceMetadata.java‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import java.util.Collections;
1919
import java.util.HashMap;
2020
import java.util.Map;
21+
import java.util.Optional;
2122

2223
import org.springframework.data.mapping.Association;
2324
import org.springframework.data.mapping.PersistentEntity;
@@ -55,8 +56,8 @@ public MappingResourceMetadata(PersistentEntity<?, ?> entity, ResourceMappings r
5556
this.entity.doWithAssociations(propertyMappings);
5657
this.entity.doWithProperties(propertyMappings);
5758

58-
RestResource annotation = entity.findAnnotation(RestResource.class);
59-
this.explicitlyExported = annotation != null && annotation.exported();
59+
Optional<RestResource> annotation = entity.findAnnotation(RestResource.class);
60+
this.explicitlyExported = annotation.map(it -> it.exported()).orElse(false);
6061
}
6162

6263
/*

‎spring-data-rest-core/src/main/java/org/springframework/data/rest/core/mapping/PersistentEntitiesResourceMappings.java‎

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.util.HashSet;
2121
import java.util.Iterator;
2222
import java.util.Map;
23+
import java.util.Optional;
2324
import java.util.Set;
2425

2526
import org.springframework.data.mapping.PersistentEntity;
@@ -84,23 +85,23 @@ public ResourceMetadata getMetadataFor(Class<?> type) {
8485
MappingResourceMetadata getMappingMetadataFor(Class<?> type) {
8586

8687
Assert.notNull(type, "Type must not be null!");
87-
type = ClassUtils.getUserClass(type);
88+
Class<?> userType = ClassUtils.getUserClass(type);
8889

89-
MappingResourceMetadata mappingMetadata = mappingCache.get(type);
90+
MappingResourceMetadata mappingMetadata = mappingCache.get(userType);
9091

9192
if (mappingMetadata != null) {
9293
return mappingMetadata;
9394
}
9495

95-
PersistentEntity<?, ?> entity = entities.getPersistentEntity(type);
96+
Optional<PersistentEntity<?, ?extendsPersistentProperty<?>>> entity = entities.getPersistentEntity(userType);
9697

97-
if (entity == null) {
98-
return null;
99-
}
98+
return entity.map(it -> {
99+
100+
MappingResourceMetadata metadata = new MappingResourceMetadata(it, this);
101+
mappingCache.put(userType, metadata);
102+
return metadata;
100103

101-
mappingMetadata = new MappingResourceMetadata(entity, this);
102-
mappingCache.put(type, mappingMetadata);
103-
return mappingMetadata;
104+
}).orElse(null);
104105
}
105106

106107
/*

‎spring-data-rest-core/src/main/java/org/springframework/data/rest/core/mapping/PersistentPropertyResourceMapping.java‎

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,13 @@
1515
*/
1616
package org.springframework.data.rest.core.mapping;
1717

18+
import java.util.Optional;
19+
1820
import org.springframework.data.mapping.PersistentProperty;
1921
import org.springframework.data.rest.core.Path;
2022
import org.springframework.data.rest.core.annotation.Description;
2123
import org.springframework.data.rest.core.annotation.RestResource;
24+
import org.springframework.data.util.Optionals;
2225
import org.springframework.util.Assert;
2326
import org.springframework.util.StringUtils;
2427

@@ -31,8 +34,8 @@ class PersistentPropertyResourceMapping implements PropertyAwareResourceMapping
3134

3235
private final PersistentProperty<?> property;
3336
private final ResourceMappings mappings;
34-
private final RestResource annotation;
35-
private final Description description;
37+
private final Optional<RestResource> annotation;
38+
private final Optional<Description> description;
3639

3740
/**
3841
* Creates a new {@link RootPropertyResourceMapping}.
@@ -46,7 +49,7 @@ public PersistentPropertyResourceMapping(PersistentProperty<?> property, Resourc
4649

4750
this.property = property;
4851
this.mappings = mappings;
49-
this.annotation = property.isAssociation() ? property.findAnnotation(RestResource.class) : null;
52+
this.annotation = property.isAssociation() ? property.findAnnotation(RestResource.class) : Optional.empty();
5053
this.description = property.findAnnotation(Description.class);
5154
}
5255

@@ -56,8 +59,10 @@ public PersistentPropertyResourceMapping(PersistentProperty<?> property, Resourc
5659
*/
5760
@Override
5861
public Path getPath() {
59-
return annotation != null && StringUtils.hasText(annotation.path()) ? new Path(annotation.path()) : new Path(
60-
property.getName());
62+
63+
return annotation.filter(it -> StringUtils.hasText(it.path()))//
64+
.map(it -> new Path(it.path()))//
65+
.orElseGet(() -> new Path(property.getName()));
6166
}
6267

6368
/*
@@ -66,7 +71,10 @@ public Path getPath() {
6671
*/
6772
@Override
6873
public String getRel() {
69-
return annotation != null && StringUtils.hasText(annotation.rel()) ? annotation.rel() : property.getName();
74+
75+
return annotation.filter(it -> StringUtils.hasText(it.rel()))//
76+
.map(it -> it.rel())//
77+
.orElseGet(() -> property.getName());
7078
}
7179

7280
/*
@@ -81,7 +89,7 @@ public boolean isExported() {
8189
}
8290

8391
ResourceMapping typeMapping = mappings.getMetadataFor(property.getActualType());
84-
return !typeMapping.isExported() ? false : annotation == null ? true : annotation.exported();
92+
return !typeMapping.isExported() ? false : annotation.map(it -> it.exported()).orElse(true);
8593
}
8694

8795
/*
@@ -103,15 +111,11 @@ public ResourceDescription getDescription() {
103111
CollectionResourceMapping ownerTypeMapping = mappings.getMetadataFor(property.getOwner().getType());
104112
ResourceDescription fallback = TypedResourceDescription.defaultFor(ownerTypeMapping.getItemResourceRel(), property);
105113

106-
if (description != null) {
107-
return new AnnotationBasedResourceDescription(description, fallback);
108-
}
109-
110-
if (annotation != null) {
111-
return new AnnotationBasedResourceDescription(annotation.description(), fallback);
112-
}
113-
114-
return fallback;
114+
return Optionals
115+
.<ResourceDescription> firstNonEmpty(//
116+
() -> description.map(it -> new AnnotationBasedResourceDescription(it, fallback)), //
117+
() -> annotation.map(it -> new AnnotationBasedResourceDescription(it.description(), fallback)))
118+
.orElse(fallback);
115119
}
116120

117121
/*

‎spring-data-rest-core/src/main/java/org/springframework/data/rest/core/mapping/RepositoryResourceMappings.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ private final void populateCache(Repositories repositories, RelProvider provider
8181

8282
for (Class<?> type : repositories) {
8383

84-
RepositoryInformation repositoryInformation = repositories.getRepositoryInformationFor(type);
84+
RepositoryInformation repositoryInformation = repositories.getRequiredRepositoryInformation(type);
8585
Class<?> repositoryInterface = repositoryInformation.getRepositoryInterface();
8686
PersistentEntity<?, ?> entity = repositories.getPersistentEntity(type);
8787

@@ -111,7 +111,7 @@ public SearchResourceMappings getSearchResourceMappings(Class<?> domainType) {
111111
return searchCache.get(domainType);
112112
}
113113

114-
RepositoryInformation repositoryInformation = repositories.getRepositoryInformationFor(domainType);
114+
RepositoryInformation repositoryInformation = repositories.getRequiredRepositoryInformation(domainType);
115115
List<MethodResourceMapping> mappings = new ArrayList<MethodResourceMapping>();
116116
ResourceMetadata resourceMapping = getMetadataFor(domainType);
117117

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /