Skip to content

Commit

Permalink
Delete linked active citations on docunit deletion
Browse files Browse the repository at this point in the history
RISDEV-2502
  • Loading branch information
HPrinz committed Sep 27, 2023
1 parent cc9976a commit 7d3895d
Show file tree
Hide file tree
Showing 2 changed files with 124 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,12 @@ public Mono<String> deleteByUuid(UUID documentUnitUuid) {
? Flux.empty()
: Flux.fromIterable(documentUnit.proceedingDecisions());

Flux<ActiveCitation> activeCitations =
documentUnit.contentRelatedIndexing() == null
|| documentUnit.contentRelatedIndexing().activeCitations() == null
? Flux.empty()
: Flux.fromIterable(documentUnit.contentRelatedIndexing().activeCitations());

String logMsg =
"Dokumentationseinheit gelöscht: "
+ documentUnitUuid
Expand All @@ -261,7 +267,14 @@ public Mono<String> deleteByUuid(UUID documentUnitUuid) {
? ""
: ", zudem die Verknüpfungen mit "
+ documentUnit.proceedingDecisions().size()
+ " vorgehenden Entscheidungen");
+ " vorgehenden Entscheidungen")
+ (documentUnit.contentRelatedIndexing() == null
|| documentUnit.contentRelatedIndexing().activeCitations() == null
|| documentUnit.contentRelatedIndexing().activeCitations().isEmpty()
? ""
: ", zudem die Verknüpfungen mit "
+ documentUnit.contentRelatedIndexing().activeCitations().size()
+ " Aktivzitierungen");

return deleteAttachedFile
.thenMany(
Expand All @@ -271,6 +284,13 @@ public Mono<String> deleteByUuid(UUID documentUnitUuid) {
documentUnitUuid,
proceedingDecision.getUuid(),
DocumentationUnitLinkType.PREVIOUS_DECISION)))
.thenMany(
activeCitations.flatMap(
activeCitation ->
removeLinkedDocumentationUnit(
documentUnitUuid,
activeCitation.getUuid(),
DocumentationUnitLinkType.ACTIVE_CITATION)))
.then(repository.delete(documentUnit))
.thenReturn(logMsg);
})
Expand All @@ -281,7 +301,7 @@ public Mono<String> deleteByUuid(UUID documentUnitUuid) {
return Mono.error(
new DocumentUnitDeletionException(
"die Dokumentationseinheit konnte nicht gelöscht werden, "
+ "da sie eine vorgehende Entscheidung für "
+ "da sie eine vorgehende Entscheidung oder Aktivzitierung für "
+ documentUnitsThisOneIsAChildOf.get()
+ " andere Dokumentationseinheiten darstellt"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,108 @@ void testDeleteByUuid_withoutFileAttached() {
verify(s3AsyncClient, times(0)).deleteObject(any(DeleteObjectRequest.class));
}

@Test
void testDeleteByUuid_withProceedingDecisions() {
var pdUuid = UUID.randomUUID();
DocumentUnit documentUnit =
DocumentUnit.builder()
.uuid(TEST_UUID)
.proceedingDecisions(
List.of(
ProceedingDecision.builder()
.uuid(pdUuid)
.dataSource(DataSource.PROCEEDING_DECISION)
.build()))
.build();
when(repository.countLinksByChildDocumentUnitUuid(TEST_UUID)).thenReturn(Mono.just(1L));
when(repository.findByUuid(TEST_UUID)).thenReturn(Mono.just(documentUnit));
when(repository.deleteIfOrphanedLinkedDocumentationUnit(pdUuid)).thenReturn(Mono.empty());
when(repository.unlinkDocumentUnit(
TEST_UUID, pdUuid, DocumentationUnitLinkType.PREVIOUS_DECISION))
.thenReturn(Mono.empty());

when(repository.findAllLinkedDocumentUnitsByParentDocumentUnitUuidAndType(
TEST_UUID, DocumentationUnitLinkType.ACTIVE_CITATION))
.thenReturn(Flux.empty());
when(repository.findAllLinkedDocumentUnitsByParentDocumentUnitUuidAndType(
TEST_UUID, DocumentationUnitLinkType.PREVIOUS_DECISION))
.thenReturn(
Flux.just(
LinkedDocumentationUnit.builder()
.uuid(pdUuid)
.dataSource(DataSource.PROCEEDING_DECISION)
.build()));
when(repository.delete(any(DocumentUnit.class))).thenReturn(Mono.just(mock(Void.class)));

StepVerifier.create(service.deleteByUuid(TEST_UUID))
.consumeNextWith(
string -> {
assertNotNull(string);
assertEquals(
"Dokumentationseinheit gelöscht: "
+ TEST_UUID
+ ", zudem die Verknüpfungen mit 1 vorgehenden Entscheidungen",
string);
})
.verifyComplete();

verify(repository)
.unlinkDocumentUnit(TEST_UUID, pdUuid, DocumentationUnitLinkType.PREVIOUS_DECISION);
verify(repository).deleteIfOrphanedLinkedDocumentationUnit(pdUuid);
}

@Test
void testDeleteByUuid_withActiveCitations() {
var acUuid = UUID.randomUUID();
DocumentUnit documentUnit =
DocumentUnit.builder()
.uuid(TEST_UUID)
.contentRelatedIndexing(
ContentRelatedIndexing.builder()
.activeCitations(
List.of(
ActiveCitation.builder()
.uuid(acUuid)
.dataSource(DataSource.ACTIVE_CITATION)
.build()))
.build())
.build();
when(repository.countLinksByChildDocumentUnitUuid(TEST_UUID)).thenReturn(Mono.just(1L));
when(repository.findByUuid(TEST_UUID)).thenReturn(Mono.just(documentUnit));
when(repository.deleteIfOrphanedLinkedDocumentationUnit(acUuid)).thenReturn(Mono.empty());
when(repository.unlinkDocumentUnit(
TEST_UUID, acUuid, DocumentationUnitLinkType.ACTIVE_CITATION))
.thenReturn(Mono.empty());
when(repository.findAllLinkedDocumentUnitsByParentDocumentUnitUuidAndType(
TEST_UUID, DocumentationUnitLinkType.PREVIOUS_DECISION))
.thenReturn(Flux.empty());
when(repository.findAllLinkedDocumentUnitsByParentDocumentUnitUuidAndType(
TEST_UUID, DocumentationUnitLinkType.ACTIVE_CITATION))
.thenReturn(
Flux.just(
LinkedDocumentationUnit.builder()
.uuid(acUuid)
.dataSource(DataSource.ACTIVE_CITATION)
.build()));
when(repository.delete(any(DocumentUnit.class))).thenReturn(Mono.just(mock(Void.class)));

StepVerifier.create(service.deleteByUuid(TEST_UUID))
.consumeNextWith(
string -> {
assertNotNull(string);
assertEquals(
"Dokumentationseinheit gelöscht: "
+ TEST_UUID
+ ", zudem die Verknüpfungen mit 1 Aktivzitierungen",
string);
})
.verifyComplete();

verify(repository)
.unlinkDocumentUnit(TEST_UUID, acUuid, DocumentationUnitLinkType.ACTIVE_CITATION);
verify(repository).deleteIfOrphanedLinkedDocumentationUnit(acUuid);
}

@Test
void testDeleteByUuid_withFileAttached() {
DocumentUnit documentUnit =
Expand Down

0 comments on commit 7d3895d

Please sign in to comment.