mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-09-25 08:50:18 +00:00
parent
b8863648d6
commit
76f8664522
@ -23,12 +23,10 @@ import org.jdbi.v3.sqlobject.statement.SqlUpdate;
|
|||||||
import org.jdbi.v3.sqlobject.transaction.Transaction;
|
import org.jdbi.v3.sqlobject.transaction.Transaction;
|
||||||
import org.openmetadata.catalog.type.AuditLog;
|
import org.openmetadata.catalog.type.AuditLog;
|
||||||
import org.openmetadata.catalog.util.EntityUtil;
|
import org.openmetadata.catalog.util.EntityUtil;
|
||||||
|
|
||||||
import org.openmetadata.catalog.util.JsonUtils;
|
import org.openmetadata.catalog.util.JsonUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -39,7 +37,6 @@ public abstract class AuditLogRepository {
|
|||||||
@CreateSqlObject
|
@CreateSqlObject
|
||||||
abstract AuditLogDAO auditLogDAO();
|
abstract AuditLogDAO auditLogDAO();
|
||||||
|
|
||||||
|
|
||||||
@Transaction
|
@Transaction
|
||||||
public List<AuditLog> list() throws IOException {
|
public List<AuditLog> list() throws IOException {
|
||||||
List<String> jsons = auditLogDAO().list();
|
List<String> jsons = auditLogDAO().list();
|
||||||
@ -59,7 +56,7 @@ public abstract class AuditLogRepository {
|
|||||||
public List<AuditLog> getByEntityType(String entityType) throws IOException {
|
public List<AuditLog> getByEntityType(String entityType) throws IOException {
|
||||||
List<String> jsons = auditLogDAO().findByEntityType(entityType);
|
List<String> jsons = auditLogDAO().findByEntityType(entityType);
|
||||||
List<AuditLog> auditLogs = new ArrayList<>();
|
List<AuditLog> auditLogs = new ArrayList<>();
|
||||||
for (String json: jsons) {
|
for (String json : jsons) {
|
||||||
auditLogs.add(JsonUtils.readValue(json, AuditLog.class));
|
auditLogs.add(JsonUtils.readValue(json, AuditLog.class));
|
||||||
}
|
}
|
||||||
return auditLogs;
|
return auditLogs;
|
||||||
@ -76,7 +73,6 @@ public abstract class AuditLogRepository {
|
|||||||
auditLogDAO().delete(id);
|
auditLogDAO().delete(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public interface AuditLogDAO {
|
public interface AuditLogDAO {
|
||||||
@SqlUpdate("INSERT INTO audit_log (json) VALUES (:json)")
|
@SqlUpdate("INSERT INTO audit_log (json) VALUES (:json)")
|
||||||
void insert(@Bind("json") String json);
|
void insert(@Bind("json") String json);
|
||||||
@ -95,6 +91,5 @@ public abstract class AuditLogRepository {
|
|||||||
|
|
||||||
@SqlUpdate("DELETE FROM audit_log_entity WHERE id = :id")
|
@SqlUpdate("DELETE FROM audit_log_entity WHERE id = :id")
|
||||||
int delete(@Bind("id") String id);
|
int delete(@Bind("id") String id);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -26,7 +26,7 @@ import org.openmetadata.catalog.resources.charts.ChartResource;
|
|||||||
import org.openmetadata.catalog.type.EntityReference;
|
import org.openmetadata.catalog.type.EntityReference;
|
||||||
import org.openmetadata.catalog.type.TagLabel;
|
import org.openmetadata.catalog.type.TagLabel;
|
||||||
import org.openmetadata.catalog.util.EntityInterface;
|
import org.openmetadata.catalog.util.EntityInterface;
|
||||||
import org.openmetadata.catalog.util.EntityUpdater3;
|
import org.openmetadata.catalog.util.EntityUpdater;
|
||||||
import org.openmetadata.catalog.util.EntityUtil;
|
import org.openmetadata.catalog.util.EntityUtil;
|
||||||
import org.openmetadata.catalog.util.EntityUtil.Fields;
|
import org.openmetadata.catalog.util.EntityUtil.Fields;
|
||||||
import org.openmetadata.catalog.util.JsonUtils;
|
import org.openmetadata.catalog.util.JsonUtils;
|
||||||
@ -296,7 +296,7 @@ public class ChartRepository extends EntityRepository<Chart> {
|
|||||||
/**
|
/**
|
||||||
* Handles entity updated from PUT and POST operation.
|
* Handles entity updated from PUT and POST operation.
|
||||||
*/
|
*/
|
||||||
public class ChartUpdater extends EntityUpdater3 {
|
public class ChartUpdater extends EntityUpdater {
|
||||||
final Chart orig;
|
final Chart orig;
|
||||||
final Chart updated;
|
final Chart updated;
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ import org.openmetadata.catalog.resources.dashboards.DashboardResource.Dashboard
|
|||||||
import org.openmetadata.catalog.type.EntityReference;
|
import org.openmetadata.catalog.type.EntityReference;
|
||||||
import org.openmetadata.catalog.type.TagLabel;
|
import org.openmetadata.catalog.type.TagLabel;
|
||||||
import org.openmetadata.catalog.util.EntityInterface;
|
import org.openmetadata.catalog.util.EntityInterface;
|
||||||
import org.openmetadata.catalog.util.EntityUpdater3;
|
import org.openmetadata.catalog.util.EntityUpdater;
|
||||||
import org.openmetadata.catalog.util.EntityUtil;
|
import org.openmetadata.catalog.util.EntityUtil;
|
||||||
import org.openmetadata.catalog.util.EntityUtil.Fields;
|
import org.openmetadata.catalog.util.EntityUtil.Fields;
|
||||||
import org.openmetadata.catalog.util.JsonUtils;
|
import org.openmetadata.catalog.util.JsonUtils;
|
||||||
@ -200,7 +200,7 @@ public class DashboardRepository extends EntityRepository<Dashboard> {
|
|||||||
|
|
||||||
private void validateRelationships(Dashboard dashboard)
|
private void validateRelationships(Dashboard dashboard)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
EntityReference dashboardService = getService(dashboard.getService());
|
EntityReference dashboardService = getService(dashboard.getService());
|
||||||
dashboard.setService(dashboardService);
|
dashboard.setService(dashboardService);
|
||||||
dashboard.setFullyQualifiedName(getFQN(dashboard));
|
dashboard.setFullyQualifiedName(getFQN(dashboard));
|
||||||
EntityUtil.populateOwner(dao.userDAO(), dao.teamDAO(), dashboard.getOwner()); // Validate owner
|
EntityUtil.populateOwner(dao.userDAO(), dao.teamDAO(), dashboard.getOwner()); // Validate owner
|
||||||
@ -341,7 +341,7 @@ public class DashboardRepository extends EntityRepository<Dashboard> {
|
|||||||
/**
|
/**
|
||||||
* Handles entity updated from PUT and POST operation.
|
* Handles entity updated from PUT and POST operation.
|
||||||
*/
|
*/
|
||||||
public class DashboardUpdater extends EntityUpdater3 {
|
public class DashboardUpdater extends EntityUpdater {
|
||||||
final Dashboard orig;
|
final Dashboard orig;
|
||||||
final Dashboard updated;
|
final Dashboard updated;
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ import org.openmetadata.catalog.resources.databases.DatabaseResource.DatabaseLis
|
|||||||
import org.openmetadata.catalog.type.EntityReference;
|
import org.openmetadata.catalog.type.EntityReference;
|
||||||
import org.openmetadata.catalog.type.TagLabel;
|
import org.openmetadata.catalog.type.TagLabel;
|
||||||
import org.openmetadata.catalog.util.EntityInterface;
|
import org.openmetadata.catalog.util.EntityInterface;
|
||||||
import org.openmetadata.catalog.util.EntityUpdater3;
|
import org.openmetadata.catalog.util.EntityUpdater;
|
||||||
import org.openmetadata.catalog.util.EntityUtil;
|
import org.openmetadata.catalog.util.EntityUtil;
|
||||||
import org.openmetadata.catalog.util.EntityUtil.Fields;
|
import org.openmetadata.catalog.util.EntityUtil.Fields;
|
||||||
import org.openmetadata.catalog.util.JsonUtils;
|
import org.openmetadata.catalog.util.JsonUtils;
|
||||||
@ -291,7 +291,7 @@ public class DatabaseRepository extends EntityRepository<Database> {
|
|||||||
/**
|
/**
|
||||||
* Handles entity updated from PUT and POST operation.
|
* Handles entity updated from PUT and POST operation.
|
||||||
*/
|
*/
|
||||||
public class DatabaseUpdater extends EntityUpdater3 {
|
public class DatabaseUpdater extends EntityUpdater {
|
||||||
final Database orig;
|
final Database orig;
|
||||||
final Database updated;
|
final Database updated;
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ import org.openmetadata.catalog.resources.metrics.MetricsResource.MetricsList;
|
|||||||
import org.openmetadata.catalog.type.EntityReference;
|
import org.openmetadata.catalog.type.EntityReference;
|
||||||
import org.openmetadata.catalog.type.TagLabel;
|
import org.openmetadata.catalog.type.TagLabel;
|
||||||
import org.openmetadata.catalog.util.EntityInterface;
|
import org.openmetadata.catalog.util.EntityInterface;
|
||||||
import org.openmetadata.catalog.util.EntityUpdater3;
|
import org.openmetadata.catalog.util.EntityUpdater;
|
||||||
import org.openmetadata.catalog.util.EntityUtil;
|
import org.openmetadata.catalog.util.EntityUtil;
|
||||||
import org.openmetadata.catalog.util.EntityUtil.Fields;
|
import org.openmetadata.catalog.util.EntityUtil.Fields;
|
||||||
import org.openmetadata.catalog.util.JsonUtils;
|
import org.openmetadata.catalog.util.JsonUtils;
|
||||||
@ -225,7 +225,7 @@ public class MetricsRepository extends EntityRepository<Metrics> {
|
|||||||
/**
|
/**
|
||||||
* Handles entity updated from PUT and POST operation.
|
* Handles entity updated from PUT and POST operation.
|
||||||
*/
|
*/
|
||||||
public class MetricsUpdater extends EntityUpdater3 {
|
public class MetricsUpdater extends EntityUpdater {
|
||||||
final Metrics orig;
|
final Metrics orig;
|
||||||
final Metrics updated;
|
final Metrics updated;
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ import org.openmetadata.catalog.resources.models.ModelResource.ModelList;
|
|||||||
import org.openmetadata.catalog.type.EntityReference;
|
import org.openmetadata.catalog.type.EntityReference;
|
||||||
import org.openmetadata.catalog.type.TagLabel;
|
import org.openmetadata.catalog.type.TagLabel;
|
||||||
import org.openmetadata.catalog.util.EntityInterface;
|
import org.openmetadata.catalog.util.EntityInterface;
|
||||||
import org.openmetadata.catalog.util.EntityUpdater3;
|
import org.openmetadata.catalog.util.EntityUpdater;
|
||||||
import org.openmetadata.catalog.util.EntityUtil;
|
import org.openmetadata.catalog.util.EntityUtil;
|
||||||
import org.openmetadata.catalog.util.EntityUtil.Fields;
|
import org.openmetadata.catalog.util.EntityUtil.Fields;
|
||||||
import org.openmetadata.catalog.util.JsonUtils;
|
import org.openmetadata.catalog.util.JsonUtils;
|
||||||
@ -309,7 +309,7 @@ public class ModelRepository extends EntityRepository<Model> {
|
|||||||
/**
|
/**
|
||||||
* Handles entity updated from PUT and POST operation.
|
* Handles entity updated from PUT and POST operation.
|
||||||
*/
|
*/
|
||||||
public class ModelUpdater extends EntityUpdater3 {
|
public class ModelUpdater extends EntityUpdater {
|
||||||
final Model orig;
|
final Model orig;
|
||||||
final Model updated;
|
final Model updated;
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ import org.openmetadata.catalog.resources.pipelines.PipelineResource.PipelineLis
|
|||||||
import org.openmetadata.catalog.type.EntityReference;
|
import org.openmetadata.catalog.type.EntityReference;
|
||||||
import org.openmetadata.catalog.type.TagLabel;
|
import org.openmetadata.catalog.type.TagLabel;
|
||||||
import org.openmetadata.catalog.util.EntityInterface;
|
import org.openmetadata.catalog.util.EntityInterface;
|
||||||
import org.openmetadata.catalog.util.EntityUpdater3;
|
import org.openmetadata.catalog.util.EntityUpdater;
|
||||||
import org.openmetadata.catalog.util.EntityUtil;
|
import org.openmetadata.catalog.util.EntityUtil;
|
||||||
import org.openmetadata.catalog.util.EntityUtil.Fields;
|
import org.openmetadata.catalog.util.EntityUtil.Fields;
|
||||||
import org.openmetadata.catalog.util.JsonUtils;
|
import org.openmetadata.catalog.util.JsonUtils;
|
||||||
@ -40,7 +40,6 @@ import javax.ws.rs.core.Response.Status;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.security.GeneralSecurityException;
|
import java.security.GeneralSecurityException;
|
||||||
import java.text.ParseException;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -64,6 +63,7 @@ public class PipelineRepository extends EntityRepository<Pipeline> {
|
|||||||
public static String getFQN(Pipeline pipeline) {
|
public static String getFQN(Pipeline pipeline) {
|
||||||
return (pipeline.getService().getName() + "." + pipeline.getName());
|
return (pipeline.getService().getName() + "." + pipeline.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transaction
|
@Transaction
|
||||||
public Pipeline create(Pipeline pipeline) throws IOException {
|
public Pipeline create(Pipeline pipeline) throws IOException {
|
||||||
validateRelationships(pipeline);
|
validateRelationships(pipeline);
|
||||||
@ -89,7 +89,7 @@ public class PipelineRepository extends EntityRepository<Pipeline> {
|
|||||||
|
|
||||||
@Transaction
|
@Transaction
|
||||||
public Pipeline patch(String id, String user, JsonPatch patch) throws IOException {
|
public Pipeline patch(String id, String user, JsonPatch patch) throws IOException {
|
||||||
Pipeline original = setFields(validatePipeline(id), PIPELINE_PATCH_FIELDS);
|
Pipeline original = setFields(dao.pipelineDAO().findEntityById(id), PIPELINE_PATCH_FIELDS);
|
||||||
Pipeline updated = JsonUtils.applyPatch(original, patch, Pipeline.class);
|
Pipeline updated = JsonUtils.applyPatch(original, patch, Pipeline.class);
|
||||||
updated.withUpdatedBy(user).withUpdatedAt(new Date());
|
updated.withUpdatedBy(user).withUpdatedAt(new Date());
|
||||||
patch(original, updated);
|
patch(original, updated);
|
||||||
@ -128,7 +128,7 @@ public class PipelineRepository extends EntityRepository<Pipeline> {
|
|||||||
|
|
||||||
public static List<EntityReference> toEntityReference(List<Task> tasks) {
|
public static List<EntityReference> toEntityReference(List<Task> tasks) {
|
||||||
List<EntityReference> refList = new ArrayList<>();
|
List<EntityReference> refList = new ArrayList<>();
|
||||||
for (Task task: tasks) {
|
for (Task task : tasks) {
|
||||||
refList.add(EntityUtil.getEntityReference(task));
|
refList.add(EntityUtil.getEntityReference(task));
|
||||||
}
|
}
|
||||||
return refList;
|
return refList;
|
||||||
@ -229,7 +229,8 @@ public class PipelineRepository extends EntityRepository<Pipeline> {
|
|||||||
updated.withFullyQualifiedName(original.getFullyQualifiedName()).withName(original.getName())
|
updated.withFullyQualifiedName(original.getFullyQualifiedName()).withName(original.getName())
|
||||||
.withService(original.getService()).withId(original.getId());
|
.withService(original.getService()).withId(original.getId());
|
||||||
validateRelationships(updated);
|
validateRelationships(updated);
|
||||||
PipelineRepository.PipelineUpdater pipelineUpdater = new PipelineRepository.PipelineUpdater(original, updated, true);
|
PipelineRepository.PipelineUpdater pipelineUpdater = new PipelineRepository.PipelineUpdater(original, updated,
|
||||||
|
true);
|
||||||
pipelineUpdater.updateAll();
|
pipelineUpdater.updateAll();
|
||||||
pipelineUpdater.store();
|
pipelineUpdater.store();
|
||||||
}
|
}
|
||||||
@ -287,7 +288,7 @@ public class PipelineRepository extends EntityRepository<Pipeline> {
|
|||||||
applyTags(pipeline);
|
applyTags(pipeline);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateTaskRelationships(Pipeline pipeline) throws IOException {
|
private void updateTaskRelationships(Pipeline pipeline) throws IOException {
|
||||||
String pipelineId = pipeline.getId().toString();
|
String pipelineId = pipeline.getId().toString();
|
||||||
|
|
||||||
// Add relationship from pipeline to task
|
// Add relationship from pipeline to task
|
||||||
@ -295,7 +296,7 @@ public class PipelineRepository extends EntityRepository<Pipeline> {
|
|||||||
// Remove any existing tasks associated with this pipeline
|
// Remove any existing tasks associated with this pipeline
|
||||||
List<Task> existingTasks = getTasks(pipeline);
|
List<Task> existingTasks = getTasks(pipeline);
|
||||||
if (existingTasks != null) {
|
if (existingTasks != null) {
|
||||||
for (Task task: existingTasks) {
|
for (Task task : existingTasks) {
|
||||||
dao.relationshipDAO().delete(pipelineId, task.getId().toString(), Relationship.CONTAINS.ordinal());
|
dao.relationshipDAO().delete(pipelineId, task.getId().toString(), Relationship.CONTAINS.ordinal());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -307,10 +308,6 @@ public class PipelineRepository extends EntityRepository<Pipeline> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Pipeline validatePipeline(String id) throws IOException {
|
|
||||||
return dao.pipelineDAO().findEntityById(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
static class PipelineEntityInterface implements EntityInterface {
|
static class PipelineEntityInterface implements EntityInterface {
|
||||||
private final Pipeline pipeline;
|
private final Pipeline pipeline;
|
||||||
|
|
||||||
@ -367,12 +364,13 @@ public class PipelineRepository extends EntityRepository<Pipeline> {
|
|||||||
/**
|
/**
|
||||||
* Handles entity updated from PUT and POST operation.
|
* Handles entity updated from PUT and POST operation.
|
||||||
*/
|
*/
|
||||||
public class PipelineUpdater extends EntityUpdater3 {
|
public class PipelineUpdater extends EntityUpdater {
|
||||||
final Pipeline orig;
|
final Pipeline orig;
|
||||||
final Pipeline updated;
|
final Pipeline updated;
|
||||||
|
|
||||||
public PipelineUpdater(Pipeline orig, Pipeline updated, boolean patchOperation) {
|
public PipelineUpdater(Pipeline orig, Pipeline updated, boolean patchOperation) {
|
||||||
super(new PipelineRepository.PipelineEntityInterface(orig), new PipelineRepository.PipelineEntityInterface(updated), patchOperation, dao.relationshipDAO(),
|
super(new PipelineRepository.PipelineEntityInterface(orig),
|
||||||
|
new PipelineRepository.PipelineEntityInterface(updated), patchOperation, dao.relationshipDAO(),
|
||||||
dao.tagDAO());
|
dao.tagDAO());
|
||||||
this.orig = orig;
|
this.orig = orig;
|
||||||
this.updated = updated;
|
this.updated = updated;
|
||||||
@ -385,7 +383,8 @@ public class PipelineRepository extends EntityRepository<Pipeline> {
|
|||||||
|
|
||||||
private void updateTasks() throws IOException {
|
private void updateTasks() throws IOException {
|
||||||
// Airflow lineage backend gets executed per task in a DAG. This means we will not a get full picture of the
|
// Airflow lineage backend gets executed per task in a DAG. This means we will not a get full picture of the
|
||||||
// pipeline in each call. Hence we may create a pipeline and add a single task when one task finishes in a pipeline
|
// pipeline in each call. Hence we may create a pipeline and add a single task when one task finishes in a
|
||||||
|
// pipeline
|
||||||
// in the next task run we may have to update. To take care of this we will merge the tasks
|
// in the next task run we may have to update. To take care of this we will merge the tasks
|
||||||
if (updated.getTasks() == null) {
|
if (updated.getTasks() == null) {
|
||||||
updated.setTasks(orig.getTasks());
|
updated.setTasks(orig.getTasks());
|
||||||
|
@ -37,7 +37,7 @@ import org.openmetadata.catalog.type.TableJoins;
|
|||||||
import org.openmetadata.catalog.type.TableProfile;
|
import org.openmetadata.catalog.type.TableProfile;
|
||||||
import org.openmetadata.catalog.type.TagLabel;
|
import org.openmetadata.catalog.type.TagLabel;
|
||||||
import org.openmetadata.catalog.util.EntityInterface;
|
import org.openmetadata.catalog.util.EntityInterface;
|
||||||
import org.openmetadata.catalog.util.EntityUpdater3;
|
import org.openmetadata.catalog.util.EntityUpdater;
|
||||||
import org.openmetadata.catalog.util.EntityUtil;
|
import org.openmetadata.catalog.util.EntityUtil;
|
||||||
import org.openmetadata.catalog.util.EntityUtil.Fields;
|
import org.openmetadata.catalog.util.EntityUtil.Fields;
|
||||||
import org.openmetadata.catalog.util.EventUtils;
|
import org.openmetadata.catalog.util.EventUtils;
|
||||||
@ -599,8 +599,8 @@ public class TableRepository extends EntityRepository<Table> {
|
|||||||
private List<TableProfile> getTableProfile(Table table) throws IOException {
|
private List<TableProfile> getTableProfile(Table table) throws IOException {
|
||||||
List<TableProfile> tableProfiles =
|
List<TableProfile> tableProfiles =
|
||||||
JsonUtils.readObjects(dao.entityExtensionDAO().getExtension(table.getId().toString(),
|
JsonUtils.readObjects(dao.entityExtensionDAO().getExtension(table.getId().toString(),
|
||||||
"table.tableProfile"),
|
"table.tableProfile"),
|
||||||
TableProfile.class);
|
TableProfile.class);
|
||||||
if (tableProfiles != null) {
|
if (tableProfiles != null) {
|
||||||
tableProfiles.sort(Comparator.comparing(p -> parseDate(p.getProfileDate(), RestUtil.DATE_FORMAT),
|
tableProfiles.sort(Comparator.comparing(p -> parseDate(p.getProfileDate(), RestUtil.DATE_FORMAT),
|
||||||
Comparator.reverseOrder()));
|
Comparator.reverseOrder()));
|
||||||
@ -665,7 +665,7 @@ public class TableRepository extends EntityRepository<Table> {
|
|||||||
/**
|
/**
|
||||||
* Handles entity updated from PUT and POST operation.
|
* Handles entity updated from PUT and POST operation.
|
||||||
*/
|
*/
|
||||||
public class TableUpdater extends EntityUpdater3 {
|
public class TableUpdater extends EntityUpdater {
|
||||||
final Table orig;
|
final Table orig;
|
||||||
final Table updated;
|
final Table updated;
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ import org.openmetadata.catalog.resources.tasks.TaskResource.TaskList;
|
|||||||
import org.openmetadata.catalog.type.EntityReference;
|
import org.openmetadata.catalog.type.EntityReference;
|
||||||
import org.openmetadata.catalog.type.TagLabel;
|
import org.openmetadata.catalog.type.TagLabel;
|
||||||
import org.openmetadata.catalog.util.EntityInterface;
|
import org.openmetadata.catalog.util.EntityInterface;
|
||||||
import org.openmetadata.catalog.util.EntityUpdater3;
|
import org.openmetadata.catalog.util.EntityUpdater;
|
||||||
import org.openmetadata.catalog.util.EntityUtil;
|
import org.openmetadata.catalog.util.EntityUtil;
|
||||||
import org.openmetadata.catalog.util.EntityUtil.Fields;
|
import org.openmetadata.catalog.util.EntityUtil.Fields;
|
||||||
import org.openmetadata.catalog.util.JsonUtils;
|
import org.openmetadata.catalog.util.JsonUtils;
|
||||||
@ -285,7 +285,7 @@ public class TaskRepository extends EntityRepository<Task> {
|
|||||||
/**
|
/**
|
||||||
* Handles entity updated from PUT and POST operation.
|
* Handles entity updated from PUT and POST operation.
|
||||||
*/
|
*/
|
||||||
public class TaskUpdater extends EntityUpdater3 {
|
public class TaskUpdater extends EntityUpdater {
|
||||||
final Task orig;
|
final Task orig;
|
||||||
final Task updated;
|
final Task updated;
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ import org.openmetadata.catalog.resources.teams.TeamResource.TeamList;
|
|||||||
import org.openmetadata.catalog.type.EntityReference;
|
import org.openmetadata.catalog.type.EntityReference;
|
||||||
import org.openmetadata.catalog.type.TagLabel;
|
import org.openmetadata.catalog.type.TagLabel;
|
||||||
import org.openmetadata.catalog.util.EntityInterface;
|
import org.openmetadata.catalog.util.EntityInterface;
|
||||||
import org.openmetadata.catalog.util.EntityUpdater3;
|
import org.openmetadata.catalog.util.EntityUpdater;
|
||||||
import org.openmetadata.catalog.util.EntityUtil;
|
import org.openmetadata.catalog.util.EntityUtil;
|
||||||
import org.openmetadata.catalog.util.EntityUtil.Fields;
|
import org.openmetadata.catalog.util.EntityUtil.Fields;
|
||||||
import org.openmetadata.catalog.util.JsonUtils;
|
import org.openmetadata.catalog.util.JsonUtils;
|
||||||
@ -227,7 +227,7 @@ public class TeamRepository extends EntityRepository<Team> {
|
|||||||
/**
|
/**
|
||||||
* Handles entity updated from PUT and POST operation.
|
* Handles entity updated from PUT and POST operation.
|
||||||
*/
|
*/
|
||||||
public class TeamUpdater extends EntityUpdater3 {
|
public class TeamUpdater extends EntityUpdater {
|
||||||
final Team orig;
|
final Team orig;
|
||||||
final Team updated;
|
final Team updated;
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ import org.openmetadata.catalog.resources.topics.TopicResource.TopicList;
|
|||||||
import org.openmetadata.catalog.type.EntityReference;
|
import org.openmetadata.catalog.type.EntityReference;
|
||||||
import org.openmetadata.catalog.type.TagLabel;
|
import org.openmetadata.catalog.type.TagLabel;
|
||||||
import org.openmetadata.catalog.util.EntityInterface;
|
import org.openmetadata.catalog.util.EntityInterface;
|
||||||
import org.openmetadata.catalog.util.EntityUpdater3;
|
import org.openmetadata.catalog.util.EntityUpdater;
|
||||||
import org.openmetadata.catalog.util.EntityUtil;
|
import org.openmetadata.catalog.util.EntityUtil;
|
||||||
import org.openmetadata.catalog.util.EntityUtil.Fields;
|
import org.openmetadata.catalog.util.EntityUtil.Fields;
|
||||||
import org.openmetadata.catalog.util.JsonUtils;
|
import org.openmetadata.catalog.util.JsonUtils;
|
||||||
@ -300,7 +300,7 @@ public class TopicRepository extends EntityRepository<Topic> {
|
|||||||
/**
|
/**
|
||||||
* Handles entity updated from PUT and POST operation.
|
* Handles entity updated from PUT and POST operation.
|
||||||
*/
|
*/
|
||||||
public class TopicUpdater extends EntityUpdater3 {
|
public class TopicUpdater extends EntityUpdater {
|
||||||
final Topic orig;
|
final Topic orig;
|
||||||
final Topic updated;
|
final Topic updated;
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ import org.openmetadata.catalog.resources.teams.UserResource.UserList;
|
|||||||
import org.openmetadata.catalog.type.EntityReference;
|
import org.openmetadata.catalog.type.EntityReference;
|
||||||
import org.openmetadata.catalog.type.TagLabel;
|
import org.openmetadata.catalog.type.TagLabel;
|
||||||
import org.openmetadata.catalog.util.EntityInterface;
|
import org.openmetadata.catalog.util.EntityInterface;
|
||||||
import org.openmetadata.catalog.util.EntityUpdater3;
|
import org.openmetadata.catalog.util.EntityUpdater;
|
||||||
import org.openmetadata.catalog.util.EntityUtil;
|
import org.openmetadata.catalog.util.EntityUtil;
|
||||||
import org.openmetadata.catalog.util.EntityUtil.Fields;
|
import org.openmetadata.catalog.util.EntityUtil.Fields;
|
||||||
import org.openmetadata.catalog.util.JsonUtils;
|
import org.openmetadata.catalog.util.JsonUtils;
|
||||||
@ -321,7 +321,7 @@ public class UserRepository extends EntityRepository<User> {
|
|||||||
/**
|
/**
|
||||||
* Handles entity updated from PUT and POST operation.
|
* Handles entity updated from PUT and POST operation.
|
||||||
*/
|
*/
|
||||||
public class UserUpdater extends EntityUpdater3 {
|
public class UserUpdater extends EntityUpdater {
|
||||||
final User orig;
|
final User orig;
|
||||||
final User updated;
|
final User updated;
|
||||||
|
|
||||||
|
@ -17,15 +17,15 @@ import java.util.List;
|
|||||||
* - description
|
* - description
|
||||||
* - tags
|
* - tags
|
||||||
* - owner
|
* - owner
|
||||||
*
|
* <p>
|
||||||
* This class handles tracking all the changes in an update operation and also versioning
|
* This class handles tracking all the changes in an update operation and also versioning
|
||||||
* of the entity.
|
* of the entity.
|
||||||
*
|
* <p>
|
||||||
* Concrete implementations need to implement update for other fields. See
|
* Concrete implementations need to implement update for other fields. See
|
||||||
* {@link TableRepository.TableUpdater} for an example implementation.
|
* {@link TableRepository.TableUpdater} for an example implementation.
|
||||||
*/
|
*/
|
||||||
public abstract class EntityUpdater3 {
|
public abstract class EntityUpdater {
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(EntityUpdater3.class);
|
private static final Logger LOG = LoggerFactory.getLogger(EntityUpdater.class);
|
||||||
private final EntityInterface originalEntity;
|
private final EntityInterface originalEntity;
|
||||||
private final EntityInterface updatedEntity;
|
private final EntityInterface updatedEntity;
|
||||||
private final EntityRelationshipDAO relationshipDAO;
|
private final EntityRelationshipDAO relationshipDAO;
|
||||||
@ -37,8 +37,8 @@ public abstract class EntityUpdater3 {
|
|||||||
protected List<String> fieldsDeleted = new ArrayList<>();
|
protected List<String> fieldsDeleted = new ArrayList<>();
|
||||||
protected boolean majorVersionChange = false;
|
protected boolean majorVersionChange = false;
|
||||||
|
|
||||||
public EntityUpdater3(EntityInterface originalEntity, EntityInterface updatedEntity, boolean patchOperation,
|
public EntityUpdater(EntityInterface originalEntity, EntityInterface updatedEntity, boolean patchOperation,
|
||||||
EntityRelationshipDAO relationshipDAO, TagDAO tagDAO) {
|
EntityRelationshipDAO relationshipDAO, TagDAO tagDAO) {
|
||||||
this.originalEntity = originalEntity;
|
this.originalEntity = originalEntity;
|
||||||
this.updatedEntity = updatedEntity;
|
this.updatedEntity = updatedEntity;
|
||||||
this.patchOperation = patchOperation;
|
this.patchOperation = patchOperation;
|
@ -42,7 +42,6 @@ import org.openmetadata.catalog.jdbi3.CollectionDAO.EntityRelationshipDAO;
|
|||||||
import org.openmetadata.catalog.jdbi3.CollectionDAO.MetricsDAO;
|
import org.openmetadata.catalog.jdbi3.CollectionDAO.MetricsDAO;
|
||||||
import org.openmetadata.catalog.jdbi3.CollectionDAO.ModelDAO;
|
import org.openmetadata.catalog.jdbi3.CollectionDAO.ModelDAO;
|
||||||
import org.openmetadata.catalog.jdbi3.CollectionDAO.PipelineDAO;
|
import org.openmetadata.catalog.jdbi3.CollectionDAO.PipelineDAO;
|
||||||
import org.openmetadata.catalog.jdbi3.Relationship;
|
|
||||||
import org.openmetadata.catalog.jdbi3.CollectionDAO.ReportDAO;
|
import org.openmetadata.catalog.jdbi3.CollectionDAO.ReportDAO;
|
||||||
import org.openmetadata.catalog.jdbi3.CollectionDAO.TableDAO;
|
import org.openmetadata.catalog.jdbi3.CollectionDAO.TableDAO;
|
||||||
import org.openmetadata.catalog.jdbi3.CollectionDAO.TagDAO;
|
import org.openmetadata.catalog.jdbi3.CollectionDAO.TagDAO;
|
||||||
@ -51,6 +50,7 @@ import org.openmetadata.catalog.jdbi3.CollectionDAO.TeamDAO;
|
|||||||
import org.openmetadata.catalog.jdbi3.CollectionDAO.TopicDAO;
|
import org.openmetadata.catalog.jdbi3.CollectionDAO.TopicDAO;
|
||||||
import org.openmetadata.catalog.jdbi3.CollectionDAO.UsageDAO;
|
import org.openmetadata.catalog.jdbi3.CollectionDAO.UsageDAO;
|
||||||
import org.openmetadata.catalog.jdbi3.CollectionDAO.UserDAO;
|
import org.openmetadata.catalog.jdbi3.CollectionDAO.UserDAO;
|
||||||
|
import org.openmetadata.catalog.jdbi3.Relationship;
|
||||||
import org.openmetadata.catalog.resources.charts.ChartResource;
|
import org.openmetadata.catalog.resources.charts.ChartResource;
|
||||||
import org.openmetadata.catalog.resources.dashboards.DashboardResource;
|
import org.openmetadata.catalog.resources.dashboards.DashboardResource;
|
||||||
import org.openmetadata.catalog.resources.databases.DatabaseResource;
|
import org.openmetadata.catalog.resources.databases.DatabaseResource;
|
||||||
@ -211,6 +211,7 @@ public final class EntityUtil {
|
|||||||
}
|
}
|
||||||
return owner;
|
return owner;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setOwner(EntityRelationshipDAO dao, UUID ownedEntityId, String ownedEntityType,
|
public static void setOwner(EntityRelationshipDAO dao, UUID ownedEntityId, String ownedEntityType,
|
||||||
EntityReference owner) {
|
EntityReference owner) {
|
||||||
// Add relationship owner --- owns ---> ownedEntity
|
// Add relationship owner --- owns ---> ownedEntity
|
||||||
@ -253,8 +254,6 @@ public final class EntityUtil {
|
|||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static EntityReference getEntityReference3(EntityReference ref, TableDAO tableDAO, DatabaseDAO databaseDAO,
|
public static EntityReference getEntityReference3(EntityReference ref, TableDAO tableDAO, DatabaseDAO databaseDAO,
|
||||||
MetricsDAO metricsDAO, DashboardDAO dashboardDAO,
|
MetricsDAO metricsDAO, DashboardDAO dashboardDAO,
|
||||||
ReportDAO reportDAO, TopicDAO topicDAO, ChartDAO chartDAO,
|
ReportDAO reportDAO, TopicDAO topicDAO, ChartDAO chartDAO,
|
||||||
@ -528,29 +527,6 @@ public final class EntityUtil {
|
|||||||
.withName(user.getName()).withType(Entity.USER);
|
.withName(user.getName()).withType(Entity.USER);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Apply tags {@code tagLabels} to the entity or field identified by {@code targetFQN}
|
|
||||||
*/
|
|
||||||
public static void applyTags(org.openmetadata.catalog.jdbi3.TagDAO tagDAO, List<TagLabel> tagLabels, String targetFQN) throws IOException {
|
|
||||||
for (TagLabel tagLabel : Optional.ofNullable(tagLabels).orElse(Collections.emptyList())) {
|
|
||||||
String json = tagDAO.findTag(tagLabel.getTagFQN());
|
|
||||||
if (json == null) {
|
|
||||||
// Invalid TagLabel
|
|
||||||
throw EntityNotFoundException.byMessage(CatalogExceptionMessage.entityNotFound(Tag.class.getSimpleName(),
|
|
||||||
tagLabel.getTagFQN()));
|
|
||||||
}
|
|
||||||
Tag tag = JsonUtils.readValue(json, Tag.class);
|
|
||||||
|
|
||||||
// Apply tagLabel to targetFQN that identifies an entity or field
|
|
||||||
tagDAO.applyTag(tagLabel.getTagFQN(), targetFQN, tagLabel.getLabelType().ordinal(),
|
|
||||||
tagLabel.getState().ordinal());
|
|
||||||
|
|
||||||
// Apply derived tags
|
|
||||||
List<TagLabel> derivedTags = getDerivedTags(tagLabel, tag);
|
|
||||||
applyTags(tagDAO, derivedTags, targetFQN);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Apply tags {@code tagLabels} to the entity or field identified by {@code targetFQN}
|
* Apply tags {@code tagLabels} to the entity or field identified by {@code targetFQN}
|
||||||
*/
|
*/
|
||||||
@ -573,6 +549,7 @@ public final class EntityUtil {
|
|||||||
applyTags(tagDAO, derivedTags, targetFQN);
|
applyTags(tagDAO, derivedTags, targetFQN);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<TagLabel> getDerivedTags(TagLabel tagLabel, Tag tag) {
|
public static List<TagLabel> getDerivedTags(TagLabel tagLabel, Tag tag) {
|
||||||
List<TagLabel> derivedTags = new ArrayList<>();
|
List<TagLabel> derivedTags = new ArrayList<>();
|
||||||
for (String fqn : Optional.ofNullable(tag.getAssociatedTags()).orElse(Collections.emptyList())) {
|
for (String fqn : Optional.ofNullable(tag.getAssociatedTags()).orElse(Collections.emptyList())) {
|
||||||
@ -581,28 +558,6 @@ public final class EntityUtil {
|
|||||||
return derivedTags;
|
return derivedTags;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Validate given list of tags and add derived tags to it
|
|
||||||
*/
|
|
||||||
public static List<TagLabel> addDerivedTags(org.openmetadata.catalog.jdbi3.TagDAO tagDAO, List<TagLabel> tagLabels) throws IOException {
|
|
||||||
List<TagLabel> updatedTagLabels = new ArrayList<>();
|
|
||||||
for (TagLabel tagLabel : Optional.ofNullable(tagLabels).orElse(Collections.emptyList())) {
|
|
||||||
String json = tagDAO.findTag(tagLabel.getTagFQN());
|
|
||||||
if (json == null) {
|
|
||||||
// Invalid TagLabel
|
|
||||||
throw EntityNotFoundException.byMessage(CatalogExceptionMessage.entityNotFound(Tag.class.getSimpleName(),
|
|
||||||
tagLabel.getTagFQN()));
|
|
||||||
}
|
|
||||||
Tag tag = JsonUtils.readValue(json, Tag.class);
|
|
||||||
updatedTagLabels.add(tagLabel);
|
|
||||||
|
|
||||||
// Apply derived tags
|
|
||||||
List<TagLabel> derivedTags = getDerivedTags(tagLabel, tag);
|
|
||||||
updatedTagLabels = EntityUtil.mergeTags(updatedTagLabels, derivedTags);
|
|
||||||
}
|
|
||||||
return updatedTagLabels;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validate given list of tags and add derived tags to it
|
* Validate given list of tags and add derived tags to it
|
||||||
*/
|
*/
|
||||||
@ -624,12 +579,9 @@ public final class EntityUtil {
|
|||||||
}
|
}
|
||||||
return updatedTagLabels;
|
return updatedTagLabels;
|
||||||
}
|
}
|
||||||
public static void removeTags(org.openmetadata.catalog.jdbi3.TagDAO tagDAO, String fullyQualifiedName) {
|
|
||||||
tagDAO.deleteTags(fullyQualifiedName);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void removeTagsByPrefix(org.openmetadata.catalog.jdbi3.TagDAO tagDAO, String fullyQualifiedName) {
|
public static void removeTags(TagDAO tagDAO, String fullyQualifiedName) {
|
||||||
tagDAO.deleteTagsByPrefix(fullyQualifiedName);
|
tagDAO.deleteTags(fullyQualifiedName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void removeTagsByPrefix(TagDAO tagDAO, String fullyQualifiedName) {
|
public static void removeTagsByPrefix(TagDAO tagDAO, String fullyQualifiedName) {
|
||||||
@ -685,6 +637,7 @@ public final class EntityUtil {
|
|||||||
}
|
}
|
||||||
return followers;
|
return followers;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Fields {
|
public static class Fields {
|
||||||
private final List<String> fieldList;
|
private final List<String> fieldList;
|
||||||
|
|
||||||
@ -719,7 +672,7 @@ public final class EntityUtil {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
List<EntityReference> refList = new ArrayList<>();
|
List<EntityReference> refList = new ArrayList<>();
|
||||||
for (Chart chart: charts) {
|
for (Chart chart : charts) {
|
||||||
refList.add(EntityUtil.getEntityReference(chart));
|
refList.add(EntityUtil.getEntityReference(chart));
|
||||||
}
|
}
|
||||||
return refList;
|
return refList;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user