Skip to content

Conversation

aderuwe
Copy link

@aderuwe aderuwe commented Mar 1, 2015

Add support for embedded items of different kinds (not just arrays) and multiplicity (grouping of embedded items so nested embedded items are supported).

This breaks the tests for now - before we fix those, I'm curious about your opinion here.

@guylabs
Copy link
Owner

guylabs commented Mar 1, 2015

Hi Alexander,

first of all thanks for contributing to the project! The change about multiple embedded items is clear to me, but could you give me an example on how to generate such a response with multiple embedded items within Spring Data REST?

And about the second change: What do you mean with embedded items of different kinds? Could you also show me an example here?

Thanks and regards,

Guy

@aderuwe
Copy link
Author

aderuwe commented Mar 1, 2015

We're actually using this outside of the Spring Data REST context.
We're using your library as a client-side complement to Symfony2 and its FOSRestBundle (https://github.com/FriendsOfSymfony/FOSRestBundle). So, no, I wouldn't have a clue how to generate the output with Spring Data REST...

We could provide some JSON that we're able to generate with our backend.

Not sure if that puts our PR out of scope or not. :)

@aderuwe
Copy link
Author

aderuwe commented Mar 2, 2015

@guylabs Here is some sample JSON we're trying to work with:

{ "progress": 0, "_links": { "self": { "href": "/sandbox/card/15" }, "random": { "href": "/sandbox/random" }, "entity": { "href": "/sandbox/entity/15" } }, "_embedded": { "entity": { "id": 15, "name": "Name1", "discr": "action", "_links": { "self": { "href": "/sandbox/entity/15" }, "content": { "href": "/sandbox/content/15" } }, "_embedded": { "content": { "id": 15, "instruction": "Instruction1", "question": "Question1", "url": "http: //www.google.be", "discr": "urlsimple", "_links": { "answers": { "href": "/sandbox/content/15/answers" } }, "_embedded": { "answers": [ { "id": 17, "answer": "a", "_links": { "self": { "href": "/sandbox/answer/17" } } }, { "id": 18, "answer": "b", "_links": { "self": { "href": "/sandbox/answer/18" } } } ] } } } } } }
@guylabs
Copy link
Owner

guylabs commented Mar 2, 2015

Ok thanks for the JSON. And how should the result JSON look like after it has been processed by the SpringDataRestAdapter? Because this structure (with nested _embedded) is currently supported as each embedded object is again processed with the SpringDataRestAdapter.

I thought that you would have a JSON like the following (having an array of embedded items):

... "_embedded": [{ "entity": { ... }, "entity2": { ... }, ... ], ...

Or do you also have something like that?

@mfagadar
Copy link

mfagadar commented Mar 7, 2015

Hello Guy,

I'm Mihai and I've worked with @aderuwe on the above pull request. Sorry for our late response, here is the result we get after processing the request (JSON-ified):

{ "progress":0, "_links":{ "self":{ "href":"/sandbox/card/1" }, "random":{ "href":"/sandbox/random" }, "learning-entity":{ "href":"/sandbox/learning-entity/1" } }, "_embeddedItems":{ "learning-entity":{ "id":1, "name":"Sample A", "discr":"action", "_links":{ "self":{ "href":"/sandbox/learning-entity/1" }, "content":{ "href":"/sandbox/content/1" } }, "_embeddedItems":{ "content":{ "id":1, "instruction":"Don't have any", "question":"Like ?", "url":"http://www.google.com", "discr":"urlsimple", "_links":{ "answers":{ "href":"/sandbox/content/1/answers" } }, "_embeddedItems":{ "answers":[ { "id":1, "answer":"Yes", "_links":{ "self":{ "href":"/sandbox/answer/1" } } }, { "id":2, "answer":"No", "_links":{ "self":{ "href":"/sandbox/answer/2" } } } ] } } } } } }

Processing will replace _embedded with _embeddedItems as in the original code. The difference lies in the structure of this JavaScript Object:

  • it contains as properties the name of the embedded entity (i.e. learning-entity, content, answers)
  • as values for those properties, it can take:
    • a single embedded entity in case of a 1-1 composition (i.e. for learning-entity, content);
    • an array of embedded entities in case of 1-* composition (i.e. for answers).

Best regards,
Mihai

@guylabs
Copy link
Owner

guylabs commented Mar 10, 2015

Hi Mihai,

thanks for your reply! Ok now I see your point. Ok then I will have a look at it right away and come up with a solution for you guys. Is that ok for you like that?

Regards,

Guy

@mfagadar
Copy link

Hi Guy,

Definitely, thank you for taking the time to look over it.

Best regards,
Mihai

Changed the moveArray method to take into account all the keys of the _embedded object.
@guylabs
Copy link
Owner

guylabs commented Mar 11, 2015

Ok I added the embeddedNamedResources configuration property and when you set it to true, the JSON will be the way you need it. You can read more about it here: https://github.com/guylabs/angular-spring-data-rest#configuration-of-the-springdatarestadapter. There is also a test here: https://github.com/guylabs/angular-spring-data-rest/blob/master/test/angular-spring-data-rest-provider.embedded-named-resources.spec.js which tests this behavior.

Could you please test this and let me know if it worked? Then I will release a new version and close this pull request. Is that ok for you guys?

Regards,

Guy

@mfagadar
Copy link

Thanks a lot, Guy! We will test it by tomorrow evening and let you know.

Best regards,
Mihai

@mfagadar
Copy link

Hi Guy,

I have added my feedback on your last commit. There's still a change to be made to moveArray, covering the scenario in which more types of named resources are present in the _embeddedobject.

Best regards,
Mihai

@guylabs
Copy link
Owner

guylabs commented Mar 12, 2015

Hi Mihai,

you are right I missed that. I just changed it and also added a test for it. So now it should work on your side ;). Can you please verify such that I can do a minor release such that you can use it through bower/npm?

Thanks and regards,

Guy

@mfagadar
Copy link

Hi Guy,

Thanks again for your quick response. I have verified it and I can confirm that it works perfectly!
I'm looking forward to getting the new release through bower :)

Best regards,
Mihai

@guylabs
Copy link
Owner

guylabs commented Mar 13, 2015

Hi Mihai,

ok nice to hear that! :) Ok I just released 0.3.2 in bower and npm. https://github.com/guylabs/angular-spring-data-rest/releases/tag/0.3.2

Thanks again for the pull request and the idea to support this.

Regards,

Guy

@guylabs guylabs closed this Mar 13, 2015
@aderuwe aderuwe deleted the embedded-support branch March 18, 2015 11:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants