Commit Graph

169 Commits

Author SHA1 Message Date
Oliver Gierke
8327b6f4ab DATAREST-935 - Prepare 3.0 development.
Upgraded version numbers and dependencies to Spring Data build parent, Commons and store modules. Fixed a compiler issue in DomainObjectReader.
2016-11-18 16:13:54 +01:00
Oliver Gierke
40bb8e8e6c DATAREST-573 - Polishing.
Removed RepositoryRestConfiguration.addCorsMapping(…) as we currently don't have any other shortcut methods for configuration like this.

Tweaked the setup of (now Repository)CorsConfigurationAccessor to be created earlier so that we avoid recreation for every lookup. Introduced a NoOpStringValueResolver to be used by default so that we don't need to deal with the case of the resolver being null at the end of the call chain. Replaced constructor of RepositoryCorsConfigurationAccessor with corresponding Lombok annotation.

Updated reference documentation accordingly.

Original pull request: #233.
2016-10-28 14:19:26 +02:00
Mark Paluch
a3870ca528 DATAREST-573 - Add support for new CORS configuration mechanisms introduced in Spring 4.2.
We now support CORS configuration mechanisms introduced in Spring 4.2. CORS can be configured on multiple levels: Repository interface, Repository REST controller and global level. Spring Data REST CORS configuration is isolated so Spring Web MVC'S CORS configuration does not apply to Spring Data REST resources.

 Multiple configuration sources are merged so different aspects of CORS can be configured in separate locations.

@CrossOrigin
interface PersonRepository extends CrudRepository<Person, Long> {}

@RepositoryRestController
@RequestMapping("/person")
public class PersonController {

	@CrossOrigin(maxAge = 3600)
	@RequestMapping(method = RequestMethod.GET, "/xml/{id}", produces = MediaType.APPLICATION_XML_VALUE)
	public Person retrieve(@PathVariable Long id) {
		// ...
	}
}

@Component
public class SpringDataRestCustomization extends RepositoryRestConfigurerAdapter {

  @Override
  public void configureRepositoryRestConfiguration(RepositoryRestConfiguration config) {

    config.addCorsMapping("/person/**")
        .allowedOrigins("http://domain2.com")
        .allowedMethods("PUT", "DELETE")
        .allowedHeaders("header1", "header2", "header3")
        .exposedHeaders("header1", "header2")
        .allowCredentials(false).maxAge(3600);
  }
}
2016-10-28 14:19:26 +02:00
Oliver Trosien
d6caac122e DATAREST-898 - Fix typo in EntityLookupConfiguration assertion message.
Original pull request: #228.
2016-09-19 15:40:56 +02:00
Oliver Gierke
eb630ef273 DATAREST-803 - Prepare next development iteration. 2016-07-27 14:32:36 +02:00
Oliver Gierke
eaca77051a DATAREST-803 - Release version 2.6 M1 (Ingalls). 2016-07-27 13:52:12 +02:00
Oliver Gierke
f2f9564882 DATAREST-825 - Fixed exposure of DELETE HTTP method if findOne(…) is not exposed.
Previously our support for the HTTP DELETE method on item resources was requiring a repository's findOne(…) method to be available and exposed. However, the latter might not be desirable as the support of GET and HEAD requests for item resources depends on that.

We now changed that to only checking that a findOne(…) method is declared on the repository as the implementation of RepositoryEntityController.deleteItemResource(…) requires it to be present to be able to trigger the events that intercept deletes for a particular type.
2016-05-18 13:43:17 +02:00
Oliver Gierke
127f1a846f DATAREST-801 - Improved nested value handling in ValidationErrors.
We now correctly handle nested values by manually traversing the potentially nested property path, creating a PropertyAccessor for each nesting step considering the property access settings defined in the mapping metadata.
2016-04-14 21:34:37 +02:00
Oliver Gierke
e18fe00ea6 DATAREST-790 - Prepare next development iteration. 2016-04-06 16:36:59 +02:00
Oliver Gierke
c49a29a247 DATAREST-790 - Release version 2.5 GA (Hopper). 2016-04-06 16:35:59 +02:00
Oliver Gierke
b530cbe471 DATAREST-798 - Fixed invalid implementation of ValidationErrors.
Changed the implementation of ValidationErrors to be based on AbstractBeanPropertyBindingResult to consider the nesting implemented in superclasses and using a PersistentPropertyAccessor to lookup the property values.

