Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Sep 15 17:55
    gregturn commented #1074
  • Sep 15 17:54
    gregturn commented #1074
  • Sep 15 17:53
    gregturn commented #1074
  • Sep 15 16:48
    gregturn commented #1073
  • Sep 11 13:58
    Puspendert commented #1076
  • Sep 11 13:48
    Puspendert commented #1076
  • Sep 11 13:34
    gregturn commented #1076
  • Sep 11 13:27
    Puspendert opened #1076
  • Sep 09 22:03
    gregturn commented #107
  • Sep 09 21:30
    rbuer commented #107
  • Sep 09 15:14
    gregturn commented #1053
  • Sep 09 15:13
    gregturn review_requested #1053
  • Sep 09 15:13
    gregturn assigned #1038
  • Sep 09 15:13
    gregturn unassigned #1038
  • Sep 09 15:13
    gregturn assigned #1038
  • Sep 09 15:12
    gregturn commented #1038
  • Sep 09 14:59
    gregturn synchronize #1053
  • Sep 09 14:59

    gregturn on alps

    #1038 - Update documentation an… (compare)

  • Sep 09 14:34
    gregturn closed #966
  • Sep 09 14:34
    gregturn commented #966
marrhub
@marrhub
I got app utilizing Spring HATEOAS where I got base abstract entity Event with subclasses Lecture and Lab
I need REST API returning events sorted by date
marrhub
@marrhub
however call to /events?sort=date returns
"_embedded": { "lectures": [...], "labs": [...] }
where lectures and labs are sorted but I need one uniform sorted collection of events
i.e. "_embedded": { "events": [...] }
is there some way to achieve this without rolling out my own controller?
Knut Schleßelmann
@kschlesselmann
@marrhub What does your controller currently look like? Why are your events separated in the first place?
marrhub
@marrhub
I've no controller I just created EventsRepository and I wanted to make use of Spring HATEOAS out-of-the-box REST API:
https://dzone.com/articles/magic-of-spring-data
but unfortunately API I get from Spring controlled /events endpoint returns events separated and it got me puzzled as well
I'm asking if this behaviour can be somehow overridden without rolling out my own controller
Knut Schleßelmann
@kschlesselmann
@marrhub So you're speaking of Spring Data REST I think
@marrhub Maybe projections will do the trick?
marrhub
@marrhub
ok, I'll see if Projection will do the work, thx
marrhub
@marrhub
unfortunately even with Projection it doesn't work as expected, i.e. projected entities are split into multiple arrays according to their final class :(
Greg Turnquist
@gregturn
@marrhub Indeed, in that scenario, you really have to bake your own controller. Simply put, there isn't enough metadata to glean whether different concrete, polymorphic objects should be put in one array or multiple.
Creating "hints" in Spring Data REST to signal that would be a corner case we have (yet) to see needing such framework support.
marrhub
@marrhub
ok, pity, I was actually hoping there is such a hint :)
Greg Turnquist
@gregturn
This is the trade off between Spring Data REST and Spring HATEOAS. Spring HATEOAS is more of a toolkit for building up hypermedia-aware controllers while Spring Data REST is aimed at the repository layer and how easily we can export proper hypermedia leveraging Spring Data's domain knowledge. This leads to gaps between the two like you've found.
marrhub
@marrhub
thanks for the explanation
I'm using Spring HATEOAS togather with angular4-hal and so far it worked like a charm but in this case angular4-hal concatenates the collections as is so I get not sorted result
as a temporary solution I run array.sort() on this result
but perhaps I'll look into rolling out my own HATEOAS compliant controller
marrhub
@marrhub
hi again
I got another issue
I'm now using @Projection for my Event enitity
marrhub
@marrhub
so the call looks as follows:
/events?projection=brief&page=0&size=10&sort=date
I get response as expected except one thing
the HATEOAS links section looks as follows:
"_links": {
    "first": {
        "href": "http://localhost:8080/events?page=0&size=10&sort=date,asc"
    },
    "self": {
        "href": "http://localhost:8080/events{?projection}",
        "templated": true
    },
    "next": {
        "href": "http://localhost:8080/events?page=1&size=10&sort=date,asc"
    },
    "last": {
        "href": "http://localhost:8080/events?page=50&size=10&sort=date,asc"
    },
    "profile": {
        "href": "http://localhost:8080/profile/events"
    },
    "search": {
        "href": "http://localhost:8080/events/search"
    }
}
marrhub
@marrhub
so if I choose to use next link for subsequent results I'll no longer get my "brief" Event projection
this again causes issue with angular4-hal lib I use which serves me results from the next link
marrhub
@marrhub
it seems to be the right behaviour and I'd expect to receive same kind of data from the call requesting next lot of data
I'd add it is inconsitent with /search functionality
marrhub
@marrhub
I got following custom search exposed in my EventRepository:
@RestResource(path = "byEventCategory", rel = "byEventCategory")
Page<Event> findAllByEventCategory(@Param("eventCategory") EventCategory eventCategory, Pageable pageable);
when I make following call:
/events/search/byEventCategory?eventCategory=RESULT&page=1&size=20&sort=date,asc
I get following links section:
"_links": {
    "first": {
        "href": "http://localhost:8080/events/search/byEventCategory?eventCategory=RESULT&page=0&size=20&sort=date,asc"
    },
    "prev": {
        "href": "http://localhost:8080/events/search/byEventCategory?eventCategory=RESULT&page=0&size=20&sort=date,asc"
    },
    "self": {
        "href": "http://localhost:8080/events/search/byEventCategory?eventCategory=RESULT&page=1&size=20&sort=date,asc"
    },
    "next": {
        "href": "http://localhost:8080/events/search/byEventCategory?eventCategory=RESULT&page=2&size=20&sort=date,asc"
    },
    "last": {
        "href": "http://localhost:8080/events/search/byEventCategory?eventCategory=RESULT&page=6&size=20&sort=date,asc"
    }
}
marrhub
@marrhub
i.e. the whole url is preserved including all the parameters allowing to get next lot of identical type of data when I follow next link
that seems to be convenient behaviour
I'd expect same behaviour from projection call
marrhub
@marrhub
I tried to expose my projection via search
but I get an error during call
marrhub
@marrhub
{
    "cause": null,
    "message": "Couldn't find PersistentEntity for type class com.sun.proxy.$Proxy182!"
}
java.lang.IllegalArgumentException: Couldn't find PersistentEntity for type class com.sun.proxy.$Proxy182!
    at org.springframework.data.mapping.context.PersistentEntities.lambda$getRequiredPersistentEntity$2(PersistentEntities.java:96) ~[spring-data-commons-2.1.9.RELEASE.jar:2.1.9.RELEASE]
    at java.util.Optional.orElseThrow(Optional.java:290) ~[na:1.8.0_172]
    at org.springframework.data.mapping.context.PersistentEntities.getRequiredPersistentEntity(PersistentEntities.java:95) ~[spring-data-commons-2.1.9.RELEASE.jar:2.1.9.RELEASE]
    at org.springframework.data.rest.webmvc.PersistentEntityResourceAssembler.wrap(PersistentEntityResourceAssembler.java:72) ~[spring-data-rest-webmvc-3.1.9.RELEASE.jar:3.1.9.RELEASE]
    at org.springframework.data.rest.webmvc.PersistentEntityResourceAssembler.toResource(PersistentEntityResourceAssembler.java:55) ~[spring-data-rest-webmvc-3.1.9.RELEASE.jar:3.1.9.RELEASE]
    at org.springframework.data.rest.webmvc.PersistentEntityResourceAssembler.toResource(PersistentEntityResourceAssembler.java:38) ~[spring-data-rest-webmvc-3.1.9.RELEASE.jar:3.1.9.RELEASE]
    at org.springframework.data.web.PagedResourcesAssembler.createResource(PagedResourcesAssembler.java:208) ~[spring-data-commons-2.1.9.RELEASE.jar:2.1.9.RELEASE]
...
Bill
@BillTian
@marrhub have you got a expect solution for exporting entity with inheritance ? i'
i'm encounter the same scenario too.
Asif Rashid
@asifrashid
What is the status of hal-explorer? I trying to use it with 2.2.0.M5 and it is not working. Never get page open. Hal browser is working fine.
Greg Turnquist
@gregturn
My bad. I hadn't realized that Hal Explorer had been added to Spring Data REST! (I've head down on Spring hATEAOS for a solid two years).
Kai Toedter
@toedter
Hi, I am the author of HAL Explorer. I will check my test projects with the latest release of Spring HATOAS this weekend. @asifrashid, a previous bug in the Sring Data Rest HAL Explorer integration was that a wrong url parameter was used. The previous version of HAL Explorer hat a bug that it ends up in an endless loop in this case. Make sure the parameter in the browser bar is url (not uri), then it should work also with older versions of HAL Explorer.
Asif Rashid
@asifrashid
@toedter HAL explorer working fine now with uri too. One quick question, can I disable HAL explorer using Spring profile? I don't want to show it on our production site.
Asif Rashid
@asifrashid

I would like to disable all operations (GET, POST, DELETE, etc) for a rest repository. I have a custom search method which I implemented as following

public interface CustomerRepository extends MongoRepository<Customer, String>,
        SearchCustomerInAllCollections{

I have override all existing methods and use @RestResource(exported = false) but it is still showing up in root index. Can I update that root list? Instead of showing getAll for repository , I would like to only show above search option only.