mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-11-02 11:39:12 +00:00
parent
6175053dd4
commit
2f7b82abe0
@ -120,7 +120,7 @@ public class ChartRepository extends EntityRepository<Chart> {
|
||||
|
||||
private EntityReference getService(Chart chart) throws IOException {
|
||||
EntityReference ref =
|
||||
EntityUtil.getService(daoCollection.relationshipDAO(), chart.getId(), Entity.DASHBOARD_SERVICE);
|
||||
EntityUtil.getService(daoCollection.relationshipDAO(), Entity.CHART, chart.getId(), Entity.DASHBOARD_SERVICE);
|
||||
if (ref != null) {
|
||||
DashboardService service = getService(ref.getId(), ref.getType());
|
||||
ref.setName(service.getName());
|
||||
|
||||
@ -341,75 +341,84 @@ public interface CollectionDAO {
|
||||
//
|
||||
@SqlQuery(
|
||||
"SELECT toId, toEntity FROM entity_relationship "
|
||||
+ "WHERE fromId = :fromId AND relation = :relation AND deleted = false "
|
||||
+ "WHERE fromId = :fromId AND fromEntity = :fromEntity AND relation = :relation AND deleted = false "
|
||||
+ "ORDER BY toId")
|
||||
@RegisterRowMapper(ToEntityReferenceMapper.class)
|
||||
List<EntityReference> findTo(@Bind("fromId") String fromId, @Bind("relation") int relation);
|
||||
List<EntityReference> findTo(@Bind("fromId") String fromId, @Bind("fromEntity") String fromEntity, @Bind("relation") int relation);
|
||||
|
||||
@SqlQuery(
|
||||
"SELECT toId FROM entity_relationship "
|
||||
+ "WHERE fromId = :fromId AND relation = :relation AND toEntity = :toEntity AND deleted = false "
|
||||
+ "WHERE fromId = :fromId AND fromEntity = :fromEntity AND relation = :relation AND toEntity = :toEntity AND deleted = false "
|
||||
+ "ORDER BY toId")
|
||||
List<String> findTo(
|
||||
@Bind("fromId") String fromId, @Bind("relation") int relation, @Bind("toEntity") String toEntity);
|
||||
@Bind("fromId") String fromId, @Bind("fromEntity") String fromEntity, @Bind("relation") int relation, @Bind("toEntity") String toEntity);
|
||||
|
||||
@SqlQuery(
|
||||
"SELECT count(*) FROM entity_relationship "
|
||||
+ "WHERE fromId = :fromId AND relation = :relation AND (toEntity = :toEntity || :toEntity IS NULL) "
|
||||
+ "WHERE fromId = :fromId AND fromEntity = :fromEntity AND relation = :relation "
|
||||
+ "AND (toEntity = :toEntity || :toEntity IS NULL) "
|
||||
+ "AND deleted = false "
|
||||
+ "ORDER BY fromId")
|
||||
int findToCount(@Bind("fromId") String fromId, @Bind("relation") int relation, @Bind("toEntity") String toEntity);
|
||||
int findToCount(@Bind("fromId") String fromId, @Bind("fromEntity") String fromEntity, @Bind("relation") int relation, @Bind("toEntity") String toEntity);
|
||||
|
||||
//
|
||||
// Find from operations
|
||||
//
|
||||
@SqlQuery(
|
||||
"SELECT fromId FROM entity_relationship "
|
||||
+ "WHERE toId = :toId AND relation = :relation AND fromEntity = :fromEntity AND deleted = false "
|
||||
+ "WHERE toId = :toId AND toEntity = :toEntity AND relation = :relation AND fromEntity = :fromEntity AND deleted = false "
|
||||
+ "ORDER BY fromId")
|
||||
List<String> findFrom(
|
||||
@Bind("toId") String toId, @Bind("relation") int relation, @Bind("fromEntity") String fromEntity);
|
||||
@Bind("toId") String toId, @Bind("toEntity") String toEntity, @Bind("relation") int relation, @Bind("fromEntity") String fromEntity);
|
||||
|
||||
@SqlQuery(
|
||||
"SELECT fromId, fromEntity FROM entity_relationship "
|
||||
+ "WHERE toId = :toId AND relation = :relation AND deleted = false "
|
||||
+ "WHERE toId = :toId AND toEntity = :toEntity AND relation = :relation AND deleted = false "
|
||||
+ "ORDER BY fromId")
|
||||
@RegisterRowMapper(FromEntityReferenceMapper.class)
|
||||
List<EntityReference> findFrom(@Bind("toId") String toId, @Bind("relation") int relation);
|
||||
List<EntityReference> findFrom(@Bind("toId") String toId, @Bind("toEntity") String toEntity, @Bind("relation") int relation);
|
||||
|
||||
@SqlQuery(
|
||||
"SELECT fromId, fromEntity FROM entity_relationship "
|
||||
+ "WHERE toId = :toId AND relation = :relation AND fromEntity = :fromEntity AND deleted = false "
|
||||
+ "WHERE toId = :toId AND toEntity = :toEntity AND relation = :relation AND fromEntity = :fromEntity AND deleted = false "
|
||||
+ "ORDER BY fromId")
|
||||
@RegisterRowMapper(FromEntityReferenceMapper.class)
|
||||
List<EntityReference> findFromEntity(
|
||||
@Bind("toId") String toId, @Bind("relation") int relation, @Bind("fromEntity") String fromEntity);
|
||||
@Bind("toId") String toId, @Bind("toEntity") String toEntity, @Bind("relation") int relation, @Bind("fromEntity") String fromEntity);
|
||||
|
||||
//
|
||||
// Delete Operations
|
||||
//
|
||||
@SqlUpdate("DELETE from entity_relationship " + "WHERE fromId = :fromId AND toId = :toId AND relation = :relation")
|
||||
void delete(@Bind("fromId") String fromId, @Bind("toId") String toId, @Bind("relation") int relation);
|
||||
@SqlUpdate("DELETE from entity_relationship WHERE fromId = :fromId "
|
||||
+ "AND fromEntity = :fromEntity AND toId = :toId AND toEntity = :toEntity "
|
||||
+ "AND relation = :relation")
|
||||
void delete(@Bind("fromId") String fromId, @Bind("fromEntity") String fromEntity, @Bind("toId") String toId,
|
||||
@Bind("toEntity") String toEntity, @Bind("relation") int relation);
|
||||
|
||||
// Delete all the entity relationship fromID --- relation --> entity of type toEntity
|
||||
@SqlUpdate(
|
||||
"DELETE from entity_relationship " + "WHERE fromId = :fromId AND relation = :relation AND toEntity = :toEntity")
|
||||
void deleteFrom(@Bind("fromId") String fromId, @Bind("relation") int relation, @Bind("toEntity") String toEntity);
|
||||
@SqlUpdate("DELETE from entity_relationship WHERE fromId = :fromId AND fromEntity = :fromEntity "
|
||||
+ "AND relation = :relation AND toEntity = :toEntity")
|
||||
void deleteFrom(@Bind("fromId") String fromId, @Bind("fromEntity") String fromEntity,
|
||||
@Bind("relation") int relation, @Bind("toEntity") String toEntity);
|
||||
|
||||
// Delete all the entity relationship fromID --- relation --> to any entity
|
||||
@SqlUpdate("DELETE from entity_relationship " + "WHERE fromId = :fromId AND relation = :relation")
|
||||
void deleteFrom(@Bind("fromId") String fromId, @Bind("relation") int relation);
|
||||
@SqlUpdate("DELETE from entity_relationship WHERE fromId = :fromId AND fromEntity = :fromEntity "
|
||||
+ "AND relation = :relation")
|
||||
void deleteFrom(@Bind("fromId") String fromId, @Bind("fromEntity") String fromEntity, @Bind("relation") int relation);
|
||||
|
||||
// Delete all the entity relationship toId <-- relation -- entity of type fromEntity
|
||||
@SqlUpdate(
|
||||
"DELETE from entity_relationship " + "WHERE toId = :toId AND relation = :relation AND fromEntity = :fromEntity")
|
||||
void deleteTo(@Bind("toId") String toId, @Bind("relation") int relation, @Bind("fromEntity") String fromEntity);
|
||||
@SqlUpdate("DELETE from entity_relationship WHERE toId = :toId AND toEntity = :toEntity AND relation = :relation "
|
||||
+ "AND fromEntity = :fromEntity")
|
||||
void deleteTo(@Bind("toId") String toId, @Bind("toEntity") String toEntity, @Bind("relation") int relation,
|
||||
@Bind("fromEntity") String fromEntity);
|
||||
|
||||
@SqlUpdate("DELETE from entity_relationship " + "WHERE toId = :id OR fromId = :id")
|
||||
void deleteAll(@Bind("id") String id);
|
||||
@SqlUpdate("DELETE from entity_relationship WHERE (toId = :id AND toEntity = :entity) OR "
|
||||
+ "(fromId = :id AND toEntity = :entity)")
|
||||
void deleteAll(@Bind("id") String id, @Bind("entity") String entity);
|
||||
|
||||
@SqlUpdate("UPDATE entity_relationship SET deleted = true WHERE toId = :id OR fromId = :id")
|
||||
void softDeleteAll(@Bind("id") String id);
|
||||
@SqlUpdate("UPDATE entity_relationship SET deleted = true WHERE (toId = :id AND toEntity = :entity) "
|
||||
+ "OR (fromId = :id AND fromEntity = :entity)")
|
||||
void softDeleteAll(@Bind("id") String id, @Bind("entity") String entity);
|
||||
}
|
||||
|
||||
interface FeedDAO {
|
||||
|
||||
@ -96,7 +96,7 @@ public class DashboardRepository extends EntityRepository<Dashboard> {
|
||||
|
||||
private EntityReference getService(Dashboard dashboard) throws IOException {
|
||||
EntityReference ref =
|
||||
EntityUtil.getService(daoCollection.relationshipDAO(), dashboard.getId(), Entity.DASHBOARD_SERVICE);
|
||||
EntityUtil.getService(daoCollection.relationshipDAO(), Entity.DASHBOARD, dashboard.getId(), Entity.DASHBOARD_SERVICE);
|
||||
if (ref != null) {
|
||||
DashboardService service = getService(ref.getId(), ref.getType());
|
||||
ref.setName(service.getName());
|
||||
@ -189,7 +189,7 @@ public class DashboardRepository extends EntityRepository<Dashboard> {
|
||||
}
|
||||
String dashboardId = dashboard.getId().toString();
|
||||
List<String> chartIds =
|
||||
daoCollection.relationshipDAO().findTo(dashboardId, Relationship.HAS.ordinal(), Entity.CHART);
|
||||
daoCollection.relationshipDAO().findTo(dashboardId, Entity.DASHBOARD, Relationship.HAS.ordinal(), Entity.CHART);
|
||||
List<EntityReference> charts = new ArrayList<>();
|
||||
for (String chartId : chartIds) {
|
||||
charts.add(daoCollection.chartDAO().findEntityReferenceById(UUID.fromString(chartId)));
|
||||
@ -219,7 +219,7 @@ public class DashboardRepository extends EntityRepository<Dashboard> {
|
||||
String dashboardId = updated.getId().toString();
|
||||
|
||||
// Remove all charts associated with this dashboard
|
||||
daoCollection.relationshipDAO().deleteFrom(dashboardId, Relationship.HAS.ordinal(), Entity.CHART);
|
||||
daoCollection.relationshipDAO().deleteFrom(dashboardId, Entity.DASHBOARD, Relationship.HAS.ordinal(), Entity.CHART);
|
||||
|
||||
// Add relationship from dashboard to chart
|
||||
if (updated.getCharts() != null) {
|
||||
@ -385,7 +385,7 @@ public class DashboardRepository extends EntityRepository<Dashboard> {
|
||||
String dashboardId = updated.getId().toString();
|
||||
|
||||
// Remove all charts associated with this dashboard
|
||||
daoCollection.relationshipDAO().deleteFrom(dashboardId, Relationship.HAS.ordinal(), Entity.CHART);
|
||||
daoCollection.relationshipDAO().deleteFrom(dashboardId, Entity.DASHBOARD, Relationship.HAS.ordinal(), Entity.CHART);
|
||||
|
||||
// Add relationship from dashboard to chart
|
||||
List<EntityReference> updatedCharts =
|
||||
|
||||
@ -60,7 +60,7 @@ public class DatabaseRepository extends EntityRepository<Database> {
|
||||
|
||||
@Transaction
|
||||
public void deleteLocation(String databaseId) {
|
||||
daoCollection.relationshipDAO().deleteFrom(databaseId, Relationship.HAS.ordinal(), Entity.LOCATION);
|
||||
daoCollection.relationshipDAO().deleteFrom(databaseId, Entity.DATABASE, Relationship.HAS.ordinal(), Entity.LOCATION);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -110,7 +110,7 @@ public class DatabaseRepository extends EntityRepository<Database> {
|
||||
}
|
||||
String databaseId = database.getId().toString();
|
||||
List<String> tableIds =
|
||||
daoCollection.relationshipDAO().findTo(databaseId, Relationship.CONTAINS.ordinal(), Entity.TABLE);
|
||||
daoCollection.relationshipDAO().findTo(databaseId, Entity.DATABASE, Relationship.CONTAINS.ordinal(), Entity.TABLE);
|
||||
List<EntityReference> tables = new ArrayList<>();
|
||||
for (String tableId : tableIds) {
|
||||
tables.add(daoCollection.tableDAO().findEntityReferenceById(UUID.fromString(tableId)));
|
||||
@ -149,7 +149,7 @@ public class DatabaseRepository extends EntityRepository<Database> {
|
||||
}
|
||||
String databaseId = database.getId().toString();
|
||||
List<String> result =
|
||||
daoCollection.relationshipDAO().findTo(databaseId, Relationship.HAS.ordinal(), Entity.LOCATION);
|
||||
daoCollection.relationshipDAO().findTo(databaseId, Entity.DATABASE, Relationship.HAS.ordinal(), Entity.LOCATION);
|
||||
if (result.size() == 1) {
|
||||
String locationId = result.get(0);
|
||||
return daoCollection.locationDAO().findEntityReferenceById(UUID.fromString(locationId));
|
||||
@ -160,7 +160,7 @@ public class DatabaseRepository extends EntityRepository<Database> {
|
||||
|
||||
private EntityReference getService(Database database) throws IOException {
|
||||
EntityReference ref =
|
||||
EntityUtil.getService(daoCollection.relationshipDAO(), database.getId(), Entity.DATABASE_SERVICE);
|
||||
EntityUtil.getService(daoCollection.relationshipDAO(), Entity.DATABASE, database.getId(), Entity.DATABASE_SERVICE);
|
||||
if (ref != null) {
|
||||
DatabaseService service = getService(ref.getId(), ref.getType());
|
||||
ref.setName(service.getName());
|
||||
@ -187,7 +187,8 @@ public class DatabaseRepository extends EntityRepository<Database> {
|
||||
daoCollection.databaseDAO().findEntityById(databaseId);
|
||||
daoCollection.locationDAO().findEntityById(locationId);
|
||||
// A database has only one location.
|
||||
daoCollection.relationshipDAO().deleteFrom(databaseId.toString(), Relationship.HAS.ordinal(), Entity.LOCATION);
|
||||
daoCollection.relationshipDAO().deleteFrom(databaseId.toString(), Entity.DATABASE, Relationship.HAS.ordinal(),
|
||||
Entity.LOCATION);
|
||||
daoCollection
|
||||
.relationshipDAO()
|
||||
.insert(
|
||||
|
||||
@ -374,7 +374,7 @@ public abstract class EntityRepository<T> {
|
||||
public final void delete(UUID id, boolean recursive) throws IOException {
|
||||
// If an entity being deleted contains other children entities, it can't be deleted
|
||||
List<EntityReference> contains =
|
||||
daoCollection.relationshipDAO().findTo(id.toString(), Relationship.CONTAINS.ordinal());
|
||||
daoCollection.relationshipDAO().findTo(id.toString(), entityName,Relationship.CONTAINS.ordinal());
|
||||
|
||||
if (contains.size() > 0) {
|
||||
if (!recursive) {
|
||||
@ -392,12 +392,12 @@ public abstract class EntityRepository<T> {
|
||||
EntityInterface<T> entityInterface = getEntityInterface(entity);
|
||||
entityInterface.setDeleted(true);
|
||||
storeEntity(entity, true);
|
||||
daoCollection.relationshipDAO().softDeleteAll(id.toString());
|
||||
daoCollection.relationshipDAO().softDeleteAll(id.toString(), entityName);
|
||||
return;
|
||||
}
|
||||
// Hard delete
|
||||
dao.delete(id);
|
||||
daoCollection.relationshipDAO().deleteAll(id.toString());
|
||||
daoCollection.relationshipDAO().deleteAll(id.toString(), entityName);
|
||||
}
|
||||
|
||||
@Transaction
|
||||
@ -409,7 +409,8 @@ public abstract class EntityRepository<T> {
|
||||
User user = daoCollection.userDAO().findEntityById(userId);
|
||||
|
||||
// Remove follower
|
||||
daoCollection.relationshipDAO().delete(userId.toString(), entityId.toString(), Relationship.FOLLOWS.ordinal());
|
||||
daoCollection.relationshipDAO().delete(userId.toString(), Entity.USER, entityId.toString(), entityName,
|
||||
Relationship.FOLLOWS.ordinal());
|
||||
|
||||
ChangeDescription change = new ChangeDescription().withPreviousVersion(entityInterface.getVersion());
|
||||
change
|
||||
@ -457,7 +458,7 @@ public abstract class EntityRepository<T> {
|
||||
EntityInterface entityInterface = getEntityInterface(entity);
|
||||
return supportsOwner && entity != null
|
||||
? EntityUtil.populateOwner(
|
||||
entityInterface.getId(), daoCollection.relationshipDAO(), daoCollection.userDAO(), daoCollection.teamDAO())
|
||||
entityInterface.getId(), entityName, daoCollection.relationshipDAO(), daoCollection.userDAO(), daoCollection.teamDAO())
|
||||
: null;
|
||||
}
|
||||
|
||||
@ -487,7 +488,7 @@ public abstract class EntityRepository<T> {
|
||||
EntityInterface<T> entityInterface = getEntityInterface(entity);
|
||||
return !supportsFollower || entity == null
|
||||
? null
|
||||
: EntityUtil.getFollowers(entityInterface.getId(), daoCollection.relationshipDAO(), daoCollection.userDAO());
|
||||
: EntityUtil.getFollowers(entityInterface.getId(), entityName, daoCollection.relationshipDAO(), daoCollection.userDAO());
|
||||
}
|
||||
|
||||
public T withHref(UriInfo uriInfo, T entity) {
|
||||
|
||||
@ -50,7 +50,7 @@ public class FeedRepository {
|
||||
|
||||
// Get owner for the addressed to Entity
|
||||
EntityReference owner =
|
||||
EntityUtil.populateOwner(aboutRef.getId(), dao.relationshipDAO(), dao.userDAO(), dao.teamDAO());
|
||||
EntityUtil.populateOwner(aboutRef.getId(), aboutRef.getType(), dao.relationshipDAO(), dao.userDAO(), dao.teamDAO());
|
||||
|
||||
// Insert a new thread
|
||||
dao.feedDAO().insert(JsonUtils.pojoToJson(thread));
|
||||
@ -163,9 +163,9 @@ public class FeedRepository {
|
||||
// For a user entitylink get created or replied relationships to the thread
|
||||
if (reference.getType().equals(Entity.USER)) {
|
||||
threadIds.addAll(
|
||||
dao.relationshipDAO().findTo(reference.getId().toString(), Relationship.CREATED.ordinal(), "thread"));
|
||||
dao.relationshipDAO().findTo(reference.getId().toString(), reference.getType(), Relationship.CREATED.ordinal(), "thread"));
|
||||
threadIds.addAll(
|
||||
dao.relationshipDAO().findTo(reference.getId().toString(), Relationship.REPLIED_TO.ordinal(), "thread"));
|
||||
dao.relationshipDAO().findTo(reference.getId().toString(), reference.getType(), Relationship.REPLIED_TO.ordinal(), "thread"));
|
||||
} else {
|
||||
// Only data assets are added as about
|
||||
result =
|
||||
|
||||
@ -125,7 +125,7 @@ public class IngestionRepository extends EntityRepository<Ingestion> {
|
||||
}
|
||||
|
||||
private EntityReference getService(Ingestion ingestion) throws IOException {
|
||||
EntityReference ref = EntityUtil.getService(daoCollection.relationshipDAO(), ingestion.getId());
|
||||
EntityReference ref = EntityUtil.getService(daoCollection.relationshipDAO(), Entity.INGESTION, ingestion.getId());
|
||||
return getService(Objects.requireNonNull(ref));
|
||||
}
|
||||
|
||||
|
||||
@ -73,8 +73,8 @@ public class LineageRepository {
|
||||
.withNodes(entities)
|
||||
.withUpstreamEdges(new ArrayList<>())
|
||||
.withDownstreamEdges(new ArrayList<>());
|
||||
addUpstreamLineage(primary.getId(), lineage, upstreamDepth);
|
||||
addDownstreamLineage(primary.getId(), lineage, downstreamDepth);
|
||||
addUpstreamLineage(primary.getId(), primary.getType(), lineage, upstreamDepth);
|
||||
addDownstreamLineage(primary.getId(), primary.getType(), lineage, downstreamDepth);
|
||||
|
||||
// Remove duplicate nodes
|
||||
lineage.withNodes(lineage.getNodes().stream().distinct().collect(Collectors.toList()));
|
||||
@ -88,35 +88,35 @@ public class LineageRepository {
|
||||
return lineage;
|
||||
}
|
||||
|
||||
private void addUpstreamLineage(UUID id, EntityLineage lineage, int upstreamDepth) {
|
||||
private void addUpstreamLineage(UUID id, String entityType, EntityLineage lineage, int upstreamDepth) {
|
||||
if (upstreamDepth == 0) {
|
||||
return;
|
||||
}
|
||||
// from this id ---> find other ids
|
||||
List<EntityReference> upstreamEntities =
|
||||
dao.relationshipDAO().findFrom(id.toString(), Relationship.UPSTREAM.ordinal());
|
||||
dao.relationshipDAO().findFrom(id.toString(), entityType, Relationship.UPSTREAM.ordinal());
|
||||
lineage.getNodes().addAll(upstreamEntities);
|
||||
|
||||
upstreamDepth--;
|
||||
for (EntityReference upstreamEntity : upstreamEntities) {
|
||||
lineage.getUpstreamEdges().add(new Edge().withFromEntity(upstreamEntity.getId()).withToEntity(id));
|
||||
addUpstreamLineage(upstreamEntity.getId(), lineage, upstreamDepth); // Recursively add upstream nodes and edges
|
||||
addUpstreamLineage(upstreamEntity.getId(), upstreamEntity.getType(), lineage, upstreamDepth); // Recursively add upstream nodes and edges
|
||||
}
|
||||
}
|
||||
|
||||
private void addDownstreamLineage(UUID id, EntityLineage lineage, int downstreamDepth) {
|
||||
private void addDownstreamLineage(UUID id, String entityType, EntityLineage lineage, int downstreamDepth) {
|
||||
if (downstreamDepth == 0) {
|
||||
return;
|
||||
}
|
||||
// from other ids ---> to this id
|
||||
List<EntityReference> downStreamEntities =
|
||||
dao.relationshipDAO().findTo(id.toString(), Relationship.UPSTREAM.ordinal());
|
||||
dao.relationshipDAO().findTo(id.toString(), entityType, Relationship.UPSTREAM.ordinal());
|
||||
lineage.getNodes().addAll(downStreamEntities);
|
||||
|
||||
downstreamDepth--;
|
||||
for (EntityReference entity : downStreamEntities) {
|
||||
lineage.getDownstreamEdges().add(new Edge().withToEntity(entity.getId()).withFromEntity(id));
|
||||
addDownstreamLineage(entity.getId(), lineage, downstreamDepth);
|
||||
addDownstreamLineage(entity.getId(), entity.getType(), lineage, downstreamDepth);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -218,7 +218,7 @@ public class LocationRepository extends EntityRepository<Location> {
|
||||
|
||||
private EntityReference getService(Location location) throws IOException {
|
||||
EntityReference ref =
|
||||
EntityUtil.getService(daoCollection.relationshipDAO(), location.getId(), Entity.STORAGE_SERVICE);
|
||||
EntityUtil.getService(daoCollection.relationshipDAO(), Entity.LOCATION, location.getId(), Entity.STORAGE_SERVICE);
|
||||
return getService(Objects.requireNonNull(ref));
|
||||
}
|
||||
|
||||
|
||||
@ -110,7 +110,7 @@ public class MetricsRepository extends EntityRepository<Metrics> {
|
||||
|
||||
private EntityReference getService(Metrics metrics) throws IOException { // Get service by metrics ID
|
||||
EntityReference ref =
|
||||
EntityUtil.getService(daoCollection.relationshipDAO(), metrics.getId(), Entity.DASHBOARD_SERVICE);
|
||||
EntityUtil.getService(daoCollection.relationshipDAO(), Entity.METRICS, metrics.getId(), Entity.DASHBOARD_SERVICE);
|
||||
return getService(Objects.requireNonNull(ref));
|
||||
}
|
||||
|
||||
|
||||
@ -203,7 +203,7 @@ public class MlModelRepository extends EntityRepository<MlModel> {
|
||||
private EntityReference getDashboard(MlModel mlModel) throws IOException {
|
||||
if (mlModel != null) {
|
||||
List<EntityReference> ids =
|
||||
daoCollection.relationshipDAO().findTo(mlModel.getId().toString(), Relationship.USES.ordinal());
|
||||
daoCollection.relationshipDAO().findTo(mlModel.getId().toString(), Entity.MLMODEL, Relationship.USES.ordinal());
|
||||
if (ids.size() > 1) {
|
||||
LOG.warn("Possible database issues - multiple dashboards {} found for model {}", ids, mlModel.getId());
|
||||
}
|
||||
@ -231,7 +231,7 @@ public class MlModelRepository extends EntityRepository<MlModel> {
|
||||
public void removeDashboard(MlModel mlModel) {
|
||||
daoCollection
|
||||
.relationshipDAO()
|
||||
.deleteFrom(mlModel.getId().toString(), Relationship.USES.ordinal(), Entity.DASHBOARD);
|
||||
.deleteFrom(mlModel.getId().toString(), Entity.MLMODEL, Relationship.USES.ordinal(), Entity.DASHBOARD);
|
||||
}
|
||||
|
||||
public static class MlModelEntityInterface implements EntityInterface<MlModel> {
|
||||
@ -439,7 +439,7 @@ public class MlModelRepository extends EntityRepository<MlModel> {
|
||||
// Remove the dashboard associated with the model, if any
|
||||
String modelId = updatedModel.getId().toString();
|
||||
if (origModel.getDashboard() != null) {
|
||||
daoCollection.relationshipDAO().deleteFrom(modelId, Relationship.USES.ordinal(), "dashboard");
|
||||
daoCollection.relationshipDAO().deleteFrom(modelId, Entity.MLMODEL, Relationship.USES.ordinal(), "dashboard");
|
||||
}
|
||||
|
||||
// Add relationship from model to dashboard
|
||||
|
||||
@ -147,7 +147,7 @@ public class PipelineRepository extends EntityRepository<Pipeline> {
|
||||
|
||||
private EntityReference getService(Pipeline pipeline) throws IOException {
|
||||
EntityReference ref =
|
||||
EntityUtil.getService(daoCollection.relationshipDAO(), pipeline.getId(), Entity.PIPELINE_SERVICE);
|
||||
EntityUtil.getService(daoCollection.relationshipDAO(), Entity.PIPELINE, pipeline.getId(), Entity.PIPELINE_SERVICE);
|
||||
PipelineService service = getService(ref.getId(), ref.getType());
|
||||
ref.setName(service.getName());
|
||||
ref.setDescription(service.getDescription());
|
||||
|
||||
@ -67,7 +67,7 @@ public class PolicyRepository extends EntityRepository<Policy> {
|
||||
@Transaction
|
||||
private EntityReference getLocationForPolicy(UUID policyId) throws IOException {
|
||||
List<String> result =
|
||||
daoCollection.relationshipDAO().findTo(policyId.toString(), Relationship.APPLIED_TO.ordinal(), Entity.LOCATION);
|
||||
daoCollection.relationshipDAO().findTo(policyId.toString(), Entity.POLICY, Relationship.APPLIED_TO.ordinal(), Entity.LOCATION);
|
||||
// There is at most one location for a policy.
|
||||
return result.size() == 1
|
||||
? daoCollection.locationDAO().findEntityReferenceById(UUID.fromString(result.get(0)))
|
||||
@ -340,7 +340,9 @@ public class PolicyRepository extends EntityRepository<Policy> {
|
||||
.relationshipDAO()
|
||||
.delete(
|
||||
origPolicy.getId().toString(),
|
||||
Entity.POLICY,
|
||||
origPolicy.getLocation().getId().toString(),
|
||||
Entity.LOCATION,
|
||||
Relationship.APPLIED_TO.ordinal());
|
||||
}
|
||||
// insert updated Policy --> Location relationship.
|
||||
|
||||
@ -81,7 +81,7 @@ public class ReportRepository extends EntityRepository<Report> {
|
||||
}
|
||||
|
||||
private EntityReference getService(Report report) {
|
||||
return report == null ? null : getService(EntityUtil.getService(daoCollection.relationshipDAO(), report.getId()));
|
||||
return report == null ? null : getService(EntityUtil.getService(daoCollection.relationshipDAO(), Entity.REPORT, report.getId()));
|
||||
}
|
||||
|
||||
private EntityReference getService(EntityReference service) {
|
||||
|
||||
@ -206,7 +206,7 @@ public class TableRepository extends EntityRepository<Table> {
|
||||
Table table = daoCollection.tableDAO().findEntityById(tableId);
|
||||
EntityReference location = daoCollection.locationDAO().findEntityReferenceById(locationId);
|
||||
// A table has only one location.
|
||||
daoCollection.relationshipDAO().deleteFrom(tableId.toString(), Relationship.HAS.ordinal(), Entity.LOCATION);
|
||||
daoCollection.relationshipDAO().deleteFrom(tableId.toString(), Entity.TABLE, Relationship.HAS.ordinal(), Entity.LOCATION);
|
||||
daoCollection
|
||||
.relationshipDAO()
|
||||
.insert(tableId.toString(), locationId.toString(), Entity.TABLE, Entity.LOCATION, Relationship.HAS.ordinal());
|
||||
@ -270,7 +270,7 @@ public class TableRepository extends EntityRepository<Table> {
|
||||
|
||||
@Transaction
|
||||
public void deleteLocation(String tableId) {
|
||||
daoCollection.relationshipDAO().deleteFrom(tableId, Relationship.HAS.ordinal(), Entity.LOCATION);
|
||||
daoCollection.relationshipDAO().deleteFrom(tableId, Entity.TABLE, Relationship.HAS.ordinal(), Entity.LOCATION);
|
||||
}
|
||||
|
||||
@Transaction
|
||||
@ -330,7 +330,7 @@ public class TableRepository extends EntityRepository<Table> {
|
||||
|
||||
private EntityReference getService(Table table) throws IOException {
|
||||
EntityReference ref =
|
||||
EntityUtil.getService(daoCollection.relationshipDAO(), table.getDatabase().getId(), Entity.DATABASE_SERVICE);
|
||||
EntityUtil.getService(daoCollection.relationshipDAO(), Entity.DATABASE, table.getDatabase().getId(), Entity.DATABASE_SERVICE);
|
||||
DatabaseService service = getService(ref.getId(), ref.getType());
|
||||
ref.setName(service.getName());
|
||||
ref.setDescription(service.getDescription());
|
||||
@ -342,7 +342,7 @@ public class TableRepository extends EntityRepository<Table> {
|
||||
String serviceId =
|
||||
daoCollection
|
||||
.relationshipDAO()
|
||||
.findFrom(table.getDatabase().getId().toString(), Relationship.CONTAINS.ordinal(), Entity.DATABASE_SERVICE)
|
||||
.findFrom(table.getDatabase().getId().toString(), Entity.DATABASE, Relationship.CONTAINS.ordinal(), Entity.DATABASE_SERVICE)
|
||||
.get(0);
|
||||
DatabaseService service = daoCollection.dbServiceDAO().findEntityById(UUID.fromString(serviceId));
|
||||
table.setService(new DatabaseServiceEntityInterface(service).getEntityReference());
|
||||
@ -436,7 +436,7 @@ public class TableRepository extends EntityRepository<Table> {
|
||||
private EntityReference getDatabase(UUID tableId) throws IOException {
|
||||
// Find database for the table
|
||||
List<String> result =
|
||||
daoCollection.relationshipDAO().findFrom(tableId.toString(), Relationship.CONTAINS.ordinal(), Entity.DATABASE);
|
||||
daoCollection.relationshipDAO().findFrom(tableId.toString(), Entity.TABLE, Relationship.CONTAINS.ordinal(), Entity.DATABASE);
|
||||
if (result.size() != 1) {
|
||||
throw EntityNotFoundException.byMessage(String.format("Database for table %s Not found", tableId));
|
||||
}
|
||||
@ -446,7 +446,7 @@ public class TableRepository extends EntityRepository<Table> {
|
||||
private EntityReference getLocation(UUID tableId) throws IOException {
|
||||
// Find the location of the table
|
||||
List<String> result =
|
||||
daoCollection.relationshipDAO().findTo(tableId.toString(), Relationship.HAS.ordinal(), Entity.LOCATION);
|
||||
daoCollection.relationshipDAO().findTo(tableId.toString(), Entity.TABLE, Relationship.HAS.ordinal(), Entity.LOCATION);
|
||||
if (result.size() == 1) {
|
||||
return daoCollection.locationDAO().findEntityReferenceById(UUID.fromString(result.get(0)));
|
||||
} else {
|
||||
|
||||
@ -129,7 +129,7 @@ public class TeamRepository extends EntityRepository<Team> {
|
||||
}
|
||||
|
||||
private List<EntityReference> getUsers(String id) throws IOException {
|
||||
List<String> userIds = daoCollection.relationshipDAO().findTo(id, Relationship.HAS.ordinal(), "user");
|
||||
List<String> userIds = daoCollection.relationshipDAO().findTo(id, Entity.TEAM, Relationship.HAS.ordinal(), "user");
|
||||
List<EntityReference> users = new ArrayList<>();
|
||||
for (String userId : userIds) {
|
||||
users.add(daoCollection.userDAO().findEntityReferenceById(UUID.fromString(userId)));
|
||||
@ -139,7 +139,7 @@ public class TeamRepository extends EntityRepository<Team> {
|
||||
|
||||
private List<EntityReference> getOwns(String teamId) throws IOException {
|
||||
// Compile entities owned by the team
|
||||
return EntityUtil.populateEntityReferences(daoCollection.relationshipDAO().findTo(teamId, OWNS.ordinal()));
|
||||
return EntityUtil.populateEntityReferences(daoCollection.relationshipDAO().findTo(teamId, Entity.TEAM, OWNS.ordinal()));
|
||||
}
|
||||
|
||||
public static class TeamEntityInterface implements EntityInterface<Team> {
|
||||
@ -272,7 +272,7 @@ public class TeamRepository extends EntityRepository<Team> {
|
||||
List<EntityReference> deleted = new ArrayList<>();
|
||||
if (recordListChange("users", origUsers, updatedUsers, added, deleted, entityReferenceMatch)) {
|
||||
// Remove users from original and add users from updated
|
||||
daoCollection.relationshipDAO().deleteFrom(origTeam.getId().toString(), Relationship.HAS.ordinal(), "user");
|
||||
daoCollection.relationshipDAO().deleteFrom(origTeam.getId().toString(), Entity.TEAM, Relationship.HAS.ordinal(), "user");
|
||||
// Add relationships
|
||||
for (EntityReference user : updatedUsers) {
|
||||
daoCollection
|
||||
|
||||
@ -124,7 +124,7 @@ public class TopicRepository extends EntityRepository<Topic> {
|
||||
return null;
|
||||
}
|
||||
// Find service by topic Id
|
||||
EntityReference service = EntityUtil.getService(daoCollection.relationshipDAO(), topic.getId());
|
||||
EntityReference service = EntityUtil.getService(daoCollection.relationshipDAO(), Entity.TOPIC, topic.getId());
|
||||
return new MessagingServiceEntityInterface(getService(service.getId(), service.getType())).getEntityReference();
|
||||
}
|
||||
|
||||
|
||||
@ -78,7 +78,7 @@ public class UsageRepository {
|
||||
// If table usage was reported, add the usage count to database
|
||||
if (entityType.equalsIgnoreCase(Entity.TABLE)) {
|
||||
List<String> databaseIds =
|
||||
dao.relationshipDAO().findFrom(entityId, Relationship.CONTAINS.ordinal(), Entity.DATABASE);
|
||||
dao.relationshipDAO().findFrom(entityId, entityType, Relationship.CONTAINS.ordinal(), Entity.DATABASE);
|
||||
dao.usageDAO().insertOrUpdateCount(usage.getDate(), databaseIds.get(0), Entity.DATABASE, usage.getCount());
|
||||
}
|
||||
}
|
||||
|
||||
@ -114,12 +114,12 @@ public class UserRepository extends EntityRepository<User> {
|
||||
private List<EntityReference> getOwns(User user) throws IOException {
|
||||
// Compile entities owned by the user
|
||||
List<EntityReference> ownedEntities =
|
||||
daoCollection.relationshipDAO().findTo(user.getId().toString(), OWNS.ordinal());
|
||||
daoCollection.relationshipDAO().findTo(user.getId().toString(), Entity.USER, OWNS.ordinal());
|
||||
|
||||
// Compile entities owned by the team the user belongs to
|
||||
List<EntityReference> teams = user.getTeams() == null ? getTeams(user) : user.getTeams();
|
||||
for (EntityReference team : teams) {
|
||||
ownedEntities.addAll(daoCollection.relationshipDAO().findTo(team.getId().toString(), OWNS.ordinal()));
|
||||
ownedEntities.addAll(daoCollection.relationshipDAO().findTo(team.getId().toString(), Entity.TEAM, OWNS.ordinal()));
|
||||
}
|
||||
// Populate details in entity reference
|
||||
return EntityUtil.populateEntityReferences(ownedEntities);
|
||||
@ -127,7 +127,7 @@ public class UserRepository extends EntityRepository<User> {
|
||||
|
||||
private List<EntityReference> getFollows(User user) throws IOException {
|
||||
return EntityUtil.populateEntityReferences(
|
||||
daoCollection.relationshipDAO().findTo(user.getId().toString(), FOLLOWS.ordinal()));
|
||||
daoCollection.relationshipDAO().findTo(user.getId().toString(), Entity.USER, FOLLOWS.ordinal()));
|
||||
}
|
||||
|
||||
public List<EntityReference> validateRoles(List<UUID> roleIds) throws IOException {
|
||||
@ -154,7 +154,7 @@ public class UserRepository extends EntityRepository<User> {
|
||||
|
||||
/* Add all the roles that user has been assigned, to User entity */
|
||||
private List<EntityReference> getRoles(User user) throws IOException {
|
||||
List<String> roleIds = daoCollection.relationshipDAO().findTo(user.getId().toString(), HAS.ordinal(), Entity.ROLE);
|
||||
List<String> roleIds = daoCollection.relationshipDAO().findTo(user.getId().toString(), Entity.USER, HAS.ordinal(), Entity.ROLE);
|
||||
List<EntityReference> roles = new ArrayList<>(roleIds.size());
|
||||
for (String roleId : roleIds) {
|
||||
roles.add(daoCollection.roleDAO().findEntityReferenceById(UUID.fromString(roleId)));
|
||||
@ -165,7 +165,7 @@ public class UserRepository extends EntityRepository<User> {
|
||||
/* Add all the teams that user belongs to User entity */
|
||||
private List<EntityReference> getTeams(User user) throws IOException {
|
||||
List<String> teamIds =
|
||||
daoCollection.relationshipDAO().findFrom(user.getId().toString(), HAS.ordinal(), Entity.TEAM);
|
||||
daoCollection.relationshipDAO().findFrom(user.getId().toString(), Entity.USER, HAS.ordinal(), Entity.TEAM);
|
||||
List<EntityReference> teams = new ArrayList<>();
|
||||
for (String teamId : teamIds) {
|
||||
teams.add(daoCollection.teamDAO().findEntityReferenceById(UUID.fromString(teamId)));
|
||||
@ -321,7 +321,7 @@ public class UserRepository extends EntityRepository<User> {
|
||||
|
||||
private void updateRoles(User origUser, User updatedUser) throws JsonProcessingException {
|
||||
// Remove roles from original and add roles from updated
|
||||
daoCollection.relationshipDAO().deleteFrom(origUser.getId().toString(), HAS.ordinal(), Entity.ROLE);
|
||||
daoCollection.relationshipDAO().deleteFrom(origUser.getId().toString(), Entity.USER, HAS.ordinal(), Entity.ROLE);
|
||||
assignRoles(updatedUser, updatedUser.getRoles());
|
||||
|
||||
List<EntityReference> origRoles = Optional.ofNullable(origUser.getRoles()).orElse(Collections.emptyList());
|
||||
@ -337,7 +337,7 @@ public class UserRepository extends EntityRepository<User> {
|
||||
|
||||
private void updateTeams(User origUser, User updatedUser) throws JsonProcessingException {
|
||||
// Remove teams from original and add teams from updated
|
||||
daoCollection.relationshipDAO().deleteTo(origUser.getId().toString(), HAS.ordinal(), Entity.TEAM);
|
||||
daoCollection.relationshipDAO().deleteTo(origUser.getId().toString(), Entity.USER, HAS.ordinal(), Entity.TEAM);
|
||||
assignTeams(updatedUser, updatedUser.getTeams());
|
||||
|
||||
List<EntityReference> origTeams = Optional.ofNullable(origUser.getTeams()).orElse(Collections.emptyList());
|
||||
|
||||
@ -152,8 +152,8 @@ public final class EntityUtil {
|
||||
return entity;
|
||||
}
|
||||
|
||||
public static EntityReference getService(EntityRelationshipDAO dao, UUID entityId) {
|
||||
List<EntityReference> refs = dao.findFrom(entityId.toString(), Relationship.CONTAINS.ordinal());
|
||||
public static EntityReference getService(EntityRelationshipDAO dao, String entityType, UUID entityId) {
|
||||
List<EntityReference> refs = dao.findFrom(entityId.toString(), entityType, Relationship.CONTAINS.ordinal());
|
||||
if (refs.size() > 1) {
|
||||
LOG.warn("Possible database issues - multiple services found for entity {}", entityId);
|
||||
return refs.get(0);
|
||||
@ -161,8 +161,8 @@ public final class EntityUtil {
|
||||
return refs.isEmpty() ? null : refs.get(0);
|
||||
}
|
||||
|
||||
public static EntityReference getService(EntityRelationshipDAO dao, UUID entityId, String serviceType) {
|
||||
List<EntityReference> refs = dao.findFromEntity(entityId.toString(), Relationship.CONTAINS.ordinal(), serviceType);
|
||||
public static EntityReference getService(EntityRelationshipDAO dao, String entityType, UUID entityId, String serviceType) {
|
||||
List<EntityReference> refs = dao.findFromEntity(entityId.toString(), entityType, Relationship.CONTAINS.ordinal(), serviceType);
|
||||
if (refs.size() > 1) {
|
||||
LOG.warn("Possible database issues - multiple services found for entity {}", entityId);
|
||||
return refs.get(0);
|
||||
@ -178,8 +178,8 @@ public final class EntityUtil {
|
||||
|
||||
// Get owner for a given entity
|
||||
public static EntityReference populateOwner(
|
||||
UUID id, EntityRelationshipDAO entityRelationshipDAO, UserDAO userDAO, TeamDAO teamDAO) throws IOException {
|
||||
List<EntityReference> ids = entityRelationshipDAO.findFrom(id.toString(), Relationship.OWNS.ordinal());
|
||||
UUID id, String entityType, EntityRelationshipDAO entityRelationshipDAO, UserDAO userDAO, TeamDAO teamDAO) throws IOException {
|
||||
List<EntityReference> ids = entityRelationshipDAO.findFrom(id.toString(), entityType, Relationship.OWNS.ordinal());
|
||||
if (ids.size() > 1) {
|
||||
LOG.warn("Possible database issues - multiple owners {} found for entity {}", ids, id);
|
||||
}
|
||||
@ -223,10 +223,10 @@ public final class EntityUtil {
|
||||
}
|
||||
|
||||
/** Unassign owner relationship for a given entity */
|
||||
public static void unassignOwner(EntityRelationshipDAO dao, EntityReference owner, String ownedEntityId) {
|
||||
public static void unassignOwner(EntityRelationshipDAO dao, EntityReference owner, String ownedEntityId, String ownedEntityType) {
|
||||
if (owner != null && owner.getId() != null) {
|
||||
LOG.info("Removing owner {}:{} for entity {}", owner.getType(), owner.getId(), ownedEntityId);
|
||||
dao.delete(owner.getId().toString(), ownedEntityId, Relationship.OWNS.ordinal());
|
||||
dao.delete(owner.getId().toString(), owner.getType(), ownedEntityId, ownedEntityType, Relationship.OWNS.ordinal());
|
||||
}
|
||||
}
|
||||
|
||||
@ -238,7 +238,7 @@ public final class EntityUtil {
|
||||
String ownedEntityType) {
|
||||
// TODO inefficient use replace instead of delete and add?
|
||||
// TODO check for orig and new owners being the same
|
||||
unassignOwner(dao, originalOwner, ownedEntityId.toString());
|
||||
unassignOwner(dao, originalOwner, ownedEntityId.toString(), ownedEntityType);
|
||||
setOwner(dao, ownedEntityId, ownedEntityType, newOwner);
|
||||
}
|
||||
|
||||
@ -372,14 +372,10 @@ public final class EntityUtil {
|
||||
> 0;
|
||||
}
|
||||
|
||||
public static void removeFollower(EntityRelationshipDAO dao, UUID followedEntityId, UUID followerId) {
|
||||
dao.delete(followerId.toString(), followedEntityId.toString(), Relationship.FOLLOWS.ordinal());
|
||||
}
|
||||
|
||||
public static List<EntityReference> getFollowers(
|
||||
UUID followedEntityId, EntityRelationshipDAO entityRelationshipDAO, UserDAO userDAO) throws IOException {
|
||||
UUID followedEntityId, String entityName, EntityRelationshipDAO entityRelationshipDAO, UserDAO userDAO) throws IOException {
|
||||
List<String> followerIds =
|
||||
entityRelationshipDAO.findFrom(followedEntityId.toString(), Relationship.FOLLOWS.ordinal(), Entity.USER);
|
||||
entityRelationshipDAO.findFrom(followedEntityId.toString(), entityName, Relationship.FOLLOWS.ordinal(), Entity.USER);
|
||||
List<EntityReference> followers = new ArrayList<>();
|
||||
for (String followerId : followerIds) {
|
||||
User user = userDAO.findEntityById(UUID.fromString(followerId));
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user