-
Notifications
You must be signed in to change notification settings - Fork 562
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support to receive aggregate references as request parameters #2239
Comments
I currently do not understand what you're asking for. The core idea of REST is to provide links to the client so that the client doesn't need to construct URLs to obtain an object but can rather navigate across the graph. If that doesn't help, please provide additional details and ideally a scenario that you want to address. |
I assume what @jacko9et refers to is that with I will have to look into this. It's not as trivial as it seems as currently, referring to the I guess we could rely on the user providing a compatible type (for example |
The actual query only needs the ID of the entity as a query parameter, but does not need to query the entity, similar to the following query.
But at present, the query of the parameter entity(User) is triggered, and then the desired query will continue to be executed. This kind of secondary query, I don’t know if data rest can solve it, or it is a problem with jpa, but it cannot be avoided in data rest. I didn't investigate @backendId carefully, it's not clear if it can be solved. |
@odrotbohm got it right. If we write the query method like this: |
The ad-hoc way I tried, I hope it helps, but it's tedious and not necessarily correct. public abstract class EntityHrefUtils {
private EntityHrefUtils() {
}
public static Optional<?> resolveIdByHref(EntityManager entityManager,
EntityLinks entityLinks,
String href, Class<?> entityClass) {
Class<?> idClass = entityManager.getMetamodel().entity(entityClass)
.getIdType().getJavaType();
UriTemplate uriTemplate = new UriTemplate(
entityLinks.linkFor(entityClass).withSelfRel().getHref().concat("/{id}"));
return Optional.ofNullable(uriTemplate.match(href).get("id"))
.map(value -> idClass.isAssignableFrom(Long.class) ? Long.parseLong(value) : value);
}
} @GetMapping(path = "/search/findByUser")
public @ResponseBody ResponseEntity<?> getUserAccounts(@RequestParam("user") String userHref) {
return EntityHrefUtils.resolveIdByHref(entityManager, entityLinks, userHref, User.class)
.map(id -> accountRepository.findByUser_Id((Long) id)
.map(account -> EntityModel.of(account,
entityLinks.linkToItemResource(Account.class, account.getId()).withSelfRel(),
Link.of(userHref, "user")
)))
.map(accounts -> ResponseEntity.ok(
CollectionModel.of(accounts.collect(Collectors.toList()),
linkTo(methodOn(AccountController.class).getUserAccounts(userHref)).withSelfRel())))
.orElse(ResponseEntity.notFound().build());
} |
That's interesting information as it further complicates the picture 🙃. To the MVC infrastructure, request parameters and path variables are I am very sure I don't want to generally hook into the I wonder if we should introduce a dedicated type |
I realize my thinking is a bit naive, this should be unavoidable, and trying to solve this is a bit cross-border, the question should be: how to make URI map domain type and implicitly extract id to apply to query. This is not data rest can things done alone. |
Fix invalid Javadoc references. See #2239
In the current design, the default behavior is not to serialize the id, but to automatically parse the href into an entity to trigger the query of the entity. The actual business only needs the id as the query identifier. Or is it possible to provide an annotation that resolves id by href without triggering a query.
The text was updated successfully, but these errors were encountered: