Commit Graph

504 Commits

Author SHA1 Message Date
Oliver Gierke
a254e1adae DATAREST-957 - Polish most critical Sonar warnings.
Fixed broken equals(…) in ProjectionDefinition. Switched to iterating over Map's entry set instead of the keys. Made UriAwareHttpServletRequest static.
2016-12-08 10:12:01 +01:00
Oliver Gierke
29345d3e49 DATAREST-956 - Polishing.
Some tiny refactorings in DomainObjectReader. We're now using TypeInformation instead of Class to preserve more generics information when it comes to deeper nesting.

Moved some code around in the unit tests.

Original pull request: #245.
2016-12-08 09:44:36 +01:00
Mathias Düsterhöft
59c7bae518 DATAREST-956 - Fixed handling of collection element addition and removal for PUT requests.
DomainObjectMerger now properly adds and removes elements to and from collections.

Original pull request: #245.
2016-12-08 09:36:22 +01:00
Oliver Gierke
a1c538c31e DATAREST-953 - Added test case to verify this is fixed.
Seems the change for DATAREST-938 has also fixed this one. Added a test case similar to what was provided in the example for the original ticket.
2016-12-07 18:46:29 +01:00
Oliver Gierke
69fcd395f6 DATAREST-938 - Polishing.
Formatting and author.

Original pull request: #241.
2016-12-07 18:35:14 +01:00
Craig Andrews
b17c8bc19b DATAREST-938 - Update nested entities instead of replacing them with new instances.
Original pull request: #241.
2016-12-07 18:34:49 +01:00
Oliver Gierke
9fbdd03b0a DATAREST-910 - Polishing.
Minor code reorganizations. Eagerly create SortTranslator to avoid repeated instantiation.

Original pull request: #232.
2016-12-06 11:57:52 +01:00
Mark Paluch
357bb7a28b DATAREST-910 - Support nested Sort properties.
We now support nested Sort properties considering Jackson mapping. Sort translation is optional and skipped if the domain class is not resolvable. Translation in the scope of a domain class maps property paths to apply sorting using embedded properties.

A sort string `nested-name` resolves to a property path `anotherWrap.embedded.name`.

class Aggregate {

	@JsonUnwrapped
	public UnwrapEmbedded anotherWrap;
}

class UnwrapEmbedded {

	@JsonUnwrapped(prefix = "nested-")
	public Embedded embedded;
}

class Embedded {
	public String name;
}

Original pull request: #232.
2016-12-06 11:57:49 +01:00
Mark Paluch
7880bef68c DATAREST-910 - Adopt interfaces for Pageable and Sort method argument resolvers.
Original pull request: #232.
2016-12-06 11:57:33 +01:00
Oliver Gierke
a928dc0e20 DATAREST-937 - Polishing.
Moved the newly added test case to the end of the list. Formatting.

Original pull request: #240.
2016-12-06 09:28:59 +01:00
Craig Andrews
30d173315a DATAREST-937 - Transient properties in JSON are now included in merge.
We now don't prematurely drop fields that don't have a persistent property exposed in DomainObjectReader. Doing so dropped values for transient fields as the latter are not exposed as persistent property in the first place. We still skip any nested merging though.

Original pull request: #240.
2016-12-06 09:28:15 +01:00
Oliver Gierke
bb26b39e81 DATAREST-925 - Polishing.
Original pull request: #238.
2016-12-02 20:16:51 +01:00
Craig Andrews
b66c8272ee DATAREST-925 - Invoke ResourceProcessors for ProjectionResources.
The serializer for projection resources now also invokes ResourceProcessor instances registered for that particular projection.

Original pull request: #238.
2016-12-02 20:16:48 +01:00
Oliver Gierke
7329e20fa8 DATAREST-919 - Merging of nested maps for PUT/PATCH requests now handles nested arrays and simple types. 2016-11-03 16:19:46 +01:00
Oliver Gierke
68d0a1aa6a DATAREST-931 - Polishing.
Switched to non-deprecated property naming strategy in test case.
2016-11-03 09:13:52 +01:00
Oliver Gierke
50d2678d01 DATAREST-931 - DomainObjectMerger now handles arrays with complex objects correctly.
We now explicitly manually merge array nodes that contain complex objects. Previously arrays would've been skipped and the subsequent Jackson update would wipe out all properties not contained in the original document even on PATCH requests.
2016-11-02 13:40:54 +01:00
Oliver Gierke
40bb8e8e6c DATAREST-573 - Polishing.
Removed RepositoryRestConfiguration.addCorsMapping(…) as we currently don't have any other shortcut methods for configuration like this.

