mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2026-01-06 04:26:57 +00:00
Fix some of the sonar cloud flagged issues (#4175)
This commit is contained in:
parent
158e8a82ed
commit
a07d08871b
@ -153,7 +153,6 @@ public class CatalogApplication extends Application<CatalogApplicationConfig> {
|
||||
return configuration.getHealthConfiguration();
|
||||
}
|
||||
});
|
||||
// bootstrap.addBundle(new CatalogJdbiExceptionsBundle());
|
||||
super.initialize(bootstrap);
|
||||
}
|
||||
|
||||
@ -180,7 +179,7 @@ public class CatalogApplication extends Application<CatalogApplicationConfig> {
|
||||
|
||||
private void registerAuthorizer(CatalogApplicationConfig catalogConfig, Environment environment)
|
||||
throws NoSuchMethodException, ClassNotFoundException, IllegalAccessException, InvocationTargetException,
|
||||
InstantiationException, IOException {
|
||||
InstantiationException {
|
||||
AuthorizerConfiguration authorizerConf = catalogConfig.getAuthorizerConfiguration();
|
||||
AuthenticationConfiguration authenticationConfiguration = catalogConfig.getAuthenticationConfiguration();
|
||||
if (authorizerConf != null) {
|
||||
|
||||
@ -58,6 +58,10 @@ public final class Entity {
|
||||
// Common field names
|
||||
public static final String FIELD_OWNER = "owner";
|
||||
public static final String FIELD_DESCRIPTION = "description";
|
||||
public static final String FIELD_SERVICE = "service";
|
||||
public static final String FIELD_FOLLOWERS = "followers";
|
||||
public static final String FIELD_TAGS = "tags";
|
||||
public static final String FIELD_DELETED = "deleted";
|
||||
|
||||
//
|
||||
// Services
|
||||
|
||||
@ -15,6 +15,8 @@
|
||||
|
||||
package org.openmetadata.catalog.elasticsearch;
|
||||
|
||||
import static org.openmetadata.catalog.Entity.FIELD_FOLLOWERS;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
@ -162,7 +164,7 @@ public class ElasticSearchEventPublisher extends AbstractEventPublisher {
|
||||
fieldAddParams.put("last_updated_timestamp", event.getTimestamp());
|
||||
scriptTxt.append("ctx._source.last_updated_timestamp=params.last_updated_timestamp;");
|
||||
for (FieldChange fieldChange : fieldsAdded) {
|
||||
if (fieldChange.getName().equalsIgnoreCase("followers")) {
|
||||
if (fieldChange.getName().equalsIgnoreCase(FIELD_FOLLOWERS)) {
|
||||
@SuppressWarnings("unchecked")
|
||||
List<EntityReference> entityReferences = (List<EntityReference>) fieldChange.getNewValue();
|
||||
List<String> newFollowers = new ArrayList<>();
|
||||
@ -175,7 +177,7 @@ public class ElasticSearchEventPublisher extends AbstractEventPublisher {
|
||||
}
|
||||
|
||||
for (FieldChange fieldChange : changeDescription.getFieldsDeleted()) {
|
||||
if (fieldChange.getName().equalsIgnoreCase("followers")) {
|
||||
if (fieldChange.getName().equalsIgnoreCase(FIELD_FOLLOWERS)) {
|
||||
@SuppressWarnings("unchecked")
|
||||
List<EntityReference> entityReferences = (List<EntityReference>) fieldChange.getOldValue();
|
||||
for (EntityReference follower : entityReferences) {
|
||||
@ -451,7 +453,7 @@ public class ElasticSearchEventPublisher extends AbstractEventPublisher {
|
||||
if (event.getEventType() == EventType.ENTITY_DELETED) {
|
||||
DatabaseService databaseService = (DatabaseService) event.getEntity();
|
||||
DeleteByQueryRequest request = new DeleteByQueryRequest(ElasticSearchIndexType.TABLE_SEARCH_INDEX.indexName);
|
||||
request.setQuery(new TermQueryBuilder("service", databaseService.getName()));
|
||||
request.setQuery(new TermQueryBuilder(Entity.FIELD_SERVICE, databaseService.getName()));
|
||||
deleteEntityFromElasticSearchByQuery(request);
|
||||
}
|
||||
}
|
||||
@ -460,7 +462,7 @@ public class ElasticSearchEventPublisher extends AbstractEventPublisher {
|
||||
if (event.getEventType() == EventType.ENTITY_DELETED) {
|
||||
PipelineService pipelineService = (PipelineService) event.getEntity();
|
||||
DeleteByQueryRequest request = new DeleteByQueryRequest(ElasticSearchIndexType.PIPELINE_SEARCH_INDEX.indexName);
|
||||
request.setQuery(new TermQueryBuilder("service", pipelineService.getName()));
|
||||
request.setQuery(new TermQueryBuilder(Entity.FIELD_SERVICE, pipelineService.getName()));
|
||||
deleteEntityFromElasticSearchByQuery(request);
|
||||
}
|
||||
}
|
||||
@ -469,7 +471,7 @@ public class ElasticSearchEventPublisher extends AbstractEventPublisher {
|
||||
if (event.getEventType() == EventType.ENTITY_DELETED) {
|
||||
MessagingService messagingService = (MessagingService) event.getEntity();
|
||||
DeleteByQueryRequest request = new DeleteByQueryRequest(ElasticSearchIndexType.TOPIC_SEARCH_INDEX.indexName);
|
||||
request.setQuery(new TermQueryBuilder("service", messagingService.getName()));
|
||||
request.setQuery(new TermQueryBuilder(Entity.FIELD_SERVICE, messagingService.getName()));
|
||||
deleteEntityFromElasticSearchByQuery(request);
|
||||
}
|
||||
}
|
||||
@ -478,7 +480,7 @@ public class ElasticSearchEventPublisher extends AbstractEventPublisher {
|
||||
if (event.getEventType() == EventType.ENTITY_DELETED) {
|
||||
DashboardService dashboardService = (DashboardService) event.getEntity();
|
||||
DeleteByQueryRequest request = new DeleteByQueryRequest(ElasticSearchIndexType.DASHBOARD_SEARCH_INDEX.indexName);
|
||||
request.setQuery(new TermQueryBuilder("service", dashboardService.getName()));
|
||||
request.setQuery(new TermQueryBuilder(Entity.FIELD_SERVICE, dashboardService.getName()));
|
||||
deleteEntityFromElasticSearchByQuery(request);
|
||||
}
|
||||
}
|
||||
|
||||
@ -40,6 +40,7 @@ import org.openmetadata.catalog.util.ChangeEventParser;
|
||||
import org.openmetadata.catalog.util.EntityInterface;
|
||||
import org.openmetadata.catalog.util.JsonUtils;
|
||||
import org.openmetadata.catalog.util.RestUtil;
|
||||
import org.openmetadata.common.utils.CommonUtil;
|
||||
|
||||
@Slf4j
|
||||
public class ChangeEventHandler implements EventHandler {
|
||||
@ -55,32 +56,30 @@ public class ChangeEventHandler implements EventHandler {
|
||||
String method = requestContext.getMethod();
|
||||
try {
|
||||
ChangeEvent changeEvent = getChangeEvent(method, responseContext);
|
||||
if (changeEvent != null) {
|
||||
LOG.info(
|
||||
"Recording change event {}:{}:{}:{}",
|
||||
changeEvent.getTimestamp(),
|
||||
changeEvent.getEntityId(),
|
||||
changeEvent.getEventType(),
|
||||
changeEvent.getEntityType());
|
||||
EventPubSub.publish(changeEvent);
|
||||
if (changeEvent.getEntity() != null) {
|
||||
Object entity = changeEvent.getEntity();
|
||||
changeEvent = copyChangeEvent(changeEvent);
|
||||
changeEvent.setEntity(JsonUtils.pojoToJson(entity));
|
||||
}
|
||||
dao.changeEventDAO().insert(JsonUtils.pojoToJson(changeEvent));
|
||||
if (changeEvent == null) {
|
||||
return null;
|
||||
}
|
||||
LOG.info(
|
||||
"Recording change event {}:{}:{}:{}",
|
||||
changeEvent.getTimestamp(),
|
||||
changeEvent.getEntityId(),
|
||||
changeEvent.getEventType(),
|
||||
changeEvent.getEntityType());
|
||||
EventPubSub.publish(changeEvent);
|
||||
if (changeEvent.getEntity() != null) {
|
||||
Object entity = changeEvent.getEntity();
|
||||
changeEvent = copyChangeEvent(changeEvent);
|
||||
changeEvent.setEntity(JsonUtils.pojoToJson(entity));
|
||||
}
|
||||
dao.changeEventDAO().insert(JsonUtils.pojoToJson(changeEvent));
|
||||
|
||||
// Add a new thread to the entity for every change event
|
||||
// for the event to appear in activity feeds
|
||||
if (Entity.shouldDisplayEntityChangeOnFeed(changeEvent.getEntityType())) {
|
||||
List<Thread> threads = getThreads(responseContext);
|
||||
if (threads != null) {
|
||||
for (var thread : threads) {
|
||||
// Don't create a thread if there is no message
|
||||
if (!thread.getMessage().isEmpty()) {
|
||||
feedDao.create(thread);
|
||||
}
|
||||
}
|
||||
// Add a new thread to the entity for every change event
|
||||
// for the event to appear in activity feeds
|
||||
if (Entity.shouldDisplayEntityChangeOnFeed(changeEvent.getEntityType())) {
|
||||
for (var thread : CommonUtil.listOrEmpty(getThreads(responseContext))) {
|
||||
// Don't create a thread if there is no message
|
||||
if (!thread.getMessage().isEmpty()) {
|
||||
feedDao.create(thread);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -13,7 +13,9 @@
|
||||
|
||||
package org.openmetadata.catalog.jdbi3;
|
||||
|
||||
import static org.openmetadata.catalog.Entity.FIELD_FOLLOWERS;
|
||||
import static org.openmetadata.catalog.Entity.FIELD_OWNER;
|
||||
import static org.openmetadata.catalog.Entity.FIELD_TAGS;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import java.io.IOException;
|
||||
@ -97,8 +99,8 @@ public class ChartRepository extends EntityRepository<Chart> {
|
||||
public Chart setFields(Chart chart, Fields fields) throws IOException {
|
||||
chart.setService(getService(chart));
|
||||
chart.setOwner(fields.contains(FIELD_OWNER) ? getOwner(chart) : null);
|
||||
chart.setFollowers(fields.contains("followers") ? getFollowers(chart) : null);
|
||||
chart.setTags(fields.contains("tags") ? getTags(chart.getFullyQualifiedName()) : null);
|
||||
chart.setFollowers(fields.contains(FIELD_FOLLOWERS) ? getFollowers(chart) : null);
|
||||
chart.setTags(fields.contains(FIELD_TAGS) ? getTags(chart.getFullyQualifiedName()) : null);
|
||||
return chart;
|
||||
}
|
||||
|
||||
|
||||
@ -13,7 +13,9 @@
|
||||
|
||||
package org.openmetadata.catalog.jdbi3;
|
||||
|
||||
import static org.openmetadata.catalog.Entity.FIELD_FOLLOWERS;
|
||||
import static org.openmetadata.catalog.Entity.FIELD_OWNER;
|
||||
import static org.openmetadata.catalog.Entity.FIELD_TAGS;
|
||||
import static org.openmetadata.common.utils.CommonUtil.listOrEmpty;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
@ -68,9 +70,9 @@ public class DashboardRepository extends EntityRepository<Dashboard> {
|
||||
dashboard.setDisplayName(dashboard.getDisplayName());
|
||||
dashboard.setService(getService(dashboard));
|
||||
dashboard.setOwner(fields.contains(FIELD_OWNER) ? getOwner(dashboard) : null);
|
||||
dashboard.setFollowers(fields.contains("followers") ? getFollowers(dashboard) : null);
|
||||
dashboard.setFollowers(fields.contains(FIELD_FOLLOWERS) ? getFollowers(dashboard) : null);
|
||||
dashboard.setCharts(fields.contains("charts") ? getCharts(dashboard) : null);
|
||||
dashboard.setTags(fields.contains("tags") ? getTags(dashboard.getFullyQualifiedName()) : null);
|
||||
dashboard.setTags(fields.contains(FIELD_TAGS) ? getTags(dashboard.getFullyQualifiedName()) : null);
|
||||
dashboard.setUsageSummary(
|
||||
fields.contains("usageSummary")
|
||||
? EntityUtil.getLatestUsage(daoCollection.usageDAO(), dashboard.getId())
|
||||
|
||||
@ -13,8 +13,11 @@
|
||||
|
||||
package org.openmetadata.catalog.jdbi3;
|
||||
|
||||
import static org.openmetadata.catalog.Entity.FIELD_DELETED;
|
||||
import static org.openmetadata.catalog.Entity.FIELD_DESCRIPTION;
|
||||
import static org.openmetadata.catalog.Entity.FIELD_FOLLOWERS;
|
||||
import static org.openmetadata.catalog.Entity.FIELD_OWNER;
|
||||
import static org.openmetadata.catalog.Entity.FIELD_TAGS;
|
||||
import static org.openmetadata.catalog.Entity.getEntityFields;
|
||||
import static org.openmetadata.catalog.type.Include.ALL;
|
||||
import static org.openmetadata.catalog.type.Include.DELETED;
|
||||
@ -140,9 +143,9 @@ public abstract class EntityRepository<T> {
|
||||
this.putFields = getFields(putFields);
|
||||
this.entityType = entityType;
|
||||
|
||||
this.supportsTags = allowedFields.contains("tags");
|
||||
this.supportsOwner = allowedFields.contains("owner");
|
||||
this.supportsFollower = allowedFields.contains("followers");
|
||||
this.supportsTags = allowedFields.contains(FIELD_TAGS);
|
||||
this.supportsOwner = allowedFields.contains(FIELD_OWNER);
|
||||
this.supportsFollower = allowedFields.contains(FIELD_FOLLOWERS);
|
||||
Entity.registerEntity(entityClass, entityType, dao, this);
|
||||
}
|
||||
|
||||
@ -445,7 +448,7 @@ public abstract class EntityRepository<T> {
|
||||
ChangeDescription change = new ChangeDescription().withPreviousVersion(entityInterface.getVersion());
|
||||
change
|
||||
.getFieldsAdded()
|
||||
.add(new FieldChange().withName("followers").withNewValue(List.of(Entity.getEntityReference(user))));
|
||||
.add(new FieldChange().withName(FIELD_FOLLOWERS).withNewValue(List.of(Entity.getEntityReference(user))));
|
||||
|
||||
ChangeEvent changeEvent =
|
||||
new ChangeEvent()
|
||||
@ -535,7 +538,7 @@ public abstract class EntityRepository<T> {
|
||||
ChangeDescription change = new ChangeDescription().withPreviousVersion(entityInterface.getVersion());
|
||||
change
|
||||
.getFieldsDeleted()
|
||||
.add(new FieldChange().withName("followers").withOldValue(List.of(Entity.getEntityReference(user))));
|
||||
.add(new FieldChange().withName(FIELD_FOLLOWERS).withOldValue(List.of(Entity.getEntityReference(user))));
|
||||
|
||||
ChangeEvent changeEvent =
|
||||
new ChangeEvent()
|
||||
@ -914,7 +917,7 @@ public abstract class EntityRepository<T> {
|
||||
updateDescription();
|
||||
updateDisplayName();
|
||||
updateOwner();
|
||||
updateTags(updated.getFullyQualifiedName(), "tags", original.getTags(), updated.getTags());
|
||||
updateTags(updated.getFullyQualifiedName(), FIELD_TAGS, original.getTags(), updated.getTags());
|
||||
entitySpecificUpdate();
|
||||
}
|
||||
|
||||
@ -942,16 +945,16 @@ public abstract class EntityRepository<T> {
|
||||
if (operation.isPut() || operation.isPatch()) {
|
||||
// Update operation can't set delete attributed to true. This can only be done as part of delete operation
|
||||
if (updated.isDeleted() != original.isDeleted() && Boolean.TRUE.equals(updated.isDeleted())) {
|
||||
throw new IllegalArgumentException(CatalogExceptionMessage.readOnlyAttribute(entityType, "deleted"));
|
||||
throw new IllegalArgumentException(CatalogExceptionMessage.readOnlyAttribute(entityType, FIELD_DELETED));
|
||||
}
|
||||
// PUT or PATCH is restoring the soft-deleted entity
|
||||
if (Boolean.TRUE.equals(original.isDeleted())) {
|
||||
updated.setDeleted(false);
|
||||
recordChange("deleted", true, false);
|
||||
recordChange(FIELD_DELETED, true, false);
|
||||
entityRestored = true;
|
||||
}
|
||||
} else {
|
||||
recordChange("deleted", original.isDeleted(), updated.isDeleted());
|
||||
recordChange(FIELD_DELETED, original.isDeleted(), updated.isDeleted());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -432,7 +432,7 @@ public class FeedRepository {
|
||||
|
||||
private boolean fieldsChanged(Thread original, Thread updated) {
|
||||
// Patch supports only isResolved and message for now
|
||||
return original.getResolved() != updated.getResolved() || !original.getMessage().equals(updated.getMessage());
|
||||
return !original.getResolved().equals(updated.getResolved()) || !original.getMessage().equals(updated.getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -17,6 +17,7 @@
|
||||
package org.openmetadata.catalog.jdbi3;
|
||||
|
||||
import static org.openmetadata.catalog.Entity.FIELD_OWNER;
|
||||
import static org.openmetadata.catalog.Entity.FIELD_TAGS;
|
||||
import static org.openmetadata.common.utils.CommonUtil.listOrEmpty;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
@ -55,7 +56,7 @@ public class GlossaryRepository extends EntityRepository<Glossary> {
|
||||
@Override
|
||||
public Glossary setFields(Glossary glossary, Fields fields) throws IOException {
|
||||
glossary.setOwner(fields.contains(FIELD_OWNER) ? getOwner(glossary) : null);
|
||||
glossary.setTags(fields.contains("tags") ? getTags(glossary.getName()) : null);
|
||||
glossary.setTags(fields.contains(FIELD_TAGS) ? getTags(glossary.getName()) : null);
|
||||
glossary.setReviewers(fields.contains("reviewers") ? getReviewers(glossary) : null);
|
||||
return glossary.withUsageCount(fields.contains("usageCount") ? getUsageCount(glossary) : null);
|
||||
}
|
||||
|
||||
@ -16,6 +16,7 @@
|
||||
|
||||
package org.openmetadata.catalog.jdbi3;
|
||||
|
||||
import static org.openmetadata.catalog.Entity.FIELD_TAGS;
|
||||
import static org.openmetadata.catalog.Entity.GLOSSARY_TERM;
|
||||
import static org.openmetadata.catalog.type.Include.ALL;
|
||||
import static org.openmetadata.catalog.util.EntityUtil.stringMatch;
|
||||
@ -66,7 +67,7 @@ public class GlossaryTermRepository extends EntityRepository<GlossaryTerm> {
|
||||
entity.setChildren(fields.contains("children") ? getChildren(entity) : null);
|
||||
entity.setRelatedTerms(fields.contains("relatedTerms") ? getRelatedTerms(entity) : null);
|
||||
entity.setReviewers(fields.contains("reviewers") ? getReviewers(entity) : null);
|
||||
entity.setTags(fields.contains("tags") ? getTags(entity.getFullyQualifiedName()) : null);
|
||||
entity.setTags(fields.contains(FIELD_TAGS) ? getTags(entity.getFullyQualifiedName()) : null);
|
||||
entity.setUsageCount(fields.contains("usageCount") ? getUsageCount(entity) : null);
|
||||
return entity;
|
||||
}
|
||||
|
||||
@ -13,7 +13,9 @@
|
||||
|
||||
package org.openmetadata.catalog.jdbi3;
|
||||
|
||||
import static org.openmetadata.catalog.Entity.FIELD_FOLLOWERS;
|
||||
import static org.openmetadata.catalog.Entity.FIELD_OWNER;
|
||||
import static org.openmetadata.catalog.Entity.FIELD_TAGS;
|
||||
import static org.openmetadata.catalog.Entity.STORAGE_SERVICE;
|
||||
|
||||
import java.io.IOException;
|
||||
@ -59,8 +61,8 @@ public class LocationRepository extends EntityRepository<Location> {
|
||||
public Location setFields(Location location, Fields fields) throws IOException {
|
||||
location.setService(getService(location));
|
||||
location.setOwner(fields.contains(FIELD_OWNER) ? getOwner(location) : null);
|
||||
location.setFollowers(fields.contains("followers") ? getFollowers(location) : null);
|
||||
location.setTags(fields.contains("tags") ? getTags(location.getFullyQualifiedName()) : null);
|
||||
location.setFollowers(fields.contains(FIELD_FOLLOWERS) ? getFollowers(location) : null);
|
||||
location.setTags(fields.contains(FIELD_TAGS) ? getTags(location.getFullyQualifiedName()) : null);
|
||||
return location;
|
||||
}
|
||||
|
||||
|
||||
@ -13,7 +13,9 @@
|
||||
|
||||
package org.openmetadata.catalog.jdbi3;
|
||||
|
||||
import static org.openmetadata.catalog.Entity.FIELD_FOLLOWERS;
|
||||
import static org.openmetadata.catalog.Entity.FIELD_OWNER;
|
||||
import static org.openmetadata.catalog.Entity.FIELD_TAGS;
|
||||
import static org.openmetadata.catalog.Entity.MLMODEL;
|
||||
import static org.openmetadata.catalog.type.Include.ALL;
|
||||
import static org.openmetadata.catalog.util.EntityUtil.entityReferenceMatch;
|
||||
@ -66,8 +68,8 @@ public class MlModelRepository extends EntityRepository<MlModel> {
|
||||
public MlModel setFields(MlModel mlModel, Fields fields) throws IOException {
|
||||
mlModel.setOwner(fields.contains(FIELD_OWNER) ? getOwner(mlModel) : null);
|
||||
mlModel.setDashboard(fields.contains("dashboard") ? getDashboard(mlModel) : null);
|
||||
mlModel.setFollowers(fields.contains("followers") ? getFollowers(mlModel) : null);
|
||||
mlModel.setTags(fields.contains("tags") ? getTags(mlModel.getFullyQualifiedName()) : null);
|
||||
mlModel.setFollowers(fields.contains(FIELD_FOLLOWERS) ? getFollowers(mlModel) : null);
|
||||
mlModel.setTags(fields.contains(FIELD_TAGS) ? getTags(mlModel.getFullyQualifiedName()) : null);
|
||||
mlModel.setUsageSummary(
|
||||
fields.contains("usageSummary") ? EntityUtil.getLatestUsage(daoCollection.usageDAO(), mlModel.getId()) : null);
|
||||
return mlModel;
|
||||
|
||||
@ -13,7 +13,9 @@
|
||||
|
||||
package org.openmetadata.catalog.jdbi3;
|
||||
|
||||
import static org.openmetadata.catalog.Entity.FIELD_FOLLOWERS;
|
||||
import static org.openmetadata.catalog.Entity.FIELD_OWNER;
|
||||
import static org.openmetadata.catalog.Entity.FIELD_TAGS;
|
||||
import static org.openmetadata.catalog.Entity.PIPELINE_SERVICE;
|
||||
import static org.openmetadata.catalog.util.EntityUtil.taskMatch;
|
||||
import static org.openmetadata.common.utils.CommonUtil.listOrEmpty;
|
||||
@ -75,12 +77,12 @@ public class PipelineRepository extends EntityRepository<Pipeline> {
|
||||
pipeline.setStartDate(pipeline.getStartDate());
|
||||
pipeline.setConcurrency(pipeline.getConcurrency());
|
||||
pipeline.setOwner(fields.contains(FIELD_OWNER) ? getOwner(pipeline) : null);
|
||||
pipeline.setFollowers(fields.contains("followers") ? getFollowers(pipeline) : null);
|
||||
pipeline.setFollowers(fields.contains(FIELD_FOLLOWERS) ? getFollowers(pipeline) : null);
|
||||
if (!fields.contains("tasks")) {
|
||||
pipeline.withTasks(null);
|
||||
}
|
||||
pipeline.setPipelineStatus(fields.contains("pipelineStatus") ? getPipelineStatus(pipeline) : null);
|
||||
pipeline.setTags(fields.contains("tags") ? getTags(pipeline.getFullyQualifiedName()) : null);
|
||||
pipeline.setTags(fields.contains(FIELD_TAGS) ? getTags(pipeline.getFullyQualifiedName()) : null);
|
||||
return pipeline;
|
||||
}
|
||||
|
||||
|
||||
@ -15,7 +15,9 @@ package org.openmetadata.catalog.jdbi3;
|
||||
|
||||
import static org.openmetadata.catalog.Entity.DATABASE_SCHEMA;
|
||||
import static org.openmetadata.catalog.Entity.FIELD_DESCRIPTION;
|
||||
import static org.openmetadata.catalog.Entity.FIELD_FOLLOWERS;
|
||||
import static org.openmetadata.catalog.Entity.FIELD_OWNER;
|
||||
import static org.openmetadata.catalog.Entity.FIELD_TAGS;
|
||||
import static org.openmetadata.catalog.Entity.LOCATION;
|
||||
import static org.openmetadata.catalog.Entity.TABLE;
|
||||
import static org.openmetadata.catalog.util.EntityUtil.getColumnField;
|
||||
@ -102,11 +104,11 @@ public class TableRepository extends EntityRepository<Table> {
|
||||
setDefaultFields(table);
|
||||
table.setTableConstraints(fields.contains("tableConstraints") ? table.getTableConstraints() : null);
|
||||
table.setOwner(fields.contains(FIELD_OWNER) ? getOwner(table) : null);
|
||||
table.setFollowers(fields.contains("followers") ? getFollowers(table) : null);
|
||||
table.setFollowers(fields.contains(FIELD_FOLLOWERS) ? getFollowers(table) : null);
|
||||
table.setUsageSummary(
|
||||
fields.contains("usageSummary") ? EntityUtil.getLatestUsage(daoCollection.usageDAO(), table.getId()) : null);
|
||||
table.setTags(fields.contains("tags") ? getTags(table.getFullyQualifiedName()) : null);
|
||||
getColumnTags(fields.contains("tags"), table.getColumns());
|
||||
table.setTags(fields.contains(FIELD_TAGS) ? getTags(table.getFullyQualifiedName()) : null);
|
||||
getColumnTags(fields.contains(FIELD_TAGS), table.getColumns());
|
||||
table.setJoins(fields.contains("joins") ? getJoins(table) : null);
|
||||
table.setSampleData(fields.contains("sampleData") ? getSampleData(table) : null);
|
||||
table.setViewDefinition(fields.contains("viewDefinition") ? table.getViewDefinition() : null);
|
||||
@ -1099,7 +1101,7 @@ public class TableRepository extends EntityRepository<Table> {
|
||||
updateColumnDataLength(stored, updated);
|
||||
updateTags(
|
||||
stored.getFullyQualifiedName(),
|
||||
EntityUtil.getFieldName(fieldName, updated.getName(), "tags"),
|
||||
EntityUtil.getFieldName(fieldName, updated.getName(), FIELD_TAGS),
|
||||
stored.getTags(),
|
||||
updated.getTags());
|
||||
updateColumnConstraint(stored, updated);
|
||||
|
||||
@ -13,7 +13,9 @@
|
||||
|
||||
package org.openmetadata.catalog.jdbi3;
|
||||
|
||||
import static org.openmetadata.catalog.Entity.FIELD_FOLLOWERS;
|
||||
import static org.openmetadata.catalog.Entity.FIELD_OWNER;
|
||||
import static org.openmetadata.catalog.Entity.FIELD_TAGS;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import java.io.IOException;
|
||||
@ -94,8 +96,8 @@ public class TopicRepository extends EntityRepository<Topic> {
|
||||
public Topic setFields(Topic topic, Fields fields) throws IOException {
|
||||
topic.setService(getService(topic));
|
||||
topic.setOwner(fields.contains(FIELD_OWNER) ? getOwner(topic) : null);
|
||||
topic.setFollowers(fields.contains("followers") ? getFollowers(topic) : null);
|
||||
topic.setTags(fields.contains("tags") ? getTags(topic.getFullyQualifiedName()) : null);
|
||||
topic.setFollowers(fields.contains(FIELD_FOLLOWERS) ? getFollowers(topic) : null);
|
||||
topic.setTags(fields.contains(FIELD_TAGS) ? getTags(topic.getFullyQualifiedName()) : null);
|
||||
return topic;
|
||||
}
|
||||
|
||||
|
||||
@ -35,6 +35,7 @@ import javax.ws.rs.client.Client;
|
||||
import javax.ws.rs.client.ClientBuilder;
|
||||
import javax.ws.rs.client.Invocation.Builder;
|
||||
import javax.ws.rs.core.Response;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.jdbi.v3.sqlobject.transaction.Transaction;
|
||||
import org.openmetadata.catalog.Entity;
|
||||
@ -115,7 +116,8 @@ public class WebhookRepository extends EntityRepository<Webhook> {
|
||||
LOG.info("Webhook subscription started for {}", webhook.getName());
|
||||
}
|
||||
|
||||
public void updateWebhookPublisher(Webhook webhook) throws InterruptedException {
|
||||
@SneakyThrows
|
||||
public void updateWebhookPublisher(Webhook webhook) {
|
||||
if (Boolean.TRUE.equals(webhook.getEnabled())) { // Only add webhook that is enabled for publishing
|
||||
// If there was a previous webhook either in disabled state or stopped due
|
||||
// to errors, update it and restart publishing
|
||||
|
||||
@ -21,12 +21,10 @@ import java.util.stream.Stream;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.exception.ExceptionUtils;
|
||||
import org.jdbi.v3.core.Jdbi;
|
||||
import org.openmetadata.catalog.Entity;
|
||||
import org.openmetadata.catalog.entity.teams.User;
|
||||
import org.openmetadata.catalog.exception.EntityNotFoundException;
|
||||
import org.openmetadata.catalog.jdbi3.CollectionDAO;
|
||||
import org.openmetadata.catalog.jdbi3.RoleRepository;
|
||||
import org.openmetadata.catalog.jdbi3.TeamRepository;
|
||||
import org.openmetadata.catalog.jdbi3.UserRepository;
|
||||
import org.openmetadata.catalog.jdbi3.EntityRepository;
|
||||
import org.openmetadata.catalog.type.EntityReference;
|
||||
import org.openmetadata.catalog.type.MetadataOperation;
|
||||
import org.openmetadata.catalog.util.EntityUtil.Fields;
|
||||
@ -34,18 +32,8 @@ import org.openmetadata.catalog.util.RestUtil;
|
||||
|
||||
@Slf4j
|
||||
public class NoopAuthorizer implements Authorizer {
|
||||
private UserRepository userRepository;
|
||||
|
||||
@Override
|
||||
public void init(AuthorizerConfiguration config, Jdbi jdbi) {
|
||||
CollectionDAO collectionDAO = jdbi.onDemand(CollectionDAO.class);
|
||||
this.userRepository = new UserRepository(collectionDAO);
|
||||
// TODO: fixme
|
||||
// RoleRepository and TeamRepository needs to be instantiated for Entity.DAO_MAP to populated.
|
||||
// As we create default admin/bots we need to have RoleRepository and TeamRepository available in DAO_MAP.
|
||||
// This needs to be handled better in future releases.
|
||||
RoleRepository roleRepository = new RoleRepository(collectionDAO);
|
||||
TeamRepository teamRepository = new TeamRepository(collectionDAO);
|
||||
addAnonymousUser();
|
||||
}
|
||||
|
||||
@ -84,7 +72,7 @@ public class NoopAuthorizer implements Authorizer {
|
||||
private void addAnonymousUser() {
|
||||
String username = "anonymous";
|
||||
try {
|
||||
userRepository.getByName(null, username, Fields.EMPTY_FIELDS);
|
||||
Entity.getEntityRepository(Entity.USER).getByName(null, username, Fields.EMPTY_FIELDS);
|
||||
} catch (EntityNotFoundException ex) {
|
||||
User user =
|
||||
new User()
|
||||
@ -101,6 +89,7 @@ public class NoopAuthorizer implements Authorizer {
|
||||
|
||||
private void addOrUpdateUser(User user) {
|
||||
try {
|
||||
EntityRepository<User> userRepository = Entity.getEntityRepository(Entity.USER);
|
||||
RestUtil.PutResponse<User> addedUser = userRepository.createOrUpdate(null, user);
|
||||
LOG.debug("Added anonymous user entry: {}", addedUser);
|
||||
} catch (IOException exception) {
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
package org.openmetadata.catalog.slack;
|
||||
|
||||
import static org.openmetadata.catalog.Entity.FIELD_DELETED;
|
||||
import static org.openmetadata.catalog.Entity.FIELD_DESCRIPTION;
|
||||
import static org.openmetadata.catalog.Entity.FIELD_FOLLOWERS;
|
||||
import static org.openmetadata.catalog.Entity.FIELD_OWNER;
|
||||
|
||||
import java.net.URI;
|
||||
@ -29,9 +31,9 @@ import org.openmetadata.catalog.type.FieldChange;
|
||||
|
||||
@Slf4j
|
||||
public class SlackWebhookEventPublisher extends AbstractEventPublisher {
|
||||
private Invocation.Builder target;
|
||||
private Client client;
|
||||
private String openMetadataUrl;
|
||||
private final Invocation.Builder target;
|
||||
private final Client client;
|
||||
private final String openMetadataUrl;
|
||||
|
||||
public SlackWebhookEventPublisher(SlackPublisherConfiguration config) {
|
||||
super(config.getBatchSize(), config.getFilters());
|
||||
@ -126,7 +128,8 @@ public class SlackWebhookEventPublisher extends AbstractEventPublisher {
|
||||
} else if (fieldChange.getName().equals(FIELD_OWNER)) {
|
||||
title.append("Added ownership");
|
||||
attachment.setText(parseOwnership((String) fieldChange.getOldValue(), (String) fieldChange.getNewValue()));
|
||||
} else if (fieldChange.getName().equals("followers")) {
|
||||
} else if (fieldChange.getName().equals(FIELD_FOLLOWERS)) {
|
||||
@SuppressWarnings("unchecked")
|
||||
String followers = parseFollowers((List<EntityReference>) fieldChange.getNewValue());
|
||||
String entityUrl = getEntityUrl(event);
|
||||
attachment.setText(followers + " started following " + entityUrl);
|
||||
@ -150,7 +153,7 @@ public class SlackWebhookEventPublisher extends AbstractEventPublisher {
|
||||
&& !changeDescription.getFieldsUpdated().isEmpty()) {
|
||||
for (FieldChange fieldChange : changeDescription.getFieldsUpdated()) {
|
||||
// when the entity is deleted we will get deleted set as true. We do not need to parse this for slack messages.
|
||||
if (!fieldChange.getName().equals("deleted")) {
|
||||
if (!fieldChange.getName().equals(FIELD_DELETED)) {
|
||||
SlackAttachment attachment = new SlackAttachment();
|
||||
attachment.setTitle("Updated " + fieldChange.getName());
|
||||
if (fieldChange.getName().equals(FIELD_OWNER)) {
|
||||
@ -186,7 +189,8 @@ public class SlackWebhookEventPublisher extends AbstractEventPublisher {
|
||||
title.append("Deleted columns ");
|
||||
attachment.setText(parseColumns((String) fieldChange.getOldValue(), event));
|
||||
attachment.setTitle(title.toString());
|
||||
} else if (fieldChange.getName().equals("followers")) {
|
||||
} else if (fieldChange.getName().equals(FIELD_FOLLOWERS)) {
|
||||
@SuppressWarnings("unchecked")
|
||||
String followers = parseFollowers((List<EntityReference>) fieldChange.getOldValue());
|
||||
String entityUrl = getEntityUrl(event);
|
||||
attachment.setText(followers + " unfollowed " + entityUrl);
|
||||
|
||||
@ -13,6 +13,8 @@
|
||||
|
||||
package org.openmetadata.catalog.util;
|
||||
|
||||
import static org.openmetadata.catalog.Entity.FIELD_OWNER;
|
||||
|
||||
import com.github.difflib.text.DiffRow;
|
||||
import com.github.difflib.text.DiffRowGenerator;
|
||||
import java.util.ArrayList;
|
||||
@ -81,49 +83,50 @@ public final class ChangeEventParser {
|
||||
}
|
||||
|
||||
private static String getFieldValue(Object fieldValue) {
|
||||
if (fieldValue != null && !fieldValue.toString().isEmpty()) {
|
||||
try {
|
||||
// Check if field value is a json string
|
||||
JsonValue json = JsonUtils.readJson(fieldValue.toString());
|
||||
if (json.getValueType() == ValueType.ARRAY) {
|
||||
JsonArray jsonArray = json.asJsonArray();
|
||||
List<String> labels = new ArrayList<>();
|
||||
for (var item : jsonArray) {
|
||||
if (item.getValueType() == ValueType.OBJECT) {
|
||||
Set<String> keys = item.asJsonObject().keySet();
|
||||
if (keys.contains("tagFQN")) {
|
||||
labels.add(item.asJsonObject().getString("tagFQN"));
|
||||
} else if (keys.contains("displayName")) {
|
||||
// Entity Reference will have a displayName
|
||||
labels.add(item.asJsonObject().getString("displayName"));
|
||||
} else if (keys.contains("name")) {
|
||||
// Glossary term references have only "name" field
|
||||
labels.add(item.asJsonObject().getString("name"));
|
||||
}
|
||||
} else if (item.getValueType() == ValueType.STRING) {
|
||||
// The string might be enclosed with double quotes
|
||||
// Check if has double quotes and strip trailing whitespaces
|
||||
String label = item.toString().replaceAll("(?:^\\\")|(?:\\\"$)", "");
|
||||
labels.add(label.strip());
|
||||
if (fieldValue == null || fieldValue.toString().isEmpty()) {
|
||||
return StringUtils.EMPTY;
|
||||
}
|
||||
|
||||
try {
|
||||
// Check if field value is a json string
|
||||
JsonValue json = JsonUtils.readJson(fieldValue.toString());
|
||||
if (json.getValueType() == ValueType.ARRAY) {
|
||||
JsonArray jsonArray = json.asJsonArray();
|
||||
List<String> labels = new ArrayList<>();
|
||||
for (var item : jsonArray) {
|
||||
if (item.getValueType() == ValueType.OBJECT) {
|
||||
Set<String> keys = item.asJsonObject().keySet();
|
||||
if (keys.contains("tagFQN")) {
|
||||
labels.add(item.asJsonObject().getString("tagFQN"));
|
||||
} else if (keys.contains("displayName")) {
|
||||
// Entity Reference will have a displayName
|
||||
labels.add(item.asJsonObject().getString("displayName"));
|
||||
} else if (keys.contains("name")) {
|
||||
// Glossary term references have only "name" field
|
||||
labels.add(item.asJsonObject().getString("name"));
|
||||
}
|
||||
}
|
||||
return String.join(", ", labels);
|
||||
} else if (json.getValueType() == ValueType.OBJECT) {
|
||||
JsonObject jsonObject = json.asJsonObject();
|
||||
// Entity Reference will have a displayName
|
||||
Set<String> keys = jsonObject.asJsonObject().keySet();
|
||||
if (keys.contains("displayName")) {
|
||||
return jsonObject.asJsonObject().getString("displayName");
|
||||
} else if (keys.contains("name")) {
|
||||
return jsonObject.asJsonObject().getString("name");
|
||||
} else if (item.getValueType() == ValueType.STRING) {
|
||||
// The string might be enclosed with double quotes
|
||||
// Check if string has double quotes and strip trailing whitespaces
|
||||
String label = item.toString().replaceAll("^\"|\"$", "");
|
||||
labels.add(label.strip());
|
||||
}
|
||||
}
|
||||
} catch (JsonParsingException ex) {
|
||||
// If unable to parse json, just return the string
|
||||
return String.join(", ", labels);
|
||||
} else if (json.getValueType() == ValueType.OBJECT) {
|
||||
JsonObject jsonObject = json.asJsonObject();
|
||||
// Entity Reference will have a displayName
|
||||
Set<String> keys = jsonObject.asJsonObject().keySet();
|
||||
if (keys.contains("displayName")) {
|
||||
return jsonObject.asJsonObject().getString("displayName");
|
||||
} else if (keys.contains("name")) {
|
||||
return jsonObject.asJsonObject().getString("name");
|
||||
}
|
||||
}
|
||||
return fieldValue.toString();
|
||||
} catch (JsonParsingException ex) {
|
||||
// If unable to parse json, just return the string
|
||||
}
|
||||
return StringUtils.EMPTY;
|
||||
return fieldValue.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -264,7 +267,7 @@ public final class ChangeEventParser {
|
||||
|
||||
if (oldValue == null || oldValue.toString().isEmpty()) {
|
||||
return String.format("Updated **%s** to %s", updatedField, getFieldValue(newValue));
|
||||
} else if (updatedField.contains("tags") || updatedField.contains("owner")) {
|
||||
} else if (updatedField.contains("tags") || updatedField.contains(FIELD_OWNER)) {
|
||||
return getPlainTextUpdateMessage(updatedField, getFieldValue(oldValue), getFieldValue(newValue));
|
||||
}
|
||||
// if old value is not empty, and is of type array or object, the updates can be across multiple keys
|
||||
@ -320,13 +323,13 @@ public final class ChangeEventParser {
|
||||
// compute the differences
|
||||
List<DiffRow> rows = generator.generateDiffRows(List.of(oldValue), List.of(newValue));
|
||||
|
||||
// merge rows by \n for new line
|
||||
// merge rows by %n for new line
|
||||
String diff = null;
|
||||
for (var row : rows) {
|
||||
if (diff == null) {
|
||||
diff = row.getOldLine();
|
||||
} else {
|
||||
diff = String.format("%s\n%s", diff, row.getOldLine());
|
||||
diff = String.format("%s%n%s", diff, row.getOldLine());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -21,6 +21,10 @@ public class FullyQualifiedName {
|
||||
// Quoted name of format "sss" or sss
|
||||
private static final Pattern namePattern = Pattern.compile("^(\")([^\"]+)(\")$|^(.*)$");
|
||||
|
||||
private FullyQualifiedName() {
|
||||
/* Utility class with private constructor */
|
||||
}
|
||||
|
||||
/** Add to an existing valid FQN the given string */
|
||||
public static String add(String fqn, String part) {
|
||||
return fqn + Entity.SEPARATOR + quoteName(part);
|
||||
|
||||
@ -34,6 +34,10 @@ public final class OpenMetadataClientSecurityUtil {
|
||||
public static final List<String> AZURE_SSO_CONFIGS = List.of(CLIENT_SECRET, CLIENT_ID, AUTHORITY, SCOPES);
|
||||
public static final List<String> CUSTOM_OIDC_SSO_CONFIGS = List.of(CLIENT_ID, SECRET_KEY, TOKEN_ENDPOINT);
|
||||
|
||||
private OpenMetadataClientSecurityUtil() {
|
||||
/* Utility class with private constructor */
|
||||
}
|
||||
|
||||
public static OpenMetadataServerConnection buildOpenMetadataServerConfig(AirflowConfiguration airflowConfiguration) {
|
||||
AuthProvider authProvider = AuthProvider.fromValue(airflowConfiguration.getAuthProvider());
|
||||
String openMetadataURL = airflowConfiguration.getMetadataApiEndpoint();
|
||||
|
||||
@ -25,6 +25,10 @@ import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.openmetadata.catalog.Entity.FIELD_DELETED;
|
||||
import static org.openmetadata.catalog.Entity.FIELD_FOLLOWERS;
|
||||
import static org.openmetadata.catalog.Entity.FIELD_OWNER;
|
||||
import static org.openmetadata.catalog.Entity.FIELD_TAGS;
|
||||
import static org.openmetadata.catalog.exception.CatalogExceptionMessage.ENTITY_ALREADY_EXISTS;
|
||||
import static org.openmetadata.catalog.exception.CatalogExceptionMessage.entityNotFound;
|
||||
import static org.openmetadata.catalog.exception.CatalogExceptionMessage.noPermission;
|
||||
@ -220,9 +224,9 @@ public abstract class EntityResourceTest<T, K> extends CatalogApplicationTest {
|
||||
this.allFields = fields;
|
||||
|
||||
List<String> allowedFields = Entity.getEntityFields(entityClass);
|
||||
this.supportsFollowers = allowedFields.contains("followers");
|
||||
this.supportsOwner = allowedFields.contains("owner");
|
||||
this.supportsTags = allowedFields.contains("tags");
|
||||
this.supportsFollowers = allowedFields.contains(FIELD_FOLLOWERS);
|
||||
this.supportsOwner = allowedFields.contains(FIELD_OWNER);
|
||||
this.supportsTags = allowedFields.contains(FIELD_TAGS);
|
||||
ENTITY_RESOURCE_TEST_MAP.put(entityType, this);
|
||||
}
|
||||
|
||||
@ -682,7 +686,7 @@ public abstract class EntityResourceTest<T, K> extends CatalogApplicationTest {
|
||||
|
||||
// Delete team and ensure the entity still exists but with owner as deleted
|
||||
teamResourceTest.deleteEntity(team.getId(), ADMIN_AUTH_HEADERS);
|
||||
entity = getEntity(entityInterface.getId(), "owner", ADMIN_AUTH_HEADERS);
|
||||
entity = getEntity(entityInterface.getId(), FIELD_OWNER, ADMIN_AUTH_HEADERS);
|
||||
entityInterface = getEntityInterface(entity);
|
||||
assertTrue(entityInterface.getOwner().getDeleted());
|
||||
}
|
||||
@ -775,7 +779,7 @@ public abstract class EntityResourceTest<T, K> extends CatalogApplicationTest {
|
||||
EntityInterface<T> entityInterface = getEntityInterface(entity);
|
||||
|
||||
// Set TEAM_OWNER1 as owner using PUT request
|
||||
FieldChange fieldChange = new FieldChange().withName("owner").withNewValue(TEAM_OWNER1);
|
||||
FieldChange fieldChange = new FieldChange().withName(FIELD_OWNER).withNewValue(TEAM_OWNER1);
|
||||
request = createRequest(getEntityName(test), "description", "displayName", TEAM_OWNER1);
|
||||
ChangeDescription change =
|
||||
getChangeDescription(entityInterface.getVersion()).withFieldsAdded(Collections.singletonList(fieldChange));
|
||||
@ -785,7 +789,7 @@ public abstract class EntityResourceTest<T, K> extends CatalogApplicationTest {
|
||||
|
||||
// Change owner from TEAM_OWNER1 to USER_OWNER1 using PUT request
|
||||
request = createRequest(getEntityName(test), "description", "displayName", USER_OWNER1);
|
||||
fieldChange = new FieldChange().withName("owner").withOldValue(TEAM_OWNER1).withNewValue(USER_OWNER1);
|
||||
fieldChange = new FieldChange().withName(FIELD_OWNER).withOldValue(TEAM_OWNER1).withNewValue(USER_OWNER1);
|
||||
change =
|
||||
getChangeDescription(entityInterface.getVersion()).withFieldsUpdated(Collections.singletonList(fieldChange));
|
||||
entity = updateAndCheckEntity(request, OK, ADMIN_AUTH_HEADERS, MINOR_UPDATE, change);
|
||||
@ -930,7 +934,7 @@ public abstract class EntityResourceTest<T, K> extends CatalogApplicationTest {
|
||||
Map<String, String> queryParams = new HashMap<>();
|
||||
queryParams.put("include", "deleted");
|
||||
EntityInterface<T> entityInterface =
|
||||
getEntityInterface(getEntity(entityId, queryParams, "followers", ADMIN_AUTH_HEADERS));
|
||||
getEntityInterface(getEntity(entityId, queryParams, FIELD_FOLLOWERS, ADMIN_AUTH_HEADERS));
|
||||
TestUtils.existsInEntityReferenceList(entityInterface.getFollowers(), user1.getId(), true);
|
||||
}
|
||||
|
||||
@ -983,7 +987,7 @@ public abstract class EntityResourceTest<T, K> extends CatalogApplicationTest {
|
||||
// Set the owner for the table.
|
||||
String originalJson = JsonUtils.pojoToJson(entity);
|
||||
ChangeDescription change = getChangeDescription(entityInterface.getVersion());
|
||||
change.getFieldsAdded().add(new FieldChange().withName("owner").withNewValue(USER_OWNER1));
|
||||
change.getFieldsAdded().add(new FieldChange().withName(FIELD_OWNER).withNewValue(USER_OWNER1));
|
||||
entityInterface.setOwner(USER_OWNER1);
|
||||
entity =
|
||||
patchEntityAndCheck(
|
||||
@ -1028,7 +1032,7 @@ public abstract class EntityResourceTest<T, K> extends CatalogApplicationTest {
|
||||
change.getFieldsAdded().add(new FieldChange().withName("description").withNewValue("description"));
|
||||
if (supportsOwner) {
|
||||
entityInterface.setOwner(TEAM_OWNER1);
|
||||
change.getFieldsAdded().add(new FieldChange().withName("owner").withNewValue(TEAM_OWNER1));
|
||||
change.getFieldsAdded().add(new FieldChange().withName(FIELD_OWNER).withNewValue(TEAM_OWNER1));
|
||||
}
|
||||
if (supportsTags) {
|
||||
entityInterface.setTags(new ArrayList<>());
|
||||
@ -1038,7 +1042,10 @@ public abstract class EntityResourceTest<T, K> extends CatalogApplicationTest {
|
||||
entityInterface.getTags().add(GLOSSARY2_TERM1_LABEL); // Add duplicated tags and make sure only one tag is added
|
||||
change
|
||||
.getFieldsAdded()
|
||||
.add(new FieldChange().withName("tags").withNewValue(List.of(USER_ADDRESS_TAG_LABEL, GLOSSARY2_TERM1_LABEL)));
|
||||
.add(
|
||||
new FieldChange()
|
||||
.withName(FIELD_TAGS)
|
||||
.withNewValue(List.of(USER_ADDRESS_TAG_LABEL, GLOSSARY2_TERM1_LABEL)));
|
||||
}
|
||||
change
|
||||
.getFieldsAdded()
|
||||
@ -1068,12 +1075,12 @@ public abstract class EntityResourceTest<T, K> extends CatalogApplicationTest {
|
||||
entityInterface.setOwner(USER_OWNER1);
|
||||
change
|
||||
.getFieldsUpdated()
|
||||
.add(new FieldChange().withName("owner").withOldValue(TEAM_OWNER1).withNewValue(USER_OWNER1));
|
||||
.add(new FieldChange().withName(FIELD_OWNER).withOldValue(TEAM_OWNER1).withNewValue(USER_OWNER1));
|
||||
}
|
||||
|
||||
if (supportsTags) {
|
||||
entityInterface.getTags().add(TIER1_TAG_LABEL);
|
||||
change.getFieldsAdded().add(new FieldChange().withName("tags").withNewValue(List.of(TIER1_TAG_LABEL)));
|
||||
change.getFieldsAdded().add(new FieldChange().withName(FIELD_TAGS).withNewValue(List.of(TIER1_TAG_LABEL)));
|
||||
}
|
||||
|
||||
entity = patchEntityAndCheck(entity, origJson, ADMIN_AUTH_HEADERS, MINOR_UPDATE, change);
|
||||
@ -1093,10 +1100,10 @@ public abstract class EntityResourceTest<T, K> extends CatalogApplicationTest {
|
||||
change = getChangeDescription(entityInterface.getVersion());
|
||||
change.getFieldsDeleted().add(new FieldChange().withName("description").withOldValue("description1"));
|
||||
if (supportsOwner) {
|
||||
change.getFieldsDeleted().add(new FieldChange().withName("owner").withOldValue(USER_OWNER1));
|
||||
change.getFieldsDeleted().add(new FieldChange().withName(FIELD_OWNER).withOldValue(USER_OWNER1));
|
||||
}
|
||||
if (supportsTags) {
|
||||
change.getFieldsDeleted().add(new FieldChange().withName("tags").withOldValue(removedTags));
|
||||
change.getFieldsDeleted().add(new FieldChange().withName(FIELD_TAGS).withOldValue(removedTags));
|
||||
}
|
||||
|
||||
patchEntityAndCheck(entity, origJson, ADMIN_AUTH_HEADERS, MINOR_UPDATE, change);
|
||||
@ -1115,7 +1122,7 @@ public abstract class EntityResourceTest<T, K> extends CatalogApplicationTest {
|
||||
assertResponse(
|
||||
() -> patchEntity(entityInterface.getId(), json, entity, ADMIN_AUTH_HEADERS),
|
||||
BAD_REQUEST,
|
||||
readOnlyAttribute(entityType, "deleted"));
|
||||
readOnlyAttribute(entityType, FIELD_DELETED));
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -1158,7 +1165,7 @@ public abstract class EntityResourceTest<T, K> extends CatalogApplicationTest {
|
||||
|
||||
// Send PUT request (with no changes) to restore the entity from soft deleted state
|
||||
ChangeDescription change = getChangeDescription(version);
|
||||
change.getFieldsUpdated().add(new FieldChange().withName("deleted").withNewValue(false).withOldValue(true));
|
||||
change.getFieldsUpdated().add(new FieldChange().withName(FIELD_DELETED).withNewValue(false).withOldValue(true));
|
||||
updateAndCheckEntity(request, Response.Status.OK, ADMIN_AUTH_HEADERS, MINOR_UPDATE, change);
|
||||
} else {
|
||||
assertEntityDeleted(entityInterface, true);
|
||||
@ -1292,7 +1299,7 @@ public abstract class EntityResourceTest<T, K> extends CatalogApplicationTest {
|
||||
EntityInterface<T> getEntityInterface = getEntityInterface(getEntity);
|
||||
assertEquals(expectedVersion, getEntityInterface.getVersion());
|
||||
ChangeDescription change = getChangeDescription(entityInterface.getVersion());
|
||||
change.getFieldsUpdated().add(new FieldChange().withName("deleted").withOldValue(false).withNewValue(true));
|
||||
change.getFieldsUpdated().add(new FieldChange().withName(FIELD_DELETED).withOldValue(false).withNewValue(true));
|
||||
assertEquals(change, getEntityInterface.getChangeDescription());
|
||||
} else { // Hard delete
|
||||
validateDeletedEvent(id, timestamp, EventType.ENTITY_DELETED, entityInterface.getVersion(), authHeaders);
|
||||
@ -1689,11 +1696,11 @@ public abstract class EntityResourceTest<T, K> extends CatalogApplicationTest {
|
||||
if (expected == actual) {
|
||||
return;
|
||||
}
|
||||
if (fieldName.endsWith("owner")) {
|
||||
if (fieldName.endsWith(FIELD_OWNER)) {
|
||||
EntityReference expectedRef = (EntityReference) expected;
|
||||
EntityReference actualRef = JsonUtils.readValue(actual.toString(), EntityReference.class);
|
||||
assertEquals(expectedRef.getId(), actualRef.getId());
|
||||
} else if (fieldName.endsWith("tags")) {
|
||||
} else if (fieldName.endsWith(FIELD_TAGS)) {
|
||||
@SuppressWarnings("unchecked")
|
||||
List<TagLabel> expectedTags = (List<TagLabel>) expected;
|
||||
List<TagLabel> actualTags = JsonUtils.readObjects(actual.toString(), TagLabel.class);
|
||||
|
||||
@ -22,6 +22,8 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.openmetadata.catalog.Entity.FIELD_OWNER;
|
||||
import static org.openmetadata.catalog.Entity.FIELD_TAGS;
|
||||
import static org.openmetadata.catalog.Entity.TABLE;
|
||||
import static org.openmetadata.catalog.exception.CatalogExceptionMessage.entityNotFound;
|
||||
import static org.openmetadata.catalog.exception.CatalogExceptionMessage.invalidColumnFQN;
|
||||
@ -1608,14 +1610,14 @@ public class TableResourceTest extends EntityResourceTest<Table, CreateTable> {
|
||||
} else {
|
||||
assertNull(table.getUsageSummary());
|
||||
}
|
||||
if (fields.contains("owner")) {
|
||||
if (fields.contains(FIELD_OWNER)) {
|
||||
assertNotNull(table.getOwner());
|
||||
} else {
|
||||
assertNull(table.getOwner());
|
||||
}
|
||||
if (fields.contains("columns")) {
|
||||
assertNotNull(table.getColumns());
|
||||
if (fields.contains("tags")) {
|
||||
if (fields.contains(FIELD_TAGS)) {
|
||||
table.getColumns().forEach(column -> assertNotNull(column.getTags()));
|
||||
} else {
|
||||
table.getColumns().forEach(column -> assertNull(column.getTags()));
|
||||
@ -1628,7 +1630,7 @@ public class TableResourceTest extends EntityResourceTest<Table, CreateTable> {
|
||||
} else {
|
||||
assertNull(table.getTableConstraints());
|
||||
}
|
||||
if (fields.contains("tags")) {
|
||||
if (fields.contains(FIELD_TAGS)) {
|
||||
assertNotNull(table.getTags());
|
||||
} else {
|
||||
assertNull(table.getTags());
|
||||
@ -2092,7 +2094,7 @@ public class TableResourceTest extends EntityResourceTest<Table, CreateTable> {
|
||||
List<TableConstraint> expectedConstraints = (List<TableConstraint>) expected;
|
||||
List<TableConstraint> actualConstraints = JsonUtils.readObjects(actual.toString(), TableConstraint.class);
|
||||
assertEquals(expectedConstraints, actualConstraints);
|
||||
} else if (fieldName.contains("columns") && !fieldName.endsWith("tags") && !fieldName.endsWith("description")) {
|
||||
} else if (fieldName.contains("columns") && !fieldName.endsWith(FIELD_TAGS) && !fieldName.endsWith("description")) {
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Column> expectedRefs = (List<Column>) expected;
|
||||
List<Column> actualRefs = JsonUtils.readObjects(actual.toString(), Column.class);
|
||||
|
||||
@ -20,6 +20,7 @@ import static javax.ws.rs.core.Response.Status.BAD_REQUEST;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.openmetadata.catalog.Entity.FIELD_TAGS;
|
||||
import static org.openmetadata.catalog.exception.CatalogExceptionMessage.glossaryTermMismatch;
|
||||
import static org.openmetadata.catalog.util.TestUtils.ADMIN_AUTH_HEADERS;
|
||||
import static org.openmetadata.catalog.util.TestUtils.UpdateType.MINOR_UPDATE;
|
||||
@ -211,7 +212,7 @@ public class GlossaryTermResourceTest extends EntityResourceTest<GlossaryTerm, C
|
||||
// Apply tags to term11
|
||||
String json = JsonUtils.pojoToJson(term11);
|
||||
ChangeDescription change = new ChangeDescription();
|
||||
change.getFieldsAdded().add(new FieldChange().withName("tags").withNewValue(List.of(PERSONAL_DATA_TAG_LABEL)));
|
||||
change.getFieldsAdded().add(new FieldChange().withName(FIELD_TAGS).withNewValue(List.of(PERSONAL_DATA_TAG_LABEL)));
|
||||
term11.setTags(List.of(PERSONAL_DATA_TAG_LABEL));
|
||||
patchEntityAndCheck(term11, json, ADMIN_AUTH_HEADERS, MINOR_UPDATE, change);
|
||||
assertEquals(term11.getTags().get(0).getTagFQN(), PERSONAL_DATA_TAG_LABEL.getTagFQN());
|
||||
|
||||
@ -18,6 +18,7 @@ import static javax.ws.rs.core.Response.Status.OK;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.openmetadata.catalog.Entity.FIELD_OWNER;
|
||||
import static org.openmetadata.catalog.util.TestUtils.ADMIN_AUTH_HEADERS;
|
||||
import static org.openmetadata.catalog.util.TestUtils.UpdateType.MINOR_UPDATE;
|
||||
import static org.openmetadata.catalog.util.TestUtils.assertListNotNull;
|
||||
@ -248,7 +249,7 @@ public class IngestionPipelineResourceTest extends EntityResourceTest<IngestionP
|
||||
assertEquals(pipelineConcurrency, ingestion.getAirflowConfig().getConcurrency());
|
||||
assertEquals(expectedFQN, ingestion.getFullyQualifiedName());
|
||||
assertEquals(expectedScheduleInterval, ingestion.getAirflowConfig().getScheduleInterval());
|
||||
ingestion = getEntity(ingestion.getId(), "owner", ADMIN_AUTH_HEADERS);
|
||||
ingestion = getEntity(ingestion.getId(), FIELD_OWNER, ADMIN_AUTH_HEADERS);
|
||||
assertEquals(expectedScheduleInterval, ingestion.getAirflowConfig().getScheduleInterval());
|
||||
}
|
||||
|
||||
@ -286,7 +287,7 @@ public class IngestionPipelineResourceTest extends EntityResourceTest<IngestionP
|
||||
assertEquals(pipelineConcurrency, ingestion.getAirflowConfig().getConcurrency());
|
||||
assertEquals(expectedFQN, ingestion.getFullyQualifiedName());
|
||||
assertEquals(expectedScheduleInterval, ingestion.getAirflowConfig().getScheduleInterval());
|
||||
ingestion = getEntity(ingestion.getId(), "owner", ADMIN_AUTH_HEADERS);
|
||||
ingestion = getEntity(ingestion.getId(), FIELD_OWNER, ADMIN_AUTH_HEADERS);
|
||||
assertEquals(expectedScheduleInterval, ingestion.getAirflowConfig().getScheduleInterval());
|
||||
}
|
||||
|
||||
@ -318,7 +319,7 @@ public class IngestionPipelineResourceTest extends EntityResourceTest<IngestionP
|
||||
assertEquals(pipelineConcurrency, ingestion.getAirflowConfig().getConcurrency());
|
||||
assertEquals(expectedFQN, ingestion.getFullyQualifiedName());
|
||||
assertEquals(expectedScheduleInterval, ingestion.getAirflowConfig().getScheduleInterval());
|
||||
ingestion = getEntity(ingestion.getId(), "owner", ADMIN_AUTH_HEADERS);
|
||||
ingestion = getEntity(ingestion.getId(), FIELD_OWNER, ADMIN_AUTH_HEADERS);
|
||||
assertEquals(expectedScheduleInterval, ingestion.getAirflowConfig().getScheduleInterval());
|
||||
DatabaseServiceMetadataPipeline metadataPipeline =
|
||||
new DatabaseServiceMetadataPipeline()
|
||||
@ -375,7 +376,7 @@ public class IngestionPipelineResourceTest extends EntityResourceTest<IngestionP
|
||||
assertEquals(pipelineConcurrency, ingestion.getAirflowConfig().getConcurrency());
|
||||
assertEquals(expectedFQN, ingestion.getFullyQualifiedName());
|
||||
assertEquals(expectedScheduleInterval, ingestion.getAirflowConfig().getScheduleInterval());
|
||||
ingestion = getEntity(ingestion.getId(), "owner", ADMIN_AUTH_HEADERS);
|
||||
ingestion = getEntity(ingestion.getId(), FIELD_OWNER, ADMIN_AUTH_HEADERS);
|
||||
assertEquals(expectedScheduleInterval, ingestion.getAirflowConfig().getScheduleInterval());
|
||||
DashboardServiceMetadataPipeline dashboardServiceMetadataPipeline =
|
||||
new DashboardServiceMetadataPipeline()
|
||||
@ -429,7 +430,7 @@ public class IngestionPipelineResourceTest extends EntityResourceTest<IngestionP
|
||||
assertEquals(pipelineConcurrency, ingestion.getAirflowConfig().getConcurrency());
|
||||
assertEquals(expectedFQN, ingestion.getFullyQualifiedName());
|
||||
assertEquals(expectedScheduleInterval, ingestion.getAirflowConfig().getScheduleInterval());
|
||||
ingestion = getEntity(ingestion.getId(), "owner", ADMIN_AUTH_HEADERS);
|
||||
ingestion = getEntity(ingestion.getId(), FIELD_OWNER, ADMIN_AUTH_HEADERS);
|
||||
assertEquals(expectedScheduleInterval, ingestion.getAirflowConfig().getScheduleInterval());
|
||||
MessagingServiceMetadataPipeline messagingServiceMetadataPipeline =
|
||||
new MessagingServiceMetadataPipeline()
|
||||
@ -489,7 +490,7 @@ public class IngestionPipelineResourceTest extends EntityResourceTest<IngestionP
|
||||
assertEquals(expectedFQN, ingestion.getFullyQualifiedName());
|
||||
assertEquals(expectedScheduleInterval, ingestion.getAirflowConfig().getScheduleInterval());
|
||||
|
||||
ingestion = getEntity(ingestion.getId(), "owner", ADMIN_AUTH_HEADERS);
|
||||
ingestion = getEntity(ingestion.getId(), FIELD_OWNER, ADMIN_AUTH_HEADERS);
|
||||
assertEquals(expectedScheduleInterval, ingestion.getAirflowConfig().getScheduleInterval());
|
||||
|
||||
// Update and connector orgs and options to database connection
|
||||
@ -593,7 +594,7 @@ public class IngestionPipelineResourceTest extends EntityResourceTest<IngestionP
|
||||
// Add description and tasks
|
||||
ChangeDescription change = getChangeDescription(ingestion.getVersion());
|
||||
change.getFieldsAdded().add(new FieldChange().withName("description").withNewValue("newDescription"));
|
||||
change.getFieldsAdded().add(new FieldChange().withName("owner").withNewValue(USER_OWNER1));
|
||||
change.getFieldsAdded().add(new FieldChange().withName(FIELD_OWNER).withNewValue(USER_OWNER1));
|
||||
updateAndCheckEntity(
|
||||
request.withDescription("newDescription").withOwner(USER_OWNER1), OK, ADMIN_AUTH_HEADERS, MINOR_UPDATE, change);
|
||||
}
|
||||
@ -619,7 +620,7 @@ public class IngestionPipelineResourceTest extends EntityResourceTest<IngestionP
|
||||
assertListNotNull(ingestion.getService());
|
||||
assertListNull(ingestion.getOwner());
|
||||
|
||||
fields = "owner";
|
||||
fields = FIELD_OWNER;
|
||||
ingestion =
|
||||
byName
|
||||
? getEntityByName(ingestion.getFullyQualifiedName(), fields, ADMIN_AUTH_HEADERS)
|
||||
|
||||
@ -15,6 +15,7 @@ package org.openmetadata.catalog.resources.topics;
|
||||
|
||||
import static javax.ws.rs.core.Response.Status.BAD_REQUEST;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.openmetadata.catalog.Entity.FIELD_OWNER;
|
||||
import static org.openmetadata.catalog.util.TestUtils.ADMIN_AUTH_HEADERS;
|
||||
import static org.openmetadata.catalog.util.TestUtils.assertListNotNull;
|
||||
import static org.openmetadata.catalog.util.TestUtils.assertListNull;
|
||||
@ -127,7 +128,7 @@ public class TopicResourceTest extends EntityResourceTest<Topic, CreateTopic> {
|
||||
ChangeDescription change = getChangeDescription(topic.getVersion());
|
||||
change
|
||||
.getFieldsUpdated()
|
||||
.add(new FieldChange().withName("owner").withOldValue(USER_OWNER1).withNewValue(TEAM_OWNER1));
|
||||
.add(new FieldChange().withName(FIELD_OWNER).withOldValue(USER_OWNER1).withNewValue(TEAM_OWNER1));
|
||||
change.getFieldsUpdated().add(new FieldChange().withName("maximumMessageSize").withOldValue(1).withNewValue(2));
|
||||
change.getFieldsUpdated().add(new FieldChange().withName("minimumInSyncReplicas").withOldValue(1).withNewValue(2));
|
||||
change.getFieldsUpdated().add(new FieldChange().withName("partitions").withOldValue(1).withNewValue(2));
|
||||
@ -182,7 +183,7 @@ public class TopicResourceTest extends EntityResourceTest<Topic, CreateTopic> {
|
||||
ChangeDescription change = getChangeDescription(topic.getVersion());
|
||||
change
|
||||
.getFieldsUpdated()
|
||||
.add(new FieldChange().withName("owner").withOldValue(USER_OWNER1).withNewValue(TEAM_OWNER1));
|
||||
.add(new FieldChange().withName(FIELD_OWNER).withOldValue(USER_OWNER1).withNewValue(TEAM_OWNER1));
|
||||
change.getFieldsUpdated().add(new FieldChange().withName("maximumMessageSize").withOldValue(1).withNewValue(2));
|
||||
change.getFieldsUpdated().add(new FieldChange().withName("minimumInSyncReplicas").withOldValue(1).withNewValue(2));
|
||||
change.getFieldsUpdated().add(new FieldChange().withName("partitions").withOldValue(1).withNewValue(2));
|
||||
|
||||
@ -14,6 +14,7 @@
|
||||
package org.openmetadata.catalog.util;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.openmetadata.catalog.Entity.FIELD_OWNER;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import java.io.IOException;
|
||||
@ -89,7 +90,7 @@ public class ChangeEventParserTest extends CatalogApplicationTest {
|
||||
EntityReference entityReference = new EntityReference();
|
||||
entityReference.withId(UUID.randomUUID()).withName("user1").withDisplayName("User One");
|
||||
FieldChange addOwner = new FieldChange();
|
||||
addOwner.withName("owner").withNewValue(JsonUtils.pojoToJson(entityReference));
|
||||
addOwner.withName(FIELD_OWNER).withNewValue(JsonUtils.pojoToJson(entityReference));
|
||||
|
||||
changeDescription.withFieldsAdded(List.of(addOwner)).withPreviousVersion(1.0);
|
||||
|
||||
|
||||
@ -151,7 +151,6 @@ public final class CommonUtil {
|
||||
|
||||
/** Get SHA256 Hash-based Message Authentication Code */
|
||||
public static String calculateHMAC(String secretKey, String message) {
|
||||
// return message;
|
||||
try {
|
||||
Mac mac = Mac.getInstance(HMAC_SHA256_ALGORITHM);
|
||||
SecretKeySpec secretKeySpec =
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user