atlas git commit: ATLAS-2984: export should include type defintions of relationships referenced by entities

2018-11-29 Thread madhan
Repository: atlas
Updated Branches:
  refs/heads/branch-1.0 943e5c711 -> ee22f0b14


ATLAS-2984: export should include type defintions of relationships referenced 
by entities

(cherry picked from commit e4921452ebea5b338c07bbc6f886c44c8843f64b)


Project: http://git-wip-us.apache.org/repos/asf/atlas/repo
Commit: http://git-wip-us.apache.org/repos/asf/atlas/commit/ee22f0b1
Tree: http://git-wip-us.apache.org/repos/asf/atlas/tree/ee22f0b1
Diff: http://git-wip-us.apache.org/repos/asf/atlas/diff/ee22f0b1

Branch: refs/heads/branch-1.0
Commit: ee22f0b140f04aa4339b1935f654a380f74e8fc4
Parents: 943e5c7
Author: Madhan Neethiraj 
Authored: Thu Nov 29 13:10:58 2018 -0800
Committer: Madhan Neethiraj 
Committed: Thu Nov 29 20:34:18 2018 -0800

--
 .../atlas/repository/impexp/ExportService.java  | 30 
 .../repository/impexp/ExportTypeProcessor.java  | 24 
 .../impexp/ImportTypeDefProcessor.java  |  1 +
 3 files changed, 55 insertions(+)
--


http://git-wip-us.apache.org/repos/asf/atlas/blob/ee22f0b1/repository/src/main/java/org/apache/atlas/repository/impexp/ExportService.java
--
diff --git 
a/repository/src/main/java/org/apache/atlas/repository/impexp/ExportService.java
 
b/repository/src/main/java/org/apache/atlas/repository/impexp/ExportService.java
index 3558d2a..5632520 100644
--- 
a/repository/src/main/java/org/apache/atlas/repository/impexp/ExportService.java
+++ 
b/repository/src/main/java/org/apache/atlas/repository/impexp/ExportService.java
@@ -32,6 +32,7 @@ import org.apache.atlas.model.typedef.AtlasBaseTypeDef;
 import org.apache.atlas.model.typedef.AtlasClassificationDef;
 import org.apache.atlas.model.typedef.AtlasEntityDef;
 import org.apache.atlas.model.typedef.AtlasEnumDef;
+import org.apache.atlas.model.typedef.AtlasRelationshipDef;
 import org.apache.atlas.model.typedef.AtlasStructDef;
 import org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef;
 import org.apache.atlas.model.typedef.AtlasTypesDef;
@@ -43,6 +44,7 @@ import org.apache.atlas.type.AtlasClassificationType;
 import org.apache.atlas.type.AtlasEntityType;
 import org.apache.atlas.type.AtlasEnumType;
 import org.apache.atlas.type.AtlasMapType;
+import org.apache.atlas.type.AtlasRelationshipType;
 import org.apache.atlas.type.AtlasStructType;
 import org.apache.atlas.type.AtlasStructType.AtlasAttribute;
 import org.apache.atlas.type.AtlasType;
@@ -175,6 +177,12 @@ public class ExportService {
 
 typesDef.getEnumDefs().add(enumDef);
 }
+
+for (String relationshipType : context.relationshipTypes) {
+AtlasRelationshipDef relationshipDef = 
typeRegistry.getRelationshipDefByName(relationshipType);
+
+typesDef.getRelationshipDefs().add(relationshipDef);
+}
 }
 
 private AtlasExportResult.OperationStatus[] 
processItems(AtlasExportRequest request, ExportContext context) {
@@ -611,6 +619,8 @@ public class ExportService {
 addStructType((AtlasStructType)type, context);
 } else if (type instanceof AtlasEnumType) {
 addEnumType((AtlasEnumType)type, context);
+} else if (type instanceof AtlasRelationshipType) {
+addRelationshipType((AtlasRelationshipType)type, context);
 }
 }
 
@@ -619,6 +629,7 @@ public class ExportService {
 context.entityTypes.add(entityType.getTypeName());
 
 addAttributeTypes(entityType, context);
+addRelationshipTypes(entityType, context);
 
 if (CollectionUtils.isNotEmpty(entityType.getAllSuperTypes())) {
 for (String superType : entityType.getAllSuperTypes()) {
@@ -656,12 +667,30 @@ public class ExportService {
 }
 }
 
+private void addRelationshipType(AtlasRelationshipType relationshipType, 
ExportContext context) {
+if 
(!context.relationshipTypes.contains(relationshipType.getTypeName())) {
+context.relationshipTypes.add(relationshipType.getTypeName());
+
+addAttributeTypes(relationshipType, context);
+addEntityType(relationshipType.getEnd1Type(), context);
+addEntityType(relationshipType.getEnd2Type(), context);
+}
+}
+
 private void addAttributeTypes(AtlasStructType structType, ExportContext 
context) {
 for (AtlasAttributeDef attributeDef : 
structType.getStructDef().getAttributeDefs()) {
 addType(attributeDef.getTypeName(), context);
 }
 }
 
+private void addRelationshipTypes(AtlasEntityType entityType, 
ExportContext context) {
+for (List relationshipTypes : 
entityType.getRelationshipAttributesType().values()) {
+for (AtlasRelationshipType relationshipType : relationshipTypes) {
+addRelationshipType(relationshipType, 

atlas git commit: ATLAS-2984: export should include type defintions of relationships referenced by entities

2018-11-29 Thread madhan
Repository: atlas
Updated Branches:
  refs/heads/master 9a5553731 -> e4921452e


ATLAS-2984: export should include type defintions of relationships referenced 
by entities


Project: http://git-wip-us.apache.org/repos/asf/atlas/repo
Commit: http://git-wip-us.apache.org/repos/asf/atlas/commit/e4921452
Tree: http://git-wip-us.apache.org/repos/asf/atlas/tree/e4921452
Diff: http://git-wip-us.apache.org/repos/asf/atlas/diff/e4921452

Branch: refs/heads/master
Commit: e4921452ebea5b338c07bbc6f886c44c8843f64b
Parents: 9a55537
Author: Madhan Neethiraj 
Authored: Thu Nov 29 13:10:58 2018 -0800
Committer: Madhan Neethiraj 
Committed: Thu Nov 29 17:33:45 2018 -0800

--
 .../atlas/repository/impexp/ExportService.java  | 30 
 .../repository/impexp/ExportTypeProcessor.java  | 24 
 .../impexp/ImportTypeDefProcessor.java  |  1 +
 3 files changed, 55 insertions(+)
--


http://git-wip-us.apache.org/repos/asf/atlas/blob/e4921452/repository/src/main/java/org/apache/atlas/repository/impexp/ExportService.java
--
diff --git 
a/repository/src/main/java/org/apache/atlas/repository/impexp/ExportService.java
 
b/repository/src/main/java/org/apache/atlas/repository/impexp/ExportService.java
index 3558d2a..5632520 100644
--- 
a/repository/src/main/java/org/apache/atlas/repository/impexp/ExportService.java
+++ 
b/repository/src/main/java/org/apache/atlas/repository/impexp/ExportService.java
@@ -32,6 +32,7 @@ import org.apache.atlas.model.typedef.AtlasBaseTypeDef;
 import org.apache.atlas.model.typedef.AtlasClassificationDef;
 import org.apache.atlas.model.typedef.AtlasEntityDef;
 import org.apache.atlas.model.typedef.AtlasEnumDef;
+import org.apache.atlas.model.typedef.AtlasRelationshipDef;
 import org.apache.atlas.model.typedef.AtlasStructDef;
 import org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef;
 import org.apache.atlas.model.typedef.AtlasTypesDef;
@@ -43,6 +44,7 @@ import org.apache.atlas.type.AtlasClassificationType;
 import org.apache.atlas.type.AtlasEntityType;
 import org.apache.atlas.type.AtlasEnumType;
 import org.apache.atlas.type.AtlasMapType;
+import org.apache.atlas.type.AtlasRelationshipType;
 import org.apache.atlas.type.AtlasStructType;
 import org.apache.atlas.type.AtlasStructType.AtlasAttribute;
 import org.apache.atlas.type.AtlasType;
@@ -175,6 +177,12 @@ public class ExportService {
 
 typesDef.getEnumDefs().add(enumDef);
 }
+
+for (String relationshipType : context.relationshipTypes) {
+AtlasRelationshipDef relationshipDef = 
typeRegistry.getRelationshipDefByName(relationshipType);
+
+typesDef.getRelationshipDefs().add(relationshipDef);
+}
 }
 
 private AtlasExportResult.OperationStatus[] 
processItems(AtlasExportRequest request, ExportContext context) {
@@ -611,6 +619,8 @@ public class ExportService {
 addStructType((AtlasStructType)type, context);
 } else if (type instanceof AtlasEnumType) {
 addEnumType((AtlasEnumType)type, context);
+} else if (type instanceof AtlasRelationshipType) {
+addRelationshipType((AtlasRelationshipType)type, context);
 }
 }
 
@@ -619,6 +629,7 @@ public class ExportService {
 context.entityTypes.add(entityType.getTypeName());
 
 addAttributeTypes(entityType, context);
+addRelationshipTypes(entityType, context);
 
 if (CollectionUtils.isNotEmpty(entityType.getAllSuperTypes())) {
 for (String superType : entityType.getAllSuperTypes()) {
@@ -656,12 +667,30 @@ public class ExportService {
 }
 }
 
+private void addRelationshipType(AtlasRelationshipType relationshipType, 
ExportContext context) {
+if 
(!context.relationshipTypes.contains(relationshipType.getTypeName())) {
+context.relationshipTypes.add(relationshipType.getTypeName());
+
+addAttributeTypes(relationshipType, context);
+addEntityType(relationshipType.getEnd1Type(), context);
+addEntityType(relationshipType.getEnd2Type(), context);
+}
+}
+
 private void addAttributeTypes(AtlasStructType structType, ExportContext 
context) {
 for (AtlasAttributeDef attributeDef : 
structType.getStructDef().getAttributeDefs()) {
 addType(attributeDef.getTypeName(), context);
 }
 }
 
+private void addRelationshipTypes(AtlasEntityType entityType, 
ExportContext context) {
+for (List relationshipTypes : 
entityType.getRelationshipAttributesType().values()) {
+for (AtlasRelationshipType relationshipType : relationshipTypes) {
+addRelationshipType(relationshipType, context);
+}
+}
+}
+
 private List>