diff --git a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/jpa/LegalPeriodicalEditionDTO.java b/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/jpa/LegalPeriodicalEditionDTO.java index d284490091..98aec37717 100644 --- a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/jpa/LegalPeriodicalEditionDTO.java +++ b/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/jpa/LegalPeriodicalEditionDTO.java @@ -30,6 +30,8 @@ @Getter @Setter public class LegalPeriodicalEditionDTO { + public static final String REFERENCE = "reference"; + public static final String LITERATURE = "literature"; @Id private UUID id; @NotNull @@ -54,21 +56,21 @@ public class LegalPeriodicalEditionDTO { // Methods to get references and literature citations public List getLiteratureCitations() { return editionReferences.stream() - .filter(ref -> "literature".equals(ref.getDtype())) + .filter(ref -> LITERATURE.equals(ref.getDtype())) .map(EditionReferenceDTO::getReferenceId) .collect(Collectors.toList()); } public List getReferences() { return editionReferences.stream() - .filter(ref -> "reference".equals(ref.getDtype())) + .filter(ref -> REFERENCE.equals(ref.getDtype())) .map(EditionReferenceDTO::getReferenceId) .collect(Collectors.toList()); } public void setLiteratureCitations(List literatureCitations) { // Remove existing literature citations - editionReferences.removeIf(ref -> "literature".equals(ref.getDtype())); + editionReferences.removeIf(ref -> LITERATURE.equals(ref.getDtype())); // Add new literature citations with updated rank for (DependentLiteratureCitationDTO citation : literatureCitations) { @@ -76,21 +78,21 @@ public void setLiteratureCitations(List literatu editionReference.setEdition(this); editionReference.setReferenceId(citation.getId()); editionReference.setRank(citation.getRank()); - editionReference.setDtype("literature"); + editionReference.setDtype(LITERATURE); editionReferences.add(editionReference); } } public void setReferences(List references) { // Remove existing references - editionReferences.removeIf(ref -> "reference".equals(ref.getDtype())); + editionReferences.removeIf(ref -> REFERENCE.equals(ref.getDtype())); // Add new references with updated rank for (ReferenceDTO reference : references) { EditionReferenceDTO editionReference = new EditionReferenceDTO(); editionReference.setReferenceId(reference.getId()); editionReference.setRank(reference.getRank()); - editionReference.setDtype("reference"); + editionReference.setDtype(REFERENCE); editionReference.setEdition(this); editionReferences.add(editionReference); } diff --git a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/jpa/PostgresLegalPeriodicalEditionRepositoryImpl.java b/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/jpa/PostgresLegalPeriodicalEditionRepositoryImpl.java index e59b5a3a17..2f2a722ad2 100644 --- a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/jpa/PostgresLegalPeriodicalEditionRepositoryImpl.java +++ b/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/jpa/PostgresLegalPeriodicalEditionRepositoryImpl.java @@ -104,14 +104,11 @@ private void deleteDocUnitLinksForDeletedReferences(LegalPeriodicalEdition updat } // Ensure it's removed from DocumentationUnit's references for (UUID reference : oldEdition.get().getReferences()) { - // skip all existing references - if (updatedEdition.references().stream() - .anyMatch(newReference -> newReference.id().equals(reference))) { - continue; - } - + // skip all existing and null references var referenceDTO = referenceRepository.findById(reference); - if (referenceDTO.isEmpty()) { + if (updatedEdition.references().stream() + .anyMatch( + newReference -> newReference.id().equals(reference) || referenceDTO.isEmpty())) { continue; } // delete all deleted references and possible source reference @@ -142,12 +139,7 @@ private List createReferenceDTOs(LegalPeriodicalEdition legalPerio var docUnit = documentationUnitRepository.findByDocumentNumber( reference.documentationUnit().getDocumentNumber()); - if (docUnit.isEmpty()) { - // don't add references to non-existing documentation units - continue; - } - - if (!reference.referenceType().equals(ReferenceType.CASELAW)) { + if (docUnit.isEmpty() || !reference.referenceType().equals(ReferenceType.CASELAW)) { continue; } var newReference = ReferenceTransformer.transformToDTO(reference); @@ -183,12 +175,7 @@ private List createLiteratureReferenceDTOs( var docUnit = documentationUnitRepository.findByDocumentNumber( reference.documentationUnit().getDocumentNumber()); - if (docUnit.isEmpty()) { - // don't add references to non-existing documentation units - continue; - } - - if (!reference.referenceType().equals(ReferenceType.LITERATURE)) { + if (docUnit.isEmpty() || !reference.referenceType().equals(ReferenceType.LITERATURE)) { continue; } diff --git a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/transformer/DocumentationUnitTransformer.java b/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/transformer/DocumentationUnitTransformer.java index 37891b6636..5e800e0e4e 100644 --- a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/transformer/DocumentationUnitTransformer.java +++ b/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/transformer/DocumentationUnitTransformer.java @@ -775,7 +775,6 @@ private static void addReferencesToDomain( .map(ReferenceTransformer::transformToDomain) .toList()); } - if (documentationUnitDTO.getDependentLiteratureCitations() != null) { references.addAll( documentationUnitDTO.getDependentLiteratureCitations().stream() diff --git a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/config/OtcObsConfig.java b/backend/src/main/java/de/bund/digitalservice/ris/caselaw/config/OtcObsConfig.java index c16d3777ef..06ba968896 100644 --- a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/config/OtcObsConfig.java +++ b/backend/src/main/java/de/bund/digitalservice/ris/caselaw/config/OtcObsConfig.java @@ -56,7 +56,7 @@ public S3Client ldmlS3Client() throws URISyntaxException { @Bean(name = "ldmlS3Client") @Profile({"production", "uat"}) - public S3Client ldmlS3NoopClient() throws URISyntaxException { + public S3Client ldmlS3NoopClient() { return new S3NoOpClient(); } diff --git a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/config/UserGroupsConfig.java b/backend/src/main/java/de/bund/digitalservice/ris/caselaw/config/UserGroupsConfig.java index fa116ea94c..2824ac6ee6 100644 --- a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/config/UserGroupsConfig.java +++ b/backend/src/main/java/de/bund/digitalservice/ris/caselaw/config/UserGroupsConfig.java @@ -8,6 +8,10 @@ @Configuration public class UserGroupsConfig { + public static final String BGH = "BGH"; + public static final String BVERWG = "BVerwG"; + public static final String DS = "DS"; + /** * Caution: Changing values will delete and recreate the affected group in our database. This * means all references to the affected group will be deleted, e.g., the links of the affected @@ -17,22 +21,22 @@ public class UserGroupsConfig { public List getDocumentationOfficeConfigUserGroups() { return List.of( UserGroupFromConfig.builder() - .docOfficeAbbreviation("BGH") + .docOfficeAbbreviation(BGH) .userGroupPathName("/caselaw/BGH") .isInternal(true) .build(), UserGroupFromConfig.builder() - .docOfficeAbbreviation("BGH") + .docOfficeAbbreviation(BGH) .userGroupPathName("/caselaw/BGH/Intern") .isInternal(true) .build(), UserGroupFromConfig.builder() - .docOfficeAbbreviation("BGH") + .docOfficeAbbreviation(BGH) .userGroupPathName("/caselaw/BGH/Extern/Miotke") .isInternal(false) .build(), UserGroupFromConfig.builder() - .docOfficeAbbreviation("BGH") + .docOfficeAbbreviation(BGH) .userGroupPathName("/caselaw/BGH/Extern/Innodata") .isInternal(false) .build(), @@ -62,22 +66,22 @@ public List getDocumentationOfficeConfigUserGroups() { .isInternal(true) .build(), UserGroupFromConfig.builder() - .docOfficeAbbreviation("BVerwG") + .docOfficeAbbreviation(BVERWG) .userGroupPathName("/caselaw/BVerwG") .isInternal(true) .build(), UserGroupFromConfig.builder() - .docOfficeAbbreviation("BVerwG") + .docOfficeAbbreviation(BVERWG) .userGroupPathName("/caselaw/BVerwG/Intern") .isInternal(true) .build(), UserGroupFromConfig.builder() - .docOfficeAbbreviation("BVerwG") + .docOfficeAbbreviation(BVERWG) .userGroupPathName("/caselaw/BVerwG/Extern/ErsterDienstleister") .isInternal(false) .build(), UserGroupFromConfig.builder() - .docOfficeAbbreviation("BVerwG") + .docOfficeAbbreviation(BVERWG) .userGroupPathName("/caselaw/BVerwG/Extern/ZweiterDienstleister") .isInternal(false) .build(), @@ -92,17 +96,17 @@ public List getDocumentationOfficeConfigUserGroups() { .isInternal(true) .build(), UserGroupFromConfig.builder() - .docOfficeAbbreviation("DS") + .docOfficeAbbreviation(DS) .userGroupPathName("/DS") .isInternal(true) .build(), UserGroupFromConfig.builder() - .docOfficeAbbreviation("DS") + .docOfficeAbbreviation(DS) .userGroupPathName("/DS/Intern") .isInternal(true) .build(), UserGroupFromConfig.builder() - .docOfficeAbbreviation("DS") + .docOfficeAbbreviation(DS) .userGroupPathName("/DS/Extern") .isInternal(false) .build(), diff --git a/backend/src/test/java/de/bund/digitalservice/ris/caselaw/adapter/DatabaseDocumentNumberRecyclingServiceTest.java b/backend/src/test/java/de/bund/digitalservice/ris/caselaw/adapter/DatabaseDocumentNumberRecyclingServiceTest.java index 6ec5096d71..7b3acbfe95 100644 --- a/backend/src/test/java/de/bund/digitalservice/ris/caselaw/adapter/DatabaseDocumentNumberRecyclingServiceTest.java +++ b/backend/src/test/java/de/bund/digitalservice/ris/caselaw/adapter/DatabaseDocumentNumberRecyclingServiceTest.java @@ -133,7 +133,7 @@ void recycleFromDeletedDocumentationUnit_shouldNotOfferUsedDocumentationUnit() { DEFAULT_DOCUMENTATION_OFFICE, Year.now())); Assertions.assertEquals( - exception.getMessage(), "Saved documentation number is currently in use"); + "Saved documentation number is currently in use", exception.getMessage()); } @ParameterizedTest diff --git a/backend/src/test/java/de/bund/digitalservice/ris/caselaw/adapter/DocumentTypeControllerTest.java b/backend/src/test/java/de/bund/digitalservice/ris/caselaw/adapter/DocumentTypeControllerTest.java index 9f279f759b..f5b06be033 100644 --- a/backend/src/test/java/de/bund/digitalservice/ris/caselaw/adapter/DocumentTypeControllerTest.java +++ b/backend/src/test/java/de/bund/digitalservice/ris/caselaw/adapter/DocumentTypeControllerTest.java @@ -53,7 +53,7 @@ void setUp() { } @Test - void shouldReturnListOfDocumentTypes_whenGetDocumentTypesIsCalled() throws Exception { + void shouldReturnListOfDocumentTypes_whenGetDocumentTypesIsCalled() { List documentTypes = List.of(documentType1, documentType2); when(service.getDocumentTypes(any(Optional.class))).thenReturn(documentTypes); @@ -89,8 +89,7 @@ void shouldReturnListOfDocumentTypes_whenGetDocumentTypesIsCalled() throws Excep } @Test - void shouldCallServiceWithSearchQueryParameter_whenGetDocumentTypesIsCalledWithSearchString() - throws Exception { + void shouldCallServiceWithSearchQueryParameter_whenGetDocumentTypesIsCalledWithSearchString() { List documentTypes = List.of(documentType1, documentType2); when(service.getDocumentTypes(any(Optional.class))).thenReturn(documentTypes); @@ -108,8 +107,7 @@ void shouldCallServiceWithSearchQueryParameter_whenGetDocumentTypesIsCalledWithS @Test void - shouldCallServiceWithSearchQueryParameter_whenGetDependentLiteratureDocumentTypesIsCalledWithSearchString() - throws Exception { + shouldCallServiceWithSearchQueryParameter_whenGetDependentLiteratureDocumentTypesIsCalledWithSearchString() { List documentTypes = List.of(documentType1, documentType2); when(service.getDependentLiteratureDocumentTypes(any(Optional.class))) diff --git a/backend/src/test/java/de/bund/digitalservice/ris/caselaw/integration/tests/LegalPeriodicalEditionIntegrationTest.java b/backend/src/test/java/de/bund/digitalservice/ris/caselaw/integration/tests/LegalPeriodicalEditionIntegrationTest.java index 92e7b9121b..94d6b6a8fa 100644 --- a/backend/src/test/java/de/bund/digitalservice/ris/caselaw/integration/tests/LegalPeriodicalEditionIntegrationTest.java +++ b/backend/src/test/java/de/bund/digitalservice/ris/caselaw/integration/tests/LegalPeriodicalEditionIntegrationTest.java @@ -564,7 +564,7 @@ void testCleanupDocUnitReferencesAndSourceWhenReferenceDeleted() .iterator() .next() .getCreatedByReference()) - .isEqualTo(null); + .isNull(); assertThat(documentationUnitService.getByDocumentNumber("DOC_NUMBER").references()).isEmpty(); }