Skip to content

Commit

Permalink
Fix sonar issues
Browse files Browse the repository at this point in the history
RISDEV-0000
  • Loading branch information
HPrinz committed Nov 26, 2024
1 parent 4e2755a commit acb6a26
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -54,43 +56,43 @@ public class LegalPeriodicalEditionDTO {
// Methods to get references and literature citations
public List<UUID> getLiteratureCitations() {
return editionReferences.stream()
.filter(ref -> "literature".equals(ref.getDtype()))
.filter(ref -> LITERATURE.equals(ref.getDtype()))
.map(EditionReferenceDTO::getReferenceId)
.collect(Collectors.toList());
}

public List<UUID> 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<DependentLiteratureCitationDTO> 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) {
EditionReferenceDTO editionReference = new EditionReferenceDTO();
editionReference.setEdition(this);
editionReference.setReferenceId(citation.getId());
editionReference.setRank(citation.getRank());
editionReference.setDtype("literature");
editionReference.setDtype(LITERATURE);
editionReferences.add(editionReference);
}
}

public void setReferences(List<ReferenceDTO> 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -142,12 +139,7 @@ private List<ReferenceDTO> 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);
Expand Down Expand Up @@ -183,12 +175,7 @@ private List<DependentLiteratureCitationDTO> 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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -775,7 +775,6 @@ private static void addReferencesToDomain(
.map(ReferenceTransformer::transformToDomain)
.toList());
}

if (documentationUnitDTO.getDependentLiteratureCitations() != null) {
references.addAll(
documentationUnitDTO.getDependentLiteratureCitations().stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -17,22 +21,22 @@ public class UserGroupsConfig {
public List<UserGroupFromConfig> 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(),
Expand Down Expand Up @@ -62,22 +66,22 @@ public List<UserGroupFromConfig> 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(),
Expand All @@ -92,17 +96,17 @@ public List<UserGroupFromConfig> 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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ void setUp() {
}

@Test
void shouldReturnListOfDocumentTypes_whenGetDocumentTypesIsCalled() throws Exception {
void shouldReturnListOfDocumentTypes_whenGetDocumentTypesIsCalled() {
List<DocumentType> documentTypes = List.of(documentType1, documentType2);

when(service.getDocumentTypes(any(Optional.class))).thenReturn(documentTypes);
Expand Down Expand Up @@ -89,8 +89,7 @@ void shouldReturnListOfDocumentTypes_whenGetDocumentTypesIsCalled() throws Excep
}

@Test
void shouldCallServiceWithSearchQueryParameter_whenGetDocumentTypesIsCalledWithSearchString()
throws Exception {
void shouldCallServiceWithSearchQueryParameter_whenGetDocumentTypesIsCalledWithSearchString() {
List<DocumentType> documentTypes = List.of(documentType1, documentType2);

when(service.getDocumentTypes(any(Optional.class))).thenReturn(documentTypes);
Expand All @@ -108,8 +107,7 @@ void shouldCallServiceWithSearchQueryParameter_whenGetDocumentTypesIsCalledWithS

@Test
void
shouldCallServiceWithSearchQueryParameter_whenGetDependentLiteratureDocumentTypesIsCalledWithSearchString()
throws Exception {
shouldCallServiceWithSearchQueryParameter_whenGetDependentLiteratureDocumentTypesIsCalledWithSearchString() {
List<DocumentType> documentTypes = List.of(documentType1, documentType2);

when(service.getDependentLiteratureDocumentTypes(any(Optional.class)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ void testCleanupDocUnitReferencesAndSourceWhenReferenceDeleted()
.iterator()
.next()
.getCreatedByReference())
.isEqualTo(null);
.isNull();

assertThat(documentationUnitService.getByDocumentNumber("DOC_NUMBER").references()).isEmpty();
}
Expand Down

0 comments on commit acb6a26

Please sign in to comment.