Commit Graph

128 Commits

Author SHA1 Message Date
Oliver Gierke
182d32b715 DATAREST-1075 - AnnotatedEventHandlerInvoker skips methods introduced by proxy.
Removed now unused Methods deprecated in Ingalls / Hopper.
2017-07-06 13:28:46 +02:00
Oliver Gierke
2ad963074c DATAREST-1104 - Adapt to API changes in mapping subsystem. 2017-07-04 15:27:54 +02:00
Oliver Gierke
e4f34aaa67 DATAREST-1076 - Expose constructor that takes RelProvider of RepositoryResourceMappings.
We now expose the constructor that takes a RelProvider in RepositoryResourceMappings so that clients can tweak the default relation names. Changed the order of constructor parameters of (previously) non-public constructors for consistency.

The RelProvider to be used with the mappings can now be configured via RepositoryRestConfiguration and defaults to the EvoInflector based one.
2017-05-18 14:49:44 +02:00
Oliver Gierke
3b0c73f109 DATAREST-1067 - EntityLookup.lookupEntity(…) now returns Optional<T>. 2017-05-04 23:56:40 +02:00
Oliver Gierke
f906695e7a DATAREST-1064 - Adapt to API changes in repository interfaces.
Additional cleanups in QuerydslAwareRootResourceInformationHandlerMethodArgumentResolver to make sure a QuerydslRepositoryInvokerAdapter is only applied if the QuerydslPredicateBuilder actually exposes a predicate. Extracted a couple of methods to make sure the mapping pipeline reads nicely.
2017-05-03 18:10:27 +02:00
Oliver Gierke
b9957d1a6c DATAREST-1008 - Adapt to API changes in Spring Data Commons, Java 8 upgrades and Mockito 2.7. 2017-03-24 11:02:54 +01:00
Oliver Gierke
7295535d16 DATAREST-1018 - Prevent NullPointerException in UriToEntityConverter.
In case PersistentEntities exposes a managed type whose raw type currently doesn't have a PersistentEntity registered, the constructor of UriToEntityConverter ran into a NullPointerException.

We now explicitly check for null and skip those types.

Filed DATAREST-1021 for further improvements in the 3.0 time frame.
2017-03-07 14:50:44 +01:00
Mark Paluch
b06f8664f1 DATAREST-992 - Remove references to Assert single-arg methods.
Replace references to Assert single-arg methods with references to methods accepting the test object and message.

Related ticket: SPR-15196.
2017-02-01 13:25:13 +01:00
Oliver Gierke
74cc5551a5 DATAREST-983 - AnnotatedEventHandlerInvoker now resolves generic handler method argument.
We now resolve the handler method argument type of an annotated repository event handler against the concrete handler type to make sure generics are resolved properly.
2017-01-24 16:57:53 +01:00
Oliver Gierke
2b9c7847b4 DATAREST-970 - AnnotationEventHandlerInvoker now considers order of event handler methods.
We now make sure that an @Order annotation on annotated event handler methods are considered and the methods are invoked in the defined order.

Non-annotation-based event handlers don't suffer from the same problem as they're ApplicationListener instances directly so that the container will enforce the correct ordering in case @Order is used or Ordered is implemented.

Some cleanup in EventHandlerMethod.

Original pull request: #248.
2017-01-19 15:09:56 +01:00
Mark Paluch
6bb989018c DATAREST-978 - Migrate ticket references in test code to Spring Framework style. 2017-01-13 10:09:53 +01:00
Oliver Gierke
83899bb42a DATAREST-793 - RepositoryRestConfiguration's setters return this consistently.
Adapted the return type of setter methods in RepositoryRestConfiguration to consistently return the current instance to allow call chaining.
2016-12-12 17:00:05 +01:00
Oliver Gierke
aa7eec4683 DATAREST-835 - Search resources returning a single resource now get and consider ETag and Last-Modified headers.
We now interpret If-None-Match and If-Modified-Since headers on requests to resources backed by query methods returning a single instance only. This allows clients to optimize GET requests to those resources to save bandwidth.
2016-12-08 21:35:37 +01:00
Oliver Gierke
42378ab34d DATAREST-957 - Polish most critical Sonar warnings.
Fixed broken equals(…) in ProjectionDefinition. Switched to iterating over Map's entry set instead of the keys. Made UriAwareHttpServletRequest static.
2016-12-08 10:12:31 +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
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
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
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
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
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