Commit Graph

59 Commits

Author SHA1 Message Date
Oliver Gierke
b73ae0fd1b DATAREST-298 - Fixed rel lookup in RepositoryMethodResourceMapping.
In case @RestResource was used to customize the path a method resource was mapped to, we didn't correctly fall back to the method name as rel in case no rel was configured explicitly.

We now check for a rel being configured and fall back to the method name if we don't discover manual configuration.
2014-04-29 12:29:48 +02:00
Oliver Gierke
7dfdaa5114 DATAREST-294 - RepositoryRestConfiguration has more fine grained control over media type defaults.
RepositorRestConfiguration now has a ….useHalAsDefaultJsonMediaType() which defaults to true. Configuring this to false allows to still use HAL as default media type in case no Accept header is set or it is set to */*. The flag decides what to return when an Accept header is set to application/json.
2014-04-29 10:09:15 +02:00
Oliver Gierke
45ef259826 DATAREST-292 - Fixed application of configured base URI.
Major overhaul of mapping detection in RepositoryRestHandlerMapping. We now correctly map URIs if a base URI is configured via RepositoryRestConfiguration.
2014-04-23 17:56:28 +02:00
Oliver Gierke
05fa30abc1 DATAREST-277 - Adapted to changed generics in BeanWrapper. 2014-03-21 11:39:31 +01:00
Oliver Gierke
572690b888 DATAREST-155 - Introduce API to alter exposed backend ids.
Introduced BackendIdConverter SPI to be able to register custom components that will be used during URI construction and URI parsing to determine the actual backend identifier.

To register a custom BackendIdConverter simply declare a bean definition for it in the ApplicationContext. The Spring Data REST URI creation infrastructure (RepositoryEntityLinks in particular) will pick it up transparently.
2014-03-11 18:13:22 +01:00
Oliver Gierke
ba71362c15 DATAREST-221 - Improvements in ProxyProjectionFactory.
PropertyAccessingMethodInterceptor now ignores Object methods and forwards them to the proxy target. ProxyProjectionFactory now correctly sets up the SpEL root object for reference in expression on accessors.
2014-03-11 10:36:47 +01:00
Oliver Gierke
6e0d153e08 DATAREST-221 - Improved return type matching in ProjectingMethodInterceptor.
We're now using Spring's ClassUtils.isAssignableFrom(…) to make sure we match primitives and wrapper types as well.
2014-03-07 19:47:35 +01:00
Oliver Gierke
1d53e84cae DATAREST-262 - Support for associations in nested types.
Previously we only handled URIs to associations on the root object level as the mapping information for potentially nested embeddables were not accessible via the Repositories instance. This is now fixed by switching to the newly introduced PersistentEntities.

Related tickets: DATACMNS-457, DATACMNS-458, DATAJPA-484.
2014-03-03 18:13:01 +01:00
Oliver Gierke
84ed09c735 DATAREST-261 - Fixed RepositoryRelProvider registration.
We now register a RepositoryRelProvider that hadn't been exported before so that clients using a RelProvider will automatically see potentially customized rels for repositories.

Changed RepositoryRelProvider to lazily depend on the ResourceMappings as will be requested eagerly for injection into the configuration class itself.
2014-02-27 14:51:44 +01:00
Oliver Gierke
af7e15b8e6 DATAREST-221 - Added support for projections.
This commit introduces support to access resources via projections, which means naming a dedicated set of properties of the entity to be exposed and being able to refer to that set through a request parameter.

## General usage

Projections are defined as interfaces that mimic the properties of the domain class to be exported:

@Projection(types = Customer.class, name = "summary")
interface Summary {
  String getFirstname();
  String getLastname();
  AddressSummary getAddress();
}

interface AddressSummary() {
  String getZipCode();
}

The projection interface can be annotated with @Projection to be auto-discovered. We scan all packages in which we find domain types to be exported for projection types and auto-register them. For manual registration, use RepositoryRestConfiguration.projectionDefinitionConfiguration().addProjection(…) and manually register them.

If a projection is registered for a given type, this will be indicated via a "projection" template variable in the URI pointing to resources with projections. The name of the variable can also be configured on ProjectionDefinitionConfiguration.

## Internals

The projection interfaces are consider bean property delegates by default. This means, that for the above interfaces we will lookup the firstname, lastname and address property of the projection target. In the case of address we re-project the result of the proxy target invocation with a sub-projection onto AddressSummary.

For more advanced use-cases you can annotate a method of the projection interface with @Value and use a SpEL expression to invoke further functionality and return that to be rendered:

interface MyProjection {

  @Value("#{@myBean.someMethod(target)}")
  SubProjection getValue();
}

This projection would call the someMethod(…) method on a Spring bean named myBean handing the proxy target to the method. The result will be projected in turn onto a type called SubProjection.

As the projection objects are exposed to Jackson as is, they can be annotated with Jackson annotations to further customize the representation.
2014-02-27 08:48:58 +01:00
Oliver Gierke
3e5914d84f DATAREST-248 - Significant overhaul in entity serialization and deserialization.
Refactored PersistentEntityJackson2Module to move a lot of the customization logic into Bean(De)SerializerModifiers. Those allow to modify the Jackson metadata for a given type programmatically so that we can register the appropriate (de)serializers for associations. 

On the serializing side of things this allows us to easily turn associations into links and simply delegate to object serialization as the delegation will simply ignore the association properties as they have been dropped using the modifier. This solves the advanced requirements of DATAREST-117 nicely as all non-association properties are serialized using standard Jackson means so that all customizations apply.

On the deserialization side, we now support URIs as values for association properties to be able to submit references for non-optional associations on creation.

Related issue: DATAREST-117.
2014-02-19 11:44:46 +01:00
Oliver Gierke
b3b091e309 DATAREST-95 - General overhaul of HTTP method handling.
Code polishing in DomainObjectMerger and related test cases. Fixed the related test cases. Cleanups in ControllerUtils to remove unneeded constants and make sure we really render no content for empty responses.

Refactorings in controller classes to reduce code duplication. We now do not allow POST requests for partial updates to property reference resources anymore but require the usage of PATCH.

Tweaked test helper methods to correctly implement basic interaction patterns.

Related pull request: #127.
2014-02-14 13:25:35 +01:00
Greg Turnquist
d65179ccc8 DATAREST-95 - Add support for PATCH to partially update entities.
Added general support for HTTP PATCH to partially update entities and amend property resources.
2014-02-14 13:08:13 +01:00
Oliver Gierke
c662065ef2 DATAREST-216 - Added integration test.
Forgot to commit integration test with 5dd33b.

Related pull request: #126.
2014-02-14 10:26:57 +01:00
Oliver Gierke
922827fe56 DATAREST-217 - Significant overhaul of HTTP method support detection.
Refactored the way the general support for an HTTP method for the resource exported. The decision is implemented in RootResourceInformation (formerly RepositoryRestRequest). Removed request specific information from that class and introduced a HandlerMethodArgumentResolver to be able to inject HttpMethod instance into controller methods (filed https://jira.springsource.org/browse/SPR-11425 to get that support into Spring Framework itself).

Generally moved away from throwing NoSuchMethodExceptions and correctly expose HttpRequestMethodNotSupportedException instead to make sure Spring MVC renders the appropriate allowed methods if possible.

Removed RepositoryInvokerHandlerMethodArgumentResolver as a RepositoryInvoker can be obtained from the RootResourceInformation where necessary.

Related pull request: #125.
2014-02-14 10:26:45 +01:00
Oliver Gierke
5dd33ba7c0 DATAREST-216 - CrudRepositoryInvoker considers redeclared methods correctly.
CrudRepositoryInvoker now detects re-declared CRUD methods and falls back to reflection invocation if the re-declaration is detected.

Inspired by PR #126 by Nick Weedon but avoiding the introduction of a dependency to Spring Security by using a more precise testing approach.

Original pull request: #126.
2014-02-13 10:28:19 +01:00
Oliver Gierke
13d90efbca DATAREST-246 - ValidatingRepositoryEntityListener now uses ObjectFactory<Repository>.
ValidatingRepositoryEntityListener previous referred to a Repositories instance which causes a circular reference on initialization after some changes in Spring Data Commons Repositories.

Major cleanups in the ValidatingRepositoryEntityListener implementation.
2014-02-12 16:03:59 +01:00
Oliver Gierke
bd8d3afa65 DATAREST-219 - Polishing.
Generally polished implementation and test cases for Greg's contribution.
Re-ordered parameters in ControllerUtils' helper methods for consistency.
Use Spring's CollectionFactory to create a suitable collection for the handled properties in the first place to avoid unnecessary conversion later on.

Removed duplication in test cases. Polished JavaDoc in UriListHttpMessageConverter and moved to a Scanner based implementation to read the request body. 

Adapted to latest changes in Spring HATEOAS. Reactivated ResourceStringUtilsTests.

Related pull requests: #128, #86.
2014-01-24 16:03:22 +01:00
Oliver Gierke
d59ec3bdd4 DATAREST-233 - Introduced @RepositoryRestResource.
@RepositoryRestResource exposes more detailed attributes tailored to the use case of exposing a repository. @RestResource is still recognized on repository interfaces but we now issue a warning and indicate the new annotation to be used.

Introduced a minimal ResourceDescription interface and let @Description be used within @RestResource and @RepositoryRestResource. We now generate default resource bundle keys and resolve them against a "rest-messages" resource bundle by default. JsonSchema converter now uses the rendered descriptions for schema descriptions.
2014-01-24 15:17:14 +01:00
Oliver Gierke
88b2f05edf DATAREST-229 - RepositoryEntityLinks now exposes templated links.
If the resource exposed for a domain or repository type is considered a paging resource we now return a templated URI. Introduced ResourceMapping.isPagingResource() to allow clients to find out about whether the resource is actually capable of pagination. Adapted implementations to inspect the findAll(…) method as well as the search methods for a Pageable parameter.

Tweaked pom.xml to create correct classpaths if the IDE uses direct workspace project references.
2014-01-23 17:11:34 +01:00
Oliver Gierke
4b6f0f620a DATAREST-31 - Search links are now rendered as link templates.
MethodResourceMapping now exposes the parameters a query method expects. The RepositorySearchController the uses these to append the 

Upgraded to Spring Data Commons 1.7.0.BUILD-SNAPSHOT.
2014-01-17 13:28:10 +01:00
Oliver Gierke
5ff6457911 DATAREST-222 - Path now quotes reference before matching.
We now actively quote the String reference to match a path against as it most likely is not a regular expression.
2014-01-17 13:22:04 +01:00
Oliver Gierke
074c77cc3e DATAREST-107 - Polishing test cases.
Extracted DATAREST-107 specific test cases into separate test method.
2014-01-14 10:28:34 +01:00
Greg Turnquist
bc30b74cbe DATAREST-107 - Add tests to verify ambiguous mapping detection. 2014-01-14 10:28:00 +01:00
Phillip Webb
e7ce0e3f0b DATAREST-107 - Respect @RestResource exported flag on query methods.
ResourceMappings now only adds a RepositoryMethodResourceMapping if it's really exported.
2014-01-14 10:18:23 +01:00
Oliver Gierke
7c66a217be DATAREST-130 - Polished test implementation.
JavaDoc, formatting, simplified implementation.
2014-01-14 10:15:53 +01:00
Greg Turnquist
d32e69c1d3 DATAREST-130 - Added test case for DomainObjectMerger. 2014-01-14 10:12:07 +01:00
Oliver Gierke
4e5fa30282 DATAREST-130 - Code polish and JavaDoc. 2014-01-14 10:11:33 +01:00
Willie Wheeler
eafdc4771e DATAREST-130 - Support nulling out properties when doing HTTP PUTs. 2014-01-14 10:11:14 +01:00
Oliver Gierke
af520871dc DATAREST-203, DATAREST-75 - Initial support for HAL.
This commit introduces support for HAL rendering and making it the default rendering option. The configuration now registers an additional MappingJackson2HttpMessageConverter with the according HAL modules registered and makes this the default JSON renderer if the default media type is configured to HAL (which it is by default). To change this, set RepositoryRestConfiguration.setDefaultMediaType(…) back to application/json.

Refactored the PersistentEntityJackson2Module to turn the PersistentEntityResource into it's correct shape (turning associations into links) and the delegate to the default rendering, so that the HAL customizations provided by Spring HATEOAS can kick in. Adapted test cases to the change in default representation format.


Upgraded to Jackson 2.3.0, Spring 3.2.6 and Spring HATEOAS 0.9.0.BUILD-SNAPSHOT. Upgraded to Gradle 1.10.
2013-12-19 16:31:29 +01:00
Oliver Gierke
4ee1850a37 DATAREST-93 - Improvements after API updates in Spring Data Commons.
Switched to the usage of Simple(Property|Association)Handler to avoid having to use raw PersistentProperty instances.
2013-11-14 10:04:28 +00:00
Oliver Gierke
8f2e3eb4fe DATAREST-163 - Fixed rendering of embedded documents for MongoDB.
Removed the attempt to add a link to the response for non-associations. Switched to the usage of Simple(Property|Association)Handlers for simplified generics.
2013-11-14 10:04:28 +00:00
Oliver Gierke
9b4b111d23 DATAREST-93 - Cleanups in repository invoker area.
Made RepositoryInvokerFactory an interface and renamed the previously existing implementation class to DefaultRepositoryInvokerFactory. Removed instantiation of the class from ResourceMetadataHandlerMethodArgumentResolver to keep the logic which implementation to use solely in the configuration.
2013-11-14 10:03:48 +00:00
Oliver Gierke
cb4770db56 DATAREST-162 - PersistentPropertyResourceMapping now considers @RestResource.
PersistentPropertyResourceMapping now inspects the @RestResource annotation on the property if it is present.
2013-11-14 10:03:48 +00:00
Oliver Gierke
6260d3fba9 DATAREST-93 - Code cleanups.
Added missing license header. Polished code in RepositoryEntityController.
2013-10-01 17:41:50 +02:00
Oliver Gierke
9acad5d55d DATAREST-111 - Slightly raised precedence of RepositoryRestHandlerMapping.
Set order of RepositoryRestHandlerMapping to LOWEST_PRECEDENCE - 100 to give core Spring Framework components the chance to hook into the right place in the chain.

Refactored RepositoryRestHandlerMapping to really check for the exposed path and added test cases for handler method resolution.
2013-08-21 12:19:46 +02:00
Oliver Gierke
252efc5196 DATAREST-112 - Moved property mapping into PropertyResourceMapping.
PersistentEntityJackson2Module now entirely relies on the property mapping to do the right thing for link creation. The PropertyResourceMapping now returns the property name for both rel and path.
2013-08-21 10:20:37 +02:00
Oliver Gierke
d2c2ec8262 DATAREST-93 - More cleanups.
Merged core and repository modules into core. Renamed some packages for consistency in naming and in preparation to break up some package cycles. Removed @BaseUri and the according resolver. Refactored controllers a bit to have more reusable chunks of code.
2013-07-24 12:59:23 +02:00
Oliver Gierke
a4d8a22428 DATAREST-93 - Further refactorings and refinements regarding the search resource mapping. 2013-07-12 14:20:32 +02:00
Oliver Gierke
c5a592bd9d DATAREST-93 - Further fixes in repository mappings.
Simplified new RepositoryMappings infrastructure. Integrated EvoInflectionRelProvider to build collection resource rels. Bumped version number to 2.0 as we're going to break backwards compatibility with the next release to straighten out the rel construction and mapping.
2013-06-18 19:17:56 +02:00
Oliver Gierke
5c61632ec2 DATAREST-93 - Fixed formatting in Spring Data REST.
Added formatter to be used within Eclipse going forward.
2013-06-18 16:21:34 +02:00
Oliver Gierke
90c4b62428 DATAREST-93 - Removed compiler warnings.
Removed dependency on jMock.
2013-06-11 15:01:03 +02:00
Oliver Gierke
cb4056e351 DATAREST-94 - Removed dependency to Guava.
Introduced simple Function interface. Replaced usage of Multimap with Spring's MultiValueMap.
2013-06-05 22:13:00 +02:00
Jon Brisbin
6ef500804b Tweak abstract base tests. 2013-03-02 11:50:09 -06:00
Jon Brisbin
6e4e7da142 Incorporated recent changes to Spring Data Commons and dependent projects that obsoleted the need to manage domain object metadata within Spring Data REST. Required updating to the latest snapshots available for spring-data-commons and spring-data-jpa.
Additional changes include:

* Re-wrote the monolithic Controller into separate controller classes that have a more narrow focus.
* Implemented common functionality as a `HandlerMethodArgumentResolver` rather than as a helper method in a controller class.
* Re-implemented JSONP functionality as an HttpMessageConverter rather than inline within a controller class.
* Updated to Jackson 2 for all JSON handling.
* By relying on spring-data-commons, spring-data-rest now handles all supported Repository types: JPA, MongoDB, and GemFire.

Added support for MongoDB and GemFire repositories by relying on spring-data-commons to provide the metadata rather than maintaining internal metadata information that is store-specific.

Replaced Spock spec tests with JMock unit and integration tests. Started integrating Jetty 8 into the testing so MVC testing can be done against a live server.
2013-01-18 10:14:29 -06:00
Jon Brisbin
5cfa242a8d Added package-info 2012-10-17 12:51:23 -04:00
Jon Brisbin
40645673bf Integrated Spring HATEOAS. 2012-08-27 15:16:02 -05:00
Jon Brisbin
3aa8905b15 Added configuration property for domain type to repository mappings. Also improved the post-processing support, though I think there's still some room for tweaking. 2012-08-20 15:06:15 -05:00
Jon Brisbin
d7e2e53ce2 Implemented a new style of JSON serialization and deserialization by registering Repository-aware components with Jackson's underlying ObjectMapper. This has the benefit of allowing us to transliterate domain objects into link representations and back again, no matter where those entities appear in complex nested object graphs. 2012-08-15 14:31:57 -05:00
Jon Brisbin
d2c6ecacc5 Tweaking fluent bean utils by adding fallback to Field access. 2012-08-15 14:28:23 -05:00