Skip to content

Improve interoperability with Spring Data Rest and other projects. #2489

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

Conversation

michael-simons
Copy link
Collaborator

@michael-simons michael-simons commented Mar 1, 2022

This improves the interoperability with Spring Data Rest by a magnitude by treating @TargetNode as association to the outside world. Why? Because no resource processing needs to be done on @RelationshipProperties to have embedded links for their target node.

Two support classes for both associations and properties have been added as internal API to chim our philosophy from that change.

To demonstrate that change have a look here: https://github.com/michael-simons/neo4j-examples-and-tips/blob/832e0334a09692bdd72474c9ba11390bc68a493b/examples/sdn6-rest/src/main/java/org/neo4j/tips/sdn/sdn6_rest/SpringDataRestConfig.java#L29-L40

This piece is necessary to include the actual Person behind the Actor as an embedded resource. Otherwise, SDR won't recognise it as association, even though it is managed by a repository.

With this change in place, we also can use proper excerpts as recommended by @odrotbohm, for example see here_

michael-simons/neo4j-examples-and-tips@9a74697

A full blown result that shows

  • Uniform excerpts on all people
  • Correctly embedded people on the actors
{
  "_embedded" : {
    "movies" : [ {
      "title" : "The Matrix",
      "description" : "Welcome to the Real World",
      "actors" : [ {
        "roles" : [ "Emil" ],
        "_embedded" : {
          "person" : {
            "name" : "Emil Eifrem",
            "_links" : {
              "self" : {
                "href" : "http://localhost:8080/people/e43fd0ea-1d26-48ee-b183-a4d74164411e{?projection}",
                "templated" : true
              }
            }
          }
        },
        "_links" : {
          "person" : {
            "href" : "http://localhost:8080/people/e43fd0ea-1d26-48ee-b183-a4d74164411e{?projection}",
            "templated" : true
          }
        }
      } ],
      "released" : 1999,
      "_embedded" : {
        "directors" : [ {
          "name" : "Lana Wachowski",
          "_links" : {
            "self" : {
              "href" : "http://localhost:8080/people/2141c773-86b2-4bab-930a-101de3ba55fc{?projection}",
              "templated" : true
            }
          }
        }, {
          "name" : "Lilly Wachowski",
          "_links" : {
            "self" : {
              "href" : "http://localhost:8080/people/9daf0125-b276-4a1a-9008-6a8e6c1b22ad{?projection}",
              "templated" : true
            }
          }
        } ]
      },
      "_links" : {
        "self" : {
          "href" : "http://localhost:8080/movies/The%20Matrix"
        },
        "movie" : {
          "href" : "http://localhost:8080/movies/The%20Matrix"
        },
        "directors" : {
          "href" : "http://localhost:8080/movies/The%20Matrix/directors{?projection}",
          "templated" : true
        }
      }
    } ]
  },
  "_links" : {
    "first" : {
      "href" : "http://localhost:8080/movies?page=0&size=1"
    },
    "self" : {
      "href" : "http://localhost:8080/movies?size=1"
    },
    "next" : {
      "href" : "http://localhost:8080/movies?page=1&size=1"
    },
    "last" : {
      "href" : "http://localhost:8080/movies?page=37&size=1"
    },
    "profile" : {
      "href" : "http://localhost:8080/profile/movies"
    }
  },
  "page" : {
    "size" : 1,
    "totalElements" : 38,
    "totalPages" : 38,
    "number" : 0
  }
}

This improves the interoperability with Spring Data Rest by a magnitude as no resource processing needs to be done on `@RelationshipProperties` to have embedded links for their target node.

Two support classes for both associations and properties have been added as internal API to chim our philosophy from that change.
@michael-simons michael-simons added the type: enhancement A general enhancement label Mar 1, 2022
@michael-simons michael-simons changed the title Treat @TargetNode as association to the outside world. Improve interoperability with Spring Data Rest and other projects. Mar 1, 2022
Copy link
Collaborator

@meistermeier meistermeier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All tests are green ✔️
I like the loose coupling between Spring Data's general associations and our relationship (properties) ✔️
We can now play better with Spring Data Rest ✔️
Haven't found any double space ✔️

@michael-simons michael-simons merged commit ff206fc into main Mar 1, 2022
@michael-simons michael-simons deleted the feature/treat-target-node-as-association-for-the-outside-world branch March 1, 2022 17:56
@michael-simons michael-simons restored the feature/treat-target-node-as-association-for-the-outside-world branch March 1, 2022 17:56
michael-simons added a commit that referenced this pull request Mar 2, 2022
This improves the interoperability with Spring Data Rest by a magnitude as no resource processing needs to be done on `@RelationshipProperties` to have embedded links for their target node.

Two support classes for both associations and properties have been added as internal API to chim our philosophy from that change.
@michael-simons michael-simons deleted the feature/treat-target-node-as-association-for-the-outside-world branch March 28, 2022 07:09
@michael-simons michael-simons mentioned this pull request Jan 4, 2023
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants