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

Add new enum to specify the direction of a relationship #785

Merged
merged 4 commits into from
Apr 7, 2020
Merged

Add new enum to specify the direction of a relationship #785

merged 4 commits into from
Apr 7, 2020

Conversation

dnl50
Copy link
Contributor

@dnl50 dnl50 commented Apr 4, 2020

Introduce a new enum Direction in the @Relationship annotation to replace String based relationship direction

Description

  • add Relationship.Direction enum and change type of "direction" member to that
    new enum
  • introduce converter branch and new method in AnnotationInfo class to support
    enum members of annotations
  • adapt return type of methods which previously returned the relationship direction string
    to now return an enum constant to only use the new enum constants internally
  • adapt @relationship annotations in node entities for integration tests
  • adapt the docs to reflect the changed return type

Related Issue

#631

Motivation and Context

Specifying the direction of a relationship through a simple string may lead to confusion and might cause unexpected behaviour when a typo is overlooked

How Has This Been Tested?

Running existing test cases and 4 newly added ones

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

* add Relationship.Direction enum and change type of "direction" member to that
 new enum
* introduce converter branch and new method in AnnotationInfo class to support
 enum members of annotations
* adapt return type of methods which previously returned the relationship direction string
to now return an enum constant
* adapt @relationship annotations in node entities for integration tests
* adapt the docs to reflect the changed type
@michael-simons michael-simons self-assigned this Apr 6, 2020
@michael-simons michael-simons self-requested a review April 6, 2020 06:38
This removes the new API on the AnnotationInfo. This API was very well done and tested, but it increases our surface again and we don’t want that. It’s needed in two places and it’s ok to duplicate it the instantiation there.

There’s one signifacant change we’re we check whether the attribute is an enum or not.  For comparision: #644
Copy link
Collaborator

@michael-simons michael-simons left a comment

Choose a reason for hiding this comment

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

I like this PR a lot and I find it very well executed.

All changes requested are on a high level. There's some polishing done in the AnnotationInfo which I hopefully pushed to the branch.

@codecov-io
Copy link

codecov-io commented Apr 6, 2020

Codecov Report

Merging #785 into master will decrease coverage by 0.00%.
The diff coverage is 94.79%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #785      +/-   ##
============================================
- Coverage     80.35%   80.35%   -0.01%     
  Complexity     3002     3002              
============================================
  Files           274      275       +1     
  Lines          9169     9163       -6     
  Branches       1379     1370       -9     
============================================
- Hits           7368     7363       -5     
  Misses         1299     1299              
+ Partials        502      501       -1     
Impacted Files Coverage Δ Complexity Δ
...neo4j/ogm/context/DirectedRelationshipForType.java 57.14% <ø> (ø) 3.00 <0.00> (ø)
.../java/org/neo4j/ogm/context/GraphEntityMapper.java 90.93% <ø> (ø) 84.00 <0.00> (ø)
...ore/src/main/java/org/neo4j/ogm/cypher/Filter.java 90.56% <ø> (ø) 47.00 <0.00> (ø)
...iler/builders/node/DefaultRelationshipBuilder.java 91.89% <ø> (ø) 19.00 <0.00> (ø)
...g/neo4j/ogm/session/delegates/SessionDelegate.java 93.33% <83.33%> (+0.18%) 23.00 <0.00> (ø)
...eo4j/ogm/metadata/reflect/EntityAccessManager.java 68.83% <88.46%> (ø) 68.00 <10.00> (ø)
.../java/org/neo4j/ogm/context/EntityGraphMapper.java 93.34% <95.00%> (-0.04%) 130.00 <3.00> (ø)
...in/java/org/neo4j/ogm/annotation/Relationship.java 100.00% <100.00%> (ø) 0.00 <0.00> (?)
...va/org/neo4j/ogm/context/DirectedRelationship.java 62.50% <100.00%> (ø) 5.00 <1.00> (ø)
...in/java/org/neo4j/ogm/context/EntityCollector.java 82.97% <100.00%> (ø) 10.00 <0.00> (ø)
... and 13 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a48d593...7a9713d. Read the comment docs.

@michael-simons
Copy link
Collaborator

Thanks for letting me push into your branch.

* replace `Relationship.*` imports with `Relationship.Direction`where possible
* use reference equals to compare enum constants
* refactor EntityGraphMapper#clearContextRelationships to use a switch statement
@michael-simons
Copy link
Collaborator

Looks very good to me now… I'm gonna go through one more time and might push a thing or two.

Would you please sign our CLA? https://neo4j.com/developer/cla/ so that I can whitelist you in our CI? Thank you.

This introduces some aliases on the `@Relationship` for the `Direction`
constants. These provide some compatibility for users relying on the
previous string constants in their declarations.

Furthermore, the availibility of the enum shows some points that should
be refactored all too painfull, especially in `ClassInfo` which has been
done.

The rest is minor polishing.
@dnl50
Copy link
Contributor Author

dnl50 commented Apr 7, 2020

Done ✔️

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

Successfully merging this pull request may close these issues.

3 participants