Commit Graph

379 Commits

Author SHA1 Message Date
Oliver Gierke
0dabf8d376 DATAREST-341 - Upgraded to Spring HATEOAS 0.14.0.RELEASE. 2014-06-30 14:08:55 +02:00
Oliver Gierke
ed77540a81 DATAREST-335 - ReflectionRepositoryInvoker correctly handles overridden delete(…) methods.
If a delete(…) method was overridden using the concrete id type, the check on invocation of course has to accommodate the concrete id type and not serializable only. 

We previously erroneously attempted a to-entity-conversion by invoking findOne(…) and then handed that result to the delete(…) method which caused an IllegalArgumentException as the argument wasn't matching the parameter type. We now explicitly check for the concrete id type in the first place and even bypass any kind of parameter conversion.
2014-06-27 17:05:15 +02:00
Oliver Gierke
57732db3ad DATAREST-327 - DomainObjectMerger doesn't merge empty collections.
The association handling in DomainObjectMerger is in place to allow the creation of resources using PUT that have non-optional associations. However, if the domain types that the request payload was unmarshalled into use default values - in particular empty collections to avoid nulls - the merger cannot really distinguish between the default set in the type versus an empty collection being submitted through the request.

As the usecase here is creation only we can safely ignore empty collections as submitting those doesn't make a difference anyway (no related items attached). By ignoring those, we fix the issue defaulted empty collections in the type definitions being considered as value to set.
2014-06-20 13:55:32 +02:00
Oliver Gierke
173d528e47 DATAREST-325 - ReflectionRepositoryInvoker now makes method accessible before invoking.
This allows methods in package protected repository interfaces to be invoked successfully.
2014-06-20 11:52:34 +02:00
Oliver Gierke
3969c34940 DATAREST-317 - Support for excerpt projections.
This commit adds a mechanism to define excerpt projections to be rendered for exposed repositories. The main user facing mechanism is the addition of the excerptProjection attribute to @RepositoryRestResource. This attribute takes a type which has to be a projection interface (see DATAREST-221 for more information about the general mechanism).

If such a excerpt projection is in place, it will be used by default when rendering instances of the domain type in _embedded clauses or if it is related to.

class Person {

  String name;
  int age;
  Person father;
  Person mother;
  Set<Person> siblings:
}

interface PersonExcerpt {
  String getName();
}

If PersonExcerpt is now configured as excerpt projection for Person the collection resource for people will return:

{ _embedded : {
    people : [{
      name : "Some name",
      _embedded : {
        mother : { name : "…" },
        father : { name : "…" },
        siblings : [ … ]
      },
      _links : { self : { href : "…" }}
    }, … ]
  }
}

Here you can see how the age property is omitted when rendering a person in a collection. Also each person contains the excerpt projections of related resources and the links to them omitted. If you now follow the link to the item resource, you'll something like this:

{ name : "Some name",
  age : 34,
  _embedded : {
    mother : { name : "…" },
    father : { name : "…" },
    siblings : [ … ]
  },
  _links : {
    self : { href : "…" },
    mother : { href : "…" },
    father : { href : "…" },
    siblings : { href : "…" }
  }
}

Note, that age appears, as the representation is now rendered entirely. We also see the excerpts of related resource but also the links pointing to them in case you want to manage them.
2014-06-12 13:16:12 +02:00
Spring Buildmaster
2db0203817 DATAREST-306 - Prepare next development iteration. 2014-05-20 20:04:39 +02:00
Spring Buildmaster
c67f79d5ae DATAREST-306 - Release version 2.1.0.RELEASE. 2014-05-20 20:04:39 +02:00
Oliver Gierke
e9e4da3062 DATAREST-306 - Prepare 2.1 GA. 2014-05-20 20:04:32 +02:00
Spring Buildmaster
cafa6f7931 DATAREST-297 - Prepare next development iteration. 2014-05-02 06:15:33 -07:00
Spring Buildmaster
5693af6f2a DATAREST-297 - Release version 2.1.0.RC1. 2014-05-02 06:15:31 -07:00
Oliver Gierke
358ff1bda8 DATAREST-297 - Prepare 2.1.0.RELEASE.
Upgraded to Spring HATEOAS 0.11.0, Spring Plugin 1.1.0 and Evo Inflector 1.1.
2014-05-01 20:52:29 +02:00
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
Spring Buildmaster
d0ccd7251d DATAREST-257 - Prepare next development iteration. 2014-03-31 08:33:17 -07:00
Spring Buildmaster
b5b5b94f01 DATAREST-257 - Release version 2.1.0.M1. 2014-03-31 08:33:14 -07: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
Spring Buildmaster
b16b2e0ec6 DATAREST-249 - Prepare next development iteration. 2014-02-25 07:45:29 +01:00
Spring Buildmaster
fb73b52be7 DATAREST-249 - Release version 2.0.0.RELEASE. 2014-02-24 10:00:15 -08: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
Spring Buildmaster
84880ffe5e DATAREST-226 - Prepare next development iteration. 2014-01-29 06:40:33 -08:00
Spring Buildmaster
3a87ad8d49 DATAREST-226 - Release version 2.0.0.RC1. 2014-01-29 06:40:30 -08:00
Oliver Gierke
20a407d40c DATAREST-226 - Prepare 2.0 RC1 release.
Upgraded to Spring Data RC modules, Spring HATEOAS 0.9.0.RELEASE and Spring Plugin 1.0.0.RELEASE. Removed placeholder for Jackson 2 version as it's in the parent build pom now. Switched to milestone repository.
2014-01-29 15:35:46 +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
f02000e619 DATAREST-224 - Introduce Maven POMs.
Adapted JpaWebTests to compile on Java6. Fixed some broken test case in Neo4jWebTests.
2014-01-20 10:18:44 +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