-
Notifications
You must be signed in to change notification settings - Fork 59
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 the process of Relationship V2 in EbeanLocalRelationshipWriterDAO #467
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #467 +/- ##
============================================
+ Coverage 67.92% 67.95% +0.03%
- Complexity 1628 1635 +7
============================================
Files 143 143
Lines 6247 6260 +13
Branches 680 683 +3
============================================
+ Hits 4243 4254 +11
- Misses 1712 1714 +2
Partials 292 292 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some comments. Thanks for adding this support!
*/ | ||
public static void checkSameUrn(@Nonnull final List<? extends RecordTemplate> relationships, | ||
@Nonnull final BaseGraphWriterDAO.RemovalOption removalOption, final String sourceField, final String destinationField) { | ||
@Nonnull final BaseGraphWriterDAO.RemovalOption removalOption, final String sourceField, | ||
final String destinationField, Urn urn) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: annotation for nullable params
// ToDo: how to handle this for Relationship V2? | ||
final Urn sourceUrn = getSourceUrnFromRelationship(relationships.get(0)); | ||
Urn sourceUrn = urn; | ||
if (!ModelUtils.isRelationshipInV2(relationships.get(0).schema())) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
index check before .get(0) needed or no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a null check at the begining of this method, so the index check won't be necessary.
sourceUrn = getSourceUrnFromRelationship(relationships.get(0)); | ||
} | ||
if (sourceUrn == null) { | ||
throw new IllegalArgumentException("Source urn is needed for Relationship V2"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The v1 v2 case is a little hard to follow. Could you add some comments or maybe consider this?
if (!ModelUtils.isRelationshipInV2(relationships.get(0).schema())) {
// v1 case
} else {
// v2 case
if (urn == null) {
throw new IllegalArgumentException("Source urn is needed for Relationship V2");
}
sourceUrn = urn;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. Moved into a separate method and added comments.
public <RELATIONSHIP extends RecordTemplate> void addRelationships(@Nonnull List<RELATIONSHIP> relationships, | ||
@Nonnull RemovalOption removalOption, boolean isTestMode) { | ||
@Nonnull RemovalOption removalOption, boolean isTestMode, Urn urn) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: @nullable Urn urn
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
urn is nullable for V1
// For relationship model V1, this given urn can be source urn or destination urn. | ||
// For relationship model V2, this given urn can only be source urn. | ||
Urn source = urn; | ||
if (!ModelUtils.isRelationshipInV2(relationship.schema())) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
duplicate code... Maybe a helper function getSourceUrnFromEither(relationship, urn)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. Put that logic into a separate method, and removed the dups.
|
||
if (removalOption == RemovalOption.REMOVE_NONE) { | ||
return; | ||
} | ||
|
||
SqlUpdate deletionSQL = _server.createSqlUpdate(SQLStatementUtils.deleteLocalRelationshipSQL(tableName, removalOption)); | ||
Urn source = getSourceUrnFromRelationship(relationship); | ||
Urn source = urn; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
^
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as the above. removed the dups. Thanks.
*/ | ||
public static void checkSameUrn(@Nonnull final List<? extends RecordTemplate> relationships, | ||
@Nonnull final BaseGraphWriterDAO.RemovalOption removalOption, final String sourceField, final String destinationField) { | ||
@Nonnull final BaseGraphWriterDAO.RemovalOption removalOption, @Nonnull final String sourceField, | ||
@Nonnull final String destinationField, Urn urn) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* @return The source asset urn. | ||
*/ | ||
public static <RELATIONSHIP extends RecordTemplate> Urn getSourceUrnBasedOnRelationshipVersion( | ||
@Nonnull RELATIONSHIP relationship, Urn urn) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
private static void checkSameUrn(@Nonnull List<? extends RecordTemplate> records, @Nonnull String field, | ||
@Nonnull Urn compare) { | ||
for (RecordTemplate relation : records) { | ||
if (ModelUtils.isRelationshipInV2(relation.schema()) && field == SOURCE) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: string should use .equals comparison
}); | ||
} | ||
@Override |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: newline after closing curly brace
private <RELATIONSHIP extends RecordTemplate> void addRelationshipGroup(@Nonnull final List<RELATIONSHIP> relationshipGroup, | ||
@Nonnull RemovalOption removalOption, boolean isTestMode) { | ||
@Nonnull RemovalOption removalOption, boolean isTestMode, Urn urn) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* Needed for Relationship V2 because source is not included in the relationshipV2 metadata. | ||
*/ | ||
private <RELATIONSHIP extends RecordTemplate> void processRemovalOption(@Nonnull String tableName, | ||
@Nonnull RELATIONSHIP relationship, @Nonnull RemovalOption removalOption, Urn urn) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: urn annotation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. thanks for the detailed PR description
Summary
This PR is to support
processLocalRelationshipUpdates
for relationship model v2.Details
Changes include:
checkSameUrn
method for model v2.isRelationshipInV2
methods public so they can be used in EbeanLocalRelationshipWriterDAO logicaddRelationships
,addRelationshipGroup
, andprocessRemovalOption
. The logic for model v1 remains the same, but the logic changes to take the passed parameter for model v2.Testing Done
Checklist