mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-08-05 07:38:26 +00:00
Merge pull request #1441 from open-metadata/issue1149
Issue1149 - Document EntityRepository to help contributors understand how to use it to add new entities
This commit is contained in:
commit
0e77ffa5d2
@ -61,10 +61,10 @@ public class BotsRepository extends EntityRepository<Bots>{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate(Bots entity) throws IOException { }
|
||||
public void prepare(Bots entity) throws IOException { }
|
||||
|
||||
@Override
|
||||
public void store(Bots entity, boolean update) throws IOException {
|
||||
public void storeEntity(Bots entity, boolean update) throws IOException {
|
||||
dao.botsDAO().insert(entity);
|
||||
}
|
||||
|
||||
|
@ -68,7 +68,7 @@ public class ChartRepository extends EntityRepository<Chart> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate(Chart chart) throws IOException {
|
||||
public void prepare(Chart chart) throws IOException {
|
||||
chart.setService(getService(chart.getService()));
|
||||
chart.setFullyQualifiedName(getFQN(chart));
|
||||
EntityUtil.populateOwner(dao.userDAO(), dao.teamDAO(), chart.getOwner()); // Validate owner
|
||||
@ -76,7 +76,7 @@ public class ChartRepository extends EntityRepository<Chart> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void store(Chart chart, boolean update) throws JsonProcessingException {
|
||||
public void storeEntity(Chart chart, boolean update) throws JsonProcessingException {
|
||||
// Relationships and fields such as href are derived and not stored as part of json
|
||||
EntityReference owner = chart.getOwner();
|
||||
List<TagLabel> tags = chart.getTags();
|
||||
|
@ -129,7 +129,7 @@ public class DashboardRepository extends EntityRepository<Dashboard> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate(Dashboard dashboard) throws IOException {
|
||||
public void prepare(Dashboard dashboard) throws IOException {
|
||||
dashboard.setService(getService(dashboard.getService()));
|
||||
dashboard.setFullyQualifiedName(getFQN(dashboard));
|
||||
EntityUtil.populateOwner(dao.userDAO(), dao.teamDAO(), dashboard.getOwner()); // Validate owner
|
||||
@ -137,7 +137,7 @@ public class DashboardRepository extends EntityRepository<Dashboard> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void store(Dashboard dashboard, boolean update) throws JsonProcessingException {
|
||||
public void storeEntity(Dashboard dashboard, boolean update) throws JsonProcessingException {
|
||||
// Relationships and fields such as href are derived and not stored as part of json
|
||||
EntityReference owner = dashboard.getOwner();
|
||||
List<TagLabel> tags = dashboard.getTags();
|
||||
|
@ -87,12 +87,12 @@ public class DashboardServiceRepository extends EntityRepository<DashboardServic
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate(DashboardService entity) throws IOException {
|
||||
public void prepare(DashboardService entity) throws IOException {
|
||||
EntityUtil.validateIngestionSchedule(entity.getIngestionSchedule());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void store(DashboardService service, boolean update) throws IOException {
|
||||
public void storeEntity(DashboardService service, boolean update) throws IOException {
|
||||
if (update) {
|
||||
dao.dashboardServiceDAO().update(service.getId(), JsonUtils.pojoToJson(service));
|
||||
} else {
|
||||
|
@ -75,14 +75,14 @@ public class DatabaseRepository extends EntityRepository<Database> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate(Database database) throws IOException {
|
||||
public void prepare(Database database) throws IOException {
|
||||
database.setService(getService(database.getService()));
|
||||
database.setFullyQualifiedName(getFQN(database));
|
||||
database.setOwner(EntityUtil.populateOwner(dao.userDAO(), dao.teamDAO(), database.getOwner())); // Validate owner
|
||||
}
|
||||
|
||||
@Override
|
||||
public void store(Database database, boolean update) throws IOException {
|
||||
public void storeEntity(Database database, boolean update) throws IOException {
|
||||
// Relationships and fields such as href are derived and not stored as part of json
|
||||
EntityReference owner = database.getOwner();
|
||||
EntityReference service = database.getService();
|
||||
|
@ -77,12 +77,12 @@ public class DatabaseServiceRepository extends EntityRepository<DatabaseService>
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate(DatabaseService entity) throws IOException {
|
||||
public void prepare(DatabaseService entity) throws IOException {
|
||||
EntityUtil.validateIngestionSchedule(entity.getIngestionSchedule());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void store(DatabaseService service, boolean update) throws IOException {
|
||||
public void storeEntity(DatabaseService service, boolean update) throws IOException {
|
||||
if (update) {
|
||||
dao.dbServiceDAO().update(service.getId(), JsonUtils.pojoToJson(service));
|
||||
} else {
|
||||
|
@ -127,7 +127,7 @@ public class DbtModelRepository extends EntityRepository<DbtModel> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate(DbtModel dbtModel) throws IOException {
|
||||
public void prepare(DbtModel dbtModel) throws IOException {
|
||||
dbtModel.setDatabase(dao.databaseDAO().findEntityReferenceById(dbtModel.getDatabase().getId()));
|
||||
|
||||
// Set data in table entity based on database relationship
|
||||
@ -145,7 +145,7 @@ public class DbtModelRepository extends EntityRepository<DbtModel> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void store(DbtModel dbtModel, boolean update) throws IOException {
|
||||
public void storeEntity(DbtModel dbtModel, boolean update) throws IOException {
|
||||
// Relationships and fields such as href are derived and not stored as part of json
|
||||
EntityReference owner = dbtModel.getOwner();
|
||||
EntityReference database = dbtModel.getDatabase();
|
||||
|
@ -19,10 +19,12 @@ package org.openmetadata.catalog.jdbi3;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import org.jdbi.v3.sqlobject.transaction.Transaction;
|
||||
import org.openmetadata.catalog.Entity;
|
||||
import org.openmetadata.catalog.entity.data.Table;
|
||||
import org.openmetadata.catalog.entity.teams.User;
|
||||
import org.openmetadata.catalog.exception.CatalogExceptionMessage;
|
||||
import org.openmetadata.catalog.exception.EntityNotFoundException;
|
||||
import org.openmetadata.catalog.jdbi3.CollectionDAO.EntityVersionPair;
|
||||
import org.openmetadata.catalog.jdbi3.TableRepository.TableUpdater;
|
||||
import org.openmetadata.catalog.type.ChangeDescription;
|
||||
import org.openmetadata.catalog.type.ChangeEvent;
|
||||
import org.openmetadata.catalog.type.EntityHistory;
|
||||
@ -60,8 +62,39 @@ import java.util.UUID;
|
||||
import java.util.function.BiPredicate;
|
||||
|
||||
/**
|
||||
* Interface used for accessing the concrete entity DAOs such as table, dashboard etc.
|
||||
* This gives a uniform access so that common boiler plate code can be reduced.
|
||||
* This is the base class used by Entity Resources to perform READ and WRITE operations to the backend database to
|
||||
* Create, * Retrieve, Update, and Delete entities.
|
||||
*
|
||||
* An entity has two types of fields - `attributes` and `relationships`.
|
||||
* <ul>
|
||||
* <li>The `attributes` are the core properties of the entity, example - entity id, name, fullyQualifiedName, columns
|
||||
* for a table, etc.</li>
|
||||
* <li>The `relationships` are an associated between two entities, example - table belongs to a database,
|
||||
* table has a tag, user owns a table, etc. All relationships are captured using {@code EntityReference}. </li>
|
||||
* </ul>
|
||||
*
|
||||
* Entities are stored as JSON documents in the database. Each entity is stored in a separate table and is accessed
|
||||
* through a <i>Data Access Object</i> or <i>DAO</i> that corresponds to each of the entity. For example,
|
||||
* <i>table_entity</i> is the database table used to store JSON docs corresponding to <i>table</i> entity and
|
||||
* {@link org.openmetadata.catalog.jdbi3.CollectionDAO.TableDAO} is used as the DAO object to access the table_entity
|
||||
* table. All DAO objects for an entity are available in {@code daoCollection}.
|
||||
*
|
||||
* <br><br>
|
||||
* Relationships between entity is stored in a separate table that captures the edge - fromEntity, toEntity, and
|
||||
* the relationship name <i>entity_relationship</i> table and are supported by
|
||||
* {@link org.openmetadata.catalog.jdbi3.CollectionDAO.EntityRelationshipDAO} DAO object.
|
||||
*
|
||||
* JSON document of an entity stores only <i>required</i> attributes of an entity. Some attributes such as
|
||||
* <i>href</i> are not stored and are created on the fly.
|
||||
*
|
||||
* <br><br>
|
||||
*
|
||||
* Json document of an entity does not store relationships. As an example, JSON document for <i>table</i> entity
|
||||
* does not store the relationship <i>database</i> which is of type <i>EntityReference</i>. This is always retrieved
|
||||
* from the the relationship table when required to ensure, the data stored is efficiently and consistently, and
|
||||
* relationship information does not become stale.
|
||||
* </p>
|
||||
*
|
||||
*/
|
||||
public abstract class EntityRepository<T> {
|
||||
public static final Logger LOG = LoggerFactory.getLogger(EntityRepository.class);
|
||||
@ -70,24 +103,13 @@ public abstract class EntityRepository<T> {
|
||||
private final String entityName;
|
||||
private final EntityDAO<T> dao;
|
||||
private final CollectionDAO daoCollection;
|
||||
|
||||
/** Fields that can be updated during PATCH operation */
|
||||
private final Fields patchFields;
|
||||
|
||||
/** Fields that can be updated during PUT operation */
|
||||
private final Fields putFields;
|
||||
|
||||
/**
|
||||
* Entity related operations that should be implemented or overridden by entities
|
||||
*/
|
||||
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(String collectionPath, String entityName, Class<T> entityClass, EntityDAO<T> entityDAO,
|
||||
CollectionDAO collectionDAO,
|
||||
Fields patchFields, Fields putFields) {
|
||||
@ -101,6 +123,75 @@ public abstract class EntityRepository<T> {
|
||||
Entity.registerEntity(entityName, dao, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Entity related operations that should be implemented or overridden by entities
|
||||
*/
|
||||
public abstract EntityInterface<T> getEntityInterface(T entity);
|
||||
|
||||
/**
|
||||
* Set the requested fields in an entity. This is used for requesting specific fields in the object during GET
|
||||
* operations. It is also used during PUT and PATCH operations to set up fields that can be updated.
|
||||
*/
|
||||
public abstract T setFields(T entity, Fields fields) throws IOException, ParseException;
|
||||
|
||||
/**
|
||||
* This method is used for validating an entity to be created during POST, PUT, and PATCH operations and prepare the
|
||||
* entity with all the required attributes and relationships.
|
||||
*
|
||||
* The implementation of this method must perform the following:
|
||||
* <ol>
|
||||
* <li>Prepare the values for attributes that are not required in the request but can be derived on the server side.
|
||||
* Example - <i>>FullyQualifiedNames</i> of an entity can be derived from the hierarchy that an entity belongs to
|
||||
* .</li>
|
||||
* <li>Validate all the attributes of an entity.</li>
|
||||
* <li>Validate all the relationships of an entity. As an example - during <i>table</i> creation,
|
||||
* relationships such as <i>Tags</i>, <i>Owner</i>, <i>Database</i>a table belongs to are validated.
|
||||
* During validation additional information that is not required in the create/update request are set up
|
||||
* in the corresponding relationship fields.</li>
|
||||
* </ol>
|
||||
*
|
||||
* At the end of this operation, entity is expected to be valid and fully constructed with all the fields that will
|
||||
* be sent as payload in the POST, PUT, and PATCH operations response.
|
||||
*
|
||||
* @see TableRepository#prepare(Table) for an example implementation
|
||||
*/
|
||||
public abstract void prepare(T entity) throws IOException;
|
||||
|
||||
/**
|
||||
* An entity is stored in the backend database as JSON document. The JSON includes only some of the attributes of the
|
||||
* entity and does not include attributes such as <i>href</i>. The relationship fields of an entity is never stored
|
||||
* in the JSON document. It is always reconstructed based on relationship edges from the backend database.
|
||||
*
|
||||
* <br><br>
|
||||
*
|
||||
* As an example, when <i>table</i> entity is stored, the attributes such as <i>href</i> and the relationships such
|
||||
* as <i>owner</i>, <i>database</i>, and <i>tags</i> are set to null. These attributes are restored back after the
|
||||
* JSON document is stored to be sent as response.
|
||||
*
|
||||
* @see TableRepository#storeEntity(Table, boolean) for an example implementation
|
||||
*/
|
||||
public abstract void storeEntity(T entity, boolean update) throws IOException;
|
||||
|
||||
/**
|
||||
* This method is called to store all the relationships of an entity. It is expected that all relationships are
|
||||
* already validated and completely setup before this method is called and no validation of relationships is required.
|
||||
*
|
||||
* @see TableRepository#storeRelationships(Table) for an example implementation
|
||||
*/
|
||||
public abstract void storeRelationships(T entity) throws IOException;
|
||||
|
||||
/**
|
||||
* PATCH operations can't overwrite certain fields, such as entity ID, fullyQualifiedNames etc. Instead of throwing
|
||||
* an error, we take lenient approach of ignoring the user error and restore those attributes based on what is
|
||||
* already stored in the original entity.
|
||||
*/
|
||||
public abstract void restorePatchAttributes(T original, T updated) throws IOException, ParseException;
|
||||
|
||||
|
||||
public EntityUpdater getUpdater(T original, T updated, boolean patchOperation) throws IOException {
|
||||
return new EntityUpdater(original, updated, patchOperation);
|
||||
}
|
||||
|
||||
@Transaction
|
||||
public final T get(UriInfo uriInfo, String id, Fields fields) throws IOException, ParseException {
|
||||
return withHref(uriInfo, setFields(dao.findEntityById(UUID.fromString(id)), fields));
|
||||
@ -195,23 +286,23 @@ public abstract class EntityRepository<T> {
|
||||
|
||||
@Transaction
|
||||
public final T createInternal(T entity) throws IOException, ParseException {
|
||||
validate(entity);
|
||||
prepare(entity);
|
||||
return createNewEntity(entity);
|
||||
}
|
||||
|
||||
@Transaction
|
||||
public final PutResponse<T> createOrUpdate(UriInfo uriInfo, T updated) throws IOException, ParseException {
|
||||
validate(updated);
|
||||
prepare(updated);
|
||||
T original = JsonUtils.readValue(dao.findJsonByFqn(getFullyQualifiedName(updated)), entityClass);
|
||||
if (original == null) {
|
||||
return new PutResponse<>(Status.CREATED, withHref(uriInfo, createNewEntity(updated)), RestUtil.ENTITY_CREATED);
|
||||
}
|
||||
// Update the existing entity
|
||||
// Get all the fields in the original entity that can be updated during PUT operation
|
||||
setFields(original, putFields);
|
||||
|
||||
// Update the attributes and relationships of an entity
|
||||
EntityUpdater entityUpdater = getUpdater(original, updated, false);
|
||||
entityUpdater.update();
|
||||
entityUpdater.store();
|
||||
String change = entityUpdater.fieldsChanged() ? RestUtil.ENTITY_UPDATED : RestUtil.ENTITY_NO_CHANGE;
|
||||
return new PutResponse<>(Status.OK, withHref(uriInfo, updated), change);
|
||||
}
|
||||
@ -219,16 +310,20 @@ public abstract class EntityRepository<T> {
|
||||
@Transaction
|
||||
public final PatchResponse<T> patch(UriInfo uriInfo, UUID id, String user, JsonPatch patch) throws IOException,
|
||||
ParseException {
|
||||
// Get all the fields in the original entity that can be updated during PATCH operation
|
||||
T original = setFields(dao.findEntityById(id), patchFields);
|
||||
|
||||
// Apply JSON patch to the original entity to get the updated entity
|
||||
T updated = JsonUtils.applyPatch(original, patch, entityClass);
|
||||
EntityInterface<T> updatedEntity = getEntityInterface(updated);
|
||||
updatedEntity.setUpdateDetails(user, new Date());
|
||||
|
||||
validate(updated);
|
||||
prepare(updated);
|
||||
restorePatchAttributes(original, updated);
|
||||
|
||||
// Update the attributes and relationships of an entity
|
||||
EntityUpdater entityUpdater = getUpdater(original, updated, true);
|
||||
entityUpdater.update();
|
||||
entityUpdater.store();
|
||||
String change = entityUpdater.fieldsChanged() ? RestUtil.ENTITY_UPDATED : RestUtil.ENTITY_NO_CHANGE;
|
||||
return new PatchResponse<>(Status.OK, withHref(uriInfo, updated), change);
|
||||
}
|
||||
@ -239,7 +334,7 @@ public abstract class EntityRepository<T> {
|
||||
T entity = dao.findEntityById(entityId);
|
||||
EntityInterface<T> entityInterface = getEntityInterface(entity);
|
||||
|
||||
// Validate user
|
||||
// Validate follower
|
||||
User user = daoCollection.userDAO().findEntityById(userId);
|
||||
if (user.getDeactivated()) {
|
||||
throw new IllegalArgumentException(CatalogExceptionMessage.deactivatedUser(userId));
|
||||
@ -266,7 +361,7 @@ public abstract class EntityRepository<T> {
|
||||
T entity = dao.findEntityById(entityId);
|
||||
EntityInterface<T> entityInterface = getEntityInterface(entity);
|
||||
|
||||
// Validate user
|
||||
// Validate follower
|
||||
User user = daoCollection.userDAO().findEntityById(userId);
|
||||
|
||||
// Remove follower
|
||||
@ -294,7 +389,7 @@ public abstract class EntityRepository<T> {
|
||||
}
|
||||
|
||||
private T createNewEntity(T entity) throws IOException {
|
||||
store(entity, false);
|
||||
storeEntity(entity, false);
|
||||
storeRelationships(entity);
|
||||
return entity;
|
||||
}
|
||||
@ -312,8 +407,15 @@ public abstract class EntityRepository<T> {
|
||||
}
|
||||
|
||||
/**
|
||||
* Class that performs PUT and PATCH UPDATE operation. Override {@code entitySpecificUpdate()} to add
|
||||
* additional entity specific fields to be updated.
|
||||
* Class that performs PUT and PATCH update operation. It takes an <i>updated</i> entity and <i>original</i> entity.
|
||||
* Performs comparison between then and updates the stored entity and also updates all the relationships. This class
|
||||
* also tracks the changes between original and updated to version the entity and produce change events.
|
||||
*
|
||||
* <br><br>
|
||||
*
|
||||
* Common entity attributes such as description, displayName, owner, tags are handled by this class.
|
||||
* Override {@code entitySpecificUpdate()} to add additional entity specific fields to be updated.
|
||||
* @see TableUpdater#entitySpecificUpdate() for example.
|
||||
*/
|
||||
public class EntityUpdater {
|
||||
protected final EntityInterface<T> original;
|
||||
@ -328,13 +430,19 @@ public abstract class EntityRepository<T> {
|
||||
this.patchOperation = patchOperation;
|
||||
}
|
||||
|
||||
public final void update() throws IOException {
|
||||
/**
|
||||
* Compare original and updated entities and perform updates. Update the entity version and track changes.
|
||||
*/
|
||||
public final void update() throws IOException, ParseException {
|
||||
updated.setId(original.getId());
|
||||
updateDescription();
|
||||
updateDisplayName();
|
||||
updateOwner();
|
||||
updateTags(updated.getFullyQualifiedName(), "tags", original.getTags(), updated.getTags());
|
||||
entitySpecificUpdate();
|
||||
|
||||
// Store the updated entity
|
||||
store();
|
||||
}
|
||||
|
||||
public void entitySpecificUpdate() throws IOException {
|
||||
@ -488,7 +596,7 @@ public abstract class EntityRepository<T> {
|
||||
JsonUtils.pojoToJson(original.getEntity()));
|
||||
|
||||
// Store the new version
|
||||
EntityRepository.this.store(updated.getEntity(), true);
|
||||
EntityRepository.this.storeEntity(updated.getEntity(), true);
|
||||
} else {
|
||||
updated.setUpdateDetails(original.getUpdatedBy(), original.getUpdatedAt());
|
||||
}
|
||||
|
@ -100,7 +100,7 @@ public class IngestionRepository extends EntityRepository<Ingestion> {
|
||||
|
||||
|
||||
@Override
|
||||
public void validate(Ingestion ingestion) throws IOException {
|
||||
public void prepare(Ingestion ingestion) throws IOException {
|
||||
ingestion.setService(getService(ingestion.getService()));
|
||||
ingestion.setFullyQualifiedName(getFQN(ingestion));
|
||||
EntityUtil.populateOwner(dao.userDAO(), dao.teamDAO(), ingestion.getOwner()); // Validate owner
|
||||
@ -109,7 +109,7 @@ public class IngestionRepository extends EntityRepository<Ingestion> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void store(Ingestion ingestion, boolean update) throws IOException {
|
||||
public void storeEntity(Ingestion ingestion, boolean update) throws IOException {
|
||||
// Relationships and fields such as href are derived and not stored as part of json
|
||||
EntityReference owner = ingestion.getOwner();
|
||||
List<TagLabel> tags = ingestion.getTags();
|
||||
|
@ -145,7 +145,7 @@ public class LocationRepository extends EntityRepository<Location> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate(Location location) throws IOException {
|
||||
public void prepare(Location location) throws IOException {
|
||||
// Set data in location entity based on storage relationship
|
||||
location.setFullyQualifiedName(getFQN(location));
|
||||
|
||||
@ -157,7 +157,7 @@ public class LocationRepository extends EntityRepository<Location> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void store(Location location, boolean update) throws IOException {
|
||||
public void storeEntity(Location location, boolean update) throws IOException {
|
||||
// Relationships and fields such as href are derived and not stored as part of json
|
||||
EntityReference owner = location.getOwner();
|
||||
EntityReference service = location.getService();
|
||||
|
@ -75,12 +75,12 @@ public class MessagingServiceRepository extends EntityRepository<MessagingServic
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate(MessagingService entity) throws IOException {
|
||||
public void prepare(MessagingService entity) throws IOException {
|
||||
EntityUtil.validateIngestionSchedule(entity.getIngestionSchedule());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void store(MessagingService service, boolean update) throws IOException {
|
||||
public void storeEntity(MessagingService service, boolean update) throws IOException {
|
||||
if (update) {
|
||||
dao.messagingServiceDAO().update(service.getId(), JsonUtils.pojoToJson(service));
|
||||
} else {
|
||||
|
@ -68,7 +68,7 @@ public class MetricsRepository extends EntityRepository<Metrics> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate(Metrics metrics) throws IOException {
|
||||
public void prepare(Metrics metrics) throws IOException {
|
||||
metrics.setFullyQualifiedName(getFQN(metrics));
|
||||
EntityUtil.populateOwner(dao.userDAO(), dao.teamDAO(), metrics.getOwner()); // Validate owner
|
||||
metrics.setService(getService(metrics.getService()));
|
||||
@ -76,7 +76,7 @@ public class MetricsRepository extends EntityRepository<Metrics> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void store(Metrics metrics, boolean update) throws IOException {
|
||||
public void storeEntity(Metrics metrics, boolean update) throws IOException {
|
||||
// Relationships and fields such as href are derived and not stored as part of json
|
||||
EntityReference owner = metrics.getOwner();
|
||||
List<TagLabel> tags = metrics.getTags();
|
||||
|
@ -119,7 +119,7 @@ public class MlModelRepository extends EntityRepository<MlModel> {
|
||||
|
||||
|
||||
@Override
|
||||
public void validate(MlModel mlModel) throws IOException {
|
||||
public void prepare(MlModel mlModel) throws IOException {
|
||||
mlModel.setFullyQualifiedName(getFQN(mlModel));
|
||||
|
||||
if (mlModel.getMlFeatures() != null && !mlModel.getMlFeatures().isEmpty()) {
|
||||
@ -140,7 +140,7 @@ public class MlModelRepository extends EntityRepository<MlModel> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void store(MlModel mlModel, boolean update) throws IOException {
|
||||
public void storeEntity(MlModel mlModel, boolean update) throws IOException {
|
||||
// Relationships and fields such as href are derived and not stored as part of json
|
||||
EntityReference owner = mlModel.getOwner();
|
||||
List<TagLabel> tags = mlModel.getTags();
|
||||
|
@ -114,7 +114,7 @@ public class PipelineRepository extends EntityRepository<Pipeline> {
|
||||
|
||||
|
||||
@Override
|
||||
public void validate(Pipeline pipeline) throws IOException {
|
||||
public void prepare(Pipeline pipeline) throws IOException {
|
||||
pipeline.setService(getService(pipeline.getService()));
|
||||
pipeline.setFullyQualifiedName(getFQN(pipeline));
|
||||
EntityUtil.populateOwner(dao.userDAO(), dao.teamDAO(), pipeline.getOwner()); // Validate owner
|
||||
@ -123,7 +123,7 @@ public class PipelineRepository extends EntityRepository<Pipeline> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void store(Pipeline pipeline, boolean update) throws IOException {
|
||||
public void storeEntity(Pipeline pipeline, boolean update) throws IOException {
|
||||
// Relationships and fields such as href are derived and not stored as part of json
|
||||
EntityReference owner = pipeline.getOwner();
|
||||
List<TagLabel> tags = pipeline.getTags();
|
||||
|
@ -75,12 +75,12 @@ public class PipelineServiceRepository extends EntityRepository<PipelineService>
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate(PipelineService entity) throws IOException {
|
||||
public void prepare(PipelineService entity) throws IOException {
|
||||
EntityUtil.validateIngestionSchedule(entity.getIngestionSchedule());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void store(PipelineService service, boolean update) throws IOException {
|
||||
public void storeEntity(PipelineService service, boolean update) throws IOException {
|
||||
if (update) {
|
||||
dao.pipelineServiceDAO().update(service.getId(), JsonUtils.pojoToJson(service));
|
||||
} else {
|
||||
|
@ -95,7 +95,7 @@ public class PolicyRepository extends EntityRepository<Policy> {
|
||||
|
||||
|
||||
@Override
|
||||
public void validate(Policy policy) throws IOException {
|
||||
public void prepare(Policy policy) throws IOException {
|
||||
policy.setFullyQualifiedName(getFQN(policy));
|
||||
|
||||
// Check if owner is valid and set the relationship
|
||||
@ -103,7 +103,7 @@ public class PolicyRepository extends EntityRepository<Policy> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void store(Policy policy, boolean update) throws IOException {
|
||||
public void storeEntity(Policy policy, boolean update) throws IOException {
|
||||
// Relationships and fields such as href are derived and not stored as part of json
|
||||
EntityReference owner = policy.getOwner();
|
||||
URI href = policy.getHref();
|
||||
|
@ -63,14 +63,14 @@ public class ReportRepository extends EntityRepository<Report> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate(Report report) throws IOException {
|
||||
public void prepare(Report report) throws IOException {
|
||||
setService(report, report.getService());
|
||||
setOwner(report, report.getOwner());
|
||||
EntityUtil.populateOwner(dao.userDAO(), dao.teamDAO(), report.getOwner()); // Validate owner
|
||||
}
|
||||
|
||||
@Override
|
||||
public void store(Report report, boolean update) throws IOException {
|
||||
public void storeEntity(Report report, boolean update) throws IOException {
|
||||
// TODO add right checks
|
||||
dao.reportDAO().insert(report);
|
||||
}
|
||||
|
@ -70,12 +70,12 @@ public class StorageServiceRepository extends EntityRepository<StorageService> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate(StorageService entity) throws IOException {
|
||||
public void prepare(StorageService entity) throws IOException {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void store(StorageService service, boolean update) throws IOException {
|
||||
public void storeEntity(StorageService service, boolean update) throws IOException {
|
||||
if (update) {
|
||||
dao.storageServiceDAO().update(service.getId(), JsonUtils.pojoToJson(service));
|
||||
} else {
|
||||
|
@ -108,7 +108,7 @@ public class TableRepository extends EntityRepository<Table> {
|
||||
|
||||
@Override
|
||||
public void restorePatchAttributes(Table original, Table updated) throws IOException, ParseException {
|
||||
// Patch can't make changes to following fields. Ignore the changes
|
||||
// Patch can't make changes to following fields. Ignore the changes.
|
||||
updated.withFullyQualifiedName(original.getFullyQualifiedName()).withName(original.getName())
|
||||
.withDatabase(original.getDatabase()).withId(original.getId());
|
||||
}
|
||||
@ -260,7 +260,7 @@ public class TableRepository extends EntityRepository<Table> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate(Table table) throws IOException {
|
||||
public void prepare(Table table) throws IOException {
|
||||
table.setDatabase(dao.databaseDAO().findEntityReferenceById(table.getDatabase().getId()));
|
||||
|
||||
// Set data in table entity based on database relationship
|
||||
@ -278,7 +278,7 @@ public class TableRepository extends EntityRepository<Table> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void store(Table table, boolean update) throws IOException {
|
||||
public void storeEntity(Table table, boolean update) throws IOException {
|
||||
// Relationships and fields such as href are derived and not stored as part of json
|
||||
EntityReference owner = table.getOwner();
|
||||
EntityReference database = table.getDatabase();
|
||||
|
@ -107,12 +107,12 @@ public class TeamRepository extends EntityRepository<Team> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate(Team team) throws IOException {
|
||||
public void prepare(Team team) throws IOException {
|
||||
validateUsers(team.getUsers());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void store(Team team, boolean update) throws IOException {
|
||||
public void storeEntity(Team team, boolean update) throws IOException {
|
||||
// Relationships and fields such as href are derived and not stored as part of json
|
||||
List<EntityReference> users = team.getUsers();
|
||||
|
||||
|
@ -72,7 +72,7 @@ public class TopicRepository extends EntityRepository<Topic> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate(Topic topic) throws IOException {
|
||||
public void prepare(Topic topic) throws IOException {
|
||||
EntityReference messagingService = getService(topic.getService());
|
||||
topic.setService(messagingService);
|
||||
topic.setFullyQualifiedName(getFQN(topic));
|
||||
@ -81,7 +81,7 @@ public class TopicRepository extends EntityRepository<Topic> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void store(Topic topic, boolean update) throws IOException {
|
||||
public void storeEntity(Topic topic, boolean update) throws IOException {
|
||||
// Relationships and fields such as href are derived and not stored as part of json
|
||||
EntityReference owner = topic.getOwner();
|
||||
List<TagLabel> tags = topic.getTags();
|
||||
|
@ -67,12 +67,12 @@ public class UserRepository extends EntityRepository<User> {
|
||||
|
||||
|
||||
@Override
|
||||
public void validate(User entity) throws IOException {
|
||||
public void prepare(User entity) throws IOException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void store(User user, boolean update) throws IOException {
|
||||
public void storeEntity(User user, boolean update) throws IOException {
|
||||
// Relationships and fields such as href are derived and not stored as part of json
|
||||
List<EntityReference> teams = user.getTeams();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user