Commit 7fcf0415 by mayanknj Committed by Sarath Subramanian

ATLAS-3310:- Fix create/update Relationships, after updating a bigint attribute.

parent 93addf06
...@@ -20,6 +20,7 @@ package org.apache.atlas.type; ...@@ -20,6 +20,7 @@ package org.apache.atlas.type;
import org.apache.atlas.AtlasErrorCode; import org.apache.atlas.AtlasErrorCode;
import org.apache.atlas.exception.AtlasBaseException; 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.instance.AtlasRelationship;
import org.apache.atlas.model.typedef.AtlasBaseTypeDef; import org.apache.atlas.model.typedef.AtlasBaseTypeDef;
import org.apache.atlas.model.typedef.AtlasRelationshipDef; import org.apache.atlas.model.typedef.AtlasRelationshipDef;
...@@ -242,14 +243,29 @@ public class AtlasRelationshipType extends AtlasStructType { ...@@ -242,14 +243,29 @@ public class AtlasRelationshipType extends AtlasStructType {
* @throws AtlasBaseException * @throws AtlasBaseException
*/ */
private boolean validateRelationship(AtlasRelationship relationship) { 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)) { AtlasObjectId end1 = relationship.getEnd1();
return end1Type.isTypeOrSuperTypeOf(end1TypeName) && end2Type.isTypeOrSuperTypeOf(end2TypeName) && super.isValidValue(relationship); 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; return false;
} }
/** /**
......
...@@ -192,7 +192,16 @@ public class AtlasRelationshipStoreV2 implements AtlasRelationshipStore { ...@@ -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); AtlasRelationship ret = updateRelationship(edge, relationship);
sendNotifications(ret, OperationType.RELATIONSHIP_UPDATE); sendNotifications(ret, OperationType.RELATIONSHIP_UPDATE);
...@@ -337,7 +346,7 @@ public class AtlasRelationshipStoreV2 implements AtlasRelationshipStore { ...@@ -337,7 +346,7 @@ public class AtlasRelationshipStoreV2 implements AtlasRelationshipStore {
AtlasEdge ret; AtlasEdge ret;
try { try {
validateRelationship(end1Vertex, end2Vertex, relationship.getTypeName(), relationship.getAttributes()); validateRelationship(end1Vertex, end2Vertex, relationship);
String relationshipLabel = getRelationshipEdgeLabel(end1Vertex, end2Vertex, relationship.getTypeName()); String relationshipLabel = getRelationshipEdgeLabel(end1Vertex, end2Vertex, relationship.getTypeName());
...@@ -623,7 +632,10 @@ public class AtlasRelationshipStoreV2 implements AtlasRelationshipStore { ...@@ -623,7 +632,10 @@ public class AtlasRelationshipStoreV2 implements AtlasRelationshipStore {
validateAndNormalize(relationship); 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); AtlasRelationshipType relationshipType = typeRegistry.getRelationshipTypeByName(relationshipName);
if (relationshipType == null) { if (relationshipType == null) {
...@@ -654,7 +666,6 @@ public class AtlasRelationshipStoreV2 implements AtlasRelationshipStore { ...@@ -654,7 +666,6 @@ public class AtlasRelationshipStoreV2 implements AtlasRelationshipStore {
} }
List<String> messages = new ArrayList<>(); List<String> messages = new ArrayList<>();
AtlasRelationship relationship = new AtlasRelationship(relationshipName, attributes);
relationshipType.validateValue(relationship, relationshipName, messages); relationshipType.validateValue(relationship, relationshipName, messages);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment