ATLAS-1940: fix to remove duplicate type which causes Atlas server to fail during startup

Signed-off-by: Madhan Neethiraj <madhan@apache.org>
diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasTypeDefGraphStore.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasTypeDefGraphStore.java
index 9d9c59d..eedcd10 100644
--- a/repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasTypeDefGraphStore.java
+++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasTypeDefGraphStore.java
@@ -159,6 +159,7 @@
 
         return ret;
     }
+
     @Override
     public AtlasRelationshipDef getRelationshipDefByName(String name) throws AtlasBaseException {
         AtlasRelationshipDef ret = typeRegistry.getRelationshipDefByName(name);
@@ -680,21 +681,37 @@
             for (AtlasStructDef structDef : typesDef.getStructDefs()) {
                 rectifyAttributesIfNeeded(entityNames, structDef);
             }
+            removeDuplicateTypeIfAny(typesDef.getStructDefs());
         }
 
         if (CollectionUtils.isNotEmpty(typesDef.getClassificationDefs())) {
             for (AtlasClassificationDef classificationDef : typesDef.getClassificationDefs()) {
                 rectifyAttributesIfNeeded(entityNames, classificationDef);
             }
+            removeDuplicateTypeIfAny(typesDef.getClassificationDefs());
         }
 
         if (CollectionUtils.isNotEmpty(typesDef.getEntityDefs())) {
             for (AtlasEntityDef entityDef : typesDef.getEntityDefs()) {
                 rectifyAttributesIfNeeded(entityNames, entityDef);
             }
+            removeDuplicateTypeIfAny(typesDef.getEntityDefs());
         }
     }
 
+    private <T extends AtlasBaseTypeDef> void removeDuplicateTypeIfAny(List<T> defList) {
+        final Set<String> entityDefNames = new HashSet<>();
+
+        for (int i = 0; i < defList.size(); i++) {
+            if (!entityDefNames.add((defList.get(i)).getName())) {
+                LOG.warn(" Found Duplicate Type => " + defList.get(i).getName());
+                defList.remove(i);
+                i--;
+            }
+        }
+    }
+
+
     private void rectifyAttributesIfNeeded(final Set<String> entityNames, AtlasStructDef structDef) {
         List<AtlasAttributeDef> attributeDefs = structDef.getAttributeDefs();