Skip to content

Commit

Permalink
Seperate reference list in docunit view
Browse files Browse the repository at this point in the history
RISDEV-5670
  • Loading branch information
leonie-koch committed Dec 11, 2024
1 parent 4a999f0 commit 908dd89
Show file tree
Hide file tree
Showing 14 changed files with 378 additions and 246 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import de.bund.digitalservice.ris.caselaw.domain.ManagementData;
import de.bund.digitalservice.ris.caselaw.domain.NormReference;
import de.bund.digitalservice.ris.caselaw.domain.PreviousDecision;
import de.bund.digitalservice.ris.caselaw.domain.ReferenceType;
import de.bund.digitalservice.ris.caselaw.domain.ShortTexts;
import de.bund.digitalservice.ris.caselaw.domain.SingleNorm;
import de.bund.digitalservice.ris.caselaw.domain.StringUtils;
Expand Down Expand Up @@ -167,7 +166,6 @@ private static void addReferences(
updatedDomainObject.references() == null
? Collections.emptyList()
: updatedDomainObject.references().stream()
.filter(reference -> reference.referenceType() == ReferenceType.CASELAW)
.map(ReferenceTransformer::transformToDTO)
.map(
referenceDTO -> {
Expand All @@ -183,10 +181,9 @@ private static void addDependentLiteratureCitations(
DocumentationUnit updatedDomainObject, DocumentationUnitDTOBuilder builder) {
AtomicInteger i = new AtomicInteger(1);
builder.dependentLiteratureCitations(
updatedDomainObject.references() == null
updatedDomainObject.literatureReferences() == null
? Collections.emptyList()
: updatedDomainObject.references().stream()
.filter(reference -> reference.referenceType() == ReferenceType.LITERATURE)
: updatedDomainObject.literatureReferences().stream()
.map(DependentLiteratureTransformer::transformToDTO)
.map(
referenceDTO -> {
Expand Down Expand Up @@ -761,6 +758,7 @@ public static DocumentationUnit transformToDomain(DocumentationUnitDTO documenta

addStatusToDomain(documentationUnitDTO, builder);
addReferencesToDomain(documentationUnitDTO, builder);
addLiteratureReferencesToDomain(documentationUnitDTO, builder);

return builder.build();
}
Expand All @@ -780,10 +778,18 @@ private static void addReferencesToDomain(
.map(ReferenceTransformer::transformToDomain)
.toList());
}
}

private static void addLiteratureReferencesToDomain(
DocumentationUnitDTO documentationUnitDTO,
DocumentationUnit.DocumentationUnitBuilder builder) {

builder.literatureReferences(new ArrayList<>());

if (documentationUnitDTO.getDependentLiteratureCitations() != null) {
builder
.build()
.references()
.literatureReferences()
.addAll(
documentationUnitDTO.getDependentLiteratureCitations().stream()
.map(DependentLiteratureTransformer::transformToDomain)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,6 @@ public record DocumentationUnit(
String note,
ContentRelatedIndexing contentRelatedIndexing,
List<Reference> references,
List<Reference> literatureReferences,
boolean isEditable,
boolean isDeletable) {}
Original file line number Diff line number Diff line change
Expand Up @@ -1349,7 +1349,8 @@ private DocumentationUnit.DocumentationUnitBuilder generateSimpleDocumentationUn
.collectiveAgreements(Collections.emptyList())
.hasLegislativeMandate(false)
.build())
.references(Collections.emptyList());
.references(Collections.emptyList())
.literatureReferences(Collections.emptyList());
}

private CoreDataBuilder generateSimpleCoreDataBuilder() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ void testGetEdition_withMixedReferencesAndLiteratureCitationsFromDocUnitAndEditi
DependentLiteratureCitationDTO.builder()
.id(UUID.randomUUID())
.rank(1)
.citation("1")
.citation("Literature Reference Citation from Docunit")
.legalPeriodicalRawValue("A")
.author("author 1")
.type(DependentLiteratureCitationType.PASSIVE)
Expand All @@ -293,9 +293,9 @@ void testGetEdition_withMixedReferencesAndLiteratureCitationsFromDocUnitAndEditi
.build(),
DependentLiteratureCitationDTO.builder()
.id(existingLiteratureCitationId)
.rank(3)
.citation("3 - original literature citation")
.author("author 3")
.rank(2)
.citation("Original Literature Reference Citation from Docunit")
.author("author 2")
.type(DependentLiteratureCitationType.PASSIVE)
.documentType(
DocumentTypeDTO.builder()
Expand All @@ -313,8 +313,8 @@ void testGetEdition_withMixedReferencesAndLiteratureCitationsFromDocUnitAndEditi
List.of(
ReferenceDTO.builder()
.id(UUID.randomUUID())
.rank(2)
.citation("2")
.rank(1)
.citation("Caselaw Reference Citation from Docunit")
.legalPeriodicalRawValue("A")
.documentationUnit(
DocumentationUnitDTO.builder()
Expand All @@ -324,9 +324,9 @@ void testGetEdition_withMixedReferencesAndLiteratureCitationsFromDocUnitAndEditi
.build(),
ReferenceDTO.builder()
.id(existingReferenceId)
.citation("Original Citation")
.citation("Original Caselaw Reference Citation from Docunit")
.legalPeriodicalRawValue("B")
.rank(4)
.rank(2)
.documentationUnit(
DocumentationUnitDTO.builder()
.id(docUnit.getId())
Expand All @@ -336,6 +336,7 @@ void testGetEdition_withMixedReferencesAndLiteratureCitationsFromDocUnitAndEditi
.build());

UUID newReferenceId = UUID.randomUUID();
UUID newLiteratureReferenceId = UUID.randomUUID();
UUID editionId = UUID.randomUUID();

RelatedDocumentationUnit relatedDocUnit =
Expand All @@ -356,14 +357,14 @@ void testGetEdition_withMixedReferencesAndLiteratureCitationsFromDocUnitAndEditi
Reference.builder()
.id(existingReferenceId)
.referenceType(ReferenceType.CASELAW)
.citation("1 - Updated Citation")
.citation("Updated Caselaw Reference Citation from Edition")
.legalPeriodicalRawValue("B")
.documentationUnit(relatedDocUnit)
.build(),
Reference.builder()
.id(existingLiteratureCitationId)
.referenceType(ReferenceType.LITERATURE)
.citation("2 - Updated Literature Citation")
.citation("Updated Literature Reference Citation from Edition")
.author("author 2")
.documentType(EBS)
.legalPeriodicalRawValue("B")
Expand All @@ -372,15 +373,15 @@ void testGetEdition_withMixedReferencesAndLiteratureCitationsFromDocUnitAndEditi
Reference.builder()
.id(newReferenceId)
.referenceType(ReferenceType.CASELAW)
.citation("3 - New Reference")
.citation("New Caselaw Reference Citation from Edition")
.legalPeriodicalRawValue("D")
.documentationUnit(relatedDocUnit)
.build(),
Reference.builder()
.id(UUID.randomUUID())
.id(newLiteratureReferenceId)
.referenceType(ReferenceType.LITERATURE)
.citation("4 - New Literature Citation")
.author("author 4")
.citation("New Literature Reference Citation from Edition")
.author("author 3")
.documentType(EAN)
.legalPeriodicalRawValue("C")
.documentationUnit(relatedDocUnit)
Expand All @@ -402,26 +403,47 @@ void testGetEdition_withMixedReferencesAndLiteratureCitationsFromDocUnitAndEditi
Assertions.assertEquals("2024 Sonderheft 1", edition.name());
List<Reference> references = editionResponse.references();
Assertions.assertEquals(4, references.size());
Assertions.assertEquals("1 - Updated Citation", references.get(0).citation());
Assertions.assertEquals("2 - Updated Literature Citation", references.get(1).citation());
Assertions.assertEquals("3 - New Reference", references.get(2).citation());
Assertions.assertEquals("4 - New Literature Citation", references.get(3).citation());
Assertions.assertEquals(
"Updated Caselaw Reference Citation from Edition", references.get(0).citation());
Assertions.assertEquals(
"Updated Literature Reference Citation from Edition", references.get(1).citation());
Assertions.assertEquals(
"New Caselaw Reference Citation from Edition", references.get(2).citation());
Assertions.assertEquals(
"New Literature Reference Citation from Edition", references.get(3).citation());

// first, caselaw references
assertThat(documentationUnitService.getByDocumentNumber("DOC_NUMBER").references())
.hasSize(6)
.hasSize(3)
.satisfies(
list -> {
// first, caselaw references
assertThat(list.get(0).citation()).isEqualTo("2");
assertThat(list.get(0).citation())
.isEqualTo("Caselaw Reference Citation from Docunit");
assertThat(list.get(1).id()).isEqualTo(existingReferenceId);
assertThat(list.get(1).citation()).isEqualTo("1 - Updated Citation");
assertThat(list.get(1).citation())
.isEqualTo("Updated Caselaw Reference Citation from Edition");
assertThat(list.get(1).rank()).isEqualTo(2);
assertThat(list.get(2).id()).isEqualTo(newReferenceId);
assertThat(list.get(2).citation()).isEqualTo("3 - New Reference");
// then, literature references
assertThat(list.get(3).citation()).isEqualTo("1");
assertThat(list.get(4).id()).isEqualTo(existingLiteratureCitationId);
assertThat(list.get(4).citation()).isEqualTo("2 - Updated Literature Citation");
assertThat(list.get(5).citation()).isEqualTo("4 - New Literature Citation");
assertThat(list.get(2).citation())
.isEqualTo("New Caselaw Reference Citation from Edition");
assertThat(list.get(2).rank()).isEqualTo(3);
});

// then, literature references
assertThat(documentationUnitService.getByDocumentNumber("DOC_NUMBER").literatureReferences())
.hasSize(3)
.satisfies(
list -> {
assertThat(list.get(0).citation())
.isEqualTo("Literature Reference Citation from Docunit");
assertThat(list.get(1).id()).isEqualTo(existingLiteratureCitationId);
assertThat(list.get(1).citation())
.isEqualTo("Updated Literature Reference Citation from Edition");
assertThat(list.get(1).rank()).isEqualTo(2);
assertThat(list.get(2).id()).isEqualTo(newLiteratureReferenceId);
assertThat(list.get(2).citation())
.isEqualTo("New Literature Reference Citation from Edition");
assertThat(list.get(2).rank()).isEqualTo(3);
});

// clean up
Expand All @@ -446,7 +468,7 @@ void testDeleteReferencesAndLiteratureCitations_fromEdition_shouldSucceed()
DependentLiteratureCitationDTO.builder()
.id(UUID.randomUUID())
.rank(1)
.citation("1")
.citation("Literature Reference from Docunit")
.legalPeriodicalRawValue("A")
.author("author 1")
.type(DependentLiteratureCitationType.PASSIVE)
Expand All @@ -466,7 +488,7 @@ void testDeleteReferencesAndLiteratureCitations_fromEdition_shouldSucceed()
ReferenceDTO.builder()
.id(UUID.randomUUID())
.rank(1)
.citation("2")
.citation("Caselaw Reference from Docunit")
.legalPeriodicalRawValue("A")
.documentationUnit(
DocumentationUnitDTO.builder()
Expand Down Expand Up @@ -499,14 +521,14 @@ void testDeleteReferencesAndLiteratureCitations_fromEdition_shouldSucceed()
Reference.builder()
.id(referenceId)
.referenceType(ReferenceType.CASELAW)
.citation("1 - New Citation")
.citation("Updated Caselaw Reference Citation from Edition")
.legalPeriodicalRawValue("B")
.documentationUnit(relatedDocUnit)
.build(),
Reference.builder()
.id(literatureCitationId)
.referenceType(ReferenceType.LITERATURE)
.citation("2 - New Literature Citation")
.citation("Updated Literature Reference Citation from Edition")
.author("author 2")
.documentType(EBS)
.legalPeriodicalRawValue("B")
Expand All @@ -515,23 +537,23 @@ void testDeleteReferencesAndLiteratureCitations_fromEdition_shouldSucceed()
Reference.builder()
.id(UUID.randomUUID())
.referenceType(ReferenceType.CASELAW)
.citation("3 - New Reference")
.citation("New Caselaw Reference from Edition")
.legalPeriodicalRawValue("D")
.documentationUnit(relatedDocUnit)
.build(),
Reference.builder()
.id(UUID.randomUUID())
.referenceType(ReferenceType.LITERATURE)
.citation("4 - New Literature Citation")
.citation("New Literature Reference from Edition")
.author("author 4")
.documentType(EAN)
.legalPeriodicalRawValue("C")
.documentationUnit(relatedDocUnit)
.build()))
.build());

edition.references().remove(0); // delete 1 - New Citation
edition.references().remove(0); // delete 2 - New Literature Citation
edition.references().remove(0); // delete Updated Caselaw Reference Citation from Edition
edition.references().remove(0); // delete Updated Literature Reference Citation from Edition

assertThat(referenceRepository.findById(referenceId)).isPresent();
assertThat(literatureCitationRepository.findById(literatureCitationId)).isPresent();
Expand All @@ -552,29 +574,34 @@ void testDeleteReferencesAndLiteratureCitations_fromEdition_shouldSucceed()
Assertions.assertEquals("2024 Sonderheft 1", edition.name());
List<Reference> references = editionResponse.references();
Assertions.assertEquals(2, references.size());
Assertions.assertEquals("3 - New Reference", references.get(0).citation());
Assertions.assertEquals("4 - New Literature Citation", references.get(1).citation());
Assertions.assertEquals("New Caselaw Reference from Edition", references.get(0).citation());
Assertions.assertEquals("New Literature Reference from Edition", references.get(1).citation());

// assure rank is updated
assertThat(references.get(0).rank()).isEqualTo(1);
assertThat(references.get(1).rank()).isEqualTo(2);

// documentation unit is updated
// documentation unit references are updated
assertThat(documentationUnitService.getByDocumentNumber("DOC_NUMBER").references())
.hasSize(4)
.hasSize(2)
.satisfies(
list -> {
// first, caselaw references
assertThat(list.get(0).citation()).isEqualTo("2");
assertThat(list.get(0).citation()).isEqualTo("Caselaw Reference from Docunit");
assertThat(list.get(0).rank()).isEqualTo(1);
assertThat(list.get(1).citation()).isEqualTo("3 - New Reference");
assertThat(list.get(1).citation()).isEqualTo("New Caselaw Reference from Edition");
assertThat(list.get(1).rank()).isEqualTo(2);
});

assertThat(documentationUnitService.getByDocumentNumber("DOC_NUMBER").literatureReferences())
.hasSize(2)
.satisfies(
list -> {
// then, literature citations
assertThat(list.get(2).citation()).isEqualTo("1");
assertThat(list.get(2).rank()).isEqualTo(1);
assertThat(list.get(3).citation()).isEqualTo("4 - New Literature Citation");
assertThat(list.get(3).rank()).isEqualTo(2);
assertThat(list.get(0).citation()).isEqualTo("Literature Reference from Docunit");
assertThat(list.get(0).rank()).isEqualTo(1);
assertThat(list.get(1).citation()).isEqualTo("New Literature Reference from Edition");
assertThat(list.get(1).rank()).isEqualTo(2);
});

assertThat(referenceRepository.findById(referenceId)).isEmpty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ void testLiteratureReferencesCanBeSaved() {
.uuid(dto.getId())
.documentNumber(dto.getDocumentNumber())
.coreData(CoreData.builder().documentationOffice(docOffice).build())
.references(
.literatureReferences(
List.of(
Reference.builder()
.id(referenceId)
Expand Down Expand Up @@ -266,11 +266,11 @@ void testLiteratureReferencesCanBeSaved() {
assertThat(response.getResponseBody()).isNotNull();
assertThat(response.getResponseBody().documentNumber())
.isEqualTo(DEFAULT_DOCUMENT_NUMBER);
assertThat(response.getResponseBody().references()).hasSize(1);
assertThat(response.getResponseBody().references())
assertThat(response.getResponseBody().literatureReferences()).hasSize(1);
assertThat(response.getResponseBody().literatureReferences())
.extracting("citation", "author", "documentType", "id")
.containsExactly(tuple("2024, S.3", "Heinz Otto", eanDocumentType, referenceId));
assertThat(response.getResponseBody().references())
assertThat(response.getResponseBody().literatureReferences())
.extracting("legalPeriodical")
.usingRecursiveComparison()
.isEqualTo(List.of(bverwgeLegalPeriodical));
Expand Down
Loading

0 comments on commit 908dd89

Please sign in to comment.