Commit Graph

305 Commits

Author SHA1 Message Date
Oliver Gierke
c12009337b DATAREST-494 - ALPS metadata now links to JSON Schema.
The ALPS document rendered now links to the JSON Schema document from within the core representation descriptor to allow clients to obtain more detailed information about the payloads to send and receive.
2015-03-23 08:49:48 +01:00
Oliver Gierke
e5ce6156f9 DATAREST-492 - Fixed JSON Schema type detection for primitive numbers.
We now correctly detect primitive numbers in domain objects so that the JSON Schema type of the property is number as expected.
2015-03-22 20:06:43 +01:00
Oliver Gierke
f80bebf04b DATAREST-491 - Fixed handling of non-entity maps in JSON processing.
During our custom JSON handling on PUT requests, we previously piped all JSON objects through code that expected that one to be mapped to a PersistentEntity. This fails for JSON objects that basically represent maps.

We now skip that code paths for non-entity properties.
2015-03-20 09:42:36 +01:00
Oliver Gierke
5486712b1b DATAREST-34 - Polishing.
Moved decision logic on whether to return response bodies int RepositoryRestConfig to ease testability of the controller. Added more unit tests and simplified the controller integration tests accordingly. Had to deactivate some Cassandra related tests as they don't seem to handle nulling of properties correctly.

Changed configuration to rely on the presence of the Accept header by default. Deprecated parameterless isReturnBodyFor…(…) methods in favor of the ones taking the Accept header to avoid the null checks on the calling side.

Polished JavaDoc for the isReturnBodyOn(Create|Update) methods. Polished formatting in RepositoryEntityController.

Original pull request: #167.
2015-03-20 08:50:47 +01:00
Jeremy Rickard
f3c74ac9db DATAREST-34 - PUT and POST request now consider Accept header by default.
By default, whether to return response bodies for PUT and POST is determined by the presence of an Accept header, unless explicitly activated or deactivated in RepositoryRestConfiguration.

Original pull request: #167.
2015-03-20 08:50:30 +01:00
Oliver Gierke
4f8298c711 DATAREST-490 - Makes sure content negotiation works for manual resource overrides with dedicated media type.
In case a manually implemented controller is registered to add a dedicated media type for a Spring Data REST resource (e.g. an HTML representation for item resources) we now continue to serve JSON in case the request indicates it wants to see it.

Previously this didn't work as the manually implemented controller method was detected to partially match (only the produces-clause not matching) and thus an exception being thrown from the HandlerMapping lookup. This caused the HandlerMapping registered for repositories not being considered at all.

This is now fixed by hiding the HandlerMapping instances we register behind a DelegatingHandlerMapping that continues to try delegates even in a case of an exception being caused in a particular resolution attempt. Should all resolution attempts fail, we then throw the original exception if one occurred in the first place.
2015-03-11 15:14:00 +01:00
Oliver Gierke
def74e6618 DATAREST-354 - General rewrite of the JSONSchema support.
Significant overhaul of the JSONSchema support. This currently adds the following features:

- Complex nested types are exposed as descriptors with the properties pointing to them whenever necessary.
- Sets are treated as unique collections.
- Enums are handled as expected (enum values are listed).
- Renamings via @JsonProperty are considered.
- @JsonProperty(required = true) is considered and added to required properties.
- Date/time types (legacy Date, JSR-310, ThreeTenBP and Joda Time) are exposed with format "date-time".
- Objects with @JsonValue methods are considered to be rendered as String value.
- Formats and patterns can be manually configured on MetadataConfiguration.

TODOs:

- Implementation polish, JavaDoc
- Automatically inspect ObjectMapper to detect customizations made through Mixins and custom Serializers.
2015-03-05 10:13:47 +01:00
Oliver Gierke
c532bb0d51 DATAREST-485 - Fixed handling of empty requests for RepositoryPropertyReferenceController.createPropertyReference(…).
The test case introduced for DATAREST-482 failed when running against Spring 4.1 generation as the handling of empty request payload changed slightly in 4.1. We now explicitly use required = false to get null handed into the controller and manually default the Resources<Object> in it.

Related tickets: DATAREST-482, SPR-12778.
2015-03-03 09:49:38 +01:00
Oliver Gierke
8b3b7bac98 DATAREST-482 - Added test cases for MongoDB association handling on PUTs.
Added a test case that verifies associations to stay intact if someone updates the item resource using a PUT. Added a second test case that shows PUTting an empty String with media type text/uri-list results in the associations wiped.
2015-02-26 11:48:08 +01:00
Oliver Gierke
0a542564bc 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.
2015-02-22 15:23:46 +01:00
Greg Turnquist
8d47fab92c DATAREST-463 - Hide ignored attributes from ALPS metadata.
If @JsonIgnore is applied to either a field or a getter method for an association, then do not expose that property's metadata down from ALPS.

Original pull request: #160.
2015-02-22 15:21:24 +01:00
Oliver Gierke
98fd079b21 DATAREST-469 - Added dedicated resource type for search links.
RepositorySearchController now returns a RepositorySearchesResources so that users can implement a custom ResourceProcessor to augment the list of links exposed for Spring Data repository query methods.
2015-02-09 10:52:37 +01:00
Oliver Gierke
ec2bd0145d DATAREST-471 - Populate Last-Modified headers from auditing information.
We now populate the Last-Modified header for requests to the item resource and search resource invocations that return a single item.
2015-02-04 21:03:57 +01:00
Oliver Gierke
14cee9c94f DATAREST-467 - RepositoryEntityLinks now exposes methods to create links to search resources.
RepositoryEntityLinks now exposes methods to obtain links to all search resources and individual ones, including overloads to pre-expand Pageable and Sort parameters potentially contained in the method signature.

Search links now also contain a projection template variable if the type returned by the query method backing the search resource has projections registered.
2015-01-30 20:46:03 +01:00
Oliver Gierke
fbd803f32a DATAREST-414 - Added retry logic to connect to embedded Cassandra.
The Cassandra tests sometimes cannot to the embedded instance on the CI server. Added a triple retry with a delay of 200ms to work around a potentially slow Cassandra bootstrap.
2015-01-21 15:24:13 +01:00
Oliver Gierke
c67b3e749d DATAREST-461 - Ignore unmapped properties when applying PUT requests.
We now make sure that unmapped properties (e.g. by using @JsonIgnore) are ignored when applying PUT request payloads. To do so we now basically use the merging algorithm used for PATCH requests but make sure we fill up the request payload with explicit null values for all mapped but not contained properties.
2015-01-21 14:44:48 +01:00
Oliver Gierke
1755a82fe2 DATAREST-460 - Polished RepositoryRestMvcConfiguration to fix CGLib proxying.
Made private methods that call @Bean methods protected so that they can become subject to CGLib proxying. Inlined getDefaultedRelProvider().
2015-01-20 10:39:21 +01:00
Neeme Praks
f755987a02 DATAREST-457 - Fixed typo in JavaDoc of BaseUri.
Original pull request: #159.
2015-01-20 08:00:50 +01:00
Oliver Gierke
65f45d6433 DATAREST-448 - RepositoryRestHandlerMapping is now checking for a repository mapping again.
Re-introduced the accidentally removed checks that the resolved handler method actually points to a repository resource.
2015-01-16 14:43:21 +01:00
Oliver Gierke
a2ba4224fb DATAREST-414 - Polishing.
Extracted groups of dependencies into auto-activated profiles to make more visible which dependencies belong to which store. Simplified dependency setup where possible.

General polishing in the test cases added.
2015-01-11 17:53:10 +01:00
Greg Turnquist
a31588cabc DATAREST-414 - Added integration tests for Cassandra.
Original pull request: #158.
2015-01-11 17:52:17 +01:00
Oliver Gierke
f09880ff16 DATAREST-437 - Moved to projections API of Spring Data Commons.
Related tickets: DATACMNS-630, DATACMNS-618.
2015-01-11 16:45:41 +01:00
Oliver Gierke
368b36951a DATAREST-434 - Forward root exception in PersistentEntityResourceHandlerMethodArgumentResolver. 2015-01-08 10:54:38 +01:00
Oliver Gierke
e39d624832 DATAREST-427 - Refactorings in UriToEntityConverter.
Instead of using a DomainClassConverter directly we now use a raw ConversionService in UriToEntityConverter. This allos us to get rid off the bean definitions for UriToEntityConverter and DomainClassConverter. The population of the ConversionService is now taken care of by calling SpringDataWebConfiguration's addFormatter(…) in defaultConversionService().

Added unit tests for UriToEntityConverter.
2015-01-05 13:55:07 +01:00
Oliver Gierke
ca8399316f DATAREST-431 - Switched to Formatters for Point and Distance of Spring Data Commons.
Dropped our Converter implementations for Point and Distance and rather use the ones provided through Spring Data Commons, the addFormatters(…) method of SpringDataWebConfiguration in particular.

Related ticket: DATACMNS-626.
2015-01-05 13:12:52 +01:00
Oliver Gierke
1c2201faa1 DATAREST-427 - Fixed NullPointerException in RepositoryRestExceptionHandler.
Handling HttpMessageNotReadableException in RepositoryRestExceptionHandler previously handed null to the badRequest(…) method resulting in an assertion failure in response(…) eventually. This is now fixed by handing in an HttpHeaders instance.
2015-01-05 12:17:35 +01:00
Oliver Gierke
55cf4cd9e0 DATAREST-429 - Improved handling of custom base paths.
Introduced a new property basePath on RepositoryRestConfiguration to allow a smooth migration to a new non-absolute base path configuration model to customize the URIs under which repository resources are exposed.

We're deprecating the current baseUri property as it previously supported absolute URIs. These are still supported but a warning is logged to ping users to move to the new base path based configuration.

We now use the base path to dynamically augment the mappings detected on our controllers with the path configured.
2015-01-03 16:32:16 +01:00
Oliver Gierke
e2a35e7ce9 DATAREST-424 - Registered HttpMessageConverters now implement Ordered.
To be able to control the order of the HttpMessageConverter beans registered by RepositoryRestMvcConfiguration we now use a dedicated subtype of TypeConstrainedMappingJackson2HttpMessageConverter which additionally implements Ordered.
2014-12-10 19:47:54 +01:00
Oliver Gierke
7c43512d1d DATAREST-423 - Fixed HandlerAdapterSetup to consider ConversionService.
The special RepositoryRestHandlerAdapter we set up for repository invocations didn't consider the ConversionService Spring Data REST sets up. This causes binding issues in case someone wants to override resource handling by declaring an @RepositoryRestController and using a domain type as handler method argument.

We now explicitly configure the RepositoryRestHandlerAdapter to use the ConversionService we set up and equip with Spring Data Commons' DomainClassConverter.
2014-12-09 13:03:08 +01:00
Greg Turnquist
11d02e12bc DATAREST-387 - Separated integration tests for individual stores.
Original pull request: #156.
2014-12-07 15:55:33 +01:00
Christoph Strobl
38d1b81a4d DATAREST-387 - Added integration tests for Spring Data Solr repositories.
Added configuration for setting up an EmbeddedSolrServer instance within a temporary directory. We use a temporary test folder created by JUnit where we copy the required configuration to. The directory will also hold all index data and will be deleted afterwards.

Original pull request: #156.
2014-12-07 15:55:33 +01:00
Oliver Gierke
28db79ef42 DATAREST-421 - Polishing of new exception handling infrastructure.
Removed leftovers from AbstractRepositoryRestController. Renamed GlobalExceptionHandler to RepositoryRestExceptionHandler and minimized visibility of exception handler methods. Restricted application of the exception handler to controllers in the Spring Data REST base package.

Relatted pull request: #155.
2014-12-05 10:27:00 +01:00
kakawait
e13be6badc DATAREST-421 - Extracted @ControllerAdvice class in order to allow easy overriding.
Original pull request: #155.
2014-12-05 10:26:56 +01:00
Oliver Gierke
7f990b006b DATAREST-388 - Improved annotation based event handling.
The annotation based event handling now relies on the type of the first method argument to determine the domain type the handler is interested in. Improved method invocation to not unnecessarily wrap exceptions thrown from them. Changed the test cases to throw a dedicated runtime exception to implicitly test that the 

