Move setting common patch and updated fields to EntityRepository (#12469)

This commit is contained in:
Suresh Srinivas 2023-07-17 21:41:25 -07:00 committed by GitHub
parent 5ca757f5e8
commit 62e82ba492
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
45 changed files with 147 additions and 197 deletions

View File

@ -23,9 +23,11 @@ import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.EnumMap; import java.util.EnumMap;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.Set;
import java.util.UUID; import java.util.UUID;
import javax.ws.rs.core.UriInfo; import javax.ws.rs.core.UriInfo;
import lombok.NonNull; 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 * 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); 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. */ /** Class for getting validated entity list from a queryParam with list of entities. */

View File

@ -57,7 +57,7 @@ public class ResourceRegistry {
private ResourceRegistry() {} private ResourceRegistry() {}
public static void addResource( 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 resourceName already exists, then no need to add the resource again
if (RESOURCE_DESCRIPTORS.stream().anyMatch(d -> d.getName().equals(resourceName))) { if (RESOURCE_DESCRIPTORS.stream().anyMatch(d -> d.getName().equals(resourceName))) {
return; return;
@ -65,7 +65,7 @@ public class ResourceRegistry {
ResourceDescriptor resourceDescriptor = ResourceDescriptor resourceDescriptor =
new ResourceDescriptor() new ResourceDescriptor()
.withName(resourceName) .withName(resourceName)
.withOperations(getOperations(resourceName, entitySpecificOperations, entityFields)); .withOperations(getOperations(resourceName, entitySpecificOperations, new ArrayList<>(entityFields)));
RESOURCE_DESCRIPTORS.sort(Comparator.comparing(ResourceDescriptor::getName)); RESOURCE_DESCRIPTORS.sort(Comparator.comparing(ResourceDescriptor::getName));
RESOURCE_DESCRIPTORS.add(resourceDescriptor); RESOURCE_DESCRIPTORS.add(resourceDescriptor);
} }

View File

@ -31,18 +31,8 @@ import org.openmetadata.service.util.FullyQualifiedName;
@Slf4j @Slf4j
public class ChartRepository extends EntityRepository<Chart> { 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) { public ChartRepository(CollectionDAO dao) {
super( super(ChartResource.COLLECTION_PATH, Entity.CHART, Chart.class, dao.chartDAO(), dao, "", "");
ChartResource.COLLECTION_PATH,
Entity.CHART,
Chart.class,
dao.chartDAO(),
dao,
CHART_PATCH_FIELDS,
CHART_UPDATE_FIELDS);
} }
@Override @Override

View File

@ -34,8 +34,8 @@ import org.openmetadata.service.util.JsonUtils;
public class ContainerRepository extends EntityRepository<Container> { public class ContainerRepository extends EntityRepository<Container> {
private static final String CONTAINER_UPDATE_FIELDS = "dataModel,owner,tags,extension"; private static final String CONTAINER_UPDATE_FIELDS = "dataModel";
private static final String CONTAINER_PATCH_FIELDS = "dataModel,owner,tags,extension"; private static final String CONTAINER_PATCH_FIELDS = "dataModel";
public ContainerRepository(CollectionDAO dao) { public ContainerRepository(CollectionDAO dao) {
super( super(

View File

@ -43,10 +43,6 @@ import org.openmetadata.service.util.JsonUtils;
@Slf4j @Slf4j
public class DashboardDataModelRepository extends EntityRepository<DashboardDataModel> { 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) { public DashboardDataModelRepository(CollectionDAO dao) {
super( super(
DashboardDataModelResource.COLLECTION_PATH, DashboardDataModelResource.COLLECTION_PATH,
@ -54,8 +50,8 @@ public class DashboardDataModelRepository extends EntityRepository<DashboardData
DashboardDataModel.class, DashboardDataModel.class,
dao.dashboardDataModelDAO(), dao.dashboardDataModelDAO(),
dao, dao,
DATA_MODEL_PATCH_FIELDS, "",
DATA_MODEL_UPDATE_FIELDS); "");
} }
@Override @Override

View File

@ -37,8 +37,8 @@ import org.openmetadata.service.util.EntityUtil.Fields;
import org.openmetadata.service.util.FullyQualifiedName; import org.openmetadata.service.util.FullyQualifiedName;
public class DashboardRepository extends EntityRepository<Dashboard> { public class DashboardRepository extends EntityRepository<Dashboard> {
private static final String DASHBOARD_UPDATE_FIELDS = "owner,tags,charts,extension,followers,dataModels"; private static final String DASHBOARD_UPDATE_FIELDS = "charts,dataModels";
private static final String DASHBOARD_PATCH_FIELDS = "owner,tags,charts,extension,followers,dataModels"; private static final String DASHBOARD_PATCH_FIELDS = "charts,dataModels";
private static final String DASHBOARD_URL = "sourceUrl"; private static final String DASHBOARD_URL = "sourceUrl";

View File

@ -11,8 +11,6 @@ import org.openmetadata.service.util.EntityUtil;
public class DataInsightChartRepository extends EntityRepository<DataInsightChart> { public class DataInsightChartRepository extends EntityRepository<DataInsightChart> {
public static final String COLLECTION_PATH = "/v1/analytics/dataInsights/charts"; public static final String COLLECTION_PATH = "/v1/analytics/dataInsights/charts";
public static final String LAST_SESSION = "lastSession"; 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 DATA_ENTITY_TYPE = "data.entityType";
public static final String TIMESTAMP = "timestamp"; public static final String TIMESTAMP = "timestamp";
public static final String ENTITY_COUNT = "entityCount"; public static final String ENTITY_COUNT = "entityCount";
@ -61,14 +59,7 @@ public class DataInsightChartRepository extends EntityRepository<DataInsightChar
"MostViewedEntities"); "MostViewedEntities");
public DataInsightChartRepository(CollectionDAO dao) { public DataInsightChartRepository(CollectionDAO dao) {
super( super(COLLECTION_PATH, DATA_INSIGHT_CHART, DataInsightChart.class, dao.dataInsightChartDAO(), dao, "", "");
COLLECTION_PATH,
DATA_INSIGHT_CHART,
DataInsightChart.class,
dao.dataInsightChartDAO(),
dao,
PATCH_FIELDS,
UPDATE_FIELDS);
} }
@Override @Override

View File

@ -31,7 +31,7 @@ import org.openmetadata.service.util.FullyQualifiedName;
@Slf4j @Slf4j
public class DataProductRepository extends EntityRepository<DataProduct> { 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) { public DataProductRepository(CollectionDAO dao) {
super( super(

View File

@ -28,18 +28,9 @@ import org.openmetadata.service.util.EntityUtil.Fields;
import org.openmetadata.service.util.FullyQualifiedName; import org.openmetadata.service.util.FullyQualifiedName;
public class DatabaseRepository extends EntityRepository<Database> { 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) { public DatabaseRepository(CollectionDAO dao) {
super( super(DatabaseResource.COLLECTION_PATH, Entity.DATABASE, Database.class, dao.databaseDAO(), dao, "", "");
DatabaseResource.COLLECTION_PATH,
Entity.DATABASE,
Database.class,
dao.databaseDAO(),
dao,
DATABASE_PATCH_FIELDS,
DATABASE_UPDATE_FIELDS);
} }
@Override @Override

View File

@ -33,9 +33,6 @@ import org.openmetadata.service.util.EntityUtil.Fields;
import org.openmetadata.service.util.FullyQualifiedName; import org.openmetadata.service.util.FullyQualifiedName;
public class DatabaseSchemaRepository extends EntityRepository<DatabaseSchema> { 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) { public DatabaseSchemaRepository(CollectionDAO dao) {
super( super(
DatabaseSchemaResource.COLLECTION_PATH, DatabaseSchemaResource.COLLECTION_PATH,
@ -43,8 +40,8 @@ public class DatabaseSchemaRepository extends EntityRepository<DatabaseSchema> {
DatabaseSchema.class, DatabaseSchema.class,
dao.databaseSchemaDAO(), dao.databaseSchemaDAO(),
dao, dao,
DATABASE_SCHEMA_PATCH_FIELDS, "",
DATABASE_SCHEMA_UPDATE_FIELDS); "");
} }
@Override @Override

View File

@ -33,7 +33,7 @@ import org.openmetadata.service.util.FullyQualifiedName;
@Slf4j @Slf4j
public class DomainRepository extends EntityRepository<Domain> { 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) { public DomainRepository(CollectionDAO dao) {
super( super(

View File

@ -161,11 +161,12 @@ public abstract class EntityRepository<T extends EntityInterface> {
@Getter protected final String entityType; @Getter protected final String entityType;
@Getter protected final EntityDAO<T> dao; @Getter protected final EntityDAO<T> dao;
protected final CollectionDAO daoCollection; protected final CollectionDAO daoCollection;
@Getter protected final List<String> allowedFields; @Getter protected final Set<String> allowedFields;
public final boolean supportsSoftDelete; public final boolean supportsSoftDelete;
@Getter protected final boolean supportsTags; @Getter protected final boolean supportsTags;
@Getter protected final boolean supportsOwner; @Getter protected final boolean supportsOwner;
protected final boolean supportsFollower; protected final boolean supportsFollower;
protected final boolean supportsExtension;
protected final boolean supportsVotes; protected final boolean supportsVotes;
protected final boolean supportsDomain; protected final boolean supportsDomain;
protected final boolean supportsDataProducts; protected final boolean supportsDataProducts;
@ -189,16 +190,38 @@ public abstract class EntityRepository<T extends EntityInterface> {
allowedFields = getEntityFields(entityClass); allowedFields = getEntityFields(entityClass);
this.dao = entityDAO; this.dao = entityDAO;
this.daoCollection = collectionDAO; this.daoCollection = collectionDAO;
this.patchFields = getFields(patchFields);
this.putFields = getFields(putFields);
this.entityType = entityType; this.entityType = entityType;
this.patchFields = getFields(patchFields);
this.putFields = getFields(putFields);
this.supportsTags = allowedFields.contains(FIELD_TAGS); 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); 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.supportsSoftDelete = allowedFields.contains(FIELD_DELETED);
this.supportsFollower = allowedFields.contains(FIELD_FOLLOWERS); 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.supportsVotes = allowedFields.contains(FIELD_VOTES);
this.supportsDomain = allowedFields.contains(FIELD_DOMAIN); 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); this.supportsDataProducts = allowedFields.contains(FIELD_DATA_PRODUCTS);
} }
@ -712,7 +735,7 @@ public abstract class EntityRepository<T extends EntityInterface> {
false); false);
} }
setFieldsInternal(originalEntity, new EntityUtil.Fields(allowedFields, "votes")); setFieldsInternal(originalEntity, new Fields(allowedFields, "votes"));
ChangeEvent changeEvent = ChangeEvent changeEvent =
new ChangeEvent() new ChangeEvent()
.withEntity(originalEntity) .withEntity(originalEntity)
@ -1451,7 +1474,7 @@ public abstract class EntityRepository<T extends EntityInterface> {
return new Fields(allowedFields, fields); return new Fields(allowedFields, fields);
} }
protected final Fields getFields(List<String> fields) { protected final Fields getFields(Set<String> fields) {
return new Fields(allowedFields, fields); return new Fields(allowedFields, fields);
} }
@ -1465,8 +1488,8 @@ public abstract class EntityRepository<T extends EntityInterface> {
return result; return result;
} }
public final List<String> getAllowedFieldsCopy() { public final Set<String> getAllowedFieldsCopy() {
return new ArrayList<>(allowedFields); return new HashSet<>(allowedFields);
} }
protected String getCustomPropertyFQNPrefix(String entityType) { protected String getCustomPropertyFQNPrefix(String entityType) {
@ -1510,7 +1533,7 @@ public abstract class EntityRepository<T extends EntityInterface> {
return Entity.getEntityReferenceById(owner.getType(), owner.getId(), ALL); return Entity.getEntityReferenceById(owner.getType(), owner.getId(), ALL);
} }
public EntityReference validateDomain(String domainFqn) throws IOException { public EntityReference validateDomain(String domainFqn) {
if (!supportsDomain || domainFqn == null) { if (!supportsDomain || domainFqn == null) {
return null; return null;
} }

View File

@ -40,8 +40,8 @@ public class EventSubscriptionRepository extends EntityRepository<EventSubscript
private static final String INVALID_ALERT = "Invalid Alert Type"; private static final String INVALID_ALERT = "Invalid Alert Type";
private static final ConcurrentHashMap<UUID, SubscriptionPublisher> subscriptionPublisherMap = private static final ConcurrentHashMap<UUID, SubscriptionPublisher> subscriptionPublisherMap =
new ConcurrentHashMap<>(); new ConcurrentHashMap<>();
static final String ALERT_PATCH_FIELDS = "owner,trigger,enabled,batchSize,timeout"; static final String ALERT_PATCH_FIELDS = "trigger,enabled,batchSize,timeout";
static final String ALERT_UPDATE_FIELDS = "owner,trigger,enabled,batchSize,timeout,filteringRules"; static final String ALERT_UPDATE_FIELDS = "trigger,enabled,batchSize,timeout,filteringRules";
public EventSubscriptionRepository(CollectionDAO dao) { public EventSubscriptionRepository(CollectionDAO dao) {
super( super(

View File

@ -60,8 +60,8 @@ import org.openmetadata.service.util.FullyQualifiedName;
@Slf4j @Slf4j
public class GlossaryRepository extends EntityRepository<Glossary> { public class GlossaryRepository extends EntityRepository<Glossary> {
private static final String UPDATE_FIELDS = "owner,tags,reviewers"; private static final String UPDATE_FIELDS = "reviewers";
private static final String PATCH_FIELDS = "owner,tags,reviewers"; private static final String PATCH_FIELDS = "reviewers";
public GlossaryRepository(CollectionDAO dao) { public GlossaryRepository(CollectionDAO dao) {
super( super(

View File

@ -55,8 +55,8 @@ import org.openmetadata.service.util.FullyQualifiedName;
@Slf4j @Slf4j
public class GlossaryTermRepository extends EntityRepository<GlossaryTerm> { public class GlossaryTermRepository extends EntityRepository<GlossaryTerm> {
private static final String UPDATE_FIELDS = "tags,references,relatedTerms,reviewers,owner,synonyms"; private static final String UPDATE_FIELDS = "references,relatedTerms,reviewers,synonyms";
private static final String PATCH_FIELDS = "tags,references,relatedTerms,reviewers,owner,synonyms"; private static final String PATCH_FIELDS = "references,relatedTerms,reviewers,synonyms";
public GlossaryTermRepository(CollectionDAO dao) { public GlossaryTermRepository(CollectionDAO dao) {
super( super(

View File

@ -47,8 +47,8 @@ import org.openmetadata.service.util.RestUtil;
import org.openmetadata.service.util.ResultList; import org.openmetadata.service.util.ResultList;
public class IngestionPipelineRepository extends EntityRepository<IngestionPipeline> { public class IngestionPipelineRepository extends EntityRepository<IngestionPipeline> {
private static final String UPDATE_FIELDS = "owner,sourceConfig,airflowConfig,loggerLevel,enabled,deployed"; private static final String UPDATE_FIELDS = "sourceConfig,airflowConfig,loggerLevel,enabled,deployed";
private static final String PATCH_FIELDS = "owner,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_JSON_SCHEMA = "ingestionPipelineStatus";
private static final String PIPELINE_STATUS_EXTENSION = "ingestionPipeline.pipelineStatus"; private static final String PIPELINE_STATUS_EXTENSION = "ingestionPipeline.pipelineStatus";

View File

@ -37,9 +37,9 @@ import org.openmetadata.service.util.ResultList;
public class KpiRepository extends EntityRepository<Kpi> { public class KpiRepository extends EntityRepository<Kpi> {
private static final String KPI_RESULT_FIELD = "kpiResult"; private static final String KPI_RESULT_FIELD = "kpiResult";
public static final String COLLECTION_PATH = "/v1/kpi"; 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 = 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 static final String KPI_RESULT_EXTENSION = "kpi.kpiResult";
public KpiRepository(CollectionDAO dao) { public KpiRepository(CollectionDAO dao) {

View File

@ -27,17 +27,8 @@ import org.openmetadata.service.util.EntityUtil.Fields;
import org.openmetadata.service.util.FullyQualifiedName; import org.openmetadata.service.util.FullyQualifiedName;
public class MetricsRepository extends EntityRepository<Metrics> { public class MetricsRepository extends EntityRepository<Metrics> {
private static final String METRICS_UPDATE_FIELDS = "owner";
public MetricsRepository(CollectionDAO dao) { public MetricsRepository(CollectionDAO dao) {
super( super(MetricsResource.COLLECTION_PATH, Entity.METRICS, Metrics.class, dao.metricsDAO(), dao, "", "");
MetricsResource.COLLECTION_PATH,
Entity.METRICS,
Metrics.class,
dao.metricsDAO(),
dao,
"",
METRICS_UPDATE_FIELDS);
} }
@Override @Override

View File

@ -50,8 +50,8 @@ import org.openmetadata.service.util.JsonUtils;
@Slf4j @Slf4j
public class MlModelRepository extends EntityRepository<MlModel> { public class MlModelRepository extends EntityRepository<MlModel> {
private static final String MODEL_UPDATE_FIELDS = "owner,dashboard,tags,extension,followers"; private static final String MODEL_UPDATE_FIELDS = "dashboard";
private static final String MODEL_PATCH_FIELDS = "owner,dashboard,tags,extension,followers"; private static final String MODEL_PATCH_FIELDS = "dashboard";
public MlModelRepository(CollectionDAO dao) { public MlModelRepository(CollectionDAO dao) {
super( super(

View File

@ -49,8 +49,8 @@ import org.openmetadata.service.util.ResultList;
public class PipelineRepository extends EntityRepository<Pipeline> { public class PipelineRepository extends EntityRepository<Pipeline> {
private static final String TASKS_FIELD = "tasks"; private static final String TASKS_FIELD = "tasks";
private static final String PIPELINE_UPDATE_FIELDS = "owner,tags,tasks,extension,followers"; private static final String PIPELINE_UPDATE_FIELDS = "tasks";
private static final String PIPELINE_PATCH_FIELDS = "owner,tags,tasks,extension,followers"; private static final String PIPELINE_PATCH_FIELDS = "tasks";
public static final String PIPELINE_STATUS_EXTENSION = "pipeline.pipelineStatus"; public static final String PIPELINE_STATUS_EXTENSION = "pipeline.pipelineStatus";
public PipelineRepository(CollectionDAO dao) { public PipelineRepository(CollectionDAO dao) {

View File

@ -48,19 +48,10 @@ import org.openmetadata.service.util.EntityUtil.Fields;
@Slf4j @Slf4j
public class PolicyRepository extends EntityRepository<Policy> { 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 static final String ENABLED = "enabled";
public PolicyRepository(CollectionDAO dao) { public PolicyRepository(CollectionDAO dao) {
super( super(PolicyResource.COLLECTION_PATH, POLICY, Policy.class, dao.policyDAO(), dao, "", "");
PolicyResource.COLLECTION_PATH,
POLICY,
Policy.class,
dao.policyDAO(),
dao,
POLICY_PATCH_FIELDS,
POLICY_UPDATE_FIELDS);
} }
@Override @Override

View File

@ -26,8 +26,8 @@ import org.openmetadata.service.util.RestUtil;
public class QueryRepository extends EntityRepository<Query> { public class QueryRepository extends EntityRepository<Query> {
private static final String QUERY_USED_IN_FIELD = "queryUsedIn"; 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_PATCH_FIELDS = "users,query";
private static final String QUERY_UPDATE_FIELDS = "owner,tags,users,votes,followers"; private static final String QUERY_UPDATE_FIELDS = "users,votes";
public QueryRepository(CollectionDAO dao) { public QueryRepository(CollectionDAO dao) {
super( super(

View File

@ -25,10 +25,8 @@ import org.openmetadata.service.util.EntityUtil.Fields;
@Slf4j @Slf4j
public class ReportRepository extends EntityRepository<Report> { public class ReportRepository extends EntityRepository<Report> {
private static final String REPORT_UPDATE_FIELDS = "owner";
public ReportRepository(CollectionDAO dao) { 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 @Override

View File

@ -30,9 +30,6 @@ import org.openmetadata.service.util.JsonUtils;
public abstract class ServiceEntityRepository< public abstract class ServiceEntityRepository<
T extends ServiceEntityInterface, S extends ServiceConnectionEntityInterface> T extends ServiceEntityInterface, S extends ServiceConnectionEntityInterface>
extends EntityRepository<T> { 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 Class<S> serviceConnectionClass;
@Getter private final ServiceType serviceType; @Getter private final ServiceType serviceType;
@ -44,7 +41,7 @@ public abstract class ServiceEntityRepository<
EntityDAO<T> entityDAO, EntityDAO<T> entityDAO,
Class<S> serviceConnectionClass, Class<S> serviceConnectionClass,
ServiceType serviceType) { ServiceType serviceType) {
this(collectionPath, service, dao, entityDAO, serviceConnectionClass, UPDATE_FIELDS, serviceType); this(collectionPath, service, dao, entityDAO, serviceConnectionClass, "", serviceType);
} }
protected ServiceEntityRepository( protected ServiceEntityRepository(
@ -55,7 +52,7 @@ public abstract class ServiceEntityRepository<
Class<S> serviceConnectionClass, Class<S> serviceConnectionClass,
String updatedFields, String updatedFields,
ServiceType serviceType) { ServiceType serviceType) {
super(collectionPath, service, entityDAO.getEntityClass(), entityDAO, dao, PATCH_FIELDS, updatedFields); super(collectionPath, service, entityDAO.getEntityClass(), entityDAO, dao, "", updatedFields);
this.serviceConnectionClass = serviceConnectionClass; this.serviceConnectionClass = serviceConnectionClass;
this.serviceType = serviceType; this.serviceType = serviceType;
} }

View File

@ -37,6 +37,7 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Optional; import java.util.Optional;
import java.util.Set;
import java.util.UUID; import java.util.UUID;
import java.util.function.Predicate; import java.util.function.Predicate;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -90,9 +91,9 @@ import org.openmetadata.service.util.ResultList;
public class TableRepository extends EntityRepository<Table> { public class TableRepository extends EntityRepository<Table> {
// Table fields that can be patched in a PATCH request // 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 // 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_COLUMN_TYPE = "table.columns.column";
public static final String FIELD_RELATION_TABLE_TYPE = "table"; public static final String FIELD_RELATION_TABLE_TYPE = "table";
@ -589,8 +590,8 @@ public class TableRepository extends EntityRepository<Table> {
} }
applyTags(table.getColumns()); applyTags(table.getColumns());
dao.update(table.getId(), FullyQualifiedName.buildHash(table.getFullyQualifiedName()), JsonUtils.pojoToJson(table)); 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(Set.of(FIELD_OWNER), FIELD_OWNER));
setFieldsInternal(table, new Fields(List.of(FIELD_TAGS), FIELD_TAGS)); setFieldsInternal(table, new Fields(Set.of(FIELD_TAGS), FIELD_TAGS));
return table; return table;
} }

View File

@ -80,8 +80,8 @@ import org.openmetadata.service.util.ResultList;
@Slf4j @Slf4j
public class TeamRepository extends EntityRepository<Team> { public class TeamRepository extends EntityRepository<Team> {
static final String PARENTS_FIELD = "parents"; 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_UPDATE_FIELDS = "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_PATCH_FIELDS = "profile,users,defaultRoles,parents,children,policies,teamType,email";
private static final String DEFAULT_ROLES = "defaultRoles"; private static final String DEFAULT_ROLES = "defaultRoles";
private Team organization = null; private Team organization = null;

View File

@ -49,8 +49,8 @@ public class TestCaseRepository extends EntityRepository<TestCase> {
private static final String TEST_SUITE_FIELD = "testSuite"; private static final String TEST_SUITE_FIELD = "testSuite";
private static final String TEST_CASE_RESULT_FIELD = "testCaseResult"; private static final String TEST_CASE_RESULT_FIELD = "testCaseResult";
public static final String COLLECTION_PATH = "/v1/dataQuality/testCases"; public static final String COLLECTION_PATH = "/v1/dataQuality/testCases";
private static final String UPDATE_FIELDS = "owner,entityLink,testSuite,testDefinition"; private static final String UPDATE_FIELDS = "entityLink,testSuite,testDefinition";
private static final String PATCH_FIELDS = "owner,entityLink,testSuite,testDefinition"; private static final String PATCH_FIELDS = "entityLink,testSuite,testDefinition";
public static final String TESTCASE_RESULT_EXTENSION = "testCase.testCaseResult"; public static final String TESTCASE_RESULT_EXTENSION = "testCase.testCaseResult";
public TestCaseRepository(CollectionDAO dao) { public TestCaseRepository(CollectionDAO dao) {

View File

@ -10,9 +10,6 @@ import org.openmetadata.service.resources.dqtests.TestDefinitionResource;
import org.openmetadata.service.util.EntityUtil; import org.openmetadata.service.util.EntityUtil;
public class TestDefinitionRepository extends EntityRepository<TestDefinition> { public class TestDefinitionRepository extends EntityRepository<TestDefinition> {
private static final String UPDATE_FIELDS = "owner";
private static final String PATCH_FIELDS = "owner";
public TestDefinitionRepository(CollectionDAO dao) { public TestDefinitionRepository(CollectionDAO dao) {
super( super(
TestDefinitionResource.COLLECTION_PATH, TestDefinitionResource.COLLECTION_PATH,
@ -20,8 +17,8 @@ public class TestDefinitionRepository extends EntityRepository<TestDefinition> {
TestDefinition.class, TestDefinition.class,
dao.testDefinitionDAO(), dao.testDefinitionDAO(),
dao, dao,
PATCH_FIELDS, "",
UPDATE_FIELDS); "");
} }
@Override @Override

View File

@ -23,8 +23,8 @@ import org.openmetadata.service.util.RestUtil;
@Slf4j @Slf4j
public class TestSuiteRepository extends EntityRepository<TestSuite> { public class TestSuiteRepository extends EntityRepository<TestSuite> {
private static final String UPDATE_FIELDS = "owner,tests"; private static final String UPDATE_FIELDS = "tests";
private static final String PATCH_FIELDS = "owner,tests"; private static final String PATCH_FIELDS = "tests";
public TestSuiteRepository(CollectionDAO dao) { public TestSuiteRepository(CollectionDAO dao) {
super( super(

View File

@ -56,9 +56,6 @@ import org.openmetadata.service.util.FullyQualifiedName;
import org.openmetadata.service.util.JsonUtils; import org.openmetadata.service.util.JsonUtils;
public class TopicRepository extends EntityRepository<Topic> { 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 @Override
public void setFullyQualifiedName(Topic topic) { public void setFullyQualifiedName(Topic topic) {
topic.setFullyQualifiedName(FullyQualifiedName.add(topic.getService().getFullyQualifiedName(), topic.getName())); topic.setFullyQualifiedName(FullyQualifiedName.add(topic.getService().getFullyQualifiedName(), topic.getName()));
@ -73,14 +70,7 @@ public class TopicRepository extends EntityRepository<Topic> {
} }
public TopicRepository(CollectionDAO dao) { public TopicRepository(CollectionDAO dao) {
super( super(TopicResource.COLLECTION_PATH, Entity.TOPIC, Topic.class, dao.topicDAO(), dao, "", "");
TopicResource.COLLECTION_PATH,
Entity.TOPIC,
Topic.class,
dao.topicDAO(),
dao,
TOPIC_PATCH_FIELDS,
TOPIC_UPDATE_FIELDS);
} }
@Override @Override
@ -291,7 +281,7 @@ public class TopicRepository extends EntityRepository<Topic> {
break; break;
} }
} }
if (childrenSchemaName != "" && schemaField != null) { if (!"".equals(childrenSchemaName) && schemaField != null) {
schemaField = getchildrenSchemaField(schemaField.getChildren(), childrenSchemaName); schemaField = getchildrenSchemaField(schemaField.getChildren(), childrenSchemaName);
} }
if (schemaField == null) { if (schemaField == null) {
@ -323,9 +313,9 @@ public class TopicRepository extends EntityRepository<Topic> {
} }
} }
if (childrenSchemaField == null) { if (childrenSchemaField == null) {
for (int i = 0; i < fields.size(); i++) { for (Field field : fields) {
if (fields.get(i).getChildren() != null) { if (field.getChildren() != null) {
childrenSchemaField = getchildrenSchemaField(fields.get(i).getChildren(), childrenSchemaName); childrenSchemaField = getchildrenSchemaField(field.getChildren(), childrenSchemaName);
if (childrenSchemaField != null) { if (childrenSchemaField != null) {
break; break;
} }

View File

@ -75,7 +75,7 @@ public class UserRepository extends EntityRepository<User> {
} }
public final Fields getFieldsWithUserAuth(String fields) { public final Fields getFieldsWithUserAuth(String fields) {
List<String> tempFields = getAllowedFieldsCopy(); Set<String> tempFields = getAllowedFieldsCopy();
if (fields != null && fields.equals("*")) { if (fields != null && fields.equals("*")) {
tempFields.add(AUTH_MECHANISM_FIELD); tempFields.add(AUTH_MECHANISM_FIELD);
return new Fields(tempFields); return new Fields(tempFields);

View File

@ -16,19 +16,10 @@ import org.openmetadata.service.util.ResultList;
public class WebAnalyticEventRepository extends EntityRepository<WebAnalyticEvent> { public class WebAnalyticEventRepository extends EntityRepository<WebAnalyticEvent> {
public static final String COLLECTION_PATH = "/v1/analytics/web/events"; 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"; private static final String WEB_ANALYTICS_EVENT_DATA_EXTENSION = "webAnalyticEvent.webAnalyticEventData";
public WebAnalyticEventRepository(CollectionDAO dao) { public WebAnalyticEventRepository(CollectionDAO dao) {
super( super(COLLECTION_PATH, WEB_ANALYTIC_EVENT, WebAnalyticEvent.class, dao.webAnalyticEventDAO(), dao, "", "");
COLLECTION_PATH,
WEB_ANALYTIC_EVENT,
WebAnalyticEvent.class,
dao.webAnalyticEventDAO(),
dao,
PATCH_FIELDS,
UPDATE_FIELDS);
} }
@Override @Override

View File

@ -13,18 +13,10 @@ import org.openmetadata.service.secrets.SecretsManagerFactory;
import org.openmetadata.service.util.EntityUtil; import org.openmetadata.service.util.EntityUtil;
public class WorkflowRepository extends EntityRepository<Workflow> { public class WorkflowRepository extends EntityRepository<Workflow> {
private static final String UPDATE_FIELDS = "owner"; private static final String PATCH_FIELDS = "status,response";
private static final String PATCH_FIELDS = "owner,status,response";
public WorkflowRepository(CollectionDAO dao) { public WorkflowRepository(CollectionDAO dao) {
super( super(WorkflowResource.COLLECTION_PATH, WORKFLOW, Workflow.class, dao.workflowDAO(), dao, PATCH_FIELDS, "");
WorkflowResource.COLLECTION_PATH,
WORKFLOW,
Workflow.class,
dao.workflowDAO(),
dao,
PATCH_FIELDS,
UPDATE_FIELDS);
} }
@Override @Override

View File

@ -76,6 +76,7 @@ import org.openmetadata.service.migration.api.MigrationStep;
import org.openmetadata.service.resources.databases.DatasourceConfig; import org.openmetadata.service.resources.databases.DatasourceConfig;
import org.openmetadata.service.resources.feeds.MessageParser; import org.openmetadata.service.resources.feeds.MessageParser;
import org.openmetadata.service.util.EntityUtil; import org.openmetadata.service.util.EntityUtil;
import org.openmetadata.service.util.EntityUtil.Fields;
import org.openmetadata.service.util.FullyQualifiedName; import org.openmetadata.service.util.FullyQualifiedName;
import org.openmetadata.service.util.JsonUtils; import org.openmetadata.service.util.JsonUtils;
@ -136,7 +137,7 @@ public class MigrationUtil {
for (String json : jsons) { for (String json : jsons) {
// Update the Statements to Database // Update the Statements to Database
T entity = JsonUtils.readValue(json, clazz); T entity = JsonUtils.readValue(json, clazz);
String hash = ""; String hash;
try { try {
hash = hash =
withName withName
@ -407,8 +408,7 @@ public class MigrationUtil {
IngestionPipelineRepository ingestionPipelineRepository = new IngestionPipelineRepository(collectionDAO); IngestionPipelineRepository ingestionPipelineRepository = new IngestionPipelineRepository(collectionDAO);
TestSuiteRepository testSuiteRepository = new TestSuiteRepository(collectionDAO); TestSuiteRepository testSuiteRepository = new TestSuiteRepository(collectionDAO);
TestCaseRepository testCaseRepository = new TestCaseRepository(collectionDAO); TestCaseRepository testCaseRepository = new TestCaseRepository(collectionDAO);
List<TestCase> testCases = List<TestCase> testCases = testCaseRepository.listAll(new Fields(Set.of("id")), new ListFilter(Include.ALL));
testCaseRepository.listAll(new EntityUtil.Fields(List.of("id")), new ListFilter(Include.ALL));
for (TestCase test : testCases) { for (TestCase test : testCases) {
@ -422,14 +422,14 @@ public class MigrationUtil {
testSuiteRepository.getByName( testSuiteRepository.getByName(
null, null,
EntityInterfaceUtil.quoteName(FullyQualifiedName.buildHash(testSuiteFqn)), EntityInterfaceUtil.quoteName(FullyQualifiedName.buildHash(testSuiteFqn)),
new EntityUtil.Fields(List.of("id")), new Fields(Set.of("id")),
Include.ALL); Include.ALL);
} catch (EntityNotFoundException entityNotFoundException) { } catch (EntityNotFoundException entityNotFoundException) {
try { try {
// Check if the test Suite Exists, this brings the data on nameHash basis // Check if the test Suite Exists, this brings the data on nameHash basis
stored = stored =
testSuiteRepository.getByName( 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( testSuiteRepository.addRelationship(
stored.getId(), test.getId(), TEST_SUITE, TEST_CASE, Relationship.CONTAINS); stored.getId(), test.getId(), TEST_SUITE, TEST_CASE, Relationship.CONTAINS);
stored.setExecutable(true); stored.setExecutable(true);
@ -477,7 +477,7 @@ public class MigrationUtil {
// Update Test Suites // Update Test Suites
ListFilter filter = new ListFilter(Include.ALL); ListFilter filter = new ListFilter(Include.ALL);
filter.addQueryParam("testSuiteType", "logical"); 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) { for (TestSuite testSuiteRecord : testSuites) {
TestSuite temp = testSuiteRepository.getDao().findEntityById(testSuiteRecord.getId()); TestSuite temp = testSuiteRepository.getDao().findEntityById(testSuiteRecord.getId());

View File

@ -49,7 +49,7 @@ import org.openmetadata.service.util.ResultList;
public abstract class EntityResource<T extends EntityInterface, K extends EntityRepository<T>> { public abstract class EntityResource<T extends EntityInterface, K extends EntityRepository<T>> {
protected final Class<T> entityClass; protected final Class<T> entityClass;
protected final String entityType; protected final String entityType;
protected final List<String> allowedFields; protected final Set<String> allowedFields;
@Getter protected final K repository; @Getter protected final K repository;
protected final Authorizer authorizer; protected final Authorizer authorizer;
protected final Map<String, MetadataOperation> fieldsToViewOperations = new HashMap<>(); protected final Map<String, MetadataOperation> fieldsToViewOperations = new HashMap<>();

View File

@ -45,6 +45,7 @@ import java.time.ZoneId;
import java.util.Base64; import java.util.Base64;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Set;
import java.util.UUID; import java.util.UUID;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import javax.json.JsonObject; 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) @Parameter(description = "Id of the user", schema = @Schema(type = "UUID")) @PathParam("id") UUID id)
throws IOException { 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())) { if (!Boolean.TRUE.equals(user.getIsBot())) {
throw new IllegalArgumentException("JWT token is only supported for bot users"); 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) @Parameter(description = "Id of the user", schema = @Schema(type = "UUID")) @PathParam("id") UUID id)
throws IOException { 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())) { if (!Boolean.TRUE.equals(user.getIsBot())) {
throw new IllegalArgumentException("JWT token is only supported for bot users"); throw new IllegalArgumentException("JWT token is only supported for bot users");
} }
@ -898,7 +899,7 @@ public class UserResource extends EntityResource<User, UserRepository> {
User registeredUser; User registeredUser;
try { try {
registeredUser = 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) { } catch (IOException | EntityNotFoundException ex) {
LOG.error( LOG.error(
"[GeneratePasswordReset] Got Error while fetching user : {}, error message {}", userName, ex.getMessage()); "[GeneratePasswordReset] Got Error while fetching user : {}, error message {}", userName, ex.getMessage());

View File

@ -18,6 +18,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.Optional; import java.util.Optional;
import java.util.Set;
import java.util.function.Function; import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import lombok.extern.slf4j.Slf4j; 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.CollectionRegistry.CollectionDetails;
import org.openmetadata.service.resources.services.ServiceEntityResource; import org.openmetadata.service.resources.services.ServiceEntityResource;
import org.openmetadata.service.util.EntityUtil; import org.openmetadata.service.util.EntityUtil;
import org.openmetadata.service.util.EntityUtil.Fields;
/** /**
* Update service using the configured secret manager. * Update service using the configured secret manager.
@ -198,7 +200,7 @@ public class SecretsManagerUpdateService {
return userRepository return userRepository
.listAfter( .listAfter(
null, null,
new EntityUtil.Fields(List.of("authenticationMechanism")), new Fields(Set.of("authenticationMechanism")),
new ListFilter(), new ListFilter(),
userRepository.getDao().listCount(new ListFilter()), userRepository.getDao().listCount(new ListFilter()),
null) null)

View File

@ -37,7 +37,6 @@ import java.io.IOException;
import java.time.Instant; import java.time.Instant;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
@ -208,7 +207,7 @@ public class BasicAuthenticator implements AuthenticatorHandler {
public void resetUserPasswordWithToken(UriInfo uriInfo, PasswordResetRequest request) throws IOException { public void resetUserPasswordWithToken(UriInfo uriInfo, PasswordResetRequest request) throws IOException {
String tokenID = request.getToken(); String tokenID = request.getToken();
PasswordResetToken passwordResetToken = (PasswordResetToken) tokenRepository.findByToken(tokenID); PasswordResetToken passwordResetToken = (PasswordResetToken) tokenRepository.findByToken(tokenID);
List<String> fields = userRepository.getAllowedFieldsCopy(); Set<String> fields = userRepository.getAllowedFieldsCopy();
fields.add(USER_PROTECTED_FIELDS); fields.add(USER_PROTECTED_FIELDS);
User storedUser = User storedUser =
userRepository.getByName( userRepository.getByName(
@ -471,17 +470,17 @@ public class BasicAuthenticator implements AuthenticatorHandler {
@Override @Override
public User lookUserInProvider(String userName) { public User lookUserInProvider(String userName) {
User storedUser = null; User storedUser;
try { try {
if (userName.contains("@")) { if (userName.contains("@")) {
// lookup by User Email // lookup by User Email
storedUser = storedUser =
userRepository.getByEmail( 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 { } else {
storedUser = storedUser =
userRepository.getByName( 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())) { if (storedUser != null && Boolean.TRUE.equals(storedUser.getIsBot())) {

View File

@ -7,7 +7,7 @@ import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache; import com.google.common.cache.LoadingCache;
import com.google.common.util.concurrent.UncheckedExecutionException; import com.google.common.util.concurrent.UncheckedExecutionException;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.Set;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import javax.annotation.CheckForNull; import javax.annotation.CheckForNull;
@ -18,7 +18,7 @@ import org.openmetadata.schema.entity.teams.User;
import org.openmetadata.service.Entity; import org.openmetadata.service.Entity;
import org.openmetadata.service.jdbi3.UserRepository; import org.openmetadata.service.jdbi3.UserRepository;
import org.openmetadata.service.resources.teams.UserResource; 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; import org.openmetadata.service.util.JsonUtils;
@Slf4j @Slf4j
@ -59,8 +59,7 @@ public class BotTokenCache {
public String load(@CheckForNull String botName) throws IOException { public String load(@CheckForNull String botName) throws IOException {
UserRepository userRepository = (UserRepository) Entity.getEntityRepository(Entity.USER); UserRepository userRepository = (UserRepository) Entity.getEntityRepository(Entity.USER);
User user = User user =
userRepository.getByName( userRepository.getByName(null, botName, new Fields(Set.of(UserResource.USER_PROTECTED_FIELDS)), NON_DELETED);
null, botName, new EntityUtil.Fields(List.of(UserResource.USER_PROTECTED_FIELDS)), NON_DELETED);
AuthenticationMechanism authenticationMechanism = user.getAuthenticationMechanism(); AuthenticationMechanism authenticationMechanism = user.getAuthenticationMechanism();
if (authenticationMechanism != null) { if (authenticationMechanism != null) {
JWTAuthMechanism jwtAuthMechanism = JWTAuthMechanism jwtAuthMechanism =

View File

@ -23,7 +23,7 @@ import org.openmetadata.service.jdbi3.CollectionDAO;
import org.openmetadata.service.jdbi3.TokenRepository; import org.openmetadata.service.jdbi3.TokenRepository;
import org.openmetadata.service.jdbi3.UserRepository; import org.openmetadata.service.jdbi3.UserRepository;
import org.openmetadata.service.resources.teams.UserResource; import org.openmetadata.service.resources.teams.UserResource;
import org.openmetadata.service.util.EntityUtil; import org.openmetadata.service.util.EntityUtil.Fields;
@Slf4j @Slf4j
public class UserTokenCache { public class UserTokenCache {
@ -74,8 +74,7 @@ public class UserTokenCache {
HashSet<String> result = new HashSet<>(); HashSet<String> result = new HashSet<>();
UserRepository userRepository = (UserRepository) Entity.getEntityRepository(Entity.USER); UserRepository userRepository = (UserRepository) Entity.getEntityRepository(Entity.USER);
User user = User user =
userRepository.getByName( userRepository.getByName(null, userName, new Fields(Set.of(UserResource.USER_PROTECTED_FIELDS)), NON_DELETED);
null, userName, new EntityUtil.Fields(List.of(UserResource.USER_PROTECTED_FIELDS)), NON_DELETED);
List<TokenInterface> tokens = List<TokenInterface> tokens =
tokenRepository.findByUserIdAndType(user.getId().toString(), TokenType.PERSONAL_ACCESS_TOKEN.value()); tokenRepository.findByUserIdAndType(user.getId().toString(), TokenType.PERSONAL_ACCESS_TOKEN.value());
tokens.forEach(t -> result.add(((PersonalAccessToken) t).getJwtToken())); tokens.forEach(t -> result.add(((PersonalAccessToken) t).getJwtToken()));

View File

@ -24,7 +24,9 @@ import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set;
import java.util.UUID; import java.util.UUID;
import java.util.function.BiPredicate; import java.util.function.BiPredicate;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@ -188,7 +190,7 @@ public final class EntityUtil {
return populateEntityReferences(refs); return populateEntityReferences(refs);
} }
public static EntityReference validateEntityLink(EntityLink entityLink) throws IOException { public static EntityReference validateEntityLink(EntityLink entityLink) {
String entityType = entityLink.getEntityType(); String entityType = entityLink.getEntityType();
String fqn = entityLink.getEntityFQN(); String fqn = entityLink.getEntityFQN();
return Entity.getEntityReferenceByName(entityType, fqn, ALL); return Entity.getEntityReferenceByName(entityType, fqn, ALL);
@ -293,19 +295,19 @@ public final class EntityUtil {
} }
public static class Fields { public static class Fields {
public static final Fields EMPTY_FIELDS = new Fields(Collections.emptyList()); public static final Fields EMPTY_FIELDS = new Fields(Collections.emptySet());
@Getter private final List<String> fieldList; @Getter private final Set<String> fieldList;
public Fields(List<String> fieldList) { public Fields(Set<String> fieldList) {
this.fieldList = fieldList; this.fieldList = fieldList;
} }
public Fields(List<String> allowedFields, String fieldsParam) { public Fields(Set<String> allowedFields, String fieldsParam) {
if (nullOrEmpty(fieldsParam)) { if (nullOrEmpty(fieldsParam)) {
fieldList = new ArrayList<>(); fieldList = new HashSet<>();
return; return;
} }
fieldList = Arrays.asList(fieldsParam.replace(" ", "").split(",")); fieldList = new HashSet<>(Arrays.asList(fieldsParam.replace(" ", "").split(",")));
for (String field : fieldList) { for (String field : fieldList) {
if (!allowedFields.contains(field)) { if (!allowedFields.contains(field)) {
throw new IllegalArgumentException(CatalogExceptionMessage.invalidField(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)) { if (CommonUtil.nullOrEmpty(fieldsParam)) {
fieldList = new ArrayList<>(); fieldList = new HashSet<>();
return; return;
} }
for (String field : fieldsParam) { for (String field : fieldsParam) {
@ -323,7 +325,14 @@ public final class EntityUtil {
throw new IllegalArgumentException(CatalogExceptionMessage.invalidField(field)); 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 @Override

View File

@ -14,7 +14,7 @@
package org.openmetadata.service.util; package org.openmetadata.service.util;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.Set;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.openmetadata.schema.api.configuration.pipelineServiceClient.PipelineServiceClientConfiguration; import org.openmetadata.schema.api.configuration.pipelineServiceClient.PipelineServiceClientConfiguration;
import org.openmetadata.schema.auth.JWTAuthMechanism; import org.openmetadata.schema.auth.JWTAuthMechanism;
@ -160,7 +160,7 @@ public class OpenMetadataConnectionBuilder {
userRepository.getByName( userRepository.getByName(
null, null,
bot1.getBotUser().getFullyQualifiedName(), bot1.getBotUser().getFullyQualifiedName(),
new EntityUtil.Fields(List.of("authenticationMechanism"))); new EntityUtil.Fields(Set.of("authenticationMechanism")));
if (user.getAuthenticationMechanism() != null) { if (user.getAuthenticationMechanism() != null) {
user.getAuthenticationMechanism().setConfig(user.getAuthenticationMechanism().getConfig()); user.getAuthenticationMechanism().setConfig(user.getAuthenticationMechanism().getConfig());
} }

View File

@ -26,7 +26,7 @@ import static org.openmetadata.service.Entity.ADMIN_USER_NAME;
import at.favre.lib.crypto.bcrypt.BCrypt; import at.favre.lib.crypto.bcrypt.BCrypt;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.Set; import java.util.Set;
@ -49,6 +49,7 @@ import org.openmetadata.service.jdbi3.EntityRepository;
import org.openmetadata.service.jdbi3.UserRepository; import org.openmetadata.service.jdbi3.UserRepository;
import org.openmetadata.service.resources.teams.RoleResource; import org.openmetadata.service.resources.teams.RoleResource;
import org.openmetadata.service.security.jwt.JWTTokenGenerator; import org.openmetadata.service.security.jwt.JWTTokenGenerator;
import org.openmetadata.service.util.EntityUtil.Fields;
@Slf4j @Slf4j
public final class UserUtil { public final class UserUtil {
@ -72,11 +73,11 @@ public final class UserUtil {
User updatedUser; User updatedUser;
try { try {
// Create Required Fields List // Create Required Fields List
List<String> fieldList = new ArrayList<>(userRepository.getPatchFields().getFieldList()); Set<String> fieldList = new HashSet<>(userRepository.getPatchFields().getFieldList());
fieldList.add("authenticationMechanism"); fieldList.add("authenticationMechanism");
// Fetch Original User, is available // 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; updatedUser = originalUser;
// Update Auth Mechanism if not present, and send mail to the user // 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) { private static User retrieveWithAuthMechanism(User user) {
EntityRepository<User> userRepository = (UserRepository) Entity.getEntityRepository(Entity.USER); EntityRepository<User> userRepository = (UserRepository) Entity.getEntityRepository(Entity.USER);
try { 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) { } catch (IOException | EntityNotFoundException e) {
LOG.debug("Bot entity: {} does not exists.", user); LOG.debug("Bot entity: {} does not exists.", user);
return null; return null;

View File

@ -82,6 +82,7 @@ import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Optional; import java.util.Optional;
import java.util.Random; import java.util.Random;
import java.util.Set;
import java.util.UUID; import java.util.UUID;
import java.util.function.BiConsumer; import java.util.function.BiConsumer;
import java.util.function.Predicate; import java.util.function.Predicate;
@ -380,7 +381,7 @@ public abstract class EntityResourceTest<T extends EntityInterface, K extends Cr
this.collectionName = collectionName; this.collectionName = collectionName;
this.allFields = fields; this.allFields = fields;
ENTITY_RESOURCE_TEST_MAP.put(entityType, this); 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.supportsFollowers = allowedFields.contains(FIELD_FOLLOWERS);
this.supportsOwner = allowedFields.contains(FIELD_OWNER); this.supportsOwner = allowedFields.contains(FIELD_OWNER);
this.supportsTags = allowedFields.contains(FIELD_TAGS); this.supportsTags = allowedFields.contains(FIELD_TAGS);

View File

@ -74,6 +74,7 @@ import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set;
import java.util.TimeZone; import java.util.TimeZone;
import java.util.UUID; import java.util.UUID;
import java.util.function.Predicate; import java.util.function.Predicate;
@ -166,7 +167,7 @@ public class UserResourceTest extends EntityResourceTest<User, CreateUser> {
USER_TEAM21 = createEntity(create, ADMIN_AUTH_HEADERS); USER_TEAM21 = createEntity(create, ADMIN_AUTH_HEADERS);
USER2_REF = USER2.getEntityReference(); USER2_REF = USER2.getEntityReference();
List<String> userFields = Entity.getEntityFields(User.class); Set<String> userFields = Entity.getEntityFields(User.class);
userFields.remove("authenticationMechanism"); userFields.remove("authenticationMechanism");
BOT_USER = getEntityByName(INGESTION_BOT, String.join(",", userFields), ADMIN_AUTH_HEADERS); BOT_USER = getEntityByName(INGESTION_BOT, String.join(",", userFields), ADMIN_AUTH_HEADERS);
} }
@ -1243,7 +1244,7 @@ public class UserResourceTest extends EntityResourceTest<User, CreateUser> {
@Override @Override
public String getAllowedFields() { public String getAllowedFields() {
List<String> allowedFields = Entity.getEntityFields(entityClass); Set<String> allowedFields = Entity.getEntityFields(entityClass);
allowedFields.removeAll(of(USER_PROTECTED_FIELDS.split(","))); allowedFields.removeAll(of(USER_PROTECTED_FIELDS.split(",")));
return String.join(",", allowedFields); return String.join(",", allowedFields);
} }