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

org.openmetadata.service.search.indexes.TestCaseIndex 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 java.util.Set;
import lombok.SneakyThrows;
import org.openmetadata.schema.tests.TestCase;
import org.openmetadata.schema.tests.TestDefinition;
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.SearchIndexUtils;
import org.openmetadata.service.search.models.SearchSuggest;

public record TestCaseIndex(TestCase testCase) implements SearchIndex {
  private static final Set excludeFields = Set.of("changeDescription", "failedRowsSample");

  @Override
  public Object getEntity() {
    return testCase;
  }

  @Override
  public void removeNonIndexableFields(Map esDoc) {
    SearchIndex.super.removeNonIndexableFields(esDoc);
    List> testSuites = (List>) esDoc.get("testSuites");
    if (testSuites != null) {
      for (Map testSuite : testSuites) {
        SearchIndexUtils.removeNonIndexableFields(testSuite, excludeFields);
      }
    }
  }

  @SneakyThrows
  public Map buildSearchIndexDocInternal(Map doc) {
    // Build Index Doc
    List suggest = new ArrayList<>();
    TestDefinition testDefinition =
        Entity.getEntity(
            Entity.TEST_DEFINITION, testCase.getTestDefinition().getId(), "", Include.ALL);
    suggest.add(SearchSuggest.builder().input(testCase.getFullyQualifiedName()).weight(5).build());
    suggest.add(SearchSuggest.builder().input(testCase.getName()).weight(10).build());
    doc.put(
        "fqnParts",
        getFQNParts(
            testCase.getFullyQualifiedName(),
            suggest.stream().map(SearchSuggest::getInput).toList()));
    doc.put("suggest", suggest);
    doc.put("entityType", Entity.TEST_CASE);
    doc.put("owners", getEntitiesWithDisplayName(testCase.getOwners()));
    doc.put("tags", testCase.getTags());
    doc.put("testPlatforms", testDefinition.getTestPlatforms());
    doc.put("dataQualityDimension", testDefinition.getDataQualityDimension());
    doc.put("followers", SearchIndexUtils.parseFollowers(testCase.getFollowers()));
    doc.put("testCaseType", testDefinition.getEntityType());
    setParentRelationships(doc, testCase);
    return doc;
  }

  private void setParentRelationships(Map doc, TestCase testCase) {
    // denormalize the parent relationships for search
    EntityReference testSuiteEntityReference = testCase.getTestSuite();
    if (testSuiteEntityReference == null) {
      return;
    }
    TestSuite testSuite = Entity.getEntityOrNull(testSuiteEntityReference, "", Include.ALL);
    EntityReference entityReference = testSuite.getExecutableEntityReference();
    TestSuiteIndex.addTestSuiteParentEntityRelations(entityReference, doc);
  }

  public static Map getFields() {
    Map fields = SearchIndex.getDefaultFields();
    fields.put("testSuite.fullyQualifiedName", 10.0f);
    fields.put("testSuite.name", 10.0f);
    fields.put("testSuite.description", 1.0f);
    fields.put("entityLink", 3.0f);
    fields.put("entityFQN", 10.0f);
    return fields;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy