spring-data-rest

How to manage REST API versioning with spring data rest?

◇◆丶佛笑我妖孽 提交于 2019-12-03 15:57:22
What is the way to go supporting API versioning in Spring Rest Data? Is it possible to do it with repository-resources or do I have to use RepositoryRestController instead? I cannot find anything about API versioning in the oficial site of Spring Rest Data I found a Joshua Long presentations about REST APIs with Spring API versions can be implemented with one of two ways: Through API URIs: https://api.foo.com/v1 Through media types: application/vnd.company.urapp-v3+json The first approach have some problems described here This is an interesting topic. The documentation of spring-data-rest does

QueryDsl web query on the key of a Map field

两盒软妹~` 提交于 2019-12-03 15:55:08
问题 Overview Given Spring Data JPA, Spring Data Rest, QueryDsl a Meetup entity with a Map<String,String> properties field persisted in a MEETUP_PROPERTY table as an @ElementCollection a MeetupRepository that extends QueryDslPredicateExecutor<Meetup> I'd expect A web query of GET /api/meetup?properties[aKey]=aValue to return only Meetups with a property entry that has the specified key and value: aKey=aValue. However, that's not working for me. What am I missing? Tried Simple Fields Simple fields

Spring Data Rest - Add link to search endpoint

假如想象 提交于 2019-12-03 15:39:29
In our Spring-Data-Rest Project we have a custom (fuzzy) search on a /buergers/search/findBuergerFuzzy?searchString="..." endpoint. Is it possible to add a link for it on the /buergers/search endpoint (Without overriding the automatically exposed Repository findBy Methods)? The Controller exposing the search: @BasePathAwareController @RequestMapping("/buergers/search/") public class BuergerSearchController { @Autowired QueryService service; @RequestMapping(value = "/findBuergerFuzzy", method = RequestMethod.GET) public @ResponseBody ResponseEntity<?> findBuergerFuzzy

Spring Data Rest - How to receive Headers in @RepositoryEventHandler

限于喜欢 提交于 2019-12-03 15:30:55
I'm using the latest Spring Data Rest and I'm handling the event " before create ". The requirement I have is to capture also the HTTP Headers submitted to the POST endpoint for the model " Client ". However, the interface for the RepositoryEventHandler does not expose that. @Component @RepositoryEventHandler public class ClientEventHandler { @Autowired private ClientService clientService; @HandleBeforeCreate public void handleClientSave(Client client) { ... ... } } How can we handle events and capture the HTTP Headers? I'd like to have access to the parameter like Spring MVC that uses the

Spring Data Rest / Spring Hateoas Custom Controller - PersistentEntityResourceAssembler

南楼画角 提交于 2019-12-03 15:04:29
I'm attempting to add some additional business logic to the auto-generated endpoints from the RepositoryRestResource. Please see the code below: Resource: @RepositoryRestResource(collectionResourceRel="event", path="event") public interface EventRepository extends PagingAndSortingRepository<Event, Long> { } Controller: @RepositoryRestController @RequestMapping(value = "/event") public class EventController { @Autowired private EventRepository eventRepository; @Autowired private PagedResourcesAssembler<Event> pagedResourcesAssembler; @RequestMapping(method = RequestMethod.GET, value = "")

Spring Data REST - How to include calculated data in a projection?

只谈情不闲聊 提交于 2019-12-03 14:53:21
I have the following domain classes defined. Loan Class @Data @Entity public class Loan { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private long id; private String loanTitle; @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) @JoinColumn(name = "loan_id") private List<Allowance> allowances; } Allowance class @Data @Entity public class Allowance { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; @ManyToOne private AllowanceType allowanceType; private Double allowanceAmount; } I also have a projection interface defined for the loan class as follows:

Spring Data Rest exception handling - Return generic error response

99封情书 提交于 2019-12-03 11:04:10
问题 I want to know how can I handle internal server error type exceptions in Spring Data Rest such as JPA exceptions etc. due to a malformed request or a database crash. I did some research found that the better way to do this is by using @ControllerAdvice but couldn't find any working example of it. I looked at both these questions but they are still unanswered. How can I handle exceptions with Spring Data Rest and the PagingAndSortingRepository? global exception handling for rest exposed spring

How to expose a complete tree structure with Spring Data REST and HATEOAS?

拈花ヽ惹草 提交于 2019-12-03 08:37:52
I have a JPA tree structure @Entity public class Document { @Id @GeneratedValue(strategy = GenerationType.AUTO) private int id; private String text; @ManyToOne @JoinColumn(name = "parent") Document parent; @OneToMany(mappedBy = "parent", fetch = FetchType.EAGER) Set<Document> children; (getters and setters) } and a projection @Projection(name = "all", types = Document.class) public interface AllDocumentsProjection { int getId(); String getText(); Set<Document> getChildren(); } When I make a GET request with url localhost:8080/documents/1?projection=all I only get the first children of the root

How to update a @ManyToOne relationship with Spring Data REST?

久未见 提交于 2019-12-03 08:12:45
I use Spring Data REST with JPA. I have a User entity that has a many to one relationship with another called AccountStatus modeled in a separate RDBMS table. The JSON representation looks like this: { "id": "123" "username": "user1", "accountStatus": { "id": "1", "status": "Active" } } The relationship in the User entity is: @ManyToOne(optional = false) @JoinColumn(name = "account_state") @Getter @Setter private AccountState accountState; Now I try to change the account status using a PATCH request on /users/123 and the payload: {"accountState":{"id":0}} But I get an error: "identifier of an

Filling entity links in custom @RepositoryRestController methods

痴心易碎 提交于 2019-12-03 07:50:02
问题 I am using Spring-data-rest to provide read APIs over some JPA entities. For writes I need to issue Command objects rather than directly write to the DB, so I added a custom controller using @RepositoryRestController and various command handling methods: @RequestMapping(method = RequestMethod.POST) public @ResponseBody MyEntity post(@RequestBody MyEntity entity) { String createdId = commands.sendAndWait(new MyCreateCommand(entity)); return repo.findOne(createdId); } I would like the output to