Skip to content
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

Handle resource links of resources inlined using @Projection [DATAREST-302] #681

Closed
spring-projects-issues opened this issue May 9, 2014 · 9 comments
Assignees
Labels
type: enhancement

Comments

@spring-projects-issues
Copy link

@spring-projects-issues spring-projects-issues commented May 9, 2014

Szymon Stasik opened DATAREST-302 and commented

Having inlined resource it would be usefull to have access to its resources. eg. for

{
  "_links" : {
    "self" : {
      "href" : "http://127.0.0.1:8080/api/orders/200"
    },
    "shippingType" : {
      "href" : "http://127.0.0.1:8080/api/orders/200/shippingType"
    },
    "customer" : {
      "href" : "http://127.0.0.1:8080/api/orders/200/customer"
    }
  }
}

and

{
  "firstName" : "John",
  "lastName" : "Doe",
  "_links" : {
    "self" : {
      "href" : "http://127.0.0.1:8080/api/customers/213"
    },
    "address" : {
      "href" : "http://127.0.0.1:8080/api/customers/213/address"
    }
  }
}

after using projection to inline customer the reference to customer.address is being lost:

{
  "customer" : {
    "firstName" : "John",
    "lastName" : "Doe",
  }
  "_links" : {
    "self" : {
      "href" : "http://127.0.0.1:8080/api/orders/200{?projection}",
      "templated" : true
    },
    "shippingType" : {
      "href" : "http://127.0.0.1:8080/api/orders/200/shippingType"
    },
    "customer" : {
      "href" : "http://127.0.0.1:8080/api/orders/200/customer"
    }
  }
}

Affects: 2.1 RC1 (Dijkstra)

Issue Links:

  • DATAREST-464 Links don't get inserted for inlined embedded associations
    (
    "is duplicated by"_)

Referenced from: commits 2697c6a, 5895b5e, b4bfee3

Backported to: 2.3.1 (Fowler SR1), 2.2.3 (Evans SR3)

1 votes, 6 watchers

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented May 9, 2014

Szymon Stasik commented

I guess natural solution would be to include _links within inlined "customer" property. Also another thing is coming to my mind - using eg. propertyName.projection parameter it might be possible to define nested inlining

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Nov 8, 2014

Ruslan Stelmachenko commented

I think Szymon Stasik is right. But we lose not only the reference to customer.address but also the reference to self. It's actually sometimes very important to know which customer it is.

For example we want to show the html table in which everty row is customer name and every cell is order.

  1. We load all customers GET /api/customers/.
  2. We load all orders GET /api/orders/

Now how we can understand from JavaScript what order whose?
From first request we get real id of every customer as customer._links.self.href: "/api/customers/CUSTOMER_ID".
From second request we get links to customers like this order._links.customer.href: "/api/orders/ORDER_ID/customer".

We can't connect loaded orders with their customers somehow.
With projections we can load orders with customers inlined but again with no links so we cannot know hyper-id of a customer.

It is real showstopper in my use case and makes me use DB ID's instead of hyper-id's to identify resources from JS.

P.S. Of course even if this proposition would be implemented we should have some parameter to explicitly specify that we need or don't need _links in inlined resources. Including them always can greatly increase the payload if we GET the collection with inlined collection for example

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Mar 3, 2015

Johannes Hiemer commented

Inlined projection entities do not contain any hrefs, which makes it nearly impossible to follow the entity with hal. This should be added in my opinion

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Apr 2, 2015

Oliver Drotbohm commented

This should be fixed guys. We now add both self links for projected entities and also keep the link pointing to the association.

I back-ported the change as far as id applied cleanly. As an example see this gist to document the before and after stage

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented May 6, 2015

Johannes Hiemer commented

Just tested it with 2.3.1.BUILD-SNAPSHOT and no links inside projected entities. :-(

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Feb 1, 2016

Johannes Schmidt commented

I tried several version of spring data rest, but not links for inline objects in projections are shown.

Spring Boot: 1.3.2 / 1.2.7
releasetrain: Gosling SR2A, SR1

Is it possible to display the links at the moment?

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Feb 16, 2016

George T commented

Tested also on 2.4.2. No links are returned.

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Apr 12, 2016

Johannes Schmidt commented

Is it possible to reopen this issue?

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Apr 12, 2016

Oliver Drotbohm commented

It unfortunately is not as it appears in change logs of already released versions. Feel free to open a new ticket if you like to see things improved

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement
Projects
None yet
Development

No branches or pull requests

2 participants