Renamed LinkSaveEvent to LinkedEntityEvent as it's not only used for save-events for entities. Make use of Methods' USER_METHOD filter. Moved the class into the util package. Removed the UUID converter as Spring's DefaultFormattingConversionService provides it out of the box.

Added missing license headers and JavaDoc. Deprecated Class<?> attributes on handling annotations.

Related pull request: #151.
2014-12-04 20:25:20 +01:00
Oliver Gierke
a32d1867b4 DATAREST-160 - Polished support for ETag headers based on version properties.
Introduced a dedicated value object for ETags and moved the logic of ETagValidator into it. Switched from an annotation based injection model to a type based one.

The HTTP status code for a non-matching ETag is now 412 Precondition failed as the HTTP specification suggests.

Original pull request: #148.
2014-11-28 22:23:59 +01:00
Pablo Lozano
8fe634cb0d DATAREST-160 - Added support for ETag/If-Match based on entity's version property.
Original pull request: #148.
2014-11-28 22:23:59 +01:00
Oliver Gierke
4b6e5bffc3 DATAREST-417 - Adapt to type reorganization in Spring Data Commons. 2014-11-25 11:37:56 +01:00
Oliver Gierke
afd1027d36 DATAREST-416 - Switched to IdentifierAccessor API where needed.
We now use the newly introduced IdentifierAccessor API to make sure we benefit from store specific optimizations when looking up identifier values.

Added some user class lookups to make sure the projection and resource mapping lookup works if proxies types are handed around.
2014-11-24 13:25:43 +01:00
Oliver Gierke
780d674012 DATAREST-415 - Moved to PersistentPropertyAccessor API.
We now use the PersistentPropertyAccessor provided by the PersistentEntity to lookup property values to benefit from store-specific customizations. Code that relies on value conversion by using a ConversionService now explicitly uses a ConvertingPropertyAccessor.

Related tickets: DATACMNS-596.
2014-11-24 13:22:08 +01:00
Oliver Gierke
458cdfa7e8 DATAREST-409 - Port RepositoryInvoker API to Spring Data Commons.
Introduced SupportedHttpMethods abstraction to be able to test the exposure of HTTp methods based on a CrudMethods instance only. Moved ResourceType to the core module.
2014-11-14 16:49:31 +01:00
Oliver Gierke
dbeec0a5de DATAREST-227 - Renamed WebTestUtils to TestMvcClient.
Renmaed WebTestUtils to TestMvcClient, added assertions to constructor and fixed formatting of JavaDoc.

Original pull request: #149.
2014-11-10 16:54:38 +01:00
Greg Turnquist
e304e14527 DATAREST-227 - Broke up AbstractWebIntegrationTest and its subclasses.
Decouple the test machinery of this class from the barrage of common test cases used against the various data stores. This way, other test suites that use the same integration approach don't have to be a part of this class hierarchy. Also move utilities and assertion methods into separate utility classes to slim down the class hierarchy.

Original pull request: #149.
2014-11-10 16:54:35 +01:00
Oliver Gierke
8504a8837c DATAREST-384 - Fixed affordances and execution of sortable search resources.
Search resources are now considered sortable if they contain a Sort parameter. This is now reflected in MethodResourceMapping.isSortableResource().

Building on top of that, the RepositorySearchController now appends the sort template variable to links generated when listing search resources. It also now accepts resolved Sort instances to forward them to the query method execution. The controller now also uses DefaultedPageable so that request missing pagination information use the defaults configured for the PageableHandlerMethodArgumentResolver.
2014-10-15 13:30:53 +02:00
Oliver Gierke
1e0e3f0ad4 DATAREST-381 - Improved HandlerMapping infrastructure to make sure controllers consider base URI.
Removed class-level @RequestMapping annotations as the controllers get picked up by standard Spring MVC and are exposed via the root even if a base URI is configured. Created custom @BaseUriAwareController and use that in AlpsController to make sure it doesn't get picked up by Spring MVC.
2014-09-05 15:44:47 +02:00
Oliver Gierke
2d64fb4d84 DATAREST-326 - Improved configuration setup for better Boot compatibility.
We now don't expose the PersistentEntityJackson2Module as bean anymore to prevent global registration in case of a Boot setup. The HttpMessageConverters registered are now TypeConstrainedMappingJackson2HttpMessageConverters so that they only get used of the object to marshal is of type ResourceSupport.
2014-07-25 16:33:07 +02:00
Oliver Gierke
aa28aebca5 DATAREST-353 - Fixed potential NullPointerException when trying to delete a non-existing resource.
We now correctly return a 404 Not Found in case we receive a DELETE request for a resource not existing.
2014-07-16 17:44:02 +02:00
Oliver Gierke
b29fea84e9 DATAREST-333, DATAREST-348 - OPTIONS requests now expose Accept-Patch header.
As recommended in RFC 5789, the support for PATCH request should be advertised in OPTIONS requests (already in place) and include an Accept-Patch header listing the patch media types supported. We now include the media types for JSON Patch, JSON Merge Patch and plain JSON in that header.

[0] http://tools.ietf.org/html/rfc5789#section-3
2014-07-10 17:07:55 +02:00
Oliver Gierke
020de45c1b DATAREST-230 - Support for serving Alps documents.
This commit adds the support to expose additional resources that serve ALPS [0] resources to document the available state transitions and representations. The exposure is enabled by default and can be customized using the RepositoryRestConfiguration.metadataConfiguration() object.

Currently the set of descriptors exposed includes:

- A descriptor for the representation of the domain type. Linkable associations are represented as safe descriptors, ones that are not linked are semantic descriptors.
- Descriptors for each supported HTTP method for both the collection and item resources to indicate the ability to update, create, delete etc.
- Safe descriptors (e.g. to access the collection or item resource) get potentially available customizations (pagination, projections) attached through nested descriptors.

Documentation

An ALPS descriptor contains a doc attribute to carry semantic information for the end user or a potential client to display. The information can be described in two ways: the first one is the @Description annotation that captures the plain text information one wants to get listed. It is supported in @RepositoryRestResource, on query methods, projection interfaces and accessors etc.

The preferred approach however is to use a resource bundle rest-messages.properties. For each descriptor we will resolve a key starting with rest.description followed by a dot path into the resource. By default, doc attributes are only rendered if the resource bundle contains an entry for the relevant key. You can enforce displaying unresolved keys by configuring MetadataConfiguration.omitUnresolvableDescriptionKeys(…).

For representation descriptors and and the parameter list of query method descriptors we will display enum values by default as comma-separated list. The list is also available as message resolution argument, so that you can refer to the list in your description message via the {0} placeholder.

TODOs:

- Improve descriptors for associations (indicate ability to update etc.)

[0] ALPS - http://alps.io
2014-07-10 17:07:55 +02:00
Oliver Gierke
ef3720be11 DATAREST-348 - Support for json-patch+json and merge-patch+json media types.
We now support PATCH request with application/json-patch+json [0] and application/merge-patch+json media types. The support is based on some customized usage of the FGE JSON Patch library [2]. 

As we need to apply the patch to an existing object, we need translate the JSON Patch remove operation into a replace operation setting the value to null so that out entity processing component registers the request for removal. Same applies to requests for merge-patch+json.

From an implementation point of view the handling of the media type has moved from the controller into PersistentEntityResourceHandlerMethodArgumentResolver and its delegates, n particular JsonPatchHandler. The application of the changes to the existing domain object is handled in the newly introduced DomainObjectReader.

Related ticket: DATAREST-345.

[0] http://tools.ietf.org/html/rfc6902
[1] http://tools.ietf.org/html/draft-ietf-appsawg-json-merge-patch
[2] https://github.com/fge/json-patch
2014-07-08 14:04:47 +02:00
Oliver Gierke
e6949f8a46 DATAREST-340 - AssociationOmittingSerializerModifier now keeps non-persistent property writers.
AssociationOmittingSerializerModifier previously dropped the writer fro a particular property if it couldn't find a PersistentProperty for the bean property. We now keep those writers to make sure that non-persistent, additional fields are written as well.

Related issues: https://github.com/spring-projects/spring-boot/issues/1190
2014-06-30 13:31:16 +02:00