Skip to content

Commit

Permalink
Delete label relations after label deleted (#289)
Browse files Browse the repository at this point in the history
* Delete label relations after label deleted

* Pull request fix

Co-authored-by: marselakhmetov <[email protected]>
  • Loading branch information
MarselAhmetov and marselakhmetov authored Dec 6, 2021
1 parent 7f39550 commit 26e587c
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public Optional<DatasetStructureDto> 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);
Expand Down Expand Up @@ -106,7 +106,7 @@ public Optional<DatasetStructureDto> 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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<LabelPojo> {
List<LabelPojo> listByDatasetFieldId(final long datasetFieldId);
Expand All @@ -11,5 +12,9 @@ public interface LabelRepository extends CRUDRepository<LabelPojo> {

void deleteRelations(final long datasetFieldId, final Collection<Long> labels);

void deleteRelations(final long id);

void deleteRelations(final Collection<Long> labels);

void createRelations(final long datasetFieldId, final Collection<Long> labels);
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,20 @@ public List<LabelPojo> listByNames(final Collection<String> names) {
.collect(Collectors.toList());
}

@Override
@Transactional
public void delete(final long id) {
deleteRelations(id);
super.delete(id);
}

@Override
@Transactional
public void delete(final List<Long> ids) {
deleteRelations(ids);
super.delete(ids);
}

@Override
@Transactional
public void deleteRelations(final long datasetFieldId, final Collection<Long> labels) {
Expand All @@ -80,6 +94,22 @@ public void deleteRelations(final long datasetFieldId, final Collection<Long> la
.execute();
}

@Override
public void deleteRelations(final long id) {
deleteRelations(List.of(id));
}

@Override
public void deleteRelations(final Collection<Long> 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<Long> labels) {
if (labels.isEmpty()) {
Expand Down

0 comments on commit 26e587c

Please sign in to comment.