2021-08-01 14:27:44 -07:00
|
|
|
/*
|
2021-12-16 07:13:50 -08:00
|
|
|
* Copyright 2021 Collate
|
2021-12-01 12:46:28 +05:30
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
2021-08-01 14:27:44 -07:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2022-09-14 23:14:02 -07:00
|
|
|
package org.openmetadata.service;
|
2021-08-01 14:27:44 -07:00
|
|
|
|
2023-08-03 18:27:01 -07:00
|
|
|
import static org.openmetadata.common.utils.CommonUtil.listOf;
|
2022-03-02 18:22:09 -08:00
|
|
|
import static org.openmetadata.common.utils.CommonUtil.listOrEmpty;
|
|
|
|
|
2022-02-25 22:13:30 -08:00
|
|
|
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
|
2023-10-03 21:03:56 -07:00
|
|
|
import io.github.classgraph.ClassGraph;
|
|
|
|
import io.github.classgraph.ClassInfoList;
|
|
|
|
import io.github.classgraph.ScanResult;
|
2023-09-30 22:13:16 -07:00
|
|
|
import java.lang.reflect.Modifier;
|
2021-11-09 13:25:08 -08:00
|
|
|
import java.net.URI;
|
2022-03-20 18:01:51 -07:00
|
|
|
import java.util.ArrayList;
|
2021-11-10 12:40:27 -08:00
|
|
|
import java.util.Arrays;
|
2021-11-09 13:25:08 -08:00
|
|
|
import java.util.Collections;
|
2023-07-10 16:50:49 -07:00
|
|
|
import java.util.EnumMap;
|
2021-11-09 13:25:08 -08:00
|
|
|
import java.util.HashMap;
|
2023-07-17 21:41:25 -07:00
|
|
|
import java.util.HashSet;
|
2021-11-09 13:25:08 -08:00
|
|
|
import java.util.List;
|
|
|
|
import java.util.Locale;
|
|
|
|
import java.util.Map;
|
2023-07-17 21:41:25 -07:00
|
|
|
import java.util.Set;
|
2021-11-09 13:25:08 -08:00
|
|
|
import java.util.UUID;
|
2021-12-16 07:13:50 -08:00
|
|
|
import javax.ws.rs.core.UriInfo;
|
2023-08-03 18:27:01 -07:00
|
|
|
import lombok.Getter;
|
2022-01-09 21:04:10 -08:00
|
|
|
import lombok.NonNull;
|
2023-08-03 18:27:01 -07:00
|
|
|
import lombok.Setter;
|
2022-01-09 21:04:10 -08:00
|
|
|
import lombok.extern.slf4j.Slf4j;
|
2023-10-03 21:03:56 -07:00
|
|
|
import org.jdbi.v3.core.Jdbi;
|
2022-09-14 23:14:02 -07:00
|
|
|
import org.openmetadata.schema.EntityInterface;
|
2023-09-22 01:17:47 +02:00
|
|
|
import org.openmetadata.schema.EntityTimeSeriesInterface;
|
2023-03-03 19:10:01 +01:00
|
|
|
import org.openmetadata.schema.entity.services.ServiceType;
|
2022-09-14 23:14:02 -07:00
|
|
|
import org.openmetadata.schema.type.EntityReference;
|
|
|
|
import org.openmetadata.schema.type.Include;
|
2023-05-04 10:05:36 -07:00
|
|
|
import org.openmetadata.schema.type.MetadataOperation;
|
2023-03-20 04:42:03 -07:00
|
|
|
import org.openmetadata.schema.type.TagLabel;
|
2022-09-14 23:14:02 -07:00
|
|
|
import org.openmetadata.service.exception.CatalogExceptionMessage;
|
|
|
|
import org.openmetadata.service.exception.EntityNotFoundException;
|
2023-09-30 22:13:16 -07:00
|
|
|
import org.openmetadata.service.jdbi3.ChangeEventRepository;
|
|
|
|
import org.openmetadata.service.jdbi3.CollectionDAO;
|
2022-09-14 23:14:02 -07:00
|
|
|
import org.openmetadata.service.jdbi3.EntityRepository;
|
2023-09-22 01:17:47 +02:00
|
|
|
import org.openmetadata.service.jdbi3.EntityTimeSeriesRepository;
|
2023-08-03 18:27:01 -07:00
|
|
|
import org.openmetadata.service.jdbi3.FeedRepository;
|
2023-09-30 22:13:16 -07:00
|
|
|
import org.openmetadata.service.jdbi3.LineageRepository;
|
|
|
|
import org.openmetadata.service.jdbi3.Repository;
|
|
|
|
import org.openmetadata.service.jdbi3.SystemRepository;
|
|
|
|
import org.openmetadata.service.jdbi3.TokenRepository;
|
|
|
|
import org.openmetadata.service.jdbi3.UsageRepository;
|
2023-05-03 07:43:35 -07:00
|
|
|
import org.openmetadata.service.resources.feeds.MessageParser.EntityLink;
|
2023-10-03 14:56:53 -07:00
|
|
|
import org.openmetadata.service.search.SearchRepository;
|
2022-11-15 12:52:15 -08:00
|
|
|
import org.openmetadata.service.util.EntityUtil.Fields;
|
2021-11-09 13:25:08 -08:00
|
|
|
|
2022-01-09 21:04:10 -08:00
|
|
|
@Slf4j
|
2021-08-01 14:27:44 -07:00
|
|
|
public final class Entity {
|
2023-09-30 22:13:16 -07:00
|
|
|
private static volatile boolean initializedRepositories = false;
|
2023-10-03 23:41:06 -07:00
|
|
|
@Getter @Setter private static CollectionDAO collectionDAO;
|
2023-09-30 22:13:16 -07:00
|
|
|
public static final String SEPARATOR = "."; // Fully qualified name separator
|
2022-03-25 14:48:20 -07:00
|
|
|
|
2022-02-15 20:54:46 -08:00
|
|
|
// Canonical entity name to corresponding EntityRepository map
|
2023-01-30 21:34:34 -08:00
|
|
|
private static final Map<String, EntityRepository<? extends EntityInterface>> ENTITY_REPOSITORY_MAP = new HashMap<>();
|
2023-09-22 01:17:47 +02:00
|
|
|
private static final Map<String, EntityTimeSeriesRepository<? extends EntityTimeSeriesInterface>>
|
|
|
|
ENTITY_TS_REPOSITORY_MAP = new HashMap<>();
|
2022-02-15 20:54:46 -08:00
|
|
|
|
2023-09-30 22:13:16 -07:00
|
|
|
@Getter @Setter private static TokenRepository tokenRepository;
|
2023-08-03 18:27:01 -07:00
|
|
|
@Getter @Setter private static FeedRepository feedRepository;
|
2023-09-30 22:13:16 -07:00
|
|
|
@Getter @Setter private static LineageRepository lineageRepository;
|
|
|
|
@Getter @Setter private static UsageRepository usageRepository;
|
|
|
|
@Getter @Setter private static SystemRepository systemRepository;
|
|
|
|
@Getter @Setter private static ChangeEventRepository changeEventRepository;
|
2023-10-03 14:56:53 -07:00
|
|
|
@Getter @Setter private static SearchRepository searchRepository;
|
2023-08-03 18:27:01 -07:00
|
|
|
|
2022-07-26 12:08:01 -07:00
|
|
|
// List of all the entities
|
2022-07-04 10:07:47 -07:00
|
|
|
private static final List<String> ENTITY_LIST = new ArrayList<>();
|
|
|
|
|
2022-02-28 19:17:19 -08:00
|
|
|
// Common field names
|
|
|
|
public static final String FIELD_OWNER = "owner";
|
2022-04-22 18:57:08 -07:00
|
|
|
public static final String FIELD_NAME = "name";
|
2022-02-28 19:17:19 -08:00
|
|
|
public static final String FIELD_DESCRIPTION = "description";
|
2022-04-17 21:49:10 -07:00
|
|
|
public static final String FIELD_FOLLOWERS = "followers";
|
2023-03-20 13:58:20 +05:30
|
|
|
public static final String FIELD_VOTES = "votes";
|
2022-04-17 21:49:10 -07:00
|
|
|
public static final String FIELD_TAGS = "tags";
|
|
|
|
public static final String FIELD_DELETED = "deleted";
|
2022-11-03 14:37:26 +05:30
|
|
|
public static final String FIELD_PIPELINE_STATUS = "pipelineStatus";
|
2022-04-22 18:57:08 -07:00
|
|
|
public static final String FIELD_DISPLAY_NAME = "displayName";
|
2022-05-18 09:52:27 -07:00
|
|
|
public static final String FIELD_EXTENSION = "extension";
|
2022-06-27 01:19:27 -07:00
|
|
|
public static final String FIELD_USAGE_SUMMARY = "usageSummary";
|
2023-08-12 15:45:56 -07:00
|
|
|
public static final String FIELD_CHILDREN = "children";
|
|
|
|
public static final String FIELD_PARENT = "parent";
|
2023-07-04 10:00:16 -07:00
|
|
|
public static final String FIELD_REVIEWERS = "reviewers";
|
2023-08-12 15:45:56 -07:00
|
|
|
public static final String FIELD_EXPERTS = "experts";
|
2023-07-03 15:42:35 -07:00
|
|
|
public static final String FIELD_DOMAIN = "domain";
|
|
|
|
public static final String FIELD_DATA_PRODUCTS = "dataProducts";
|
2023-08-12 15:45:56 -07:00
|
|
|
public static final String FIELD_ASSETS = "assets";
|
2022-02-28 19:17:19 -08:00
|
|
|
|
2023-09-17 20:01:55 -07:00
|
|
|
public static final String FIELD_STYLE = "style";
|
|
|
|
|
2023-09-19 05:03:57 -07:00
|
|
|
public static final String FIELD_LIFE_CYCLE = "lifeCycle";
|
|
|
|
|
2023-10-12 16:11:24 -07:00
|
|
|
public static final String FIELD_DISABLED = "disabled";
|
|
|
|
|
2021-11-09 13:25:08 -08:00
|
|
|
//
|
2022-05-14 10:57:19 -07:00
|
|
|
// Service entities
|
2021-11-09 13:25:08 -08:00
|
|
|
//
|
2021-08-01 14:27:44 -07:00
|
|
|
public static final String DATABASE_SERVICE = "databaseService";
|
2021-08-17 14:59:37 -07:00
|
|
|
public static final String MESSAGING_SERVICE = "messagingService";
|
2021-08-25 13:19:35 -07:00
|
|
|
public static final String DASHBOARD_SERVICE = "dashboardService";
|
2021-09-24 08:54:04 -07:00
|
|
|
public static final String PIPELINE_SERVICE = "pipelineService";
|
2021-11-03 08:51:36 +01:00
|
|
|
public static final String STORAGE_SERVICE = "storageService";
|
2022-06-21 14:54:36 +02:00
|
|
|
public static final String MLMODEL_SERVICE = "mlmodelService";
|
2022-11-11 13:16:54 +05:30
|
|
|
public static final String METADATA_SERVICE = "metadataService";
|
2023-08-10 16:47:37 -07:00
|
|
|
public static final String SEARCH_SERVICE = "searchService";
|
2021-11-09 13:25:08 -08:00
|
|
|
//
|
2022-05-14 10:57:19 -07:00
|
|
|
// Data asset entities
|
2021-11-09 13:25:08 -08:00
|
|
|
//
|
2021-08-01 14:27:44 -07:00
|
|
|
public static final String TABLE = "table";
|
2023-08-24 23:14:30 -07:00
|
|
|
public static final String STORED_PROCEDURE = "storedProcedure";
|
2021-08-01 14:27:44 -07:00
|
|
|
public static final String DATABASE = "database";
|
2022-04-04 22:06:41 -07:00
|
|
|
public static final String DATABASE_SCHEMA = "databaseSchema";
|
2021-08-01 14:27:44 -07:00
|
|
|
public static final String METRICS = "metrics";
|
|
|
|
public static final String DASHBOARD = "dashboard";
|
2023-08-03 18:27:01 -07:00
|
|
|
public static final String DASHBOARD_DATA_MODEL = "dashboardDataModel";
|
2021-09-24 08:54:04 -07:00
|
|
|
public static final String PIPELINE = "pipeline";
|
2021-08-25 13:19:35 -07:00
|
|
|
public static final String CHART = "chart";
|
2023-10-10 11:32:37 +05:30
|
|
|
public static final String APPLICATION = "app";
|
|
|
|
public static final String APP_MARKET_PLACE_DEF = "appMarketPlaceDefinition";
|
2021-08-01 14:27:44 -07:00
|
|
|
public static final String REPORT = "report";
|
2021-08-18 10:35:48 -07:00
|
|
|
public static final String TOPIC = "topic";
|
2023-08-10 16:47:37 -07:00
|
|
|
public static final String SEARCH_INDEX = "searchIndex";
|
2021-11-27 21:31:55 +01:00
|
|
|
public static final String MLMODEL = "mlmodel";
|
2023-02-25 00:34:08 +00:00
|
|
|
public static final String CONTAINER = "container";
|
2023-03-16 09:25:30 +05:30
|
|
|
public static final String QUERY = "query";
|
|
|
|
|
2022-02-15 20:54:46 -08:00
|
|
|
public static final String GLOSSARY = "glossary";
|
|
|
|
public static final String GLOSSARY_TERM = "glossaryTerm";
|
2022-02-25 20:53:53 -08:00
|
|
|
public static final String TAG = "tag";
|
2022-12-26 12:32:17 -08:00
|
|
|
public static final String CLASSIFICATION = "classification";
|
2022-05-14 10:57:19 -07:00
|
|
|
public static final String TYPE = "type";
|
2022-07-28 13:58:41 -07:00
|
|
|
public static final String TEST_DEFINITION = "testDefinition";
|
2023-03-05 10:17:08 +01:00
|
|
|
public static final String TEST_CONNECTION_DEFINITION = "testConnectionDefinition";
|
2022-07-28 13:58:41 -07:00
|
|
|
public static final String TEST_SUITE = "testSuite";
|
2022-11-09 13:06:13 +05:30
|
|
|
public static final String KPI = "kpi";
|
2022-07-28 13:58:41 -07:00
|
|
|
public static final String TEST_CASE = "testCase";
|
2022-10-20 16:38:54 +02:00
|
|
|
public static final String WEB_ANALYTIC_EVENT = "webAnalyticEvent";
|
2022-11-03 10:21:14 +01:00
|
|
|
public static final String DATA_INSIGHT_CHART = "dataInsightChart";
|
2021-08-01 14:27:44 -07:00
|
|
|
|
2021-11-09 13:25:08 -08:00
|
|
|
//
|
2022-05-14 10:57:19 -07:00
|
|
|
// Policy entity
|
2021-11-09 13:25:08 -08:00
|
|
|
//
|
2021-11-04 22:55:27 -07:00
|
|
|
public static final String POLICY = "policy";
|
2022-08-12 22:15:57 +05:30
|
|
|
public static final String POLICIES = "policies";
|
2021-11-04 22:55:27 -07:00
|
|
|
|
2021-11-09 13:25:08 -08:00
|
|
|
//
|
2022-05-14 10:57:19 -07:00
|
|
|
// Role, team and user entities
|
2021-11-09 13:25:08 -08:00
|
|
|
//
|
2021-12-30 08:30:12 -08:00
|
|
|
public static final String ROLE = "role";
|
2021-08-01 14:27:44 -07:00
|
|
|
public static final String USER = "user";
|
|
|
|
public static final String TEAM = "team";
|
2023-09-29 19:13:56 -07:00
|
|
|
public static final String PERSONA = "persona";
|
2023-08-03 18:27:01 -07:00
|
|
|
public static final String BOT = "bot";
|
2021-08-01 14:27:44 -07:00
|
|
|
|
2021-12-06 22:29:20 -08:00
|
|
|
//
|
2022-05-14 10:57:19 -07:00
|
|
|
// Operation related entities
|
2021-12-06 22:29:20 -08:00
|
|
|
//
|
2022-04-04 12:46:09 -07:00
|
|
|
public static final String INGESTION_PIPELINE = "ingestionPipeline";
|
2021-11-09 20:56:45 -08:00
|
|
|
|
2023-07-02 11:32:52 -07:00
|
|
|
//
|
|
|
|
// Domain related entities
|
|
|
|
//
|
|
|
|
public static final String DOMAIN = "domain";
|
2023-07-03 15:42:35 -07:00
|
|
|
public static final String DATA_PRODUCT = "dataProduct";
|
2023-07-02 11:32:52 -07:00
|
|
|
|
2023-08-03 18:27:01 -07:00
|
|
|
//
|
|
|
|
// Other entities
|
|
|
|
public static final String EVENT_SUBSCRIPTION = "eventsubscription";
|
|
|
|
public static final String THREAD = "THREAD";
|
|
|
|
public static final String WORKFLOW = "workflow";
|
|
|
|
|
2023-09-22 01:17:47 +02:00
|
|
|
//
|
|
|
|
// Time series entities
|
2023-10-11 08:14:21 +02:00
|
|
|
public static final String ENTITY_REPORT_DATA = "entityReportData";
|
|
|
|
public static final String WEB_ANALYTIC_ENTITY_VIEW_REPORT_DATA = "webAnalyticEntityViewReportData";
|
|
|
|
public static final String WEB_ANALYTIC_USER_ACTIVITY_REPORT_DATA = "webAnalyticUserActivityReportData";
|
|
|
|
public static final String RAW_COST_ANALYSIS_REPORT_DATA = "rawCostAnalysisReportData";
|
|
|
|
public static final String AGGREGATED_COST_ANALYSIS_REPORT_DATA = "aggregatedCostAnalysisReportData";
|
2023-09-22 01:17:47 +02:00
|
|
|
|
2022-08-02 17:33:36 -07:00
|
|
|
//
|
|
|
|
// Reserved names in OpenMetadata
|
|
|
|
//
|
2022-09-29 10:57:57 -07:00
|
|
|
public static final String ADMIN_USER_NAME = "admin";
|
2022-08-02 17:33:36 -07:00
|
|
|
public static final String ORGANIZATION_NAME = "Organization";
|
2022-11-01 12:46:18 -07:00
|
|
|
public static final String ORGANIZATION_POLICY_NAME = "OrganizationPolicy";
|
2022-10-21 08:38:52 -07:00
|
|
|
public static final String INGESTION_BOT_NAME = "ingestion-bot";
|
2022-10-24 17:53:11 -07:00
|
|
|
public static final String INGESTION_BOT_ROLE = "IngestionBotRole";
|
|
|
|
public static final String PROFILER_BOT_NAME = "profiler-bot";
|
|
|
|
public static final String PROFILER_BOT_ROLE = "ProfilerBotRole";
|
|
|
|
public static final String QUALITY_BOT_NAME = "quality-bot";
|
|
|
|
public static final String QUALITY_BOT_ROLE = "QualityBotRole";
|
2023-03-14 06:12:31 -07:00
|
|
|
public static final String ALL_RESOURCES = "All";
|
2022-08-02 17:33:36 -07:00
|
|
|
|
2023-09-29 19:13:56 -07:00
|
|
|
public static final String DOCUMENT = "document";
|
2023-03-03 19:10:01 +01:00
|
|
|
// ServiceType - Service Entity name map
|
2023-07-10 16:50:49 -07:00
|
|
|
static final Map<ServiceType, String> SERVICE_TYPE_ENTITY_MAP = new EnumMap<>(ServiceType.class);
|
|
|
|
|
|
|
|
static {
|
|
|
|
SERVICE_TYPE_ENTITY_MAP.put(ServiceType.DATABASE, DATABASE_SERVICE);
|
|
|
|
SERVICE_TYPE_ENTITY_MAP.put(ServiceType.MESSAGING, MESSAGING_SERVICE);
|
|
|
|
SERVICE_TYPE_ENTITY_MAP.put(ServiceType.DASHBOARD, DASHBOARD_SERVICE);
|
|
|
|
SERVICE_TYPE_ENTITY_MAP.put(ServiceType.PIPELINE, PIPELINE_SERVICE);
|
|
|
|
SERVICE_TYPE_ENTITY_MAP.put(ServiceType.ML_MODEL, MLMODEL_SERVICE);
|
|
|
|
SERVICE_TYPE_ENTITY_MAP.put(ServiceType.METADATA, METADATA_SERVICE);
|
|
|
|
SERVICE_TYPE_ENTITY_MAP.put(ServiceType.STORAGE, STORAGE_SERVICE);
|
2023-09-08 12:40:48 +05:30
|
|
|
SERVICE_TYPE_ENTITY_MAP.put(ServiceType.SEARCH, SEARCH_SERVICE);
|
2023-07-10 16:50:49 -07:00
|
|
|
}
|
2023-03-03 19:10:01 +01:00
|
|
|
|
2022-03-03 21:15:10 -08:00
|
|
|
//
|
|
|
|
// List of entities whose changes should not be published to the Activity Feed
|
|
|
|
//
|
2022-03-20 01:37:15 -07:00
|
|
|
public static final List<String> ACTIVITY_FEED_EXCLUDED_ENTITIES =
|
|
|
|
List.of(
|
|
|
|
USER,
|
|
|
|
TEAM,
|
|
|
|
ROLE,
|
|
|
|
POLICY,
|
2022-05-05 15:09:06 -07:00
|
|
|
BOT,
|
2022-04-04 12:46:09 -07:00
|
|
|
INGESTION_PIPELINE,
|
2022-03-20 01:37:15 -07:00
|
|
|
DATABASE_SERVICE,
|
|
|
|
PIPELINE_SERVICE,
|
|
|
|
DASHBOARD_SERVICE,
|
2023-04-24 18:59:09 +05:30
|
|
|
MESSAGING_SERVICE,
|
2023-06-27 18:18:22 +05:30
|
|
|
WORKFLOW,
|
2023-09-29 19:13:56 -07:00
|
|
|
TEST_SUITE,
|
|
|
|
DOCUMENT);
|
2022-03-03 21:15:10 -08:00
|
|
|
|
2021-12-16 07:13:50 -08:00
|
|
|
private Entity() {}
|
2021-11-09 13:25:08 -08:00
|
|
|
|
2023-10-03 23:41:06 -07:00
|
|
|
public static void initializeRepositories(Jdbi jdbi) {
|
2023-09-30 22:13:16 -07:00
|
|
|
if (!initializedRepositories) {
|
2023-10-03 23:41:06 -07:00
|
|
|
tokenRepository = new TokenRepository();
|
2023-10-03 21:03:56 -07:00
|
|
|
List<Class<?>> repositories = getRepositories();
|
2023-09-30 22:13:16 -07:00
|
|
|
for (Class<?> clz : repositories) {
|
|
|
|
if (Modifier.isAbstract(clz.getModifiers())) {
|
|
|
|
continue; // Don't instantiate abstract classes
|
|
|
|
}
|
|
|
|
try {
|
2023-10-03 23:41:06 -07:00
|
|
|
clz.getDeclaredConstructor().newInstance();
|
2023-09-30 22:13:16 -07:00
|
|
|
} catch (Exception e) {
|
2023-10-03 21:03:56 -07:00
|
|
|
try {
|
|
|
|
clz.getDeclaredConstructor(Jdbi.class).newInstance(jdbi);
|
|
|
|
} catch (Exception ex) {
|
|
|
|
LOG.warn("Exception encountered", ex);
|
|
|
|
}
|
2023-09-30 22:13:16 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
initializedRepositories = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void cleanup() {
|
|
|
|
initializedRepositories = false;
|
2023-10-03 23:41:06 -07:00
|
|
|
collectionDAO = null;
|
|
|
|
searchRepository = null;
|
2023-09-30 22:13:16 -07:00
|
|
|
ENTITY_REPOSITORY_MAP.clear();
|
|
|
|
}
|
|
|
|
|
2022-05-15 11:10:26 -07:00
|
|
|
public static <T extends EntityInterface> void registerEntity(
|
2023-09-30 22:13:16 -07:00
|
|
|
Class<T> clazz, String entity, EntityRepository<T> entityRepository) {
|
2021-11-10 16:07:06 -08:00
|
|
|
ENTITY_REPOSITORY_MAP.put(entity, entityRepository);
|
2022-09-14 23:14:02 -07:00
|
|
|
EntityInterface.CANONICAL_ENTITY_NAME_MAP.put(entity.toLowerCase(Locale.ROOT), entity);
|
2023-01-10 12:56:10 +05:30
|
|
|
EntityInterface.ENTITY_TYPE_TO_CLASS_MAP.put(entity.toLowerCase(Locale.ROOT), clazz);
|
2022-07-04 10:07:47 -07:00
|
|
|
ENTITY_LIST.add(entity);
|
|
|
|
Collections.sort(ENTITY_LIST);
|
|
|
|
|
2022-08-03 12:08:19 -07:00
|
|
|
LOG.info("Registering entity {} {}", clazz, entity);
|
2021-11-09 13:25:08 -08:00
|
|
|
}
|
|
|
|
|
2023-09-22 01:17:47 +02:00
|
|
|
public static <T extends EntityTimeSeriesInterface> void registerEntity(
|
2023-09-30 22:13:16 -07:00
|
|
|
Class<T> clazz, String entity, EntityTimeSeriesRepository<T> entityRepository) {
|
2023-09-22 01:17:47 +02:00
|
|
|
ENTITY_TS_REPOSITORY_MAP.put(entity, entityRepository);
|
|
|
|
EntityTimeSeriesInterface.CANONICAL_ENTITY_NAME_MAP.put(entity.toLowerCase(Locale.ROOT), entity);
|
|
|
|
EntityTimeSeriesInterface.ENTITY_TYPE_TO_CLASS_MAP.put(entity.toLowerCase(Locale.ROOT), clazz);
|
|
|
|
ENTITY_LIST.add(entity);
|
|
|
|
Collections.sort(ENTITY_LIST);
|
|
|
|
|
2023-09-30 22:13:16 -07:00
|
|
|
LOG.info("Registering entity time series {} {}", clazz, entity);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void registerResourcePermissions(String entity, List<MetadataOperation> entitySpecificOperations) {
|
2023-09-22 01:17:47 +02:00
|
|
|
// Set up entity operations for permissions
|
2023-09-30 22:13:16 -07:00
|
|
|
Class<?> clazz = getEntityClassFromType(entity);
|
2023-09-22 01:17:47 +02:00
|
|
|
ResourceRegistry.addResource(entity, entitySpecificOperations, getEntityFields(clazz));
|
2023-09-30 22:13:16 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
public static void registerTimeSeriesResourcePermissions(String entity) {
|
|
|
|
// Set up entity operations for permissions
|
|
|
|
Class<?> clazz = getEntityTimeSeriesClassFromType(entity);
|
|
|
|
ResourceRegistry.addResource(entity, null, getEntityFields(clazz));
|
2023-09-22 01:17:47 +02:00
|
|
|
}
|
|
|
|
|
2022-07-26 12:08:01 -07:00
|
|
|
public static List<String> getEntityList() {
|
2022-07-04 10:07:47 -07:00
|
|
|
return Collections.unmodifiableList(ENTITY_LIST);
|
|
|
|
}
|
|
|
|
|
2023-08-06 18:16:04 -07:00
|
|
|
public static EntityReference getEntityReference(EntityReference ref, Include include) {
|
2023-02-13 00:08:55 -08:00
|
|
|
if (ref == null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return ref.getId() != null
|
|
|
|
? getEntityReferenceById(ref.getType(), ref.getId(), include)
|
|
|
|
: getEntityReferenceByName(ref.getType(), ref.getFullyQualifiedName(), include);
|
2022-12-26 12:32:17 -08:00
|
|
|
}
|
|
|
|
|
2023-08-06 18:16:04 -07:00
|
|
|
public static EntityReference getEntityReferenceById(@NonNull String entityType, @NonNull UUID id, Include include) {
|
2023-08-08 16:42:54 -07:00
|
|
|
EntityRepository<? extends EntityInterface> repository = getEntityRepository(entityType);
|
2022-05-14 10:57:19 -07:00
|
|
|
include = repository.supportsSoftDelete ? Include.ALL : include;
|
2023-08-08 16:42:54 -07:00
|
|
|
return repository.getReference(id, include);
|
2022-03-12 18:13:48 -08:00
|
|
|
}
|
2021-12-15 20:22:17 -08:00
|
|
|
|
2023-07-10 16:50:49 -07:00
|
|
|
public static EntityReference getEntityReferenceByName(@NonNull String entityType, String fqn, Include include) {
|
2022-12-26 12:32:17 -08:00
|
|
|
if (fqn == null) {
|
|
|
|
return null;
|
|
|
|
}
|
2023-08-08 16:42:54 -07:00
|
|
|
EntityRepository<? extends EntityInterface> repository = getEntityRepository(entityType);
|
|
|
|
return repository.getReferenceByName(fqn, include);
|
2022-03-12 18:13:48 -08:00
|
|
|
}
|
|
|
|
|
2023-08-06 18:16:04 -07:00
|
|
|
public static EntityReference getOwner(@NonNull EntityReference reference) {
|
2022-03-12 18:13:48 -08:00
|
|
|
EntityRepository<?> repository = getEntityRepository(reference.getType());
|
2022-03-29 16:30:27 -07:00
|
|
|
return repository.getOwner(reference);
|
2021-11-09 13:25:08 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
public static void withHref(UriInfo uriInfo, List<EntityReference> list) {
|
2022-03-02 18:22:09 -08:00
|
|
|
listOrEmpty(list).forEach(ref -> withHref(uriInfo, ref));
|
2021-11-09 13:25:08 -08:00
|
|
|
}
|
|
|
|
|
2022-05-22 15:28:55 -07:00
|
|
|
public static void withHref(UriInfo uriInfo, EntityReference ref) {
|
2021-11-09 13:25:08 -08:00
|
|
|
if (ref == null) {
|
2022-05-22 15:28:55 -07:00
|
|
|
return;
|
2021-11-09 13:25:08 -08:00
|
|
|
}
|
2022-01-23 15:23:19 -08:00
|
|
|
String entityType = ref.getType();
|
2022-03-12 18:13:48 -08:00
|
|
|
EntityRepository<?> entityRepository = getEntityRepository(entityType);
|
2021-11-09 13:25:08 -08:00
|
|
|
URI href = entityRepository.getHref(uriInfo, ref.getId());
|
2022-05-22 15:28:55 -07:00
|
|
|
ref.withHref(href);
|
2021-11-09 13:25:08 -08:00
|
|
|
}
|
2021-08-01 14:27:44 -07:00
|
|
|
|
2022-03-12 18:13:48 -08:00
|
|
|
/** Returns true if the change events of the given entity type should be published to the activity feed. */
|
2022-03-03 21:15:10 -08:00
|
|
|
public static boolean shouldDisplayEntityChangeOnFeed(@NonNull String entityType) {
|
|
|
|
return !ACTIVITY_FEED_EXCLUDED_ENTITIES.contains(entityType);
|
|
|
|
}
|
|
|
|
|
2023-04-05 18:47:51 +05:30
|
|
|
public static Fields getFields(String entityType, List<String> fields) {
|
|
|
|
EntityRepository<?> entityRepository = Entity.getEntityRepository(entityType);
|
|
|
|
return entityRepository.getFields(String.join(",", fields));
|
|
|
|
}
|
|
|
|
|
2023-08-06 18:16:04 -07:00
|
|
|
public static <T> T getEntity(EntityReference ref, String fields, Include include) {
|
2023-02-13 00:08:55 -08:00
|
|
|
return ref.getId() != null
|
|
|
|
? getEntity(ref.getType(), ref.getId(), fields, include)
|
|
|
|
: getEntityByName(ref.getType(), ref.getFullyQualifiedName(), fields, include);
|
2022-01-09 21:04:10 -08:00
|
|
|
}
|
|
|
|
|
2023-08-06 18:16:04 -07:00
|
|
|
public static <T> T getEntity(EntityLink link, String fields, Include include) {
|
2023-05-03 07:43:35 -07:00
|
|
|
return getEntityByName(link.getEntityType(), link.getEntityFQN(), fields, include);
|
|
|
|
}
|
|
|
|
|
2023-02-13 00:08:55 -08:00
|
|
|
/** Retrieve the entity using id from given entity reference and fields */
|
2023-08-18 20:47:47 +02:00
|
|
|
public static <T> T getEntity(String entityType, UUID id, String fields, Include include, boolean fromCache) {
|
2023-02-13 00:08:55 -08:00
|
|
|
EntityRepository<?> entityRepository = Entity.getEntityRepository(entityType);
|
|
|
|
@SuppressWarnings("unchecked")
|
2023-08-18 20:47:47 +02:00
|
|
|
T entity = (T) entityRepository.get(null, id, entityRepository.getFields(fields), include, fromCache);
|
2023-02-13 00:08:55 -08:00
|
|
|
return entity;
|
2022-11-16 13:59:45 -08:00
|
|
|
}
|
|
|
|
|
2023-08-18 20:47:47 +02:00
|
|
|
public static <T> T getEntity(String entityType, UUID id, String fields, Include include) {
|
|
|
|
return getEntity(entityType, id, fields, include, true);
|
|
|
|
}
|
|
|
|
|
2022-03-20 18:01:51 -07:00
|
|
|
/** Retrieve the entity using id from given entity reference and fields */
|
2023-08-18 20:47:47 +02:00
|
|
|
public static <T> T getEntityByName(
|
|
|
|
String entityType, String fqn, String fields, Include include, boolean fromCache) {
|
2022-03-20 18:01:51 -07:00
|
|
|
EntityRepository<?> entityRepository = Entity.getEntityRepository(entityType);
|
2022-01-09 21:04:10 -08:00
|
|
|
@SuppressWarnings("unchecked")
|
2023-08-18 20:47:47 +02:00
|
|
|
T entity = (T) entityRepository.getByName(null, fqn, entityRepository.getFields(fields), include, fromCache);
|
2022-01-09 21:04:10 -08:00
|
|
|
return entity;
|
|
|
|
}
|
|
|
|
|
2023-08-18 20:47:47 +02:00
|
|
|
public static <T> T getEntityByName(String entityType, String fqn, String fields, Include include) {
|
|
|
|
return getEntityByName(entityType, fqn, fields, include, true);
|
|
|
|
}
|
|
|
|
|
2023-02-13 00:08:55 -08:00
|
|
|
/** Retrieve the corresponding entity repository for a given entity name. */
|
2023-01-30 21:34:34 -08:00
|
|
|
public static EntityRepository<? extends EntityInterface> getEntityRepository(@NonNull String entityType) {
|
|
|
|
EntityRepository<? extends EntityInterface> entityRepository = ENTITY_REPOSITORY_MAP.get(entityType);
|
2021-11-09 13:25:08 -08:00
|
|
|
if (entityRepository == null) {
|
2023-09-27 11:49:21 +02:00
|
|
|
throw EntityNotFoundException.byMessage(CatalogExceptionMessage.entityRepositoryNotFound(entityType));
|
2021-11-09 13:25:08 -08:00
|
|
|
}
|
2022-01-09 21:04:10 -08:00
|
|
|
return entityRepository;
|
2021-08-01 14:27:44 -07:00
|
|
|
}
|
2021-11-10 12:40:27 -08:00
|
|
|
|
2023-09-22 01:17:47 +02:00
|
|
|
public static EntityTimeSeriesRepository<? extends EntityTimeSeriesInterface> getEntityTimeSeriesRepository(
|
|
|
|
@NonNull String entityType) {
|
|
|
|
EntityTimeSeriesRepository<? extends EntityTimeSeriesInterface> entityTimeSeriesRepository =
|
|
|
|
ENTITY_TS_REPOSITORY_MAP.get(entityType);
|
|
|
|
if (entityTimeSeriesRepository == null) {
|
|
|
|
throw EntityNotFoundException.byMessage(CatalogExceptionMessage.entityTypeNotFound(entityType));
|
|
|
|
}
|
|
|
|
return entityTimeSeriesRepository;
|
|
|
|
}
|
|
|
|
|
2023-03-03 19:10:01 +01:00
|
|
|
/** Retrieve the corresponding entity repository for a given entity name. */
|
|
|
|
public static EntityRepository<? extends EntityInterface> getServiceEntityRepository(
|
|
|
|
@NonNull ServiceType serviceType) {
|
|
|
|
EntityRepository<? extends EntityInterface> entityRepository =
|
|
|
|
ENTITY_REPOSITORY_MAP.get(SERVICE_TYPE_ENTITY_MAP.get(serviceType));
|
|
|
|
if (entityRepository == null) {
|
|
|
|
throw EntityNotFoundException.byMessage(CatalogExceptionMessage.entityTypeNotFound(serviceType.value()));
|
|
|
|
}
|
|
|
|
return entityRepository;
|
|
|
|
}
|
|
|
|
|
2023-05-04 10:05:36 -07:00
|
|
|
public static List<TagLabel> getEntityTags(String entityType, EntityInterface entity) {
|
|
|
|
EntityRepository<? extends EntityInterface> entityRepository = getEntityRepository(entityType);
|
2023-03-20 04:42:03 -07:00
|
|
|
return listOrEmpty(entityRepository.getAllTags(entity));
|
|
|
|
}
|
|
|
|
|
2022-03-20 18:01:51 -07:00
|
|
|
public static void deleteEntity(
|
2023-08-06 18:16:04 -07:00
|
|
|
String updatedBy, String entityType, UUID entityId, boolean recursive, boolean hardDelete) {
|
2022-03-12 18:13:48 -08:00
|
|
|
EntityRepository<?> dao = getEntityRepository(entityType);
|
2022-08-09 05:57:39 -07:00
|
|
|
dao.delete(updatedBy, entityId, recursive, hardDelete);
|
2021-12-31 09:30:27 -08:00
|
|
|
}
|
|
|
|
|
2023-08-06 18:16:04 -07:00
|
|
|
public static void restoreEntity(String updatedBy, String entityType, UUID entityId) {
|
2022-03-12 18:13:48 -08:00
|
|
|
EntityRepository<?> dao = getEntityRepository(entityType);
|
2022-02-28 18:42:25 -08:00
|
|
|
dao.restoreEntity(updatedBy, entityType, entityId);
|
|
|
|
}
|
|
|
|
|
2022-01-23 15:23:19 -08:00
|
|
|
public static <T> String getEntityTypeFromClass(Class<T> clz) {
|
2022-09-14 23:14:02 -07:00
|
|
|
return EntityInterface.CANONICAL_ENTITY_NAME_MAP.get(clz.getSimpleName().toLowerCase(Locale.ROOT));
|
2021-12-06 22:29:20 -08:00
|
|
|
}
|
|
|
|
|
2022-01-23 15:23:19 -08:00
|
|
|
public static String getEntityTypeFromObject(Object object) {
|
2022-09-14 23:14:02 -07:00
|
|
|
return EntityInterface.CANONICAL_ENTITY_NAME_MAP.get(object.getClass().getSimpleName().toLowerCase(Locale.ROOT));
|
2021-11-26 14:16:29 -08:00
|
|
|
}
|
|
|
|
|
2023-01-10 12:56:10 +05:30
|
|
|
public static Class<? extends EntityInterface> getEntityClassFromType(String entityType) {
|
2023-05-05 16:52:33 -07:00
|
|
|
return EntityInterface.ENTITY_TYPE_TO_CLASS_MAP.get(entityType.toLowerCase(Locale.ROOT));
|
2023-01-10 12:56:10 +05:30
|
|
|
}
|
|
|
|
|
2023-09-30 22:13:16 -07:00
|
|
|
public static Class<? extends EntityTimeSeriesInterface> getEntityTimeSeriesClassFromType(String entityType) {
|
|
|
|
return EntityTimeSeriesInterface.ENTITY_TYPE_TO_CLASS_MAP.get(entityType.toLowerCase(Locale.ROOT));
|
|
|
|
}
|
|
|
|
|
2022-02-25 22:13:30 -08:00
|
|
|
/**
|
|
|
|
* Get list of all the entity field names from JsonPropertyOrder annotation from generated java class from entity.json
|
|
|
|
*/
|
2023-07-17 21:41:25 -07:00
|
|
|
public static <T> Set<String> getEntityFields(Class<T> clz) {
|
2022-02-25 22:13:30 -08:00
|
|
|
JsonPropertyOrder propertyOrder = clz.getAnnotation(JsonPropertyOrder.class);
|
2023-07-17 21:41:25 -07:00
|
|
|
return new HashSet<>(Arrays.asList(propertyOrder.value()));
|
2022-02-25 22:13:30 -08:00
|
|
|
}
|
|
|
|
|
2023-08-03 18:27:01 -07:00
|
|
|
/** Returns true if the entity supports activity feeds, announcement, and tasks */
|
|
|
|
public static boolean supportsFeed(String entityType) {
|
|
|
|
return listOf(
|
|
|
|
TABLE,
|
|
|
|
DATABASE,
|
|
|
|
DATABASE_SCHEMA,
|
|
|
|
METRICS,
|
|
|
|
DASHBOARD,
|
|
|
|
DASHBOARD_DATA_MODEL,
|
|
|
|
PIPELINE,
|
|
|
|
CHART,
|
|
|
|
REPORT,
|
|
|
|
TOPIC,
|
|
|
|
MLMODEL,
|
|
|
|
CONTAINER,
|
|
|
|
QUERY,
|
|
|
|
GLOSSARY,
|
|
|
|
GLOSSARY_TERM,
|
|
|
|
TAG,
|
|
|
|
CLASSIFICATION)
|
|
|
|
.contains(entityType);
|
|
|
|
}
|
|
|
|
|
2021-12-31 09:30:27 -08:00
|
|
|
/** Class for getting validated entity list from a queryParam with list of entities. */
|
2021-11-10 12:40:27 -08:00
|
|
|
public static class EntityList {
|
2022-02-23 20:40:25 -08:00
|
|
|
private EntityList() {}
|
|
|
|
|
2021-11-26 14:16:29 -08:00
|
|
|
public static List<String> getEntityList(String name, String entitiesParam) {
|
2021-11-10 12:40:27 -08:00
|
|
|
if (entitiesParam == null) {
|
2022-02-28 19:17:19 -08:00
|
|
|
return Collections.emptyList();
|
2021-11-10 12:40:27 -08:00
|
|
|
}
|
2022-01-06 00:27:18 +05:30
|
|
|
entitiesParam = entitiesParam.replace(" ", "");
|
2021-12-26 12:20:20 -08:00
|
|
|
if (entitiesParam.equals("*")) {
|
|
|
|
return List.of("*");
|
|
|
|
}
|
|
|
|
List<String> list = Arrays.asList(entitiesParam.split(","));
|
2021-11-26 14:16:29 -08:00
|
|
|
validateEntities(name, list);
|
|
|
|
return list;
|
2021-11-10 12:40:27 -08:00
|
|
|
}
|
|
|
|
|
2021-11-26 14:16:29 -08:00
|
|
|
private static void validateEntities(String name, List<String> list) {
|
|
|
|
for (String entity : list) {
|
|
|
|
if (ENTITY_REPOSITORY_MAP.get(entity) == null) {
|
|
|
|
throw new IllegalArgumentException(String.format("Invalid entity %s in query param %s", entity, name));
|
|
|
|
}
|
|
|
|
}
|
2021-11-10 12:40:27 -08:00
|
|
|
}
|
|
|
|
}
|
2023-09-30 22:13:16 -07:00
|
|
|
|
|
|
|
/** Compile a list of REST collections based on Resource classes marked with {@code Repository} annotation */
|
2023-10-03 21:03:56 -07:00
|
|
|
private static List<Class<?>> getRepositories() {
|
|
|
|
try (ScanResult scanResult = new ClassGraph().enableAnnotationInfo().scan()) {
|
|
|
|
ClassInfoList classList = scanResult.getClassesWithAnnotation(Repository.class);
|
|
|
|
return classList.loadClasses();
|
|
|
|
}
|
2023-09-30 22:13:16 -07:00
|
|
|
}
|
2021-08-01 14:27:44 -07:00
|
|
|
}
|