Commit Graph

98 Commits

Author SHA1 Message Date
Oliver Gierke
3a6b9ea3ff DATAREST-699 - Fixed pageable parameters showing up as is in search resource links on Java 8.
We now explicitly drop parameters of type Pageable and Sort from being exposed as search resource parameters as they're added via the UriComponentsContributors anyway. This prevents "pageable" from showing up as parameter on Java 8 code compiled with -parameters. The latter adds naming information for the Pageable parameter and caused it showing up as is despite the fact that the UriComponentsContributor for Pageables exposes a dedicated syntax.
2015-11-06 16:36:47 +01:00
Oliver Gierke
9280a4e4b6 DATAREST-655 - Fixed type in exception message for parameter checks of ParameterMetadata. 2015-08-21 16:00:16 +02:00
Oliver Gierke
06b6b266db DATAREST-654 - Added suport for internationalization of enum values.
RepositoryRestConfiguration now exposes an option to enable enum value serialization and a nested configuration object to tweak the details.

If enabled, a Jackson serializer and deserializer is registered trying to resolve the enum values from the Spring Data REST resource bundle using the fully-qualified enum value name as key. If no explicitly configured value is configured a default translation is triggered that capitalizes the lowercased value name replacing the underscores with spaces (e.g. PAYMENT_EXPECTED -> Payment expected). This can be opted out of, of course.

On the parsing side the deserializer will also consult the resourcebundle and default translation but also accepting the enum name as is (also opt-outable).

Deprecated non-bean-style accessors for projection and metadata configuration on RepositoryRestConfiguration to make these options tweakable via Spring Boot application properties by default.
2015-08-21 15:22:27 +02:00
Oliver Gierke
d4dbeb93a0 DATAREST-644 - Improvements to JSON Schema output.
Fixed JSON Schema output use "definitions" keyword instead of the previously used wrong "descriptors".

We now also include the title attribute for properties, using rest.description.$type.$property._title as i18n key. Titles are now also defaulted to the camel-case property name split up, lowercased and capitalized, e.g. "orderDate" will become "Order date".

JacksonMetadata now allows obtaining the Jackson serializer being used for a given type and exposes whether a property is considered read-only for Jackson.

Introduced JsonSchemaPropertyCustomizer to potentially tweak the JSON schema property definition. This is helpful in case custom JsonSerializers are implemented to also reflect the change in representation in the schema.
2015-08-14 19:13:23 +02:00
Oliver Gierke
5b0b368353 DATAREST-625 - Removed references to BeanWrapper.
DomainObjectMerger is now using the PersistentPropertyAccessor API instead of the BeanWrapper.

Related ticket: DATACMNS-738.
2015-07-22 21:09:56 +02:00
Oliver Gierke
de5a98d47b DATAREST-606 - Polishing.
Moved the accessibility tweak to the EventHandlerMethod's constructor so that the modification only occurs at detection time. Polished unit test.

Original pull request: #187.
2015-07-19 12:53:47 +02:00
Fabian Trampusch
698643cf18 DATAREST-606 - Allow non-public @RepositoryEventHandler methods.
AnnotatedEventHandlerInvoker now makes sure the method about to be invoked is accessible.

Original pull request: #187.
2015-07-19 12:52:34 +02:00
Oliver Gierke
be8964c465 DATAREST-582 - Fixed potential double invocation of annotated event handlers.
AnnotatedEventHandlerInvoker now uses the user class to detect handler methods on to make sure we don't accidentally find CGLib generated methods and thus invoke the handler multiple times later on.

Extended MethodFilter Methods.USER_METHODS to filter methods on CGLib proxy classes, too.

Added missing license header and Javadocs where necessary.
2015-07-06 12:30:05 +02:00
Oliver Gierke
290c1886f0 DATAREST-577 - Excerpt projections are now configured automatically.
Excerpt projections defined in @RepositoryRestResource had to be discoverable (i.e. located in a sub-package of the domain type). RepositoryRestMvcConfiguration now uses an newly introduced constructor of ProjectionDefinitionConfiguration that automatically registers all projects in the given ResourceMappings.
2015-06-16 15:24:31 +02:00
Oliver Gierke
e4277378a0 DATAREST-553 - Polishing.
Removed obsolete logger in RepositoryRestConfiguration. Removed obsolete Commons IO dependency from POM.

Original pull request: #178.
2015-06-01 13:38:34 +02:00
Greg Turnquist
07986acc54 DATAREST-553 - Removed RepositoryRestConfiguration.setBaseUri(…).
Updated existing unit tests to use setBasePath. Added extra assertion to setBasePath to guard against sending in a URI with a protocol.

Original pull request: #178.
2015-06-01 13:38:34 +02:00
Oliver Gierke
f2d8a996bc DATAREST-523 - Re-enabled POST for collection based association resources.
We now support augmenting elements of a collection resource by using POST which previously only worked with PATCH requests. Took the chance to clean up RepositoryPropertyReferenceController by quite a bit and refactor functionality to discover the supported HTTP methods for a PersistentProperty into RootResourceInformation.
2015-05-19 15:36:56 +02:00
Oliver Gierke
17305f4067 DATAREST-479 - Empty collections now render a dedicated _embedded property.
Instead of rendering an empty _embedded document for empty collections and pages we now explicitly trigger the creations of an EmbeddedWrapper for that empty, collection to preserve the collection's element type.

Tweaked ResourceProcessorHandlerMethodReturnValueHandler to invoke ResourceProcessor instances for those empty collections, too. PRHMRVH now checks the assignability of the raw resource type before analyzing the value type for a match.

RepositorySearchController now adds additional self links for the list of searches and a search execution.
2015-05-18 19:55:23 +02:00
Oliver Gierke
3537bbd20b DATAREST-518 - MappingResourceMetadata is now not exported by default. 2015-04-14 22:27:02 +02:00
Oliver Gierke
7c3b93fffd DATAREST-511 - Support for executing repository methods returning Optionals.
Added an UnwrappingRepositoryInvokerFactory that transparently unwraps JDK 8 and Guava Optionals to make sure the consuming code works with values or plain nulls correctly.
2015-04-13 08:38:44 +02:00
Oliver Gierke
c412bc3a76 DATAREST-514 - Fixed resource exposure for customized associations.
We no correctly handle the customized association path if @RestResource is used on an association. Took the chance to refactor the resource mapping subsystem quite significantly to improve the handling of property mappings. Those had been externalized before.
2015-04-10 16:08:51 +02:00
Oliver Gierke
1bb228df17 DATAREST-502 - Prepare request parameters to enable URI-to-entity resolution for executing searches.
RepositorySearchController now takes all request parameters as MultiValueMap to execute query methods. For parameters mapping to a managed resource we try to interpret the given parameter value as URI to actually trigger the URI-to-entity resolution through the newly registered UriToEntityConverter.

The latter is now registered with the default ConversionService registered so that it's

A lot of cleanups in RepositorySearchController. Removed some obsolete prints to the console to reduce log output during test execution.

Related ticket: DATACMNS-678.
2015-04-07 17:02:16 +02: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
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
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
c3ffe7793b DATAREST-446 - Removed RepositoriesUtils in favor of RepositoryMetadata.
To be sure to pick up domain type lookup customizations we now consistently use RepositoryMetadata instead of trying to be clever and re-detecting it via RepositoriesUtils.
2015-01-16 13:15:38 +01:00
Oliver Gierke
8700c60cef DATAREST-445 - Fixed domain type lookup in RepositoryCollectionResourceMapping.
We now use the domain type provided by RepositoryMetadata instead of manually looking up to be sure to pick up customizations correctly.
2015-01-16 12:22: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
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
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
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
e6a19a366d DATAREST-394, DATAREST-408 - Projections now consider collections and maps.
The ProjectingMethodInterceptor now inspects collections and maps to apply projections to collection elements and map values. Test cases inspired by a contribution of Saulo Medeiros de Araujo.

Related pull request: #152.
2014-12-01 19:05:48 +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
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
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
0b5726ac41 DATAREST-385 - Projection definition configurations are now detected for super types.
Projections defined for a parent type are now also available for sub-types.
2014-10-15 11:56:39 +02:00
Oliver Gierke
07a8dd2ca6 DATAREST-319 - Adapt to changes in Spring Data Commons.
Fixed ReflectionRepositoryInvokerIntegrationTests after some CRUD method detection changes that invalidated the test cases.

Related ticket: DATACMNS-539.
2014-07-15 11:03:18 +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
ca2e88ae34 DATAREST-346 - Fixed invocation of overridden delete(…) methods.
We now defensively invoke the ConversionService prior to the reflective invocation of the delete method as we have to assume the clients providing the id value in a raw form, i.e. as obtained from the request and thus most likely as String.

Related ticket: DATAREST-335.
2014-07-02 13:26:03 +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
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