Close #1696: Find operations in relationship should be safer (#2000)

This commit is contained in:
Alberto Miorin 2022-01-03 21:54:34 +01:00 committed by GitHub
parent 6175053dd4
commit 2f7b82abe0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 104 additions and 95 deletions

View File

@ -120,7 +120,7 @@ public class ChartRepository extends EntityRepository<Chart> {
private EntityReference getService(Chart chart) throws IOException { private EntityReference getService(Chart chart) throws IOException {
EntityReference ref = 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) { if (ref != null) {
DashboardService service = getService(ref.getId(), ref.getType()); DashboardService service = getService(ref.getId(), ref.getType());
ref.setName(service.getName()); ref.setName(service.getName());

View File

@ -341,75 +341,84 @@ public interface CollectionDAO {
// //
@SqlQuery( @SqlQuery(
"SELECT toId, toEntity FROM entity_relationship " "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") + "ORDER BY toId")
@RegisterRowMapper(ToEntityReferenceMapper.class) @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( @SqlQuery(
"SELECT toId FROM entity_relationship " "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") + "ORDER BY toId")
List<String> findTo( 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( @SqlQuery(
"SELECT count(*) FROM entity_relationship " "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 " + "AND deleted = false "
+ "ORDER BY fromId") + "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 // Find from operations
// //
@SqlQuery( @SqlQuery(
"SELECT fromId FROM entity_relationship " "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") + "ORDER BY fromId")
List<String> findFrom( 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( @SqlQuery(
"SELECT fromId, fromEntity FROM entity_relationship " "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") + "ORDER BY fromId")
@RegisterRowMapper(FromEntityReferenceMapper.class) @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( @SqlQuery(
"SELECT fromId, fromEntity FROM entity_relationship " "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") + "ORDER BY fromId")
@RegisterRowMapper(FromEntityReferenceMapper.class) @RegisterRowMapper(FromEntityReferenceMapper.class)
List<EntityReference> findFromEntity( 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 // Delete Operations
// //
@SqlUpdate("DELETE from entity_relationship " + "WHERE fromId = :fromId AND toId = :toId AND relation = :relation") @SqlUpdate("DELETE from entity_relationship WHERE fromId = :fromId "
void delete(@Bind("fromId") String fromId, @Bind("toId") String toId, @Bind("relation") int relation); + "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 // Delete all the entity relationship fromID --- relation --> entity of type toEntity
@SqlUpdate( @SqlUpdate("DELETE from entity_relationship WHERE fromId = :fromId AND fromEntity = :fromEntity "
"DELETE from entity_relationship " + "WHERE fromId = :fromId AND relation = :relation AND toEntity = :toEntity") + "AND relation = :relation AND toEntity = :toEntity")
void deleteFrom(@Bind("fromId") String fromId, @Bind("relation") int relation, @Bind("toEntity") String 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 // Delete all the entity relationship fromID --- relation --> to any entity
@SqlUpdate("DELETE from entity_relationship " + "WHERE fromId = :fromId AND relation = :relation") @SqlUpdate("DELETE from entity_relationship WHERE fromId = :fromId AND fromEntity = :fromEntity "
void deleteFrom(@Bind("fromId") String fromId, @Bind("relation") int relation); + "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 // Delete all the entity relationship toId <-- relation -- entity of type fromEntity
@SqlUpdate( @SqlUpdate("DELETE from entity_relationship WHERE toId = :toId AND toEntity = :toEntity AND relation = :relation "
"DELETE from entity_relationship " + "WHERE toId = :toId AND relation = :relation AND fromEntity = :fromEntity") + "AND fromEntity = :fromEntity")
void deleteTo(@Bind("toId") String toId, @Bind("relation") int relation, @Bind("fromEntity") String 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") @SqlUpdate("DELETE from entity_relationship WHERE (toId = :id AND toEntity = :entity) OR "
void deleteAll(@Bind("id") String id); + "(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") @SqlUpdate("UPDATE entity_relationship SET deleted = true WHERE (toId = :id AND toEntity = :entity) "
void softDeleteAll(@Bind("id") String id); + "OR (fromId = :id AND fromEntity = :entity)")
void softDeleteAll(@Bind("id") String id, @Bind("entity") String entity);
} }
interface FeedDAO { interface FeedDAO {

View File

@ -96,7 +96,7 @@ public class DashboardRepository extends EntityRepository<Dashboard> {
private EntityReference getService(Dashboard dashboard) throws IOException { private EntityReference getService(Dashboard dashboard) throws IOException {
EntityReference ref = 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) { if (ref != null) {
DashboardService service = getService(ref.getId(), ref.getType()); DashboardService service = getService(ref.getId(), ref.getType());
ref.setName(service.getName()); ref.setName(service.getName());
@ -189,7 +189,7 @@ public class DashboardRepository extends EntityRepository<Dashboard> {
} }
String dashboardId = dashboard.getId().toString(); String dashboardId = dashboard.getId().toString();
List<String> chartIds = 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<>(); List<EntityReference> charts = new ArrayList<>();
for (String chartId : chartIds) { for (String chartId : chartIds) {
charts.add(daoCollection.chartDAO().findEntityReferenceById(UUID.fromString(chartId))); charts.add(daoCollection.chartDAO().findEntityReferenceById(UUID.fromString(chartId)));
@ -219,7 +219,7 @@ public class DashboardRepository extends EntityRepository<Dashboard> {
String dashboardId = updated.getId().toString(); String dashboardId = updated.getId().toString();
// Remove all charts associated with this dashboard // 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 // Add relationship from dashboard to chart
if (updated.getCharts() != null) { if (updated.getCharts() != null) {
@ -385,7 +385,7 @@ public class DashboardRepository extends EntityRepository<Dashboard> {
String dashboardId = updated.getId().toString(); String dashboardId = updated.getId().toString();
// Remove all charts associated with this dashboard // 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 // Add relationship from dashboard to chart
List<EntityReference> updatedCharts = List<EntityReference> updatedCharts =

View File

@ -60,7 +60,7 @@ public class DatabaseRepository extends EntityRepository<Database> {
@Transaction @Transaction
public void deleteLocation(String databaseId) { 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 @Override
@ -110,7 +110,7 @@ public class DatabaseRepository extends EntityRepository<Database> {
} }
String databaseId = database.getId().toString(); String databaseId = database.getId().toString();
List<String> tableIds = 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<>(); List<EntityReference> tables = new ArrayList<>();
for (String tableId : tableIds) { for (String tableId : tableIds) {
tables.add(daoCollection.tableDAO().findEntityReferenceById(UUID.fromString(tableId))); tables.add(daoCollection.tableDAO().findEntityReferenceById(UUID.fromString(tableId)));
@ -149,7 +149,7 @@ public class DatabaseRepository extends EntityRepository<Database> {
} }
String databaseId = database.getId().toString(); String databaseId = database.getId().toString();
List<String> result = 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) { if (result.size() == 1) {
String locationId = result.get(0); String locationId = result.get(0);
return daoCollection.locationDAO().findEntityReferenceById(UUID.fromString(locationId)); return daoCollection.locationDAO().findEntityReferenceById(UUID.fromString(locationId));
@ -160,7 +160,7 @@ public class DatabaseRepository extends EntityRepository<Database> {
private EntityReference getService(Database database) throws IOException { private EntityReference getService(Database database) throws IOException {
EntityReference ref = 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) { if (ref != null) {
DatabaseService service = getService(ref.getId(), ref.getType()); DatabaseService service = getService(ref.getId(), ref.getType());
ref.setName(service.getName()); ref.setName(service.getName());
@ -187,7 +187,8 @@ public class DatabaseRepository extends EntityRepository<Database> {
daoCollection.databaseDAO().findEntityById(databaseId); daoCollection.databaseDAO().findEntityById(databaseId);
daoCollection.locationDAO().findEntityById(locationId); daoCollection.locationDAO().findEntityById(locationId);
// A database has only one location. // 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 daoCollection
.relationshipDAO() .relationshipDAO()
.insert( .insert(

View File

@ -374,7 +374,7 @@ public abstract class EntityRepository<T> {
public final void delete(UUID id, boolean recursive) throws IOException { public final void delete(UUID id, boolean recursive) throws IOException {
// If an entity being deleted contains other children entities, it can't be deleted // If an entity being deleted contains other children entities, it can't be deleted
List<EntityReference> contains = 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 (contains.size() > 0) {
if (!recursive) { if (!recursive) {
@ -392,12 +392,12 @@ public abstract class EntityRepository<T> {
EntityInterface<T> entityInterface = getEntityInterface(entity); EntityInterface<T> entityInterface = getEntityInterface(entity);
entityInterface.setDeleted(true); entityInterface.setDeleted(true);
storeEntity(entity, true); storeEntity(entity, true);
daoCollection.relationshipDAO().softDeleteAll(id.toString()); daoCollection.relationshipDAO().softDeleteAll(id.toString(), entityName);
return; return;
} }
// Hard delete // Hard delete
dao.delete(id); dao.delete(id);
daoCollection.relationshipDAO().deleteAll(id.toString()); daoCollection.relationshipDAO().deleteAll(id.toString(), entityName);
} }
@Transaction @Transaction
@ -409,7 +409,8 @@ public abstract class EntityRepository<T> {
User user = daoCollection.userDAO().findEntityById(userId); User user = daoCollection.userDAO().findEntityById(userId);
// Remove follower // 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()); ChangeDescription change = new ChangeDescription().withPreviousVersion(entityInterface.getVersion());
change change
@ -457,7 +458,7 @@ public abstract class EntityRepository<T> {
EntityInterface entityInterface = getEntityInterface(entity); EntityInterface entityInterface = getEntityInterface(entity);
return supportsOwner && entity != null return supportsOwner && entity != null
? EntityUtil.populateOwner( ? EntityUtil.populateOwner(
entityInterface.getId(), daoCollection.relationshipDAO(), daoCollection.userDAO(), daoCollection.teamDAO()) entityInterface.getId(), entityName, daoCollection.relationshipDAO(), daoCollection.userDAO(), daoCollection.teamDAO())
: null; : null;
} }
@ -487,7 +488,7 @@ public abstract class EntityRepository<T> {
EntityInterface<T> entityInterface = getEntityInterface(entity); EntityInterface<T> entityInterface = getEntityInterface(entity);
return !supportsFollower || entity == null return !supportsFollower || entity == null
? 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) { public T withHref(UriInfo uriInfo, T entity) {

View File

@ -50,7 +50,7 @@ public class FeedRepository {
// Get owner for the addressed to Entity // Get owner for the addressed to Entity
EntityReference owner = 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 // Insert a new thread
dao.feedDAO().insert(JsonUtils.pojoToJson(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 // For a user entitylink get created or replied relationships to the thread
if (reference.getType().equals(Entity.USER)) { if (reference.getType().equals(Entity.USER)) {
threadIds.addAll( 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( 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 { } else {
// Only data assets are added as about // Only data assets are added as about
result = result =

View File

@ -125,7 +125,7 @@ public class IngestionRepository extends EntityRepository<Ingestion> {
} }
private EntityReference getService(Ingestion ingestion) throws IOException { 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)); return getService(Objects.requireNonNull(ref));
} }

View File

@ -73,8 +73,8 @@ public class LineageRepository {
.withNodes(entities) .withNodes(entities)
.withUpstreamEdges(new ArrayList<>()) .withUpstreamEdges(new ArrayList<>())
.withDownstreamEdges(new ArrayList<>()); .withDownstreamEdges(new ArrayList<>());
addUpstreamLineage(primary.getId(), lineage, upstreamDepth); addUpstreamLineage(primary.getId(), primary.getType(), lineage, upstreamDepth);
addDownstreamLineage(primary.getId(), lineage, downstreamDepth); addDownstreamLineage(primary.getId(), primary.getType(), lineage, downstreamDepth);
// Remove duplicate nodes // Remove duplicate nodes
lineage.withNodes(lineage.getNodes().stream().distinct().collect(Collectors.toList())); lineage.withNodes(lineage.getNodes().stream().distinct().collect(Collectors.toList()));
@ -88,35 +88,35 @@ public class LineageRepository {
return lineage; 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) { if (upstreamDepth == 0) {
return; return;
} }
// from this id ---> find other ids // from this id ---> find other ids
List<EntityReference> upstreamEntities = List<EntityReference> upstreamEntities =
dao.relationshipDAO().findFrom(id.toString(), Relationship.UPSTREAM.ordinal()); dao.relationshipDAO().findFrom(id.toString(), entityType, Relationship.UPSTREAM.ordinal());
lineage.getNodes().addAll(upstreamEntities); lineage.getNodes().addAll(upstreamEntities);
upstreamDepth--; upstreamDepth--;
for (EntityReference upstreamEntity : upstreamEntities) { for (EntityReference upstreamEntity : upstreamEntities) {
lineage.getUpstreamEdges().add(new Edge().withFromEntity(upstreamEntity.getId()).withToEntity(id)); 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) { if (downstreamDepth == 0) {
return; return;
} }
// from other ids ---> to this id // from other ids ---> to this id
List<EntityReference> downStreamEntities = List<EntityReference> downStreamEntities =
dao.relationshipDAO().findTo(id.toString(), Relationship.UPSTREAM.ordinal()); dao.relationshipDAO().findTo(id.toString(), entityType, Relationship.UPSTREAM.ordinal());
lineage.getNodes().addAll(downStreamEntities); lineage.getNodes().addAll(downStreamEntities);
downstreamDepth--; downstreamDepth--;
for (EntityReference entity : downStreamEntities) { for (EntityReference entity : downStreamEntities) {
lineage.getDownstreamEdges().add(new Edge().withToEntity(entity.getId()).withFromEntity(id)); lineage.getDownstreamEdges().add(new Edge().withToEntity(entity.getId()).withFromEntity(id));
addDownstreamLineage(entity.getId(), lineage, downstreamDepth); addDownstreamLineage(entity.getId(), entity.getType(), lineage, downstreamDepth);
} }
} }
} }

View File

@ -218,7 +218,7 @@ public class LocationRepository extends EntityRepository<Location> {
private EntityReference getService(Location location) throws IOException { private EntityReference getService(Location location) throws IOException {
EntityReference ref = 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)); return getService(Objects.requireNonNull(ref));
} }

View File

@ -110,7 +110,7 @@ public class MetricsRepository extends EntityRepository<Metrics> {
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 = 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)); return getService(Objects.requireNonNull(ref));
} }

View File

@ -203,7 +203,7 @@ public class MlModelRepository extends EntityRepository<MlModel> {
private EntityReference getDashboard(MlModel mlModel) throws IOException { private EntityReference getDashboard(MlModel mlModel) throws IOException {
if (mlModel != null) { if (mlModel != null) {
List<EntityReference> ids = 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) { if (ids.size() > 1) {
LOG.warn("Possible database issues - multiple dashboards {} found for model {}", ids, mlModel.getId()); 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) { public void removeDashboard(MlModel mlModel) {
daoCollection daoCollection
.relationshipDAO() .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> { 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 // Remove the dashboard associated with the model, if any
String modelId = updatedModel.getId().toString(); String modelId = updatedModel.getId().toString();
if (origModel.getDashboard() != null) { 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 // Add relationship from model to dashboard

View File

@ -147,7 +147,7 @@ public class PipelineRepository extends EntityRepository<Pipeline> {
private EntityReference getService(Pipeline pipeline) throws IOException { private EntityReference getService(Pipeline pipeline) throws IOException {
EntityReference ref = 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()); PipelineService service = getService(ref.getId(), ref.getType());
ref.setName(service.getName()); ref.setName(service.getName());
ref.setDescription(service.getDescription()); ref.setDescription(service.getDescription());

View File

@ -67,7 +67,7 @@ public class PolicyRepository extends EntityRepository<Policy> {
@Transaction @Transaction
private EntityReference getLocationForPolicy(UUID policyId) throws IOException { private EntityReference getLocationForPolicy(UUID policyId) throws IOException {
List<String> result = 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. // There is at most one location for a policy.
return result.size() == 1 return result.size() == 1
? daoCollection.locationDAO().findEntityReferenceById(UUID.fromString(result.get(0))) ? daoCollection.locationDAO().findEntityReferenceById(UUID.fromString(result.get(0)))
@ -340,7 +340,9 @@ public class PolicyRepository extends EntityRepository<Policy> {
.relationshipDAO() .relationshipDAO()
.delete( .delete(
origPolicy.getId().toString(), origPolicy.getId().toString(),
Entity.POLICY,
origPolicy.getLocation().getId().toString(), origPolicy.getLocation().getId().toString(),
Entity.LOCATION,
Relationship.APPLIED_TO.ordinal()); Relationship.APPLIED_TO.ordinal());
} }
// insert updated Policy --> Location relationship. // insert updated Policy --> Location relationship.

View File

@ -81,7 +81,7 @@ public class ReportRepository extends EntityRepository<Report> {
} }
private EntityReference getService(Report 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) { private EntityReference getService(EntityReference service) {

View File

@ -206,7 +206,7 @@ public class TableRepository extends EntityRepository<Table> {
Table table = daoCollection.tableDAO().findEntityById(tableId); Table table = daoCollection.tableDAO().findEntityById(tableId);
EntityReference location = daoCollection.locationDAO().findEntityReferenceById(locationId); EntityReference location = daoCollection.locationDAO().findEntityReferenceById(locationId);
// A table has only one location. // 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 daoCollection
.relationshipDAO() .relationshipDAO()
.insert(tableId.toString(), locationId.toString(), Entity.TABLE, Entity.LOCATION, Relationship.HAS.ordinal()); .insert(tableId.toString(), locationId.toString(), Entity.TABLE, Entity.LOCATION, Relationship.HAS.ordinal());
@ -270,7 +270,7 @@ public class TableRepository extends EntityRepository<Table> {
@Transaction @Transaction
public void deleteLocation(String tableId) { 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 @Transaction
@ -330,7 +330,7 @@ public class TableRepository extends EntityRepository<Table> {
private EntityReference getService(Table table) throws IOException { private EntityReference getService(Table table) throws IOException {
EntityReference ref = 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()); DatabaseService service = getService(ref.getId(), ref.getType());
ref.setName(service.getName()); ref.setName(service.getName());
ref.setDescription(service.getDescription()); ref.setDescription(service.getDescription());
@ -342,7 +342,7 @@ public class TableRepository extends EntityRepository<Table> {
String serviceId = String serviceId =
daoCollection daoCollection
.relationshipDAO() .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); .get(0);
DatabaseService service = daoCollection.dbServiceDAO().findEntityById(UUID.fromString(serviceId)); DatabaseService service = daoCollection.dbServiceDAO().findEntityById(UUID.fromString(serviceId));
table.setService(new DatabaseServiceEntityInterface(service).getEntityReference()); table.setService(new DatabaseServiceEntityInterface(service).getEntityReference());
@ -436,7 +436,7 @@ public class TableRepository extends EntityRepository<Table> {
private EntityReference getDatabase(UUID tableId) throws IOException { private EntityReference getDatabase(UUID tableId) throws IOException {
// Find database for the table // Find database for the table
List<String> result = 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) { if (result.size() != 1) {
throw EntityNotFoundException.byMessage(String.format("Database for table %s Not found", tableId)); 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 { private EntityReference getLocation(UUID tableId) throws IOException {
// Find the location of the table // Find the location of the table
List<String> result = 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) { if (result.size() == 1) {
return daoCollection.locationDAO().findEntityReferenceById(UUID.fromString(result.get(0))); return daoCollection.locationDAO().findEntityReferenceById(UUID.fromString(result.get(0)));
} else { } else {

View File

@ -129,7 +129,7 @@ public class TeamRepository extends EntityRepository<Team> {
} }
private List<EntityReference> getUsers(String id) throws IOException { 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<>(); List<EntityReference> users = new ArrayList<>();
for (String userId : userIds) { for (String userId : userIds) {
users.add(daoCollection.userDAO().findEntityReferenceById(UUID.fromString(userId))); 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 { private List<EntityReference> getOwns(String teamId) throws IOException {
// Compile entities owned by the team // 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> { public static class TeamEntityInterface implements EntityInterface<Team> {
@ -272,7 +272,7 @@ public class TeamRepository extends EntityRepository<Team> {
List<EntityReference> deleted = new ArrayList<>(); List<EntityReference> deleted = new ArrayList<>();
if (recordListChange("users", origUsers, updatedUsers, added, deleted, entityReferenceMatch)) { if (recordListChange("users", origUsers, updatedUsers, added, deleted, entityReferenceMatch)) {
// Remove users from original and add users from updated // 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 // Add relationships
for (EntityReference user : updatedUsers) { for (EntityReference user : updatedUsers) {
daoCollection daoCollection

View File

@ -124,7 +124,7 @@ public class TopicRepository extends EntityRepository<Topic> {
return null; return null;
} }
// Find service by topic Id // 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(); return new MessagingServiceEntityInterface(getService(service.getId(), service.getType())).getEntityReference();
} }

View File

@ -78,7 +78,7 @@ public class UsageRepository {
// If table usage was reported, add the usage count to database // If table usage was reported, add the usage count to database
if (entityType.equalsIgnoreCase(Entity.TABLE)) { if (entityType.equalsIgnoreCase(Entity.TABLE)) {
List<String> databaseIds = 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()); dao.usageDAO().insertOrUpdateCount(usage.getDate(), databaseIds.get(0), Entity.DATABASE, usage.getCount());
} }
} }

View File

@ -114,12 +114,12 @@ public class UserRepository extends EntityRepository<User> {
private List<EntityReference> getOwns(User user) throws IOException { private List<EntityReference> getOwns(User user) throws IOException {
// Compile entities owned by the user // Compile entities owned by the user
List<EntityReference> ownedEntities = 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 // Compile entities owned by the team the user belongs to
List<EntityReference> teams = user.getTeams() == null ? getTeams(user) : user.getTeams(); List<EntityReference> teams = user.getTeams() == null ? getTeams(user) : user.getTeams();
for (EntityReference team : teams) { 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 // Populate details in entity reference
return EntityUtil.populateEntityReferences(ownedEntities); return EntityUtil.populateEntityReferences(ownedEntities);
@ -127,7 +127,7 @@ public class UserRepository extends EntityRepository<User> {
private List<EntityReference> getFollows(User user) throws IOException { private List<EntityReference> getFollows(User user) throws IOException {
return EntityUtil.populateEntityReferences( 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 { 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 */ /* Add all the roles that user has been assigned, to User entity */
private List<EntityReference> getRoles(User user) throws IOException { 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()); List<EntityReference> roles = new ArrayList<>(roleIds.size());
for (String roleId : roleIds) { for (String roleId : roleIds) {
roles.add(daoCollection.roleDAO().findEntityReferenceById(UUID.fromString(roleId))); 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 */ /* Add all the teams that user belongs to User entity */
private List<EntityReference> getTeams(User user) throws IOException { private List<EntityReference> getTeams(User user) throws IOException {
List<String> teamIds = 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<>(); List<EntityReference> teams = new ArrayList<>();
for (String teamId : teamIds) { for (String teamId : teamIds) {
teams.add(daoCollection.teamDAO().findEntityReferenceById(UUID.fromString(teamId))); 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 { private void updateRoles(User origUser, User updatedUser) throws JsonProcessingException {
// Remove roles from original and add roles from updated // 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()); assignRoles(updatedUser, updatedUser.getRoles());
List<EntityReference> origRoles = Optional.ofNullable(origUser.getRoles()).orElse(Collections.emptyList()); 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 { private void updateTeams(User origUser, User updatedUser) throws JsonProcessingException {
// Remove teams from original and add teams from updated // 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()); assignTeams(updatedUser, updatedUser.getTeams());
List<EntityReference> origTeams = Optional.ofNullable(origUser.getTeams()).orElse(Collections.emptyList()); List<EntityReference> origTeams = Optional.ofNullable(origUser.getTeams()).orElse(Collections.emptyList());

View File

@ -152,8 +152,8 @@ public final class EntityUtil {
return entity; return entity;
} }
public static EntityReference getService(EntityRelationshipDAO dao, UUID entityId) { public static EntityReference getService(EntityRelationshipDAO dao, String entityType, UUID entityId) {
List<EntityReference> refs = dao.findFrom(entityId.toString(), Relationship.CONTAINS.ordinal()); List<EntityReference> refs = dao.findFrom(entityId.toString(), entityType, Relationship.CONTAINS.ordinal());
if (refs.size() > 1) { if (refs.size() > 1) {
LOG.warn("Possible database issues - multiple services found for entity {}", entityId); LOG.warn("Possible database issues - multiple services found for entity {}", entityId);
return refs.get(0); return refs.get(0);
@ -161,8 +161,8 @@ public final class EntityUtil {
return refs.isEmpty() ? null : refs.get(0); return refs.isEmpty() ? null : refs.get(0);
} }
public static EntityReference getService(EntityRelationshipDAO dao, UUID entityId, String serviceType) { public static EntityReference getService(EntityRelationshipDAO dao, String entityType, UUID entityId, String serviceType) {
List<EntityReference> refs = dao.findFromEntity(entityId.toString(), Relationship.CONTAINS.ordinal(), serviceType); List<EntityReference> refs = dao.findFromEntity(entityId.toString(), entityType, Relationship.CONTAINS.ordinal(), serviceType);
if (refs.size() > 1) { if (refs.size() > 1) {
LOG.warn("Possible database issues - multiple services found for entity {}", entityId); LOG.warn("Possible database issues - multiple services found for entity {}", entityId);
return refs.get(0); return refs.get(0);
@ -178,8 +178,8 @@ public final class EntityUtil {
// Get owner for a given entity // Get owner for a given entity
public static EntityReference populateOwner( public static EntityReference populateOwner(
UUID id, EntityRelationshipDAO entityRelationshipDAO, UserDAO userDAO, TeamDAO teamDAO) throws IOException { UUID id, String entityType, EntityRelationshipDAO entityRelationshipDAO, UserDAO userDAO, TeamDAO teamDAO) throws IOException {
List<EntityReference> ids = entityRelationshipDAO.findFrom(id.toString(), Relationship.OWNS.ordinal()); List<EntityReference> ids = entityRelationshipDAO.findFrom(id.toString(), entityType, Relationship.OWNS.ordinal());
if (ids.size() > 1) { if (ids.size() > 1) {
LOG.warn("Possible database issues - multiple owners {} found for entity {}", ids, id); 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 */ /** 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) { if (owner != null && owner.getId() != null) {
LOG.info("Removing owner {}:{} for entity {}", owner.getType(), owner.getId(), ownedEntityId); 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) { String ownedEntityType) {
// TODO inefficient use replace instead of delete and add? // TODO inefficient use replace instead of delete and add?
// TODO check for orig and new owners being the same // 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); setOwner(dao, ownedEntityId, ownedEntityType, newOwner);
} }
@ -372,14 +372,10 @@ public final class EntityUtil {
> 0; > 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( 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 = 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<>(); List<EntityReference> followers = new ArrayList<>();
for (String followerId : followerIds) { for (String followerId : followerIds) {
User user = userDAO.findEntityById(UUID.fromString(followerId)); User user = userDAO.findEntityById(UUID.fromString(followerId));