ValidatingRepositoryEventListener now uses this implementation if a PersistentEntity can be obtained for the type under consideration, falling back to a DirectFieldBindingResult otherwise.
2016-04-04 15:12:33 +02:00
Oliver Gierke
05c723fe50 DATAREST-782 - Prepare next development iteration. 2016-03-18 11:15:51 +01:00
Oliver Gierke
03a720d1c0 DATAREST-782 - Release version 2.5 RC1 (Hopper). 2016-03-18 11:15:00 +01:00
Oliver Gierke
6075f3052a DATAREST-782 - Fixed build after Spring 4.2.5 update.
Upgraded to JSONPath 1.1.0 as 0.9 is not supported with Spring 4.2 anymore. Tweaked integration tests due to changed semantics and internals of JSONPath >= 1.0.
2016-03-17 21:29:20 +01:00
Oliver Gierke
892409da2c DATAREST-774 - Separated integration tests from core project to avoid classpath overlap.
Extracted store specific tests into separate test modules to prevent classpath overlap between projects. Those tests are now executed in an "it" build profile to prevent the tests being packaged for distribution on release.

Use Map-based repositories and mapping contexts for test in the Core and WebMvc module.

Slightly changed the configuration API for lookup types on RepositoryRestConfiguration.

Related ticket: DATAREST-776.
2016-02-29 19:40:10 +01:00
Oliver Gierke
897bc88d69 DATAREST-775 - Support for nested association links.
Tweaked custom Jackson serialization to make sure nested entities are rendered as resources so that links to related resources can be collected on nested levels as well.

Extracted EmbeddedResourcesAssembler from PersistentEntityResourceAssembler so that embedded resources can also be build for nested entities. Extracted a ResourceProcessorInvoker from ResourceProcessorHandlerMethodReturnValueHandler to allow ResourceSupport instances created for nested entities get the ResourceProcessor instance registered for them invoked as well.

ProjectionDefinitionRegistrar now also allows the domain type of a repository being registered as excerpt, too.

Related tickets: DATAREST-776.
2016-02-29 19:38:59 +01:00
Oliver Gierke
c74576b91e DATAREST-756 - Prepare next development iteration. 2016-02-12 15:43:39 +01:00
Oliver Gierke
1c850a5909 DATAREST-756 - Release version 2.5 M1 (Hopper). 2016-02-12 15:42:47 +01:00
Oliver Gierke
c49754ebb3 DATAREST-747 - ProjectionDefinitionConfiguration now returns the most concrete projection.
In case multiple projections are defined with a given name, we now return the projection defined for the most concrete type match.
2016-01-11 19:26:54 +01:00
Oliver Gierke
3ce10774d8 DATAREST-741 - UriToEntityDeserializer now uses RepositoryInvoker directly.
UriToEntityDeserializer now uses the RepositoryInvokerFactory to resolve entity instances directly to make sure potentially registered EntityLookup instances are considered for the lookup.
2016-01-06 14:17:42 +01:00
Oliver Gierke
482c78c925 DATAREST-724 - Fixed invocation of DELETE on item resource with entity lookup present.
Tweaked the RepositoryEntityController to lookup the identifier of the entity to be deleted from the entity obtained rather than forwarding the given id directly. This makes sure we use the real entity identifier on calls to delete in case the one to be used in URIs is customized via an EntityLookup.
2016-01-05 12:47:47 +01:00
Oliver Gierke
414f314684 DATAREST-723 - PropertyMappings now get eagerly initialized.
Switched to eager initialization of PropertyMappings to avoid potential ConcurrentModificationException.
2015-12-16 16:28:12 +01:00
Oliver Gierke
3a66bc75e2 DATAREST-724 - Added configuration API for entity lookup customizations.
RepositoryRestConfiguration now exposes a withCustomEntityLookup() returning an EntityLookupRegistrar that allows to define customizations as follows on Java 8:

config.withCustomEntityLookup()
  .forRepository(UserRepository.class)
  .withIdMapping(User::getUsername)
  .withLookup(UserRepository::findByUsername);

or even abbreviated to:

config.withCustomEntityLookup()
  .forRepository(UserRepository.class, User::getUsername, UserRepository::findByUsername);

The API basically takes two lambdas or method references to define the id mapping (User::getUsername in this case) as well as the lookup call based on the repository type with which the customization builder was set up in the first place (UserRepository::findByUsername in this case).
2015-12-09 16:00:32 +01:00
Oliver Gierke
44ab756873 DATAREST-724 - Added support for customizing the property to be used for URI generation.
Spring Data REST now exposes an EntityLookup interface that allows to customize the property of an entity that shall be used to create item resource URIs. By default this mechanism uses the backend identifier and uses the repository's findOne(…) method.

The EntityLookup now exposes one method to return the property value to be used for URI generation as well as one method to obtain the entity instance from the very same raw identifier value. The EntityLookups are registered with both the SelfLinkProvider (for link creation) and the RepositoryInvoker (to obtain the entity instance).
2015-12-09 12:42:15 +01:00
Oliver Gierke
dc36dfb67a DATAREST-473 - Introduced configuration option to control default exposure of repositories.
RepositoryRestConfiguration now exposes a setRepositoryDetectionStrategy(…) to define which repositories should be detected for exposure by default. The default value for that will consider the repository interfaces visibility but also take the exported flag of @(Repository)RestResource into account. See all other options in RepositoryDetectionStrategies.

Tweaked the auto-registration of excerpt projections to avoid a circular dependency between configuration and resource mappings and moved it onto a BeanPostProcessor implementation.
2015-11-25 13:40:26 +01:00
Oliver Gierke
5fa89a9c98 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:32:11 +01:00
Spring Buildmaster
123b7a01c2 DATAREST-663 - Prepare next development iteration. 2015-09-01 02:46:04 -07:00
Spring Buildmaster
1a38f96602 DATAREST-663 - Release version 2.4.0.RELEASE (Gosling GA). 2015-09-01 02:46:01 -07:00
Oliver Gierke
2dfce406e9 DATAREST-663 - Switched to Spring HATEOAS version property from build parent. 2015-09-01 11:28:41 +02: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
39eb338025 DATAREST-651 - Upgraded to Spring HATEOAS 0.19.
Upgraded to snapshots of Spring HATEOAS to use the now extended constructor of HalHandlerInstantiator to be able to render title attributes for links.
2015-08-19 19:13:03 +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
Spring Buildmaster
1d7e7f4ea4 DATAREST-634 - Prepare next development iteration. 2015-08-04 05:06:47 -07:00
Spring Buildmaster
402d7c9382 DATAREST-634 - Release version 2.4.0.RC1 (Gosling RC1). 2015-08-04 05:06:44 -07:00
Oliver Gierke
4e40bb456a DATAREST-634 - Upgraded to Spring HATEOAS 0.18.0.
Upgraded to Hibernate 4.3.10 along the way.
2015-08-04 13:11:03 +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
5346215d47 DATAREST-588 - Upgraded to Spring HATEOAS 0.18.0 to benefit from downstream fix. 2015-06-19 16:56:55 +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
Spring Buildmaster
42fc85afdc DATAREST-563 - Prepare next development iteration. 2015-06-02 01:58:14 -07:00
Spring Buildmaster
0604e7b876 DATAREST-563 - Release version 2.4.0 M1 (Gosling). 2015-06-02 01:58:12 -07: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