diff --git a/odd-platform-api/src/main/java/org/opendatadiscovery/oddplatform/repository/DatasetVersionRepositoryImpl.java b/odd-platform-api/src/main/java/org/opendatadiscovery/oddplatform/repository/DatasetVersionRepositoryImpl.java index 5b39a6045..ebba63a15 100644 --- a/odd-platform-api/src/main/java/org/opendatadiscovery/oddplatform/repository/DatasetVersionRepositoryImpl.java +++ b/odd-platform-api/src/main/java/org/opendatadiscovery/oddplatform/repository/DatasetVersionRepositoryImpl.java @@ -67,7 +67,7 @@ public Optional getDatasetVersion(final long datasetVersion .leftJoin(DATASET_STRUCTURE).on(DATASET_STRUCTURE.DATASET_VERSION_ID.eq(DATASET_VERSION.ID)) .leftJoin(DATASET_FIELD).on(DATASET_FIELD.ID.eq(DATASET_STRUCTURE.DATASET_FIELD_ID)) .leftJoin(LABEL_TO_DATASET_FIELD).on(DATASET_FIELD.ID.eq(LABEL_TO_DATASET_FIELD.DATASET_FIELD_ID)) - .leftJoin(LABEL).on(LABEL_TO_DATASET_FIELD.LABEL_ID.eq(LABEL.ID)) + .leftJoin(LABEL).on(LABEL_TO_DATASET_FIELD.LABEL_ID.eq(LABEL.ID)).and(LABEL.IS_DELETED.isFalse()) .where(DATASET_VERSION.ID.eq(datasetVersionId)) .groupBy(selectFields) .fetchGroups(this::extractDatasetVersion, this::extractDatasetFieldDto); @@ -106,7 +106,7 @@ public Optional getLatestDatasetVersion(final long datasetI .leftJoin(DATASET_STRUCTURE).on(DATASET_STRUCTURE.DATASET_VERSION_ID.eq(DATASET_VERSION.ID)) .leftJoin(DATASET_FIELD).on(DATASET_FIELD.ID.eq(DATASET_STRUCTURE.DATASET_FIELD_ID)) .leftJoin(LABEL_TO_DATASET_FIELD).on(DATASET_FIELD.ID.eq(LABEL_TO_DATASET_FIELD.DATASET_FIELD_ID)) - .leftJoin(LABEL).on(LABEL_TO_DATASET_FIELD.LABEL_ID.eq(LABEL.ID)) + .leftJoin(LABEL).on(LABEL_TO_DATASET_FIELD.LABEL_ID.eq(LABEL.ID)).and(LABEL.IS_DELETED.isFalse()) .groupBy(selectFields) .fetchGroups(this::extractDatasetVersion, this::extractDatasetFieldDto); diff --git a/odd-platform-api/src/main/java/org/opendatadiscovery/oddplatform/repository/LabelRepository.java b/odd-platform-api/src/main/java/org/opendatadiscovery/oddplatform/repository/LabelRepository.java index 3a2ff730d..a244b4d30 100644 --- a/odd-platform-api/src/main/java/org/opendatadiscovery/oddplatform/repository/LabelRepository.java +++ b/odd-platform-api/src/main/java/org/opendatadiscovery/oddplatform/repository/LabelRepository.java @@ -3,6 +3,7 @@ import java.util.Collection; import java.util.List; import org.opendatadiscovery.oddplatform.model.tables.pojos.LabelPojo; +import org.springframework.transaction.annotation.Transactional; public interface LabelRepository extends CRUDRepository { List listByDatasetFieldId(final long datasetFieldId); @@ -11,5 +12,9 @@ public interface LabelRepository extends CRUDRepository { void deleteRelations(final long datasetFieldId, final Collection labels); + void deleteRelations(final long id); + + void deleteRelations(final Collection labels); + void createRelations(final long datasetFieldId, final Collection labels); } diff --git a/odd-platform-api/src/main/java/org/opendatadiscovery/oddplatform/repository/LabelRepositoryImpl.java b/odd-platform-api/src/main/java/org/opendatadiscovery/oddplatform/repository/LabelRepositoryImpl.java index 2740e8dd6..2b17a3891 100644 --- a/odd-platform-api/src/main/java/org/opendatadiscovery/oddplatform/repository/LabelRepositoryImpl.java +++ b/odd-platform-api/src/main/java/org/opendatadiscovery/oddplatform/repository/LabelRepositoryImpl.java @@ -67,6 +67,20 @@ public List listByNames(final Collection names) { .collect(Collectors.toList()); } + @Override + @Transactional + public void delete(final long id) { + deleteRelations(id); + super.delete(id); + } + + @Override + @Transactional + public void delete(final List ids) { + deleteRelations(ids); + super.delete(ids); + } + @Override @Transactional public void deleteRelations(final long datasetFieldId, final Collection labels) { @@ -80,6 +94,22 @@ public void deleteRelations(final long datasetFieldId, final Collection la .execute(); } + @Override + public void deleteRelations(final long id) { + deleteRelations(List.of(id)); + } + + @Override + public void deleteRelations(final Collection ids) { + if (ids.isEmpty()) { + return; + } + + dslContext.delete(LABEL_TO_DATASET_FIELD) + .where(LABEL_TO_DATASET_FIELD.LABEL_ID.in(ids)) + .execute(); + } + @Override public void createRelations(final long datasetFieldId, final Collection labels) { if (labels.isEmpty()) {