Tweaked the setup of (now Repository)CorsConfigurationAccessor to be created earlier so that we avoid recreation for every lookup. Introduced a NoOpStringValueResolver to be used by default so that we don't need to deal with the case of the resolver being null at the end of the call chain. Replaced constructor of RepositoryCorsConfigurationAccessor with corresponding Lombok annotation.

Updated reference documentation accordingly.

Original pull request: #233.
2016-10-28 14:19:26 +02:00
Mark Paluch
a3870ca528 DATAREST-573 - Add support for new CORS configuration mechanisms introduced in Spring 4.2.
We now support CORS configuration mechanisms introduced in Spring 4.2. CORS can be configured on multiple levels: Repository interface, Repository REST controller and global level. Spring Data REST CORS configuration is isolated so Spring Web MVC'S CORS configuration does not apply to Spring Data REST resources.

 Multiple configuration sources are merged so different aspects of CORS can be configured in separate locations.

@CrossOrigin
interface PersonRepository extends CrudRepository<Person, Long> {}

@RepositoryRestController
@RequestMapping("/person")
public class PersonController {

	@CrossOrigin(maxAge = 3600)
	@RequestMapping(method = RequestMethod.GET, "/xml/{id}", produces = MediaType.APPLICATION_XML_VALUE)
	public Person retrieve(@PathVariable Long id) {
		// ...
	}
}

@Component
public class SpringDataRestCustomization extends RepositoryRestConfigurerAdapter {

  @Override
  public void configureRepositoryRestConfiguration(RepositoryRestConfiguration config) {

    config.addCorsMapping("/person/**")
        .allowedOrigins("http://domain2.com")
        .allowedMethods("PUT", "DELETE")
        .allowedHeaders("header1", "header2", "header3")
        .exposedHeaders("header1", "header2")
        .allowCredentials(false).maxAge(3600);
  }
}
2016-10-28 14:19:26 +02:00
Oliver Gierke
19aa41926a DATAREST-929 - Polishing.
Some formatting.
2016-10-26 11:50:30 +02:00
Oliver Gierke
b4f99b83a0 DATAREST-929 - EnumTranslatingDeserializers now handles container types correctly.
When translating enumerations, we now inspect the property and use a container type's value type as translation target.
2016-10-26 11:50:27 +02:00
Oliver Gierke
a516d8e61f DATAREST-575 - Fixed property lookup in MappedProperties.
Previously, MappedProperties didn't handle Jackson properties correctly, that do not expose a PersistentProperty, e.g. transient ones. That led to potential nullPointerExceptions in clients as the guarding hasPersistentPropertyForField(…) still answered true, as the backing cache contained an entry with a null value. We now skip those properties completely.
2016-10-23 20:36:59 +02:00
Mark Paluch
b436662304 DATAREST-906 - Consider default Pageable even if Sort is empty.
We now resolve default configured Pageable without dropping them if their Sort is empty. Previously, any default Pageable was dropped if its Sort was empty which caused null being handed to controller methods of @RepositoryRestController instances.

Original pull request: #231.
2016-09-23 15:20:56 +02:00
Oliver Gierke
90f57bd1e7 DATAREST-872 - Polishing.
Simplified types used for testing. Removed unnecessary repository interface.

Related pull request: #221.
2016-09-19 10:28:12 +02:00
Alex Leigh
c36267a447 DATAREST-872 - PersistentEntityJackson2Module now serializes JsonTypeInfo correctly.
NestedEntitySerializer now overrides serializeWithType(…) so that @JsonTypeInfo is rendered properly.

Related pull request: #221.
2016-09-19 10:28:09 +02:00
Oliver Gierke
216e267fce DATAREST-883 - Polishing.
Switched to use @RequiredArgsConstructor where possible. Slightly rearranged test cases. Inlined JacksonMappingAwareSortTranslator to not expose it as bean unless necessary. Use static Jackson BeanClassIntrospector to avoid unnecessary recreation.

Original pull request: #222.
2016-09-19 08:05:45 +02:00
Mark Paluch
a999bd3ca8 DATAREST-883 - Consider Jackson field names in Sort mapping.
We now consider Jackson field names when resolving Sort arguments. Domain model properties annotated with @JsonProperty("sales") can be specified by their Jackson-mapped field name in sort arguments. Field names are mapped to their according persistent property names to be used in repository query method sorting. Unknown field names are silently dropped.

Original pull request: #222.
2016-09-19 08:05:45 +02:00
Oliver Gierke
bacd8be4fc DATAREST-897 - Switched to use approximated Map in NestedEntitySerializer.
We now use CollectionFactory.createApproximateMap(…) to avoid picking up persistence technology specific Map implementations that might cause issues (e.g. requiring a Session in the case of Hibernate).

Related tickets: DATAREST-864.
2016-09-19 07:09:04 +02:00
Oliver Gierke
254c4515e1 DATAREST-864 - NestedEntitySerializer now handles Maps correctly.
Previously, NestedEntitySerializer failed to handle Maps correctly as the logic to convert the found values to nested resources tried to handle the values as is, not explicitly looking at the values instead.

We now use an explicit code path to turn the values into resources so that links pointing to other resources are rendered correctly.

Original pull request: #219.
2016-09-16 16:34:06 +02:00
Oliver Gierke
1c70b9175d DATAREST-889 - Polishing.
Improved test cases by using JUnit's ExpectedException for simpler assertions.

Original pull request: #227.
2016-09-14 10:16:22 +02:00
Oliver Trosien
48125faea3 DATAREST-889 - JsonPatchPatchConverter explicitly rejects unknown paths and values.
JsonPatchPatchConverter now explicitly rejects problematic JSON Patch payloads (e.g. incorrect paths, incorrect values) throwing a PatchException.

Original pull request: #227.
2016-09-12 16:08:32 +02:00
Oliver Gierke
1513482b9c DATAREST-885 - Polishing.
Original pull request: #226.
2016-09-12 13:00:48 +02:00
Oliver Trosien
1fd9a03c68 DATAREST-885 - Support array values in JsonPatchPatchConverter.
Original pull request: #226.
2016-09-12 13:00:02 +02:00
Oliver Gierke
2710b988b5 DATAREST-885, DATAREST-885 - Cleanups in JSON Patch code. 2016-09-12 11:20:49 +02:00
Oliver Gierke
2493d3c2f1 DATAREST-885 - Polishing.
Formatting. Copyright ranges.
2016-09-12 11:02:15 +02:00
Mathias Düsterhöft
518cab040f DATAREST-885 - PatchOperation now evaluates SpEL expression.
Original pull request: #223.
2016-09-12 11:01:48 +02:00
Oliver Gierke
3643e06b1f DATAREST-887 - Polishing.
Code formatting. Author tags. Assertions in Constructor. JavaDoc.

Original pull request: #224.
2016-09-12 10:47:50 +02:00
Mathias Düsterhöft
0a6dcc9825 DATAREST-887 - JsonPatchPatchHandler now uses external ObjectMapper.
The previously static ObjectMapper used by JsonPatchPatchHandler now has to be provided by clients instantiating the handler.

Original pull request: #224.
2016-09-12 10:47:13 +02:00
Oliver Gierke
31c894e880 DATAREST-607 - Register Jackson Hibernate 5 module automatically if present.
Just as we do for the Jackson Hibernate integration for Hibernate 4, we now register the module for Hibernate 5 as well.
2016-09-09 23:04:03 +02:00
Oliver Gierke
4cb0632518 DATAREST-880 - Prevent nested-entity-as-resource handling for unwrapped properties.
We now exclude properties that are marked as to be unwrapped from getting the nested-entity-as-resource behavour applied as it doesn't make any sense.
2016-08-29 19:26:07 +02:00
Oliver Gierke
72e4ef025d DATAREST-837 - DomainObjectMerger doesn't nullify read-only properties on PUT.
PUT requests are supposed to replace the state of the resource with the request payload. However, Spring Data REST already handles a couple of domain object propoerties in a special way as theri values map to dedicated HTTP features: identifiers (URIs), last-modified dates (header) etc.

