Commit Graph

492 Commits

Author SHA1 Message Date
Simon Allegraud
ce17416e16 DATAREST-1181 - Prevent NullPointerException during JsonLateObjectEvaluator.evaluate(…).
Original pull request: #287.
2018-01-18 13:49:46 +01:00
Oliver Gierke
9b0f0c7101 DATAREST-1174 - Enable constructor properties to make sure WrappedPropertiesUnitTests continue to work.
Removed Lombok constructor and accessor generation to avoid having to deal with the changed default in Lombok 1.16.20 not generating @ConstructorProperties by default anymore.
2018-01-10 12:53:57 +01:00
Oliver Gierke
1bc7982d52 DATAREST-1152 - Overhaul of patch expression handling.
Significantly refactored the way that patch path expressions are handled and evaluated. The new design is centered around SpelPath that is aware of the original path as well as the derived SpEL expression. That SpelPath then requires clients to bind it to a type so that the original path can be validated (and rejected if invalid) and provide API to read, set, copy and move values backed by the original path. Both SpelPath and TypedSpelPath instances are cached to avoid repeated creation.

PatchOperation implementations now provide more fluent factory methods, in some cases via intermediate builders. Removed a lot of obsolete code that created JsonNodes from a list of PatchOperations as we don't actually use that functionality anywhere. Removed obsolete generics where possible.
2017-10-25 17:35:29 +02:00
Simmo Saan
28bb6abfea DATAREST-1148 - Fix eager toString() call on domain object in ResourceStatus.
Originl pull request: #282.
2017-10-12 23:12:50 +02:00
Oliver Gierke
d47e87aee0 DATAREST-1006 - Polishing.
Fixed assertions to use Hamcrest instead of AssertJ.
2017-10-10 09:28:08 +02:00
Oliver Gierke
dde3d18f41 DATAREST-1006 - Polishing.
Added unit test on MappingProperties directly.

Original pull request: #258.
2017-10-04 11:35:11 +02:00
Mathias Düsterhöft
7704a435d9 DATAREST-1006 - MappedProperties now skips all ignored properties.
Original pull request: #258.
2017-10-04 11:35:08 +02:00
Oliver Gierke
d330455e53 DATAREST-1137 - All patch operations now verify path expressions.
We now make sure that all patch operations now get the path they're supposed to be applied to verified before execution.
2017-09-25 19:11:22 +02:00
Oliver Gierke
1b959bd8f4 DATAREST-1132 - Fixed @BasePathAwareController annotation lookup from CGLib proxies.
We now inspect the user class of the given bean type in BasePathAwareHandlerMapping.isHandler(…). We can't use AnnotationUtils as @RepositoryRestController is also annotated with @BasePathAwareController but must not be handled by this mapping.
2017-09-25 12:02:55 +02:00
Oliver Gierke
824e51a130 DATAREST-1127 - Patch operations now always verify paths before operation application.
Previously, the SpEL expression created from JSON Patch path expressions were executed without double checking whether these paths actually exist on the target object in the first place. This check is now in place.
2017-09-08 12:00:30 +02:00
Oliver Gierke
c575757093 DATAREST-1121 - Skip last modified detection for query methods that project.
For an execution of a projecting query method we now skip the last modified detection as it actually doesn't make sense if applied to non-aggregates.
2017-08-24 21:50:31 +02:00
Oliver Gierke
c3f1c23ff8 DATAREST-1060 - Improve AssociationOmittingSerializerModifier to not break on Jackson 2.9.
According to this upstream ticket [0] we need to override BeanSerializerModifier.changeProperties(…) rather than ….updateBuilder(…). The commit just does that.

[0] https://github.com/FasterXML/jackson-databind/issues/1664

