This is an automated email from the ASF dual-hosted git repository. sarath pushed a commit to branch branch-2.0 in repository https://gitbox.apache.org/repos/asf/atlas.git
commit b18e66ac77a7fd5a77edbb7406be9c31211fa5af Author: mayanknj <[email protected]> AuthorDate: Tue Jul 16 18:49:40 2019 +0530 ATLAS-3310:- Fix create/update Relationships, after updating a bigint attribute. (cherry picked from commit 7fcf04159887d4719631e8e3d54f4297e17f4c4d) --- .../apache/atlas/type/AtlasRelationshipType.java | 24 ++++++++++++++++++---- .../store/graph/v2/AtlasRelationshipStoreV2.java | 19 +++++++++++++---- 2 files changed, 35 insertions(+), 8 deletions(-) diff --git a/intg/src/main/java/org/apache/atlas/type/AtlasRelationshipType.java b/intg/src/main/java/org/apache/atlas/type/AtlasRelationshipType.java index 98071b2..6d1c64b 100644 --- a/intg/src/main/java/org/apache/atlas/type/AtlasRelationshipType.java +++ b/intg/src/main/java/org/apache/atlas/type/AtlasRelationshipType.java @@ -20,6 +20,7 @@ package org.apache.atlas.type; import org.apache.atlas.AtlasErrorCode; import org.apache.atlas.exception.AtlasBaseException; +import org.apache.atlas.model.instance.AtlasObjectId; import org.apache.atlas.model.instance.AtlasRelationship; import org.apache.atlas.model.typedef.AtlasBaseTypeDef; import org.apache.atlas.model.typedef.AtlasRelationshipDef; @@ -242,14 +243,29 @@ public class AtlasRelationshipType extends AtlasStructType { * @throws AtlasBaseException */ private boolean validateRelationship(AtlasRelationship relationship) { - String end1TypeName = relationship.getEnd1() != null ? relationship.getEnd1().getTypeName() : null; - String end2TypeName = relationship.getEnd2() != null ? relationship.getEnd2().getTypeName() : null; - if (StringUtils.isNotEmpty(end1TypeName) && StringUtils.isNotEmpty(end2TypeName)) { - return end1Type.isTypeOrSuperTypeOf(end1TypeName) && end2Type.isTypeOrSuperTypeOf(end2TypeName) && super.isValidValue(relationship); + AtlasObjectId end1 = relationship.getEnd1(); + AtlasObjectId end2 = relationship.getEnd2(); + + if (end1 != null && end2 != null) { + + String end1TypeName = end1.getTypeName(); + String end2TypeName = end2.getTypeName(); + + if (StringUtils.isNotEmpty(end1TypeName) && StringUtils.isNotEmpty(end2TypeName)) { + + return end1Type.isTypeOrSuperTypeOf(end1TypeName) && end2Type.isTypeOrSuperTypeOf(end2TypeName) && super.isValidValue(relationship); + + } else { + + return StringUtils.isNotEmpty(end1.getGuid()) && StringUtils.isNotEmpty(end2.getGuid()); + + } + } return false; + } /** diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/AtlasRelationshipStoreV2.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/AtlasRelationshipStoreV2.java index 54059e8..1c8b057 100644 --- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/AtlasRelationshipStoreV2.java +++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/AtlasRelationshipStoreV2.java @@ -192,7 +192,16 @@ public class AtlasRelationshipStoreV2 implements AtlasRelationshipStore { } } - validateRelationship(end1Vertex, end2Vertex, edgeType, relationship.getAttributes()); + boolean relationshipTypeNotExists = false; + if (StringUtils.isEmpty(relationship.getTypeName())) { + relationship.setTypeName(edgeType); + relationshipTypeNotExists = true; + } + validateRelationship(end1Vertex, end2Vertex, relationship); + + if (relationshipTypeNotExists) { + relationship.setTypeName(null); + } AtlasRelationship ret = updateRelationship(edge, relationship); sendNotifications(ret, OperationType.RELATIONSHIP_UPDATE); @@ -337,7 +346,7 @@ public class AtlasRelationshipStoreV2 implements AtlasRelationshipStore { AtlasEdge ret; try { - validateRelationship(end1Vertex, end2Vertex, relationship.getTypeName(), relationship.getAttributes()); + validateRelationship(end1Vertex, end2Vertex, relationship); String relationshipLabel = getRelationshipEdgeLabel(end1Vertex, end2Vertex, relationship.getTypeName()); @@ -623,7 +632,10 @@ public class AtlasRelationshipStoreV2 implements AtlasRelationshipStore { validateAndNormalize(relationship); } - private void validateRelationship(AtlasVertex end1Vertex, AtlasVertex end2Vertex, String relationshipName, Map<String, Object> attributes) throws AtlasBaseException { + private void validateRelationship(AtlasVertex end1Vertex, AtlasVertex end2Vertex, AtlasRelationship relationship) throws AtlasBaseException { + + String relationshipName = relationship.getTypeName(); + AtlasRelationshipType relationshipType = typeRegistry.getRelationshipTypeByName(relationshipName); if (relationshipType == null) { @@ -654,7 +666,6 @@ public class AtlasRelationshipStoreV2 implements AtlasRelationshipStore { } List<String> messages = new ArrayList<>(); - AtlasRelationship relationship = new AtlasRelationship(relationshipName, attributes); relationshipType.validateValue(relationship, relationshipName, messages);
