All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.openmetadata.service.search.indexes.TestSuiteIndex Maven / Gradle / Ivy

There is a newer version: 1.5.11
Show newest version
package org.openmetadata.service.search.indexes;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.openmetadata.schema.entity.data.Table;
import org.openmetadata.schema.tests.TestSuite;
import org.openmetadata.schema.type.EntityReference;
import org.openmetadata.schema.type.Include;
import org.openmetadata.service.Entity;
import org.openmetadata.service.search.ParseTags;
import org.openmetadata.service.search.SearchIndexUtils;
import org.openmetadata.service.search.models.SearchSuggest;

public record TestSuiteIndex(TestSuite testSuite) implements SearchIndex {
  @Override
  public Object getEntity() {
    return testSuite;
  }

  public Map buildSearchIndexDocInternal(Map doc) {
    List suggest = new ArrayList<>();
    suggest.add(SearchSuggest.builder().input(testSuite.getFullyQualifiedName()).weight(5).build());
    suggest.add(SearchSuggest.builder().input(testSuite.getName()).weight(10).build());
    doc.put(
        "fqnParts",
        getFQNParts(
            testSuite.getFullyQualifiedName(),
            suggest.stream().map(SearchSuggest::getInput).toList()));
    doc.put("suggest", suggest);
    doc.put("entityType", Entity.TEST_SUITE);
    doc.put("owners", getEntitiesWithDisplayName(testSuite.getOwners()));
    doc.put("followers", SearchIndexUtils.parseFollowers(testSuite.getFollowers()));
    ParseTags parseTags = new ParseTags(Entity.getEntityTags(Entity.TEST_SUITE, testSuite));
    doc.put("tags", parseTags.getTags());
    setParentRelationships(doc, testSuite);
    return doc;
  }

  private void setParentRelationships(Map doc, TestSuite testSuite) {
    // denormalize the parent relationships for search
    EntityReference entityReference = testSuite.getExecutableEntityReference();
    if (entityReference == null) return;
    addTestSuiteParentEntityRelations(entityReference, doc);
  }

  protected static void addTestSuiteParentEntityRelations(
      EntityReference testSuiteRef, Map doc) {
    if (testSuiteRef.getType().equals(Entity.TABLE)) {
      Table table = Entity.getEntity(testSuiteRef, "", Include.ALL);
      doc.put("table", table.getEntityReference());
      doc.put("database", table.getDatabase());
      doc.put("databaseSchema", table.getDatabaseSchema());
      doc.put("service", table.getService());
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy