Skip to content

Commit

Permalink
Literature references (#2386)
Browse files Browse the repository at this point in the history
* Show input fields based on reference type

RISDEV-5238

* Add new endpoint for dependant literature doctypes

RISDEV-5422

* Add frontend test

RISDEV-5238

* Also add literature inputs to docunit references

RISDEV-5238

* Fix e2e test

RISDEV-5238

* Adapt to design

RISDEV-5238

* Fix spotless

RISDEV-0000

* Literature citations can be saved to database

RISDEV-5436

* Bump schema

RISDEV-0000

* Integration test for saving literature references

RISDEV-5436

* Display of literature reference list item

RISDEV-5237

* Renaming of method names

RISDEV-5240

* Give more meaningful radio button ids

RISDEV-0000

* Add field validation for literature references

RISDEV-5454

* Fix backend tests

RISDEV-0000

* RISDEV-0000

* Fix validation in docunit

RISDEV-5454

* [WIP] save from edition

RISDEV-5533

* Save lierature citations from edition

RISDEV-5533

* Do not use repos in transformer

RISDEV-5533

* Fix test

RISDEV-0000

* Fix test

RISDEV-0000

* Review finding

RISDEV-0000

---------

Co-authored-by: Hanna Prinz <[email protected]>
  • Loading branch information
leonie-koch and HPrinz authored Nov 26, 2024
1 parent 0330809 commit 4e2755a
Show file tree
Hide file tree
Showing 40 changed files with 1,690 additions and 527 deletions.
2 changes: 1 addition & 1 deletion backend/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ dependencies {
// implementation(files("../../neuris-juris-xml-export/build/libs/neuris-juris-xml-export-0.10.19.jar"))
// or with local gradle project (look also into settings.gradle.kts)
// implementation(project(":exporter"))

implementation("de.bund.digitalservice:neuris-caselaw-migration-schema:0.0.29")
// for local development:
// implementation(files("../../ris-data-migration/schema/build/libs/schema-0.0.28.jar"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,11 @@ public List<DocumentType> getDocumentTypes(
@RequestParam(value = "q") Optional<String> searchStr) {
return service.getDocumentTypes(searchStr);
}

@GetMapping(value = "/dependent-literature", produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("isAuthenticated()")
public List<DocumentType> getDependentLiteratureDocumentTypes(
@RequestParam(value = "q") Optional<String> searchStr) {
return service.getDependentLiteratureDocumentTypes(searchStr);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package de.bund.digitalservice.ris.caselaw.adapter.database.jpa;

import java.util.UUID;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface DatabaseReferenceRepository extends JpaRepository<ReferenceDTO, UUID> {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package de.bund.digitalservice.ris.caselaw.adapter.database.jpa;

import de.bund.digitalservice.ris.caselaw.domain.DependentLiteratureCitationType;
import jakarta.persistence.Column;
import jakarta.persistence.Convert;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import java.util.UUID;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Builder(toBuilder = true)
@Entity
@Table(schema = "incremental_migration", name = "dependent_literature_citation")
public class DependentLiteratureCitationDTO {
@Id private UUID id;

private String author;

@NotBlank private String citation;

@JoinColumn(name = "document_type_id")
@ManyToOne
private DocumentTypeDTO documentType;

@Column(name = "legal_periodical_raw_value")
@NotNull
private String legalPeriodicalRawValue;

@JoinColumn(name = "legal_periodical_id")
@ManyToOne
private LegalPeriodicalDTO legalPeriodical;

@Column(name = "dtype")
@Convert(converter = DependentLiteratureCitationTypeConverter.class)
private DependentLiteratureCitationType type;

@ManyToOne
@JoinColumn(name = "documentation_unit_id")
private DocumentationUnitDTO documentationUnit;

@Column(name = "document_type_raw_value")
private String documentTypeRawValue;

private Integer rank;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package de.bund.digitalservice.ris.caselaw.adapter.database.jpa;

import java.util.UUID;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface DependentLiteratureCitationRepository
extends JpaRepository<DependentLiteratureCitationDTO, UUID> {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package de.bund.digitalservice.ris.caselaw.adapter.database.jpa;

import de.bund.digitalservice.ris.caselaw.domain.DependentLiteratureCitationType;
import jakarta.persistence.AttributeConverter;
import jakarta.persistence.Converter;

@Converter(autoApply = true)
public class DependentLiteratureCitationTypeConverter
implements AttributeConverter<DependentLiteratureCitationType, String> {

@Override
public String convertToDatabaseColumn(DependentLiteratureCitationType attribute) {
return (attribute == null) ? null : attribute.getValue(); // Store "passive" or "active"
}

@Override
public DependentLiteratureCitationType convertToEntityAttribute(String dbData) {
return (dbData == null) ? null : DependentLiteratureCitationType.of(dbData);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,11 @@ public class DocumentationUnitDTO implements DocumentationUnitListItemDTO {
@OrderBy("rank")
private List<ReferenceDTO> references = new ArrayList<>();

@OneToMany(mappedBy = "documentationUnit", cascade = CascadeType.ALL, orphanRemoval = true)
@Builder.Default
@OrderBy("rank")
private List<DependentLiteratureCitationDTO> dependentLiteratureCitations = new ArrayList<>();

@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, orphanRemoval = true)
@JoinColumn(name = "documentation_unit_id", nullable = false)
@OrderBy("rank")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package de.bund.digitalservice.ris.caselaw.adapter.database.jpa;

import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
Expand Down Expand Up @@ -35,11 +34,6 @@ public class EditionReferenceDTO {
@JoinColumn(name = "edition_id", nullable = false)
private LegalPeriodicalEditionDTO edition;

// @ManyToOne
// @JoinColumn(name = "reference_id", insertable = false, updatable = false)
// private DependentLiteratureCitationDTO literatureCitation;

@ManyToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "reference_id")
private ReferenceDTO reference;
@Column(name = "reference_id")
private UUID referenceId;
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,35 +52,34 @@ public class LegalPeriodicalEditionDTO {
private List<EditionReferenceDTO> editionReferences = new ArrayList<>();

// Methods to get references and literature citations
// public List<DependentLiteratureCitationDTO> getLiteratureCitations() {
// return editionReferences.stream()
// .filter(ref -> "literature".equals(ref.getDtype()))
// .map(EditionReferenceDTO::getLiteratureCitation)
// .collect(Collectors.toList());
// }
public List<UUID> getLiteratureCitations() {
return editionReferences.stream()
.filter(ref -> "literature".equals(ref.getDtype()))
.map(EditionReferenceDTO::getReferenceId)
.collect(Collectors.toList());
}

public List<ReferenceDTO> getReferences() {
public List<UUID> getReferences() {
return editionReferences.stream()
.filter(ref -> "reference".equals(ref.getDtype()))
.map(EditionReferenceDTO::getReference)
.map(EditionReferenceDTO::getReferenceId)
.collect(Collectors.toList());
}

//
// public void setLiteratureCitations(List<DependentLiteratureCitationDTO> literatureCitations) {
// // Remove existing literature citations
// 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.setLiteratureCitation(citation);
// editionReference.setRank(citation.getRank());
// editionReference.setDtype("literature");
// editionReferences.add(editionReference);
// }
// }
public void setLiteratureCitations(List<DependentLiteratureCitationDTO> literatureCitations) {
// Remove existing literature citations
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");
editionReferences.add(editionReference);
}
}

public void setReferences(List<ReferenceDTO> references) {
// Remove existing references
Expand All @@ -89,7 +88,7 @@ public void setReferences(List<ReferenceDTO> references) {
// Add new references with updated rank
for (ReferenceDTO reference : references) {
EditionReferenceDTO editionReference = new EditionReferenceDTO();
editionReference.setReference(reference);
editionReference.setReferenceId(reference.getId());
editionReference.setRank(reference.getRank());
editionReference.setDtype("reference");
editionReference.setEdition(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,25 @@ public List<DocumentType> findCaselawBySearchStr(String searchString) {
.toList();
}

@Override
public List<DocumentType> findDependentLiteratureBySearchStr(String searchString) {
return repository
.findCaselawBySearchStrAndCategory(
searchString, categoryRepository.findFirstByLabel("U").getId())
.stream()
.map(DocumentTypeTransformer::transformToDomain)
.toList();
}

@Override
public List<DocumentType> findAllDependentLiteratureOrderByAbbreviationAscLabelAsc() {
return repository
.findAllByCategoryOrderByAbbreviationAscLabelAsc(categoryRepository.findFirstByLabel("U"))
.stream()
.map(DocumentTypeTransformer::transformToDomain)
.toList();
}

@Override
public Optional<DocumentType> findUniqueCaselawBySearchStr(String searchString) {
return repository
Expand Down
Loading

0 comments on commit 4e2755a

Please sign in to comment.