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


The following commit(s) were added to refs/heads/branch-2.0 by this push:
     new b2c25a8  ATLAS-3675 Enable quick search and suggestions for business 
metadata attributes
b2c25a8 is described below

commit b2c25a860f4e695c0eff9981cd21d421348c83ca
Author: Mandar Ambawane <[email protected]>
AuthorDate: Sat Mar 21 13:58:17 2020 +0530

    ATLAS-3675 Enable quick search and suggestions for business metadata 
attributes
    
    Signed-off-by: Sarath Subramanian <[email protected]>
    (cherry picked from commit df8502ea4962e95ad02a7e05b5bb1ae50ccd0bcb)
---
 .../org/apache/atlas/listener/ChangedTypeDefs.java | 21 +++++++++++++++++++++
 .../repository/graph/GraphBackedSearchIndexer.java | 10 ++++++++++
 .../atlas/repository/graph/SolrIndexHelper.java    | 22 ++++++++++++++++++++--
 3 files changed, 51 insertions(+), 2 deletions(-)

diff --git a/intg/src/main/java/org/apache/atlas/listener/ChangedTypeDefs.java 
b/intg/src/main/java/org/apache/atlas/listener/ChangedTypeDefs.java
index af00f6c..58e889a 100644
--- a/intg/src/main/java/org/apache/atlas/listener/ChangedTypeDefs.java
+++ b/intg/src/main/java/org/apache/atlas/listener/ChangedTypeDefs.java
@@ -18,6 +18,7 @@
 package org.apache.atlas.listener;
 
 import org.apache.atlas.model.typedef.AtlasBaseTypeDef;
+import org.apache.atlas.model.typedef.AtlasBusinessMetadataDef;
 import org.apache.atlas.model.typedef.AtlasEntityDef;
 import org.apache.commons.collections.CollectionUtils;
 
@@ -89,4 +90,24 @@ public class ChangedTypeDefs {
 
         return ret;
     }
+
+    public boolean hasBusinessMetadataDef() {
+        return hasBusinessMetadataDef(createdTypeDefs) || 
hasEntityDef(updatedTypeDefs) || hasEntityDef(deletedTypeDefs);
+    }
+
+    private boolean hasBusinessMetadataDef(List<? extends AtlasBaseTypeDef> 
typeDefs) {
+        boolean ret = false;
+
+        if (CollectionUtils.isNotEmpty(typeDefs)) {
+            for (AtlasBaseTypeDef typeDef : typeDefs) {
+                if (typeDef instanceof AtlasBusinessMetadataDef) {
+                    ret = true;
+
+                    break;
+                }
+            }
+        }
+
+        return ret;
+    }
 }
diff --git 
a/repository/src/main/java/org/apache/atlas/repository/graph/GraphBackedSearchIndexer.java
 
b/repository/src/main/java/org/apache/atlas/repository/graph/GraphBackedSearchIndexer.java
index f96e6a6..f1dfc69 100755
--- 
a/repository/src/main/java/org/apache/atlas/repository/graph/GraphBackedSearchIndexer.java
+++ 
b/repository/src/main/java/org/apache/atlas/repository/graph/GraphBackedSearchIndexer.java
@@ -377,6 +377,10 @@ public class GraphBackedSearchIndexer implements 
SearchIndexer, ActiveStateChang
                 AtlasEntityType entityType = 
typeRegistry.getEntityTypeByName(baseTypeDef.getName());
 
                 resolveIndexFieldNames(managementSystem, entityType);
+            } else 
if(TypeCategory.BUSINESS_METADATA.equals(baseTypeDef.getCategory())) {
+                AtlasBusinessMetadataType businessMetadataType = 
typeRegistry.getBusinessMetadataTypeByName(baseTypeDef.getName());
+
+                resolveIndexFieldNames(managementSystem, businessMetadataType);
             } else {
                 LOG.debug("Ignoring the non-entity type definition {}", 
baseTypeDef.getName());
             }
@@ -389,6 +393,12 @@ public class GraphBackedSearchIndexer implements 
SearchIndexer, ActiveStateChang
         }
     }
 
+    private void resolveIndexFieldNames(AtlasGraphManagement managementSystem, 
AtlasBusinessMetadataType businessMetadataType) {
+        for (AtlasAttribute attribute : 
businessMetadataType.getAllAttributes().values()) {
+            resolveIndexFieldName(managementSystem, attribute);
+        }
+    }
+
     private void resolveIndexFieldName(AtlasGraphManagement managementSystem, 
AtlasAttribute attribute) {
         try {
             if (attribute.getIndexFieldName() == null && 
TypeCategory.PRIMITIVE.equals(attribute.getAttributeType().getTypeCategory())) {
diff --git 
a/repository/src/main/java/org/apache/atlas/repository/graph/SolrIndexHelper.java
 
b/repository/src/main/java/org/apache/atlas/repository/graph/SolrIndexHelper.java
index 4ec0086..814b9f5 100644
--- 
a/repository/src/main/java/org/apache/atlas/repository/graph/SolrIndexHelper.java
+++ 
b/repository/src/main/java/org/apache/atlas/repository/graph/SolrIndexHelper.java
@@ -23,6 +23,7 @@ import 
org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef;
 import org.apache.atlas.repository.Constants;
 import org.apache.atlas.repository.graphdb.AtlasGraph;
 import org.apache.atlas.repository.graphdb.AtlasGraphIndexClient;
+import org.apache.atlas.type.AtlasBusinessMetadataType;
 import org.apache.atlas.type.AtlasEntityType;
 import org.apache.atlas.type.AtlasStructType.AtlasAttribute;
 import org.apache.atlas.type.AtlasTypeRegistry;
@@ -67,7 +68,7 @@ public class SolrIndexHelper implements IndexChangeListener {
     @Override
     public void onChange(ChangedTypeDefs changedTypeDefs) {
         if (!AtlasRepositoryConfiguration.isFreeTextSearchEnabled() ||
-            changedTypeDefs == null || !changedTypeDefs.hasEntityDef()) { // 
nothing to do if there are no changes to entity-defs
+            changedTypeDefs == null || !(changedTypeDefs.hasEntityDef() || 
changedTypeDefs.hasBusinessMetadataDef())) { // nothing to do if there are no 
changes to entity-defs
             return;
         }
         if(initializationCompleted) {
@@ -119,6 +120,7 @@ public class SolrIndexHelper implements IndexChangeListener 
{
     private Map<String, Integer> geIndexFieldNamesWithSearchWeights() {
         Map<String, Integer>        ret         = new HashMap<>();
         Collection<AtlasEntityType> entityTypes = 
typeRegistry.getAllEntityTypes();
+        Collection<AtlasBusinessMetadataType> businessMetadataTypes = 
typeRegistry.getAllBusinessMetadataTypes();
 
         //the following properties are specially added manually.
         //as, they don't come in the entity definitions as attributes.
@@ -128,7 +130,7 @@ public class SolrIndexHelper implements IndexChangeListener 
{
         
ret.put(typeRegistry.getIndexFieldName(CUSTOM_ATTRIBUTES_PROPERTY_KEY), 
SEARCHWEIGHT_FOR_CUSTOM_ATTRS);
         ret.put(typeRegistry.getIndexFieldName(TYPE_NAME_PROPERTY_KEY), 
SEARCHWEIGHT_FOR_TYPENAME);
 
-        if (!CollectionUtils.isNotEmpty(entityTypes)) {
+        if (!CollectionUtils.isNotEmpty(entityTypes) && 
CollectionUtils.isEmpty(businessMetadataTypes)) {
             return ret;
         }
 
@@ -140,9 +142,25 @@ public class SolrIndexHelper implements 
IndexChangeListener {
             processEntityType(ret, entityType);
         }
 
+        for(AtlasBusinessMetadataType businessMetadataType : 
businessMetadataTypes){
+            processBusinessMetadataType(ret, businessMetadataType);
+        }
+
         return ret;
     }
 
+    private void processBusinessMetadataType(Map<String, Integer> 
indexFieldNameWithSearchWeights, AtlasBusinessMetadataType 
businessMetadataType) {
+        List<AtlasAttributeDef> attributes = 
businessMetadataType.getBusinessMetadataDef().getAttributeDefs();
+
+        if (CollectionUtils.isNotEmpty(attributes)) {
+            for (AtlasAttributeDef attribute : attributes) {
+                processAttribute(indexFieldNameWithSearchWeights, 
businessMetadataType.getAttribute(attribute.getName()));
+            }
+        } else {
+            LOG.debug("No attributes are defined for BusinessMetadata {}", 
businessMetadataType.getTypeName());
+        }
+    }
+
     private void processEntityType(Map<String, Integer> 
indexFieldNameWithSearchWeights, AtlasEntityType entityType) {
         List<AtlasAttributeDef> attributes = 
entityType.getEntityDef().getAttributeDefs();
 

Reply via email to