0

I have an application where I am using Spring Data Rest to expose my entities in one service, and then use FeignClient from another service to access and update those resources.

In examples I've seen POSTing a @OneToMany sub-resource association in Spring Data REST, the way to establish these relationships is as follows:

  1. Create the entity
  2. Get the "self" href of the newly created entity
  3. Create a list of existing entities of the owning entity for that type and then add that newly created link to the list
  4. Do a "PUT" with the list of URIs to the association URI (with a Content-Type of "text/uri-list") to create the association.

I have done this using AngularJs and it works fine. However, I really do not want my javascript controller to have such an intimate knowledge of my domain objects, I would prefer to have Spring HATEOAS do that work for me.

So what I've done is to create a service in my client application that uses the Spring Cloud FeignClient access those endpoints and do the work that the Angular is presently doing.

The problem that I am running into is that when I get my reference to my associations (e.g. "http://myapp/myobjects/3/myassociation") and then do a "GET" to that URI, it returns "Resources<MyAssociation>" which has no way of getting at the list of URIs of the association objects. All I get for "Links" is the reference to the associations from the owning entity (e.g. "http://myapp/myobjects/3/myassociation").

Is there a way that I can find that list of associations without having to make several other GETs so that I can add the newly added one to it?

Thanks in advance,

CS

Community
  • 1
  • 1

1 Answers1

0
URI.create(Resource.getId().getHref()).getPath()

U can try this.