mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-11-19 12:23:36 +00:00
Move setting common patch and updated fields to EntityRepository (#12469)
This commit is contained in:
parent
5ca757f5e8
commit
62e82ba492
@ -23,9 +23,11 @@ import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumMap;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
import lombok.NonNull;
|
||||
@ -355,9 +357,9 @@ public final class Entity {
|
||||
/**
|
||||
* Get list of all the entity field names from JsonPropertyOrder annotation from generated java class from entity.json
|
||||
*/
|
||||
public static <T> List<String> getEntityFields(Class<T> clz) {
|
||||
public static <T> Set<String> getEntityFields(Class<T> clz) {
|
||||
JsonPropertyOrder propertyOrder = clz.getAnnotation(JsonPropertyOrder.class);
|
||||
return new ArrayList<>(Arrays.asList(propertyOrder.value()));
|
||||
return new HashSet<>(Arrays.asList(propertyOrder.value()));
|
||||
}
|
||||
|
||||
/** Class for getting validated entity list from a queryParam with list of entities. */
|
||||
|
||||
@ -57,7 +57,7 @@ public class ResourceRegistry {
|
||||
private ResourceRegistry() {}
|
||||
|
||||
public static void addResource(
|
||||
String resourceName, List<MetadataOperation> entitySpecificOperations, List<String> entityFields) {
|
||||
String resourceName, List<MetadataOperation> entitySpecificOperations, Set<String> entityFields) {
|
||||
// If resourceName already exists, then no need to add the resource again
|
||||
if (RESOURCE_DESCRIPTORS.stream().anyMatch(d -> d.getName().equals(resourceName))) {
|
||||
return;
|
||||
@ -65,7 +65,7 @@ public class ResourceRegistry {
|
||||
ResourceDescriptor resourceDescriptor =
|
||||
new ResourceDescriptor()
|
||||
.withName(resourceName)
|
||||
.withOperations(getOperations(resourceName, entitySpecificOperations, entityFields));
|
||||
.withOperations(getOperations(resourceName, entitySpecificOperations, new ArrayList<>(entityFields)));
|
||||
RESOURCE_DESCRIPTORS.sort(Comparator.comparing(ResourceDescriptor::getName));
|
||||
RESOURCE_DESCRIPTORS.add(resourceDescriptor);
|
||||
}
|
||||
|
||||
@ -31,18 +31,8 @@ import org.openmetadata.service.util.FullyQualifiedName;
|
||||
|
||||
@Slf4j
|
||||
public class ChartRepository extends EntityRepository<Chart> {
|
||||
private static final String CHART_UPDATE_FIELDS = "owner";
|
||||
private static final String CHART_PATCH_FIELDS = "owner,tags";
|
||||
|
||||
public ChartRepository(CollectionDAO dao) {
|
||||
super(
|
||||
ChartResource.COLLECTION_PATH,
|
||||
Entity.CHART,
|
||||
Chart.class,
|
||||
dao.chartDAO(),
|
||||
dao,
|
||||
CHART_PATCH_FIELDS,
|
||||
CHART_UPDATE_FIELDS);
|
||||
super(ChartResource.COLLECTION_PATH, Entity.CHART, Chart.class, dao.chartDAO(), dao, "", "");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -34,8 +34,8 @@ import org.openmetadata.service.util.JsonUtils;
|
||||
|
||||
public class ContainerRepository extends EntityRepository<Container> {
|
||||
|
||||
private static final String CONTAINER_UPDATE_FIELDS = "dataModel,owner,tags,extension";
|
||||
private static final String CONTAINER_PATCH_FIELDS = "dataModel,owner,tags,extension";
|
||||
private static final String CONTAINER_UPDATE_FIELDS = "dataModel";
|
||||
private static final String CONTAINER_PATCH_FIELDS = "dataModel";
|
||||
|
||||
public ContainerRepository(CollectionDAO dao) {
|
||||
super(
|
||||
|
||||
@ -43,10 +43,6 @@ import org.openmetadata.service.util.JsonUtils;
|
||||
|
||||
@Slf4j
|
||||
public class DashboardDataModelRepository extends EntityRepository<DashboardDataModel> {
|
||||
|
||||
private static final String DATA_MODEL_UPDATE_FIELDS = "owner,tags,followers";
|
||||
private static final String DATA_MODEL_PATCH_FIELDS = "owner,tags,followers";
|
||||
|
||||
public DashboardDataModelRepository(CollectionDAO dao) {
|
||||
super(
|
||||
DashboardDataModelResource.COLLECTION_PATH,
|
||||
@ -54,8 +50,8 @@ public class DashboardDataModelRepository extends EntityRepository<DashboardData
|
||||
DashboardDataModel.class,
|
||||
dao.dashboardDataModelDAO(),
|
||||
dao,
|
||||
DATA_MODEL_PATCH_FIELDS,
|
||||
DATA_MODEL_UPDATE_FIELDS);
|
||||
"",
|
||||
"");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -37,8 +37,8 @@ import org.openmetadata.service.util.EntityUtil.Fields;
|
||||
import org.openmetadata.service.util.FullyQualifiedName;
|
||||
|
||||
public class DashboardRepository extends EntityRepository<Dashboard> {
|
||||
private static final String DASHBOARD_UPDATE_FIELDS = "owner,tags,charts,extension,followers,dataModels";
|
||||
private static final String DASHBOARD_PATCH_FIELDS = "owner,tags,charts,extension,followers,dataModels";
|
||||
private static final String DASHBOARD_UPDATE_FIELDS = "charts,dataModels";
|
||||
private static final String DASHBOARD_PATCH_FIELDS = "charts,dataModels";
|
||||
|
||||
private static final String DASHBOARD_URL = "sourceUrl";
|
||||
|
||||
|
||||
@ -11,8 +11,6 @@ import org.openmetadata.service.util.EntityUtil;
|
||||
public class DataInsightChartRepository extends EntityRepository<DataInsightChart> {
|
||||
public static final String COLLECTION_PATH = "/v1/analytics/dataInsights/charts";
|
||||
public static final String LAST_SESSION = "lastSession";
|
||||
private static final String UPDATE_FIELDS = "owner";
|
||||
private static final String PATCH_FIELDS = "owner";
|
||||
public static final String DATA_ENTITY_TYPE = "data.entityType";
|
||||
public static final String TIMESTAMP = "timestamp";
|
||||
public static final String ENTITY_COUNT = "entityCount";
|
||||
@ -61,14 +59,7 @@ public class DataInsightChartRepository extends EntityRepository<DataInsightChar
|
||||
"MostViewedEntities");
|
||||
|
||||
public DataInsightChartRepository(CollectionDAO dao) {
|
||||
super(
|
||||
COLLECTION_PATH,
|
||||
DATA_INSIGHT_CHART,
|
||||
DataInsightChart.class,
|
||||
dao.dataInsightChartDAO(),
|
||||
dao,
|
||||
PATCH_FIELDS,
|
||||
UPDATE_FIELDS);
|
||||
super(COLLECTION_PATH, DATA_INSIGHT_CHART, DataInsightChart.class, dao.dataInsightChartDAO(), dao, "", "");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -31,7 +31,7 @@ import org.openmetadata.service.util.FullyQualifiedName;
|
||||
|
||||
@Slf4j
|
||||
public class DataProductRepository extends EntityRepository<DataProduct> {
|
||||
private static final String UPDATE_FIELDS = "domain,owner,experts"; // Domain field can't be updated
|
||||
private static final String UPDATE_FIELDS = "experts"; // Domain field can't be updated
|
||||
|
||||
public DataProductRepository(CollectionDAO dao) {
|
||||
super(
|
||||
|
||||
@ -28,18 +28,9 @@ import org.openmetadata.service.util.EntityUtil.Fields;
|
||||
import org.openmetadata.service.util.FullyQualifiedName;
|
||||
|
||||
public class DatabaseRepository extends EntityRepository<Database> {
|
||||
private static final String DATABASE_UPDATE_FIELDS = "owner,tags,extension";
|
||||
private static final String DATABASE_PATCH_FIELDS = DATABASE_UPDATE_FIELDS;
|
||||
|
||||
public DatabaseRepository(CollectionDAO dao) {
|
||||
super(
|
||||
DatabaseResource.COLLECTION_PATH,
|
||||
Entity.DATABASE,
|
||||
Database.class,
|
||||
dao.databaseDAO(),
|
||||
dao,
|
||||
DATABASE_PATCH_FIELDS,
|
||||
DATABASE_UPDATE_FIELDS);
|
||||
super(DatabaseResource.COLLECTION_PATH, Entity.DATABASE, Database.class, dao.databaseDAO(), dao, "", "");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -33,9 +33,6 @@ import org.openmetadata.service.util.EntityUtil.Fields;
|
||||
import org.openmetadata.service.util.FullyQualifiedName;
|
||||
|
||||
public class DatabaseSchemaRepository extends EntityRepository<DatabaseSchema> {
|
||||
private static final String DATABASE_SCHEMA_UPDATE_FIELDS = "owner,tags,extension";
|
||||
private static final String DATABASE_SCHEMA_PATCH_FIELDS = DATABASE_SCHEMA_UPDATE_FIELDS;
|
||||
|
||||
public DatabaseSchemaRepository(CollectionDAO dao) {
|
||||
super(
|
||||
DatabaseSchemaResource.COLLECTION_PATH,
|
||||
@ -43,8 +40,8 @@ public class DatabaseSchemaRepository extends EntityRepository<DatabaseSchema> {
|
||||
DatabaseSchema.class,
|
||||
dao.databaseSchemaDAO(),
|
||||
dao,
|
||||
DATABASE_SCHEMA_PATCH_FIELDS,
|
||||
DATABASE_SCHEMA_UPDATE_FIELDS);
|
||||
"",
|
||||
"");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -33,7 +33,7 @@ import org.openmetadata.service.util.FullyQualifiedName;
|
||||
|
||||
@Slf4j
|
||||
public class DomainRepository extends EntityRepository<Domain> {
|
||||
private static final String UPDATE_FIELDS = "parent,children,owner,experts";
|
||||
private static final String UPDATE_FIELDS = "parent,children,experts";
|
||||
|
||||
public DomainRepository(CollectionDAO dao) {
|
||||
super(
|
||||
|
||||
@ -161,11 +161,12 @@ public abstract class EntityRepository<T extends EntityInterface> {
|
||||
@Getter protected final String entityType;
|
||||
@Getter protected final EntityDAO<T> dao;
|
||||
protected final CollectionDAO daoCollection;
|
||||
@Getter protected final List<String> allowedFields;
|
||||
@Getter protected final Set<String> allowedFields;
|
||||
public final boolean supportsSoftDelete;
|
||||
@Getter protected final boolean supportsTags;
|
||||
@Getter protected final boolean supportsOwner;
|
||||
protected final boolean supportsFollower;
|
||||
protected final boolean supportsExtension;
|
||||
protected final boolean supportsVotes;
|
||||
protected final boolean supportsDomain;
|
||||
protected final boolean supportsDataProducts;
|
||||
@ -189,16 +190,38 @@ public abstract class EntityRepository<T extends EntityInterface> {
|
||||
allowedFields = getEntityFields(entityClass);
|
||||
this.dao = entityDAO;
|
||||
this.daoCollection = collectionDAO;
|
||||
this.patchFields = getFields(patchFields);
|
||||
this.putFields = getFields(putFields);
|
||||
this.entityType = entityType;
|
||||
|
||||
this.patchFields = getFields(patchFields);
|
||||
this.putFields = getFields(putFields);
|
||||
|
||||
this.supportsTags = allowedFields.contains(FIELD_TAGS);
|
||||
if (supportsTags) {
|
||||
this.patchFields.addField(allowedFields, FIELD_TAGS);
|
||||
this.putFields.addField(allowedFields, FIELD_TAGS);
|
||||
}
|
||||
this.supportsOwner = allowedFields.contains(FIELD_OWNER);
|
||||
if (supportsOwner) {
|
||||
this.patchFields.addField(allowedFields, FIELD_OWNER);
|
||||
this.putFields.addField(allowedFields, FIELD_OWNER);
|
||||
}
|
||||
this.supportsSoftDelete = allowedFields.contains(FIELD_DELETED);
|
||||
this.supportsFollower = allowedFields.contains(FIELD_FOLLOWERS);
|
||||
if (supportsFollower) {
|
||||
this.patchFields.addField(allowedFields, FIELD_FOLLOWERS);
|
||||
this.putFields.addField(allowedFields, FIELD_FOLLOWERS);
|
||||
}
|
||||
this.supportsExtension = allowedFields.contains(FIELD_EXTENSION);
|
||||
if (supportsExtension) {
|
||||
this.patchFields.addField(allowedFields, FIELD_EXTENSION);
|
||||
this.putFields.addField(allowedFields, FIELD_EXTENSION);
|
||||
}
|
||||
this.supportsVotes = allowedFields.contains(FIELD_VOTES);
|
||||
this.supportsDomain = allowedFields.contains(FIELD_DOMAIN);
|
||||
if (supportsDomain) {
|
||||
this.patchFields.addField(allowedFields, FIELD_DOMAIN);
|
||||
this.putFields.addField(allowedFields, FIELD_DOMAIN);
|
||||
}
|
||||
this.supportsDataProducts = allowedFields.contains(FIELD_DATA_PRODUCTS);
|
||||
}
|
||||
|
||||
@ -712,7 +735,7 @@ public abstract class EntityRepository<T extends EntityInterface> {
|
||||
false);
|
||||
}
|
||||
|
||||
setFieldsInternal(originalEntity, new EntityUtil.Fields(allowedFields, "votes"));
|
||||
setFieldsInternal(originalEntity, new Fields(allowedFields, "votes"));
|
||||
ChangeEvent changeEvent =
|
||||
new ChangeEvent()
|
||||
.withEntity(originalEntity)
|
||||
@ -1451,7 +1474,7 @@ public abstract class EntityRepository<T extends EntityInterface> {
|
||||
return new Fields(allowedFields, fields);
|
||||
}
|
||||
|
||||
protected final Fields getFields(List<String> fields) {
|
||||
protected final Fields getFields(Set<String> fields) {
|
||||
return new Fields(allowedFields, fields);
|
||||
}
|
||||
|
||||
@ -1465,8 +1488,8 @@ public abstract class EntityRepository<T extends EntityInterface> {
|
||||
return result;
|
||||
}
|
||||
|
||||
public final List<String> getAllowedFieldsCopy() {
|
||||
return new ArrayList<>(allowedFields);
|
||||
public final Set<String> getAllowedFieldsCopy() {
|
||||
return new HashSet<>(allowedFields);
|
||||
}
|
||||
|
||||
protected String getCustomPropertyFQNPrefix(String entityType) {
|
||||
@ -1510,7 +1533,7 @@ public abstract class EntityRepository<T extends EntityInterface> {
|
||||
return Entity.getEntityReferenceById(owner.getType(), owner.getId(), ALL);
|
||||
}
|
||||
|
||||
public EntityReference validateDomain(String domainFqn) throws IOException {
|
||||
public EntityReference validateDomain(String domainFqn) {
|
||||
if (!supportsDomain || domainFqn == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -40,8 +40,8 @@ public class EventSubscriptionRepository extends EntityRepository<EventSubscript
|
||||
private static final String INVALID_ALERT = "Invalid Alert Type";
|
||||
private static final ConcurrentHashMap<UUID, SubscriptionPublisher> subscriptionPublisherMap =
|
||||
new ConcurrentHashMap<>();
|
||||
static final String ALERT_PATCH_FIELDS = "owner,trigger,enabled,batchSize,timeout";
|
||||
static final String ALERT_UPDATE_FIELDS = "owner,trigger,enabled,batchSize,timeout,filteringRules";
|
||||
static final String ALERT_PATCH_FIELDS = "trigger,enabled,batchSize,timeout";
|
||||
static final String ALERT_UPDATE_FIELDS = "trigger,enabled,batchSize,timeout,filteringRules";
|
||||
|
||||
public EventSubscriptionRepository(CollectionDAO dao) {
|
||||
super(
|
||||
|
||||
@ -60,8 +60,8 @@ import org.openmetadata.service.util.FullyQualifiedName;
|
||||
|
||||
@Slf4j
|
||||
public class GlossaryRepository extends EntityRepository<Glossary> {
|
||||
private static final String UPDATE_FIELDS = "owner,tags,reviewers";
|
||||
private static final String PATCH_FIELDS = "owner,tags,reviewers";
|
||||
private static final String UPDATE_FIELDS = "reviewers";
|
||||
private static final String PATCH_FIELDS = "reviewers";
|
||||
|
||||
public GlossaryRepository(CollectionDAO dao) {
|
||||
super(
|
||||
|
||||
@ -55,8 +55,8 @@ import org.openmetadata.service.util.FullyQualifiedName;
|
||||
|
||||
@Slf4j
|
||||
public class GlossaryTermRepository extends EntityRepository<GlossaryTerm> {
|
||||
private static final String UPDATE_FIELDS = "tags,references,relatedTerms,reviewers,owner,synonyms";
|
||||
private static final String PATCH_FIELDS = "tags,references,relatedTerms,reviewers,owner,synonyms";
|
||||
private static final String UPDATE_FIELDS = "references,relatedTerms,reviewers,synonyms";
|
||||
private static final String PATCH_FIELDS = "references,relatedTerms,reviewers,synonyms";
|
||||
|
||||
public GlossaryTermRepository(CollectionDAO dao) {
|
||||
super(
|
||||
|
||||
@ -47,8 +47,8 @@ import org.openmetadata.service.util.RestUtil;
|
||||
import org.openmetadata.service.util.ResultList;
|
||||
|
||||
public class IngestionPipelineRepository extends EntityRepository<IngestionPipeline> {
|
||||
private static final String UPDATE_FIELDS = "owner,sourceConfig,airflowConfig,loggerLevel,enabled,deployed";
|
||||
private static final String PATCH_FIELDS = "owner,sourceConfig,airflowConfig,loggerLevel,enabled,deployed";
|
||||
private static final String UPDATE_FIELDS = "sourceConfig,airflowConfig,loggerLevel,enabled,deployed";
|
||||
private static final String PATCH_FIELDS = "sourceConfig,airflowConfig,loggerLevel,enabled,deployed";
|
||||
|
||||
private static final String PIPELINE_STATUS_JSON_SCHEMA = "ingestionPipelineStatus";
|
||||
private static final String PIPELINE_STATUS_EXTENSION = "ingestionPipeline.pipelineStatus";
|
||||
|
||||
@ -37,9 +37,9 @@ import org.openmetadata.service.util.ResultList;
|
||||
public class KpiRepository extends EntityRepository<Kpi> {
|
||||
private static final String KPI_RESULT_FIELD = "kpiResult";
|
||||
public static final String COLLECTION_PATH = "/v1/kpi";
|
||||
private static final String UPDATE_FIELDS = "owner,targetDefinition,dataInsightChart,startDate,endDate,metricType";
|
||||
private static final String UPDATE_FIELDS = "targetDefinition,dataInsightChart,startDate,endDate,metricType";
|
||||
private static final String PATCH_FIELDS =
|
||||
"owner,targetDefinition,dataInsightChart,description,owner,startDate,endDate,metricType";
|
||||
"targetDefinition,dataInsightChart,description,startDate,endDate,metricType";
|
||||
public static final String KPI_RESULT_EXTENSION = "kpi.kpiResult";
|
||||
|
||||
public KpiRepository(CollectionDAO dao) {
|
||||
|
||||
@ -27,17 +27,8 @@ import org.openmetadata.service.util.EntityUtil.Fields;
|
||||
import org.openmetadata.service.util.FullyQualifiedName;
|
||||
|
||||
public class MetricsRepository extends EntityRepository<Metrics> {
|
||||
private static final String METRICS_UPDATE_FIELDS = "owner";
|
||||
|
||||
public MetricsRepository(CollectionDAO dao) {
|
||||
super(
|
||||
MetricsResource.COLLECTION_PATH,
|
||||
Entity.METRICS,
|
||||
Metrics.class,
|
||||
dao.metricsDAO(),
|
||||
dao,
|
||||
"",
|
||||
METRICS_UPDATE_FIELDS);
|
||||
super(MetricsResource.COLLECTION_PATH, Entity.METRICS, Metrics.class, dao.metricsDAO(), dao, "", "");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -50,8 +50,8 @@ import org.openmetadata.service.util.JsonUtils;
|
||||
|
||||
@Slf4j
|
||||
public class MlModelRepository extends EntityRepository<MlModel> {
|
||||
private static final String MODEL_UPDATE_FIELDS = "owner,dashboard,tags,extension,followers";
|
||||
private static final String MODEL_PATCH_FIELDS = "owner,dashboard,tags,extension,followers";
|
||||
private static final String MODEL_UPDATE_FIELDS = "dashboard";
|
||||
private static final String MODEL_PATCH_FIELDS = "dashboard";
|
||||
|
||||
public MlModelRepository(CollectionDAO dao) {
|
||||
super(
|
||||
|
||||
@ -49,8 +49,8 @@ import org.openmetadata.service.util.ResultList;
|
||||
|
||||
public class PipelineRepository extends EntityRepository<Pipeline> {
|
||||
private static final String TASKS_FIELD = "tasks";
|
||||
private static final String PIPELINE_UPDATE_FIELDS = "owner,tags,tasks,extension,followers";
|
||||
private static final String PIPELINE_PATCH_FIELDS = "owner,tags,tasks,extension,followers";
|
||||
private static final String PIPELINE_UPDATE_FIELDS = "tasks";
|
||||
private static final String PIPELINE_PATCH_FIELDS = "tasks";
|
||||
public static final String PIPELINE_STATUS_EXTENSION = "pipeline.pipelineStatus";
|
||||
|
||||
public PipelineRepository(CollectionDAO dao) {
|
||||
|
||||
@ -48,19 +48,10 @@ import org.openmetadata.service.util.EntityUtil.Fields;
|
||||
|
||||
@Slf4j
|
||||
public class PolicyRepository extends EntityRepository<Policy> {
|
||||
private static final String POLICY_UPDATE_FIELDS = "owner";
|
||||
private static final String POLICY_PATCH_FIELDS = "owner";
|
||||
public static final String ENABLED = "enabled";
|
||||
|
||||
public PolicyRepository(CollectionDAO dao) {
|
||||
super(
|
||||
PolicyResource.COLLECTION_PATH,
|
||||
POLICY,
|
||||
Policy.class,
|
||||
dao.policyDAO(),
|
||||
dao,
|
||||
POLICY_PATCH_FIELDS,
|
||||
POLICY_UPDATE_FIELDS);
|
||||
super(PolicyResource.COLLECTION_PATH, POLICY, Policy.class, dao.policyDAO(), dao, "", "");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -26,8 +26,8 @@ import org.openmetadata.service.util.RestUtil;
|
||||
|
||||
public class QueryRepository extends EntityRepository<Query> {
|
||||
private static final String QUERY_USED_IN_FIELD = "queryUsedIn";
|
||||
private static final String QUERY_PATCH_FIELDS = "owner,tags,users,followers,query";
|
||||
private static final String QUERY_UPDATE_FIELDS = "owner,tags,users,votes,followers";
|
||||
private static final String QUERY_PATCH_FIELDS = "users,query";
|
||||
private static final String QUERY_UPDATE_FIELDS = "users,votes";
|
||||
|
||||
public QueryRepository(CollectionDAO dao) {
|
||||
super(
|
||||
|
||||
@ -25,10 +25,8 @@ import org.openmetadata.service.util.EntityUtil.Fields;
|
||||
|
||||
@Slf4j
|
||||
public class ReportRepository extends EntityRepository<Report> {
|
||||
private static final String REPORT_UPDATE_FIELDS = "owner";
|
||||
|
||||
public ReportRepository(CollectionDAO dao) {
|
||||
super(ReportResource.COLLECTION_PATH, Entity.REPORT, Report.class, dao.reportDAO(), dao, "", REPORT_UPDATE_FIELDS);
|
||||
super(ReportResource.COLLECTION_PATH, Entity.REPORT, Report.class, dao.reportDAO(), dao, "", "");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -30,9 +30,6 @@ import org.openmetadata.service.util.JsonUtils;
|
||||
public abstract class ServiceEntityRepository<
|
||||
T extends ServiceEntityInterface, S extends ServiceConnectionEntityInterface>
|
||||
extends EntityRepository<T> {
|
||||
private static final String UPDATE_FIELDS = "owner,tags";
|
||||
private static final String PATCH_FIELDS = UPDATE_FIELDS;
|
||||
|
||||
@Getter private final Class<S> serviceConnectionClass;
|
||||
|
||||
@Getter private final ServiceType serviceType;
|
||||
@ -44,7 +41,7 @@ public abstract class ServiceEntityRepository<
|
||||
EntityDAO<T> entityDAO,
|
||||
Class<S> serviceConnectionClass,
|
||||
ServiceType serviceType) {
|
||||
this(collectionPath, service, dao, entityDAO, serviceConnectionClass, UPDATE_FIELDS, serviceType);
|
||||
this(collectionPath, service, dao, entityDAO, serviceConnectionClass, "", serviceType);
|
||||
}
|
||||
|
||||
protected ServiceEntityRepository(
|
||||
@ -55,7 +52,7 @@ public abstract class ServiceEntityRepository<
|
||||
Class<S> serviceConnectionClass,
|
||||
String updatedFields,
|
||||
ServiceType serviceType) {
|
||||
super(collectionPath, service, entityDAO.getEntityClass(), entityDAO, dao, PATCH_FIELDS, updatedFields);
|
||||
super(collectionPath, service, entityDAO.getEntityClass(), entityDAO, dao, "", updatedFields);
|
||||
this.serviceConnectionClass = serviceConnectionClass;
|
||||
this.serviceType = serviceType;
|
||||
}
|
||||
|
||||
@ -37,6 +37,7 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
@ -90,9 +91,9 @@ import org.openmetadata.service.util.ResultList;
|
||||
public class TableRepository extends EntityRepository<Table> {
|
||||
|
||||
// Table fields that can be patched in a PATCH request
|
||||
static final String PATCH_FIELDS = "owner,tags,tableConstraints,tablePartition,extension,followers";
|
||||
static final String PATCH_FIELDS = "tableConstraints,tablePartition";
|
||||
// Table fields that can be updated in a PUT request
|
||||
static final String UPDATE_FIELDS = "owner,tags,tableConstraints,tablePartition,dataModel,extension,followers";
|
||||
static final String UPDATE_FIELDS = "tableConstraints,tablePartition,dataModel";
|
||||
|
||||
public static final String FIELD_RELATION_COLUMN_TYPE = "table.columns.column";
|
||||
public static final String FIELD_RELATION_TABLE_TYPE = "table";
|
||||
@ -589,8 +590,8 @@ public class TableRepository extends EntityRepository<Table> {
|
||||
}
|
||||
applyTags(table.getColumns());
|
||||
dao.update(table.getId(), FullyQualifiedName.buildHash(table.getFullyQualifiedName()), JsonUtils.pojoToJson(table));
|
||||
setFieldsInternal(table, new Fields(List.of(FIELD_OWNER), FIELD_OWNER));
|
||||
setFieldsInternal(table, new Fields(List.of(FIELD_TAGS), FIELD_TAGS));
|
||||
setFieldsInternal(table, new Fields(Set.of(FIELD_OWNER), FIELD_OWNER));
|
||||
setFieldsInternal(table, new Fields(Set.of(FIELD_TAGS), FIELD_TAGS));
|
||||
return table;
|
||||
}
|
||||
|
||||
|
||||
@ -80,8 +80,8 @@ import org.openmetadata.service.util.ResultList;
|
||||
@Slf4j
|
||||
public class TeamRepository extends EntityRepository<Team> {
|
||||
static final String PARENTS_FIELD = "parents";
|
||||
static final String TEAM_UPDATE_FIELDS = "owner,profile,users,defaultRoles,parents,children,policies,teamType,email";
|
||||
static final String TEAM_PATCH_FIELDS = "owner,profile,users,defaultRoles,parents,children,policies,teamType,email";
|
||||
static final String TEAM_UPDATE_FIELDS = "profile,users,defaultRoles,parents,children,policies,teamType,email";
|
||||
static final String TEAM_PATCH_FIELDS = "profile,users,defaultRoles,parents,children,policies,teamType,email";
|
||||
private static final String DEFAULT_ROLES = "defaultRoles";
|
||||
private Team organization = null;
|
||||
|
||||
|
||||
@ -49,8 +49,8 @@ public class TestCaseRepository extends EntityRepository<TestCase> {
|
||||
private static final String TEST_SUITE_FIELD = "testSuite";
|
||||
private static final String TEST_CASE_RESULT_FIELD = "testCaseResult";
|
||||
public static final String COLLECTION_PATH = "/v1/dataQuality/testCases";
|
||||
private static final String UPDATE_FIELDS = "owner,entityLink,testSuite,testDefinition";
|
||||
private static final String PATCH_FIELDS = "owner,entityLink,testSuite,testDefinition";
|
||||
private static final String UPDATE_FIELDS = "entityLink,testSuite,testDefinition";
|
||||
private static final String PATCH_FIELDS = "entityLink,testSuite,testDefinition";
|
||||
public static final String TESTCASE_RESULT_EXTENSION = "testCase.testCaseResult";
|
||||
|
||||
public TestCaseRepository(CollectionDAO dao) {
|
||||
|
||||
@ -10,9 +10,6 @@ import org.openmetadata.service.resources.dqtests.TestDefinitionResource;
|
||||
import org.openmetadata.service.util.EntityUtil;
|
||||
|
||||
public class TestDefinitionRepository extends EntityRepository<TestDefinition> {
|
||||
private static final String UPDATE_FIELDS = "owner";
|
||||
private static final String PATCH_FIELDS = "owner";
|
||||
|
||||
public TestDefinitionRepository(CollectionDAO dao) {
|
||||
super(
|
||||
TestDefinitionResource.COLLECTION_PATH,
|
||||
@ -20,8 +17,8 @@ public class TestDefinitionRepository extends EntityRepository<TestDefinition> {
|
||||
TestDefinition.class,
|
||||
dao.testDefinitionDAO(),
|
||||
dao,
|
||||
PATCH_FIELDS,
|
||||
UPDATE_FIELDS);
|
||||
"",
|
||||
"");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -23,8 +23,8 @@ import org.openmetadata.service.util.RestUtil;
|
||||
|
||||
@Slf4j
|
||||
public class TestSuiteRepository extends EntityRepository<TestSuite> {
|
||||
private static final String UPDATE_FIELDS = "owner,tests";
|
||||
private static final String PATCH_FIELDS = "owner,tests";
|
||||
private static final String UPDATE_FIELDS = "tests";
|
||||
private static final String PATCH_FIELDS = "tests";
|
||||
|
||||
public TestSuiteRepository(CollectionDAO dao) {
|
||||
super(
|
||||
|
||||
@ -56,9 +56,6 @@ import org.openmetadata.service.util.FullyQualifiedName;
|
||||
import org.openmetadata.service.util.JsonUtils;
|
||||
|
||||
public class TopicRepository extends EntityRepository<Topic> {
|
||||
private static final String TOPIC_UPDATE_FIELDS = "owner,tags,extension,followers";
|
||||
private static final String TOPIC_PATCH_FIELDS = "owner,tags,extension,followers";
|
||||
|
||||
@Override
|
||||
public void setFullyQualifiedName(Topic topic) {
|
||||
topic.setFullyQualifiedName(FullyQualifiedName.add(topic.getService().getFullyQualifiedName(), topic.getName()));
|
||||
@ -73,14 +70,7 @@ public class TopicRepository extends EntityRepository<Topic> {
|
||||
}
|
||||
|
||||
public TopicRepository(CollectionDAO dao) {
|
||||
super(
|
||||
TopicResource.COLLECTION_PATH,
|
||||
Entity.TOPIC,
|
||||
Topic.class,
|
||||
dao.topicDAO(),
|
||||
dao,
|
||||
TOPIC_PATCH_FIELDS,
|
||||
TOPIC_UPDATE_FIELDS);
|
||||
super(TopicResource.COLLECTION_PATH, Entity.TOPIC, Topic.class, dao.topicDAO(), dao, "", "");
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -291,7 +281,7 @@ public class TopicRepository extends EntityRepository<Topic> {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (childrenSchemaName != "" && schemaField != null) {
|
||||
if (!"".equals(childrenSchemaName) && schemaField != null) {
|
||||
schemaField = getchildrenSchemaField(schemaField.getChildren(), childrenSchemaName);
|
||||
}
|
||||
if (schemaField == null) {
|
||||
@ -323,9 +313,9 @@ public class TopicRepository extends EntityRepository<Topic> {
|
||||
}
|
||||
}
|
||||
if (childrenSchemaField == null) {
|
||||
for (int i = 0; i < fields.size(); i++) {
|
||||
if (fields.get(i).getChildren() != null) {
|
||||
childrenSchemaField = getchildrenSchemaField(fields.get(i).getChildren(), childrenSchemaName);
|
||||
for (Field field : fields) {
|
||||
if (field.getChildren() != null) {
|
||||
childrenSchemaField = getchildrenSchemaField(field.getChildren(), childrenSchemaName);
|
||||
if (childrenSchemaField != null) {
|
||||
break;
|
||||
}
|
||||
|
||||
@ -75,7 +75,7 @@ public class UserRepository extends EntityRepository<User> {
|
||||
}
|
||||
|
||||
public final Fields getFieldsWithUserAuth(String fields) {
|
||||
List<String> tempFields = getAllowedFieldsCopy();
|
||||
Set<String> tempFields = getAllowedFieldsCopy();
|
||||
if (fields != null && fields.equals("*")) {
|
||||
tempFields.add(AUTH_MECHANISM_FIELD);
|
||||
return new Fields(tempFields);
|
||||
|
||||
@ -16,19 +16,10 @@ import org.openmetadata.service.util.ResultList;
|
||||
|
||||
public class WebAnalyticEventRepository extends EntityRepository<WebAnalyticEvent> {
|
||||
public static final String COLLECTION_PATH = "/v1/analytics/web/events";
|
||||
private static final String UPDATE_FIELDS = "owner";
|
||||
private static final String PATCH_FIELDS = "owner";
|
||||
private static final String WEB_ANALYTICS_EVENT_DATA_EXTENSION = "webAnalyticEvent.webAnalyticEventData";
|
||||
|
||||
public WebAnalyticEventRepository(CollectionDAO dao) {
|
||||
super(
|
||||
COLLECTION_PATH,
|
||||
WEB_ANALYTIC_EVENT,
|
||||
WebAnalyticEvent.class,
|
||||
dao.webAnalyticEventDAO(),
|
||||
dao,
|
||||
PATCH_FIELDS,
|
||||
UPDATE_FIELDS);
|
||||
super(COLLECTION_PATH, WEB_ANALYTIC_EVENT, WebAnalyticEvent.class, dao.webAnalyticEventDAO(), dao, "", "");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -13,18 +13,10 @@ import org.openmetadata.service.secrets.SecretsManagerFactory;
|
||||
import org.openmetadata.service.util.EntityUtil;
|
||||
|
||||
public class WorkflowRepository extends EntityRepository<Workflow> {
|
||||
private static final String UPDATE_FIELDS = "owner";
|
||||
private static final String PATCH_FIELDS = "owner,status,response";
|
||||
private static final String PATCH_FIELDS = "status,response";
|
||||
|
||||
public WorkflowRepository(CollectionDAO dao) {
|
||||
super(
|
||||
WorkflowResource.COLLECTION_PATH,
|
||||
WORKFLOW,
|
||||
Workflow.class,
|
||||
dao.workflowDAO(),
|
||||
dao,
|
||||
PATCH_FIELDS,
|
||||
UPDATE_FIELDS);
|
||||
super(WorkflowResource.COLLECTION_PATH, WORKFLOW, Workflow.class, dao.workflowDAO(), dao, PATCH_FIELDS, "");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -76,6 +76,7 @@ import org.openmetadata.service.migration.api.MigrationStep;
|
||||
import org.openmetadata.service.resources.databases.DatasourceConfig;
|
||||
import org.openmetadata.service.resources.feeds.MessageParser;
|
||||
import org.openmetadata.service.util.EntityUtil;
|
||||
import org.openmetadata.service.util.EntityUtil.Fields;
|
||||
import org.openmetadata.service.util.FullyQualifiedName;
|
||||
import org.openmetadata.service.util.JsonUtils;
|
||||
|
||||
@ -136,7 +137,7 @@ public class MigrationUtil {
|
||||
for (String json : jsons) {
|
||||
// Update the Statements to Database
|
||||
T entity = JsonUtils.readValue(json, clazz);
|
||||
String hash = "";
|
||||
String hash;
|
||||
try {
|
||||
hash =
|
||||
withName
|
||||
@ -407,8 +408,7 @@ public class MigrationUtil {
|
||||
IngestionPipelineRepository ingestionPipelineRepository = new IngestionPipelineRepository(collectionDAO);
|
||||
TestSuiteRepository testSuiteRepository = new TestSuiteRepository(collectionDAO);
|
||||
TestCaseRepository testCaseRepository = new TestCaseRepository(collectionDAO);
|
||||
List<TestCase> testCases =
|
||||
testCaseRepository.listAll(new EntityUtil.Fields(List.of("id")), new ListFilter(Include.ALL));
|
||||
List<TestCase> testCases = testCaseRepository.listAll(new Fields(Set.of("id")), new ListFilter(Include.ALL));
|
||||
|
||||
for (TestCase test : testCases) {
|
||||
|
||||
@ -422,14 +422,14 @@ public class MigrationUtil {
|
||||
testSuiteRepository.getByName(
|
||||
null,
|
||||
EntityInterfaceUtil.quoteName(FullyQualifiedName.buildHash(testSuiteFqn)),
|
||||
new EntityUtil.Fields(List.of("id")),
|
||||
new Fields(Set.of("id")),
|
||||
Include.ALL);
|
||||
} catch (EntityNotFoundException entityNotFoundException) {
|
||||
try {
|
||||
// Check if the test Suite Exists, this brings the data on nameHash basis
|
||||
stored =
|
||||
testSuiteRepository.getByName(
|
||||
null, EntityInterfaceUtil.quoteName(testSuiteFqn), new EntityUtil.Fields(List.of("id")), Include.ALL);
|
||||
null, EntityInterfaceUtil.quoteName(testSuiteFqn), new Fields(Set.of("id")), Include.ALL);
|
||||
testSuiteRepository.addRelationship(
|
||||
stored.getId(), test.getId(), TEST_SUITE, TEST_CASE, Relationship.CONTAINS);
|
||||
stored.setExecutable(true);
|
||||
@ -477,7 +477,7 @@ public class MigrationUtil {
|
||||
// Update Test Suites
|
||||
ListFilter filter = new ListFilter(Include.ALL);
|
||||
filter.addQueryParam("testSuiteType", "logical");
|
||||
List<TestSuite> testSuites = testSuiteRepository.listAll(new EntityUtil.Fields(List.of("id")), filter);
|
||||
List<TestSuite> testSuites = testSuiteRepository.listAll(new Fields(Set.of("id")), filter);
|
||||
|
||||
for (TestSuite testSuiteRecord : testSuites) {
|
||||
TestSuite temp = testSuiteRepository.getDao().findEntityById(testSuiteRecord.getId());
|
||||
|
||||
@ -49,7 +49,7 @@ import org.openmetadata.service.util.ResultList;
|
||||
public abstract class EntityResource<T extends EntityInterface, K extends EntityRepository<T>> {
|
||||
protected final Class<T> entityClass;
|
||||
protected final String entityType;
|
||||
protected final List<String> allowedFields;
|
||||
protected final Set<String> allowedFields;
|
||||
@Getter protected final K repository;
|
||||
protected final Authorizer authorizer;
|
||||
protected final Map<String, MetadataOperation> fieldsToViewOperations = new HashMap<>();
|
||||
|
||||
@ -45,6 +45,7 @@ import java.time.ZoneId;
|
||||
import java.util.Base64;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
import javax.json.JsonObject;
|
||||
@ -656,7 +657,7 @@ public class UserResource extends EntityResource<User, UserRepository> {
|
||||
@Parameter(description = "Id of the user", schema = @Schema(type = "UUID")) @PathParam("id") UUID id)
|
||||
throws IOException {
|
||||
|
||||
User user = repository.get(uriInfo, id, new Fields(List.of(AUTH_MECHANISM_FIELD)));
|
||||
User user = repository.get(uriInfo, id, new Fields(Set.of(AUTH_MECHANISM_FIELD)));
|
||||
if (!Boolean.TRUE.equals(user.getIsBot())) {
|
||||
throw new IllegalArgumentException("JWT token is only supported for bot users");
|
||||
}
|
||||
@ -693,7 +694,7 @@ public class UserResource extends EntityResource<User, UserRepository> {
|
||||
@Parameter(description = "Id of the user", schema = @Schema(type = "UUID")) @PathParam("id") UUID id)
|
||||
throws IOException {
|
||||
|
||||
User user = repository.get(uriInfo, id, new Fields(List.of(AUTH_MECHANISM_FIELD)));
|
||||
User user = repository.get(uriInfo, id, new Fields(Set.of(AUTH_MECHANISM_FIELD)));
|
||||
if (!Boolean.TRUE.equals(user.getIsBot())) {
|
||||
throw new IllegalArgumentException("JWT token is only supported for bot users");
|
||||
}
|
||||
@ -898,7 +899,7 @@ public class UserResource extends EntityResource<User, UserRepository> {
|
||||
User registeredUser;
|
||||
try {
|
||||
registeredUser =
|
||||
repository.getByName(uriInfo, userName, new Fields(List.of(USER_PROTECTED_FIELDS), USER_PROTECTED_FIELDS));
|
||||
repository.getByName(uriInfo, userName, new Fields(Set.of(USER_PROTECTED_FIELDS), USER_PROTECTED_FIELDS));
|
||||
} catch (IOException | EntityNotFoundException ex) {
|
||||
LOG.error(
|
||||
"[GeneratePasswordReset] Got Error while fetching user : {}, error message {}", userName, ex.getMessage());
|
||||
|
||||
@ -18,6 +18,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@ -37,6 +38,7 @@ import org.openmetadata.service.resources.CollectionRegistry;
|
||||
import org.openmetadata.service.resources.CollectionRegistry.CollectionDetails;
|
||||
import org.openmetadata.service.resources.services.ServiceEntityResource;
|
||||
import org.openmetadata.service.util.EntityUtil;
|
||||
import org.openmetadata.service.util.EntityUtil.Fields;
|
||||
|
||||
/**
|
||||
* Update service using the configured secret manager.
|
||||
@ -198,7 +200,7 @@ public class SecretsManagerUpdateService {
|
||||
return userRepository
|
||||
.listAfter(
|
||||
null,
|
||||
new EntityUtil.Fields(List.of("authenticationMechanism")),
|
||||
new Fields(Set.of("authenticationMechanism")),
|
||||
new ListFilter(),
|
||||
userRepository.getDao().listCount(new ListFilter()),
|
||||
null)
|
||||
|
||||
@ -37,7 +37,6 @@ import java.io.IOException;
|
||||
import java.time.Instant;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
@ -208,7 +207,7 @@ public class BasicAuthenticator implements AuthenticatorHandler {
|
||||
public void resetUserPasswordWithToken(UriInfo uriInfo, PasswordResetRequest request) throws IOException {
|
||||
String tokenID = request.getToken();
|
||||
PasswordResetToken passwordResetToken = (PasswordResetToken) tokenRepository.findByToken(tokenID);
|
||||
List<String> fields = userRepository.getAllowedFieldsCopy();
|
||||
Set<String> fields = userRepository.getAllowedFieldsCopy();
|
||||
fields.add(USER_PROTECTED_FIELDS);
|
||||
User storedUser =
|
||||
userRepository.getByName(
|
||||
@ -471,17 +470,17 @@ public class BasicAuthenticator implements AuthenticatorHandler {
|
||||
|
||||
@Override
|
||||
public User lookUserInProvider(String userName) {
|
||||
User storedUser = null;
|
||||
User storedUser;
|
||||
try {
|
||||
if (userName.contains("@")) {
|
||||
// lookup by User Email
|
||||
storedUser =
|
||||
userRepository.getByEmail(
|
||||
null, userName, new EntityUtil.Fields(List.of(USER_PROTECTED_FIELDS), USER_PROTECTED_FIELDS));
|
||||
null, userName, new EntityUtil.Fields(Set.of(USER_PROTECTED_FIELDS), USER_PROTECTED_FIELDS));
|
||||
} else {
|
||||
storedUser =
|
||||
userRepository.getByName(
|
||||
null, userName, new EntityUtil.Fields(List.of(USER_PROTECTED_FIELDS), USER_PROTECTED_FIELDS));
|
||||
null, userName, new EntityUtil.Fields(Set.of(USER_PROTECTED_FIELDS), USER_PROTECTED_FIELDS));
|
||||
}
|
||||
|
||||
if (storedUser != null && Boolean.TRUE.equals(storedUser.getIsBot())) {
|
||||
|
||||
@ -7,7 +7,7 @@ import com.google.common.cache.CacheLoader;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
import com.google.common.util.concurrent.UncheckedExecutionException;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import javax.annotation.CheckForNull;
|
||||
@ -18,7 +18,7 @@ import org.openmetadata.schema.entity.teams.User;
|
||||
import org.openmetadata.service.Entity;
|
||||
import org.openmetadata.service.jdbi3.UserRepository;
|
||||
import org.openmetadata.service.resources.teams.UserResource;
|
||||
import org.openmetadata.service.util.EntityUtil;
|
||||
import org.openmetadata.service.util.EntityUtil.Fields;
|
||||
import org.openmetadata.service.util.JsonUtils;
|
||||
|
||||
@Slf4j
|
||||
@ -59,8 +59,7 @@ public class BotTokenCache {
|
||||
public String load(@CheckForNull String botName) throws IOException {
|
||||
UserRepository userRepository = (UserRepository) Entity.getEntityRepository(Entity.USER);
|
||||
User user =
|
||||
userRepository.getByName(
|
||||
null, botName, new EntityUtil.Fields(List.of(UserResource.USER_PROTECTED_FIELDS)), NON_DELETED);
|
||||
userRepository.getByName(null, botName, new Fields(Set.of(UserResource.USER_PROTECTED_FIELDS)), NON_DELETED);
|
||||
AuthenticationMechanism authenticationMechanism = user.getAuthenticationMechanism();
|
||||
if (authenticationMechanism != null) {
|
||||
JWTAuthMechanism jwtAuthMechanism =
|
||||
|
||||
@ -23,7 +23,7 @@ import org.openmetadata.service.jdbi3.CollectionDAO;
|
||||
import org.openmetadata.service.jdbi3.TokenRepository;
|
||||
import org.openmetadata.service.jdbi3.UserRepository;
|
||||
import org.openmetadata.service.resources.teams.UserResource;
|
||||
import org.openmetadata.service.util.EntityUtil;
|
||||
import org.openmetadata.service.util.EntityUtil.Fields;
|
||||
|
||||
@Slf4j
|
||||
public class UserTokenCache {
|
||||
@ -74,8 +74,7 @@ public class UserTokenCache {
|
||||
HashSet<String> result = new HashSet<>();
|
||||
UserRepository userRepository = (UserRepository) Entity.getEntityRepository(Entity.USER);
|
||||
User user =
|
||||
userRepository.getByName(
|
||||
null, userName, new EntityUtil.Fields(List.of(UserResource.USER_PROTECTED_FIELDS)), NON_DELETED);
|
||||
userRepository.getByName(null, userName, new Fields(Set.of(UserResource.USER_PROTECTED_FIELDS)), NON_DELETED);
|
||||
List<TokenInterface> tokens =
|
||||
tokenRepository.findByUserIdAndType(user.getId().toString(), TokenType.PERSONAL_ACCESS_TOKEN.value());
|
||||
tokens.forEach(t -> result.add(((PersonalAccessToken) t).getJwtToken()));
|
||||
|
||||
@ -24,7 +24,9 @@ import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.function.BiPredicate;
|
||||
import java.util.regex.Pattern;
|
||||
@ -188,7 +190,7 @@ public final class EntityUtil {
|
||||
return populateEntityReferences(refs);
|
||||
}
|
||||
|
||||
public static EntityReference validateEntityLink(EntityLink entityLink) throws IOException {
|
||||
public static EntityReference validateEntityLink(EntityLink entityLink) {
|
||||
String entityType = entityLink.getEntityType();
|
||||
String fqn = entityLink.getEntityFQN();
|
||||
return Entity.getEntityReferenceByName(entityType, fqn, ALL);
|
||||
@ -293,19 +295,19 @@ public final class EntityUtil {
|
||||
}
|
||||
|
||||
public static class Fields {
|
||||
public static final Fields EMPTY_FIELDS = new Fields(Collections.emptyList());
|
||||
@Getter private final List<String> fieldList;
|
||||
public static final Fields EMPTY_FIELDS = new Fields(Collections.emptySet());
|
||||
@Getter private final Set<String> fieldList;
|
||||
|
||||
public Fields(List<String> fieldList) {
|
||||
public Fields(Set<String> fieldList) {
|
||||
this.fieldList = fieldList;
|
||||
}
|
||||
|
||||
public Fields(List<String> allowedFields, String fieldsParam) {
|
||||
public Fields(Set<String> allowedFields, String fieldsParam) {
|
||||
if (nullOrEmpty(fieldsParam)) {
|
||||
fieldList = new ArrayList<>();
|
||||
fieldList = new HashSet<>();
|
||||
return;
|
||||
}
|
||||
fieldList = Arrays.asList(fieldsParam.replace(" ", "").split(","));
|
||||
fieldList = new HashSet<>(Arrays.asList(fieldsParam.replace(" ", "").split(",")));
|
||||
for (String field : fieldList) {
|
||||
if (!allowedFields.contains(field)) {
|
||||
throw new IllegalArgumentException(CatalogExceptionMessage.invalidField(field));
|
||||
@ -313,9 +315,9 @@ public final class EntityUtil {
|
||||
}
|
||||
}
|
||||
|
||||
public Fields(List<String> allowedFields, List<String> fieldsParam) {
|
||||
public Fields(Set<String> allowedFields, Set<String> fieldsParam) {
|
||||
if (CommonUtil.nullOrEmpty(fieldsParam)) {
|
||||
fieldList = new ArrayList<>();
|
||||
fieldList = new HashSet<>();
|
||||
return;
|
||||
}
|
||||
for (String field : fieldsParam) {
|
||||
@ -323,7 +325,14 @@ public final class EntityUtil {
|
||||
throw new IllegalArgumentException(CatalogExceptionMessage.invalidField(field));
|
||||
}
|
||||
}
|
||||
fieldList = fieldsParam;
|
||||
fieldList = new HashSet<>(fieldsParam);
|
||||
}
|
||||
|
||||
public void addField(Set<String> allowedFields, String field) {
|
||||
if (!allowedFields.contains(field)) {
|
||||
throw new IllegalArgumentException(CatalogExceptionMessage.invalidField(field));
|
||||
}
|
||||
fieldList.add(field);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -14,7 +14,7 @@
|
||||
package org.openmetadata.service.util;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.openmetadata.schema.api.configuration.pipelineServiceClient.PipelineServiceClientConfiguration;
|
||||
import org.openmetadata.schema.auth.JWTAuthMechanism;
|
||||
@ -160,7 +160,7 @@ public class OpenMetadataConnectionBuilder {
|
||||
userRepository.getByName(
|
||||
null,
|
||||
bot1.getBotUser().getFullyQualifiedName(),
|
||||
new EntityUtil.Fields(List.of("authenticationMechanism")));
|
||||
new EntityUtil.Fields(Set.of("authenticationMechanism")));
|
||||
if (user.getAuthenticationMechanism() != null) {
|
||||
user.getAuthenticationMechanism().setConfig(user.getAuthenticationMechanism().getConfig());
|
||||
}
|
||||
|
||||
@ -26,7 +26,7 @@ import static org.openmetadata.service.Entity.ADMIN_USER_NAME;
|
||||
|
||||
import at.favre.lib.crypto.bcrypt.BCrypt;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
@ -49,6 +49,7 @@ import org.openmetadata.service.jdbi3.EntityRepository;
|
||||
import org.openmetadata.service.jdbi3.UserRepository;
|
||||
import org.openmetadata.service.resources.teams.RoleResource;
|
||||
import org.openmetadata.service.security.jwt.JWTTokenGenerator;
|
||||
import org.openmetadata.service.util.EntityUtil.Fields;
|
||||
|
||||
@Slf4j
|
||||
public final class UserUtil {
|
||||
@ -72,11 +73,11 @@ public final class UserUtil {
|
||||
User updatedUser;
|
||||
try {
|
||||
// Create Required Fields List
|
||||
List<String> fieldList = new ArrayList<>(userRepository.getPatchFields().getFieldList());
|
||||
Set<String> fieldList = new HashSet<>(userRepository.getPatchFields().getFieldList());
|
||||
fieldList.add("authenticationMechanism");
|
||||
|
||||
// Fetch Original User, is available
|
||||
User originalUser = userRepository.getByName(null, username, new EntityUtil.Fields(fieldList));
|
||||
User originalUser = userRepository.getByName(null, username, new Fields(fieldList));
|
||||
updatedUser = originalUser;
|
||||
|
||||
// Update Auth Mechanism if not present, and send mail to the user
|
||||
@ -248,7 +249,7 @@ public final class UserUtil {
|
||||
private static User retrieveWithAuthMechanism(User user) {
|
||||
EntityRepository<User> userRepository = (UserRepository) Entity.getEntityRepository(Entity.USER);
|
||||
try {
|
||||
return userRepository.getByName(null, user.getName(), new EntityUtil.Fields(List.of("authenticationMechanism")));
|
||||
return userRepository.getByName(null, user.getName(), new Fields(Set.of("authenticationMechanism")));
|
||||
} catch (IOException | EntityNotFoundException e) {
|
||||
LOG.debug("Bot entity: {} does not exists.", user);
|
||||
return null;
|
||||
|
||||
@ -82,6 +82,7 @@ import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Optional;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Predicate;
|
||||
@ -380,7 +381,7 @@ public abstract class EntityResourceTest<T extends EntityInterface, K extends Cr
|
||||
this.collectionName = collectionName;
|
||||
this.allFields = fields;
|
||||
ENTITY_RESOURCE_TEST_MAP.put(entityType, this);
|
||||
List<String> allowedFields = Entity.getEntityFields(entityClass);
|
||||
Set<String> allowedFields = Entity.getEntityFields(entityClass);
|
||||
this.supportsFollowers = allowedFields.contains(FIELD_FOLLOWERS);
|
||||
this.supportsOwner = allowedFields.contains(FIELD_OWNER);
|
||||
this.supportsTags = allowedFields.contains(FIELD_TAGS);
|
||||
|
||||
@ -74,6 +74,7 @@ import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TimeZone;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Predicate;
|
||||
@ -166,7 +167,7 @@ public class UserResourceTest extends EntityResourceTest<User, CreateUser> {
|
||||
USER_TEAM21 = createEntity(create, ADMIN_AUTH_HEADERS);
|
||||
USER2_REF = USER2.getEntityReference();
|
||||
|
||||
List<String> userFields = Entity.getEntityFields(User.class);
|
||||
Set<String> userFields = Entity.getEntityFields(User.class);
|
||||
userFields.remove("authenticationMechanism");
|
||||
BOT_USER = getEntityByName(INGESTION_BOT, String.join(",", userFields), ADMIN_AUTH_HEADERS);
|
||||
}
|
||||
@ -1243,7 +1244,7 @@ public class UserResourceTest extends EntityResourceTest<User, CreateUser> {
|
||||
|
||||
@Override
|
||||
public String getAllowedFields() {
|
||||
List<String> allowedFields = Entity.getEntityFields(entityClass);
|
||||
Set<String> allowedFields = Entity.getEntityFields(entityClass);
|
||||
allowedFields.removeAll(of(USER_PROTECTED_FIELDS.split(",")));
|
||||
return String.join(",", allowedFields);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user