Related ticket: FasterXML/jackson-databind#1664
2017-06-19 17:39:36 +02:00
Oliver Gierke
37c1a0a808 DATAREST-1092 - Improve exception handling in PatchOperation for Spring 5 compatibility.
We now also catch SpelEvaluationException in the attempt to set a null value for an expression as Spring 5 now reports a failed attempt (e.g. if the target type is not nullable) using that type whereas Spring 4.3 threw a NullPointerException.
2017-06-14 11:30:44 +02:00
Oliver Gierke
ac75ec56d2 DATAREST-1031 - Fixed setup of ExceptionHandlerExceptionResolver.
Fixed the setup of our custom ExceptionHandlerExceptionResolver to conclude with a call to afterPropertiesSet() to make sure it's properly initialized.
2017-06-09 09:57:22 +02:00
Oliver Gierke
1f95a3387b DATAREST-1076 - Expose constructor that takes RelProvider of RepositoryResourceMappings.
We now expose the constructor that takes a RelProvider in RepositoryResourceMappings so that clients can tweak the default relation names. Changed the order of constructor parameters of (previously) non-public constructors for consistency.

The RelProvider to be used with the mappings can now be configured via RepositoryRestConfiguration and defaults to the EvoInflector based one.
2017-05-18 14:50:50 +02:00
Oliver Gierke
0813faf0d5 DATAREST-1039 - Fix appending a complex value appended to a collection via JSON Patch.
When a PATCH call using JSON Patch tried to append an item to an empty collection, it previously failed to look up the type to unmarshal the incoming payload to. We now inspect the declared types on the wrapped object's property to determine that type for append operations.

Also, an uninitialized collection is now initialized using Spring's CollectionFactory.
2017-05-12 14:42:38 +02:00
Mark Paluch
ef508ed6dc DATAREST-1019 - Consider base URI when resolving cross-origin configuration on repositories.
We now consider the base URI when resolving CORS configuration from repository interfaces. The base URI is now stripped from the request. Previously the base URI was not stripped from the request and was used to determine an exported resource.
2017-04-18 19:35:06 +02:00
Oliver Gierke
2b63e4bcdb DATAREST-1050 - PUT for create now makes sure the resource id is set on the instance to create.
So far, we handed the plain instance deserialized from the request body to the repository to persist it. That caused issues in PUT for create scenarios where the URI contains the identifier to be used for the aggregate to create and identifier generation being used in the backend. In that case the identifier submitted was never considered and subsequent requests would've created new instances, effectively breaking the idempotent nature of PUT.

We now make sure the backend identifier derived from the resource is set on the aggregate instance about to be created, so that backend can either accept that situation (new entity + manually defined identifier) or reject it (in case it insists on identifier generation).
2017-04-11 08:26:47 +02:00
Oliver Gierke
4354d35c9c DATAREST-1030 - Reinstantiate PATCH behaviour for associations.
We now completely opt out of merging values if the property is a linkable association.
2017-04-10 19:08:16 +02:00
Oliver Gierke
941408daff DATAREST-1003 - Entity resources don't answer arbitrary JSON requests.
Previously, when a request was sending an Accept header of some arbitrary *+json, the request was routed through the controllers and might have ended up producing a PersistentEntityResource that was then mapped using an uncustomized Jackson ObjectMapper. That has caused a huge JSON object to be unfolded which is highly undesirable.

We now only answer JSON requests to repository resources that contain an Accept header with any of the explicit JSON media types we got registered.

Tweaked the setup of the ExceptionHandlerExceptionResolver to not expose a bean in the first place but rather use the Spring MVC provided callbacks to register custom ones. We also now make sure MVC is bootstrapped property for integration tests through the inclusion of DelegatingWebMvcConfiguration.
2017-03-01 21:30:37 +01:00
Oliver Gierke
f4b8ee3be2 DATAREST-995 - Fixed detection of collection append operations for JSON Patch requests.
We previously erroneously looked for a ~ in a JSON Pointer to indicate collection append in e.g. an add operation. We now also support the actually correct - keeping the original behavior for now to not break clients that currently make use of it.
2017-02-08 20:00:03 +01:00
Jens Schauder
e94ba4a1fa DATAREST-994 - Fixed two argument constructor of RepositoryRestHandlerMapping.
Repositories in RepositoryCorsConfigurationAccessor may be null now. findCorsConfiguration returns null when no repositories are provided.

Original pull request: #257.
2017-02-03 09:06:59 +01:00
Mark Paluch
d2386dc64e DATAREST-992 - Remove references to Assert single-arg methods.
Replace references to Assert single-arg methods with references to methods accepting the test object and message.

Related ticket: SPR-15196.
2017-02-01 13:23:59 +01:00
Oliver Gierke
fe75811812 DATAREST-944 - DomainObjectMerger now also merges associations for PUT.
We now explicitly merge associations skipping the linkable ones. We also try to reuse the existing collections and maps if they're mutable falling back to a completely new one if not.

Extracted PropertyHandler and AssociationHandler implementations.
2017-01-26 07:39:54 +01:00
Oliver Gierke
8e1af29bf2 DATAREST-977 - Fixed reading of complex enums on collection expansion for PATCH.
When merging collections on PATCH we now don't use the first collection item's type for all elements but inspect the values for each existing element found. When it comes to appending elements to the collection, wen now just stick to the declared component type as type hint for reading the provided value.
2017-01-24 16:10:37 +01:00
Oliver Gierke
2738982576 DATAREST-957 - Improved PUT handling for transient properties not backed by a field.
When copying the transient properties of an aggregate, we now try field based access first and fall back to accessor based copying in case both a setter and getter are exposed on the type.

Previously we always expected a field to be present which doesn't necessarily has to be the case.

Related ticket: DATAREST-986.
2017-01-24 13:21:47 +01:00
Oliver Gierke
132807cbf1 DATAREST-965 - Switched to property based application of PUT requests.
Jacksons ObjectMapper.readerForUpdate(…) unfortunately doesn't handle nested objects properly. We already have a manual merge process in place for PATCH requests but tweaking that to also handle PUT requests gracefully caused more complexity than anticipated.

We now switched to an object based merge so that we can read in the source JSON structure into a new object and then merge the objects.

Related pull request: #247.
2017-01-23 15:34:52 +01:00
Oliver Gierke
294db99e63 DATAREST-986 - DomainObjectReader now merges complex nested maps correctly.
We now use a Map property's generic type information to make sure we convert both the key and the value into the declared types. Previously we just used Object if the source value to map was null. Object is still used as fallback for raw maps though.
2017-01-23 09:24:14 +01:00
Mark Paluch
ffe96e4079 DATAREST-976 - Embedded properties are now considered in sort property paths.
We now allow sorting by properties of embedded objects. An embedded object is not linkable to a root object but embedded in the resource itself. If any part of the sort property path points to a linkable association, the whole sort property path is discarded silently and not used for sorting any further.

Original pull request: #251.
2017-01-16 13:30:30 +01:00
Mark Paluch
4837ba83b1 DATAREST-978 - Polishing.
Convert @see http://… links to valid format using @see <a href=…>…</a>.
2017-01-13 10:09:17 +01:00
Mark Paluch
636956944c DATAREST-978 - Migrate ticket references in test code to Spring Framework style. 2017-01-13 10:07:40 +01:00
Oliver Gierke
4eeef2fee1 DATAREST-899 - Prefer user registered modules over default ones.
We now issue the user registration of Jackson modules before any of the default modules Spring Data registers get applied. Testing module registration seems to be rather difficult as Jackson doesn't actually expose API to do so. An issue [0] was filed for Jackson to improve on this.

[0] https://github.com/FasterXML/jackson-databind/issues/1478
2016-12-20 12:51:01 +01:00
Oliver Gierke
839682d619 DATAREST-964 - Removed deprecated configuration methods in RepositoryRestMvcConfiguration. 2016-12-20 12:06:06 +01:00
Oliver Gierke
7a473658ae DATAREST-959 - Polishing.
Skip all merge logic if the source value is null. That frees all nested logic from handling with that case and us falling back to plain Jackson reading.

The array handling now also opts out if the source value is not a collection or array in the first place as it means we need to let Jackson override the value with the collection given to be deserialized.

Original pull request: #246.
2016-12-13 09:54:26 +01:00
Milos Cubrilo
a3873a90df DATAREST-959 - Fix adding elements to empty array in DomainObjectReader.
Original pull request: #246.
2016-12-13 09:25:02 +01:00
Oliver Gierke
50c2197a37 DATAREST-835 - Search resources returning a single resource now get and consider ETag and Last-Modified headers.
We now interpret If-None-Match and If-Modified-Since headers on requests to resources backed by query methods returning a single instance only. This allows clients to optimize GET requests to those resources to save bandwidth.
2016-12-08 21:32:58 +01:00
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