For users, it might be worthwhile to exclude other properties from being set by applying the payload, like properties that are completely under the control of the server, e.g. creation user and date, last modifying user etc. So far, users didn't have any means to exclude those properties as the handling of PUT requests treated every missing property of the payload as null value.

DomainObjectMerger now checks whether a property is actually writable before applying the implicit null value. The application can be disabled by annotation a property with @ReadOnlyProperty.
2016-08-18 13:07:02 +02:00
Oliver Gierke
8d931ceb59 DATAREST-866 - Avoid premature initialization of RepositoryRestMvcConfiguration.
Previously, RepositoryRestMvcConfiguration declared a BeanPostProcessor instance in a non-static bean factory method. That required Spring to instantiate the configuration class and keeping it in uninitialized state, which could in turn cause issues downstream.

We now use a static method so that the container can obtain the bean instance without having to create an instance of the configuration class and thus deferring its initialization.
2016-08-08 12:08:43 +02:00
Oliver Gierke
344c3ac840 DATAREST-863 - Adapt to changes in Accept header lookup in Spring 4.3.
Spring 4.3's HeaderContentNegotiationStrategy switched from looking up the Accept header via the method returning a single (potentially comma separated) one to the method returning multiple headers in the first place. We now added an override of HttpServletRequestWrapper.getHeaders(…) to out custom adapter defaulting the media type to make sure the defaulting is visible and thus the right handler methods are looked up.

That previously missing caused the DelegatingHandlerMapping selecting the redirect to the HAL browser in case a request to the API root was sent without an accept header as the defaulting of the header to application/hal+json wasn't properly exposed anymore and the redirect to the browser — declaring a produces clause of text/html — was not causing any media type mismatch anymore.
2016-08-04 21:15:19 -07:00
Oliver Gierke
eb630ef273 DATAREST-803 - Prepare next development iteration. 2016-07-27 14:32:36 +02:00
Oliver Gierke
eaca77051a DATAREST-803 - Release version 2.6 M1 (Ingalls). 2016-07-27 13:52:12 +02:00
Oliver Gierke
0b6a0a0a8d DATAREST-847 - RepositoryEntityCotroller.saveAndReturn(…) now uses save result.
Previously we handed the original entity to the AfterSaveEvent. This should work in most cases but actually repositories are allowed to return a completely different instance so that we now hand over the instance returned by the repository interaction to avoid potentially occurring issues.
2016-07-01 14:44:40 +02:00
Oliver Gierke
cbbf21fcef DATAREST-849 - Remove obsolete reference to ConversionService from RepositoryEntityController. 2016-07-01 14:35:42 +02:00
Oliver Gierke
9e5fd30c68 DATAREST-837 - Move to ResourceProcessor invcation infrastructure in Spring HATEOAS.
Deprecated the ResourceProcessor invoking infrastructure in place here in favor of the types moved to Spring HATEOAS. Refactored our codebase to make use of these newly introduced types right away.

Related tickets: spring-projects/spring-hateoas#362.
2016-06-10 21:33:33 +02:00
Oliver Gierke
f21e150692 DATAREST-840 - HalHandlerInstantiator now gets BeanFactory forwarded.
We now forward the AutowireCapableBeanFactory contained in the ApplicationContext to the HalHandlerInstantiator to make sure Jackson components can use dependency injection to access Spring managed beans.

Upgraded to Spring HATEOAS 0.21 snapshots to see the changes necessary in HalHandlerInstantiator.

Related ticket: spring-projects/spring-hateoas#460.
2016-06-09 17:43:36 +02:00
Oliver Gierke
4bec3229b5 DATAREST-809 - Fixed application of explicit projections for excerpts.
A refactoring in the course of the 2.5 development dropped the application of explicit projection in case of excerpts being requested. This particularly applies to collection resources with explicit projection requests which need to get the explicit projection applied over the default excerpt projection potentially registered.

This is now fixed by the explicitly selected projection (if existing) always trumping the excerpt one.
2016-04-14 20:11:44 +02:00
Oliver Gierke
c8abdf0139 DATAREST-805 - ValidationError nor exposes rejected value as is.
Previously ValidationError captured the toString() variant of the rejected value. We now return the rejected value as is.
2016-04-14 20:11:40 +02:00