mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-12-16 18:15:17 +00:00
Provide default methods to prevent repository classes having to override the methods
This commit is contained in:
parent
a30fc96fa9
commit
363262a699
@ -48,7 +48,6 @@ public class CatalogGenericExceptionMapper implements ExceptionMapper<Throwable>
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Response toResponse(Throwable ex) {
|
public Response toResponse(Throwable ex) {
|
||||||
ex.printStackTrace();
|
|
||||||
if (ex instanceof ProcessingException || ex instanceof IllegalArgumentException) {
|
if (ex instanceof ProcessingException || ex instanceof IllegalArgumentException) {
|
||||||
final Response response = BadRequestException.of().getResponse();
|
final Response response = BadRequestException.of().getResponse();
|
||||||
return Response.fromResponse(response)
|
return Response.fromResponse(response)
|
||||||
|
|||||||
@ -81,11 +81,6 @@ public class BotsRepository extends EntityRepository<Bots>{
|
|||||||
@Override
|
@Override
|
||||||
public void storeRelationships(Bots entity) throws IOException { }
|
public void storeRelationships(Bots entity) throws IOException { }
|
||||||
|
|
||||||
@Override
|
|
||||||
public EntityUpdater getUpdater(Bots original, Bots updated, boolean patchOperation) throws IOException {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
static class BotsEntityInterface implements EntityInterface<Bots> {
|
static class BotsEntityInterface implements EntityInterface<Bots> {
|
||||||
private final Bots entity;
|
private final Bots entity;
|
||||||
|
|
||||||
|
|||||||
@ -104,12 +104,6 @@ public class ChartRepository extends EntityRepository<Chart> {
|
|||||||
applyTags(chart);
|
applyTags(chart);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public EntityUpdater getUpdater(Chart original, Chart updated, boolean patchOperation) throws IOException {
|
|
||||||
return new ChartUpdater(original, updated, patchOperation);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private void applyTags(Chart chart) throws IOException {
|
private void applyTags(Chart chart) throws IOException {
|
||||||
// Add chart level tags by adding tag to chart relationship
|
// Add chart level tags by adding tag to chart relationship
|
||||||
EntityUtil.applyTags(dao.tagDAO(), chart.getTags(), chart.getFullyQualifiedName());
|
EntityUtil.applyTags(dao.tagDAO(), chart.getTags(), chart.getFullyQualifiedName());
|
||||||
@ -270,18 +264,4 @@ public class ChartRepository extends EntityRepository<Chart> {
|
|||||||
entity.setTags(tags);
|
entity.setTags(tags);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Handles entity updated from PUT and POST operation.
|
|
||||||
*/
|
|
||||||
public class ChartUpdater extends EntityUpdater {
|
|
||||||
public ChartUpdater(Chart original, Chart updated, boolean patchOperation) {
|
|
||||||
super(original, updated, patchOperation);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void entitySpecificUpdate() throws IOException {
|
|
||||||
// No special updates beyond
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -341,6 +341,11 @@ public class DashboardRepository extends EntityRepository<Dashboard> {
|
|||||||
super(original, updated, patchOperation);
|
super(original, updated, patchOperation);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void entitySpecificUpdate() throws IOException {
|
||||||
|
updateCharts();
|
||||||
|
}
|
||||||
|
|
||||||
private void updateCharts() {
|
private void updateCharts() {
|
||||||
String dashboardId = updated.getId().toString();
|
String dashboardId = updated.getId().toString();
|
||||||
|
|
||||||
@ -358,10 +363,5 @@ public class DashboardRepository extends EntityRepository<Dashboard> {
|
|||||||
List<UUID> updatedChartIds = EntityUtil.getIDList(updated.getEntity().getCharts());
|
List<UUID> updatedChartIds = EntityUtil.getIDList(updated.getEntity().getCharts());
|
||||||
recordChange("charts", origChartIds, updatedChartIds);
|
recordChange("charts", origChartIds, updatedChartIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void entitySpecificUpdate() throws IOException {
|
|
||||||
updateCharts();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -111,12 +111,6 @@ public class DashboardServiceRepository extends EntityRepository<DashboardServic
|
|||||||
public void storeRelationships(DashboardService entity) throws IOException {
|
public void storeRelationships(DashboardService entity) throws IOException {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public EntityUpdater getUpdater(DashboardService original, DashboardService updated, boolean patchOperation)
|
|
||||||
throws IOException {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class DashboardServiceEntityInterface implements EntityInterface<DashboardService> {
|
public static class DashboardServiceEntityInterface implements EntityInterface<DashboardService> {
|
||||||
private final DashboardService entity;
|
private final DashboardService entity;
|
||||||
|
|
||||||
|
|||||||
@ -100,15 +100,9 @@ public class DatabaseRepository extends EntityRepository<Database> {
|
|||||||
EntityUtil.setOwner(dao.relationshipDAO(), database.getId(), Entity.DATABASE, database.getOwner());
|
EntityUtil.setOwner(dao.relationshipDAO(), database.getId(), Entity.DATABASE, database.getOwner());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public EntityUpdater getUpdater(Database original, Database updated, boolean patchOperation) throws IOException {
|
|
||||||
return new DatabaseUpdater(original, updated, patchOperation);
|
|
||||||
}
|
|
||||||
|
|
||||||
public EntityReference getOwner(Database database) throws IOException {
|
public EntityReference getOwner(Database database) throws IOException {
|
||||||
return database != null ? EntityUtil.populateOwner(database.getId(), dao.relationshipDAO(), dao.userDAO(),
|
return database != null ? EntityUtil.populateOwner(database.getId(), dao.relationshipDAO(), dao.userDAO(),
|
||||||
dao.teamDAO())
|
dao.teamDAO()) : null;
|
||||||
: null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<EntityReference> getTables(Database database) throws IOException {
|
private List<EntityReference> getTables(Database database) throws IOException {
|
||||||
@ -241,18 +235,4 @@ public class DatabaseRepository extends EntityRepository<Database> {
|
|||||||
@Override
|
@Override
|
||||||
public void setTags(List<TagLabel> tags) { }
|
public void setTags(List<TagLabel> tags) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Handles entity updated from PUT and POST operation.
|
|
||||||
*/
|
|
||||||
public class DatabaseUpdater extends EntityUpdater {
|
|
||||||
public DatabaseUpdater(Database original, Database updated, boolean patchOperation) {
|
|
||||||
super(original, updated, patchOperation);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void entitySpecificUpdate() throws IOException {
|
|
||||||
// Nothing special to do
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -111,11 +111,6 @@ public class DatabaseServiceRepository extends EntityRepository<DatabaseService>
|
|||||||
public void storeRelationships(DatabaseService entity) throws IOException {
|
public void storeRelationships(DatabaseService entity) throws IOException {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public EntityUpdater getUpdater(DatabaseService original, DatabaseService updated, boolean patchOperation) throws IOException {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class DatabaseServiceEntityInterface implements EntityInterface<DatabaseService> {
|
public static class DatabaseServiceEntityInterface implements EntityInterface<DatabaseService> {
|
||||||
private final DatabaseService entity;
|
private final DatabaseService entity;
|
||||||
|
|
||||||
|
|||||||
@ -36,6 +36,25 @@ public abstract class EntityRepository<T> {
|
|||||||
private final Fields patchFields;
|
private final Fields patchFields;
|
||||||
private final Fields putFields;
|
private final Fields putFields;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Entity related operations that should be implemented or overridden by entities
|
||||||
|
*/
|
||||||
|
public abstract String getFullyQualifiedName(T entity);
|
||||||
|
public abstract ResultList<T> getResultList(List<T> entities, String beforeCursor, String afterCursor,
|
||||||
|
int total) throws GeneralSecurityException, UnsupportedEncodingException;
|
||||||
|
public abstract EntityInterface<T> getEntityInterface(T entity);
|
||||||
|
|
||||||
|
public abstract T setFields(T entity, Fields fields) throws IOException, ParseException;
|
||||||
|
public abstract void restorePatchAttributes(T original, T updated) throws IOException, ParseException;
|
||||||
|
|
||||||
|
public abstract void validate(T entity) throws IOException;
|
||||||
|
public abstract void store(T entity, boolean update) throws IOException;
|
||||||
|
public abstract void storeRelationships(T entity) throws IOException;
|
||||||
|
|
||||||
|
public EntityUpdater getUpdater(T original, T updated, boolean patchOperation) throws IOException {
|
||||||
|
return new EntityUpdater(original, updated, patchOperation);
|
||||||
|
}
|
||||||
|
|
||||||
EntityRepository(Class<T> entityClass, EntityDAO<T> entityDAO, CollectionDAO collectionDAO,
|
EntityRepository(Class<T> entityClass, EntityDAO<T> entityDAO, CollectionDAO collectionDAO,
|
||||||
Fields patchFields, Fields putFields) {
|
Fields patchFields, Fields putFields) {
|
||||||
this.entityClass = entityClass;
|
this.entityClass = entityClass;
|
||||||
@ -129,8 +148,8 @@ public abstract class EntityRepository<T> {
|
|||||||
updatedEntity.setUpdatedBy(user);
|
updatedEntity.setUpdatedBy(user);
|
||||||
updatedEntity.setUpdatedAt(new Date());
|
updatedEntity.setUpdatedAt(new Date());
|
||||||
|
|
||||||
restorePatchAttributes(original, updated);
|
|
||||||
validate(updated);
|
validate(updated);
|
||||||
|
restorePatchAttributes(original, updated);
|
||||||
EntityUpdater entityUpdater = getUpdater(original, updated, true);
|
EntityUpdater entityUpdater = getUpdater(original, updated, true);
|
||||||
entityUpdater.update();
|
entityUpdater.update();
|
||||||
entityUpdater.store();
|
entityUpdater.store();
|
||||||
@ -144,25 +163,11 @@ public abstract class EntityRepository<T> {
|
|||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO clean up all the exceptions and check if they are really thrown
|
|
||||||
/**
|
/**
|
||||||
* Entity related operations
|
* Class that performs PUT and PATCH UPDATE operation. Override {@code entitySpecificUpdate()} to add
|
||||||
|
* additional entity specific fields to be updated.
|
||||||
*/
|
*/
|
||||||
public abstract String getFullyQualifiedName(T entity);
|
public class EntityUpdater {
|
||||||
public abstract ResultList<T> getResultList(List<T> entities, String beforeCursor, String afterCursor,
|
|
||||||
int total) throws GeneralSecurityException, UnsupportedEncodingException;
|
|
||||||
public abstract EntityInterface<T> getEntityInterface(T entity);
|
|
||||||
|
|
||||||
public abstract T setFields(T entity, Fields fields) throws IOException, ParseException;
|
|
||||||
public abstract void restorePatchAttributes(T original, T updated) throws IOException, ParseException;
|
|
||||||
|
|
||||||
public abstract void validate(T entity) throws IOException;
|
|
||||||
public abstract void store(T entity, boolean update) throws IOException;
|
|
||||||
public abstract void storeRelationships(T entity) throws IOException;
|
|
||||||
public abstract EntityUpdater getUpdater(T original, T updated, boolean patchOperation) throws IOException;
|
|
||||||
|
|
||||||
// TODO better name
|
|
||||||
public abstract class EntityUpdater {
|
|
||||||
protected final EntityInterface<T> original;
|
protected final EntityInterface<T> original;
|
||||||
protected final EntityInterface<T> updated;
|
protected final EntityInterface<T> updated;
|
||||||
protected final boolean patchOperation;
|
protected final boolean patchOperation;
|
||||||
@ -186,6 +191,10 @@ public abstract class EntityRepository<T> {
|
|||||||
entitySpecificUpdate();
|
entitySpecificUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void entitySpecificUpdate() throws IOException {
|
||||||
|
// Default implementation. Override this to add any entity specific field updates
|
||||||
|
}
|
||||||
|
|
||||||
private void updateDescription() {
|
private void updateDescription() {
|
||||||
if (!patchOperation &&
|
if (!patchOperation &&
|
||||||
original.getDescription() != null && !original.getDescription().isEmpty()) {
|
original.getDescription() != null && !original.getDescription().isEmpty()) {
|
||||||
@ -229,7 +238,6 @@ public abstract class EntityRepository<T> {
|
|||||||
EntityUtil.applyTags(daoCollection.tagDAO(), updated.getTags(), updated.getFullyQualifiedName());
|
EntityUtil.applyTags(daoCollection.tagDAO(), updated.getTags(), updated.getFullyQualifiedName());
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract void entitySpecificUpdate() throws IOException;
|
|
||||||
|
|
||||||
public final Double getNewVersion(Double oldVersion) {
|
public final Double getNewVersion(Double oldVersion) {
|
||||||
Double newVersion = oldVersion;
|
Double newVersion = oldVersion;
|
||||||
|
|||||||
@ -112,12 +112,6 @@ public class MessagingServiceRepository extends EntityRepository<MessagingServic
|
|||||||
@Override
|
@Override
|
||||||
public void storeRelationships(MessagingService entity) throws IOException { }
|
public void storeRelationships(MessagingService entity) throws IOException { }
|
||||||
|
|
||||||
@Override
|
|
||||||
public EntityUpdater getUpdater(MessagingService original, MessagingService updated, boolean patchOperation)
|
|
||||||
throws IOException {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class MessagingServiceEntityInterface implements EntityInterface<MessagingService> {
|
public static class MessagingServiceEntityInterface implements EntityInterface<MessagingService> {
|
||||||
private final MessagingService entity;
|
private final MessagingService entity;
|
||||||
|
|
||||||
|
|||||||
@ -114,11 +114,6 @@ public class MetricsRepository extends EntityRepository<Metrics> {
|
|||||||
applyTags(metrics);
|
applyTags(metrics);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public EntityUpdater getUpdater(Metrics original, Metrics updated, boolean patchOperation) throws IOException {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private EntityReference getService(Metrics metrics) throws IOException { // Get service by metrics Id
|
private EntityReference getService(Metrics metrics) throws IOException { // Get service by metrics Id
|
||||||
EntityReference ref = EntityUtil.getService(dao.relationshipDAO(), metrics.getId(), Entity.DASHBOARD_SERVICE);
|
EntityReference ref = EntityUtil.getService(dao.relationshipDAO(), metrics.getId(), Entity.DASHBOARD_SERVICE);
|
||||||
return getService(ref);
|
return getService(ref);
|
||||||
@ -228,18 +223,4 @@ public class MetricsRepository extends EntityRepository<Metrics> {
|
|||||||
entity.setTags(tags);
|
entity.setTags(tags);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Handles entity updates from PUT and POST operation.
|
|
||||||
*/
|
|
||||||
public class MetricsUpdater extends EntityUpdater {
|
|
||||||
public MetricsUpdater(Metrics original, Metrics updated, boolean patchOperation) {
|
|
||||||
super(original, updated, patchOperation);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void entitySpecificUpdate() throws IOException {
|
|
||||||
// No entity specific update
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -114,11 +114,6 @@ public class PipelineServiceRepository extends EntityRepository<PipelineService>
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public EntityUpdater getUpdater(PipelineService original, PipelineService updated, boolean patchOperation) throws IOException {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class PipelineServiceEntityInterface implements EntityInterface<PipelineService> {
|
public static class PipelineServiceEntityInterface implements EntityInterface<PipelineService> {
|
||||||
private final PipelineService entity;
|
private final PipelineService entity;
|
||||||
|
|
||||||
|
|||||||
@ -97,11 +97,6 @@ public class ReportRepository extends EntityRepository<Report> {
|
|||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public EntityUpdater getUpdater(Report original, Report updated, boolean patchOperation) throws IOException {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private EntityReference getService(Report report) {
|
private EntityReference getService(Report report) {
|
||||||
return report == null ? null : getService(EntityUtil.getService(dao.relationshipDAO(), report.getId()));
|
return report == null ? null : getService(EntityUtil.getService(dao.relationshipDAO(), report.getId()));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -105,11 +105,6 @@ public class TaskRepository extends EntityRepository<Task> {
|
|||||||
applyTags(task);
|
applyTags(task);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public EntityUpdater getUpdater(Task original, Task updated, boolean patchOperation) throws IOException {
|
|
||||||
return new TaskUpdater(original, updated, patchOperation);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void applyTags(Task task) throws IOException {
|
private void applyTags(Task task) throws IOException {
|
||||||
// Add task level tags by adding tag to task relationship
|
// Add task level tags by adding tag to task relationship
|
||||||
EntityUtil.applyTags(dao.tagDAO(), task.getTags(), task.getFullyQualifiedName());
|
EntityUtil.applyTags(dao.tagDAO(), task.getTags(), task.getFullyQualifiedName());
|
||||||
@ -266,18 +261,4 @@ public class TaskRepository extends EntityRepository<Task> {
|
|||||||
entity.setTags(tags);
|
entity.setTags(tags);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Handles entity updated from PUT and POST operation.
|
|
||||||
*/
|
|
||||||
public class TaskUpdater extends EntityUpdater {
|
|
||||||
public TaskUpdater(Task original, Task updated, boolean patchOperation) {
|
|
||||||
super(original, updated, patchOperation);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void entitySpecificUpdate() throws IOException {
|
|
||||||
// No specific updates for tasks
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -108,11 +108,6 @@ public class TopicRepository extends EntityRepository<Topic> {
|
|||||||
applyTags(topic);
|
applyTags(topic);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public EntityUpdater getUpdater(Topic original, Topic updated, boolean patchOperation) throws IOException {
|
|
||||||
return new TopicUpdater(original, updated, patchOperation);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void applyTags(Topic topic) throws IOException {
|
private void applyTags(Topic topic) throws IOException {
|
||||||
// Add topic level tags by adding tag to topic relationship
|
// Add topic level tags by adding tag to topic relationship
|
||||||
EntityUtil.applyTags(dao.tagDAO(), topic.getTags(), topic.getFullyQualifiedName());
|
EntityUtil.applyTags(dao.tagDAO(), topic.getTags(), topic.getFullyQualifiedName());
|
||||||
@ -281,18 +276,4 @@ public class TopicRepository extends EntityRepository<Topic> {
|
|||||||
entity.setTags(tags);
|
entity.setTags(tags);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Handles entity updated from PUT and POST operation.
|
|
||||||
*/
|
|
||||||
public class TopicUpdater extends EntityUpdater {
|
|
||||||
public TopicUpdater(Topic original, Topic updated, boolean patchOperation) {
|
|
||||||
super(original, updated, patchOperation);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void entitySpecificUpdate() throws IOException {
|
|
||||||
// No specific update for Topic
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user