From ce10d4f9382b50ae6d64d2f0acf5a3dfb5316476 Mon Sep 17 00:00:00 2001 From: Hanna Prinz Date: Mon, 23 Oct 2023 15:24:00 +0200 Subject: [PATCH] Use migration schema for norm abbreviation (#791) * Use migration schema for norm abbreviation * Use migration schema for norm element * Make norm abbreviation test reliable * Extend migration schema local doc * Remove reactive from most of norm abbr * Add legacy doc_unit_id column in norm reference --- Co-authored-by: Ralph von Petersdorff-Campen --- .talismanrc | 2 +- .../LookupTableImporterController.java | 15 - .../adapter/LookupTableImporterService.java | 46 -- .../adapter/NormAbbreviationController.java | 32 +- .../adapter/NormAbbreviationService.java | 28 +- .../DatabaseDocumentCategoryRepository.java | 12 + .../jpa/DatabaseDocumentTypeRepository.java | 38 ++ .../DatabaseNormAbbreviationRepository.java | 58 +++ ...ava => DatabaseNormElementRepository.java} | 8 +- .../jpa/DatabaseNormReferenceRepository.java | 11 + ...ory.java => DatabaseRegionRepository.java} | 3 +- .../database/jpa/DocumentCategoryDTO.java | 26 + .../adapter/database/jpa/DocumentTypeDTO.java | 44 ++ .../database/jpa/JPADocumentTypeDTO.java | 40 -- .../database/jpa/NormAbbreviationDTO.java | 97 ++++ ...ormElementDTO.java => NormElementDTO.java} | 10 +- .../database/jpa/NormReferenceDTO.java | 47 ++ .../PostgresDocumentTypeRepositoryImpl.java | 39 ++ ...ostgresNormAbbreviationRepositoryImpl.java | 108 ++++ ...=> PostgresNormElementRepositoryImpl.java} | 7 +- .../adapter/database/jpa/RegionDTO.java | 28 + ...atabaseDocumentUnitMetadataRepository.java | 4 +- .../DatabaseDocumentUnitNormRepository.java | 11 - .../r2dbc/DatabaseNormElementRepository.java | 17 - .../database/r2dbc/DocumentUnitDTO.java | 3 +- .../r2dbc/DocumentUnitMetadataDTO.java | 4 +- .../database/r2dbc/DocumentUnitNormDTO.java | 28 - .../database/r2dbc/NormElementDTO.java | 25 - .../PostgresDocumentUnitRepositoryImpl.java | 145 +++--- .../DatabaseDocumentCategoryRepository.java | 7 - .../DatabaseDocumentTypeNewRepository.java | 10 - .../DatabaseDocumentTypeRepository.java | 34 -- ...ormAbbreviationDocumentTypeRepository.java | 10 - ...abaseNormAbbreviationRegionRepository.java | 10 - .../DatabaseNormAbbreviationRepository.java | 106 ---- .../lookuptable/DatabaseRegionRepository.java | 6 - .../lookuptable/DocumentCategoryDTO.java | 27 - .../r2dbc/lookuptable/DocumentTypeDTO.java | 37 -- .../r2dbc/lookuptable/DocumentTypeNewDTO.java | 39 -- .../lookuptable/NormAbbreviationDTO.java | 38 -- .../NormAbbreviationDocumentTypeDTO.java | 31 -- .../NormAbbreviationRegionDTO.java | 31 -- .../PostgresDocumentTypeRepositoryImpl.java | 30 -- ...ostgresNormAbbreviationRepositoryImpl.java | 201 -------- .../database/r2dbc/lookuptable/RegionDTO.java | 28 - .../DocumentTypeNewTransformer.java | 19 - .../transformer/DocumentTypeTransformer.java | 4 +- .../DocumentUnitNormTransformer.java | 5 +- .../transformer/DocumentUnitTransformer.java | 6 +- .../LinkedDocumentationUnitTransformer.java | 6 +- .../NormAbbreviationTransformer.java | 21 +- .../transformer/RegionTransformer.java | 4 +- .../domain/DocumentTypeRepository.java | 6 +- .../ris/caselaw/domain/DocumentUnitNorm.java | 7 +- .../caselaw/domain/LookupTableService.java | 6 +- .../domain/lookuptable/DocumentTypeNew.java | 12 - .../domain/lookuptable/NormAbbreviation.java | 9 +- .../NormAbbreviationRepository.java | 11 +- .../caselaw/domain/lookuptable/Region.java | 2 +- .../src/main/resources/application-local.yaml | 2 + ...orm_abbreviation_migration_search_view.sql | 40 ++ ...selaw_crate_document_type_id_migration.sql | 68 +++ ...nit_column_in_migration_norm_reference.sql | 4 + .../LookupTableImporterControllerTest.java | 16 - .../LookupTableImporterServiceTest.java | 50 +- .../domain/LookupTableServiceTest.java | 20 +- .../tests/ActiveCitationIntegrationTest.java | 56 +- .../tests/AuthIntegrationTest.java | 3 +- ...mentUnitControllerAuthIntegrationTest.java | 3 +- ...DocumentUnitFieldOfLawIntegrationTest.java | 3 +- .../tests/DocumentUnitIntegrationTest.java | 67 ++- .../DocumentUnitKeywordIntegrationTest.java | 3 +- .../DocumentUnitListEntryIntegrationTest.java | 3 +- .../tests/FieldOfLawIntegrationTest.java | 3 +- .../tests/HealthEndpointIntegrationTest.java | 3 +- .../LookupTableImporterIntegrationTest.java | 45 +- .../tests/LookupTableIntegrationTest.java | 9 +- .../NormAbbreviationIntegrationTest.java | 488 ++++++++---------- .../tests/ProcedureIntegrationTest.java | 3 +- .../ProceedingDecisionIntegrationTest.java | 49 +- .../PublishDocumentUnitIntegrationTest.java | 3 +- .../tests/SaveNormIntegrationTest.java | 180 +++---- .../tests/SecurityIntegrationTest.java | 3 +- .../SingleNormValidationIntegrationTest.java | 7 +- .../PostgresTestcontainerIntegrationTest.kt | 2 +- .../test/resources/db/create_extension.sql | 2 - ...create_migration_scheme_and_extensions.sql | 124 +++++ compose.yaml | 1 + frontend/src/domain/normAbbreviation.ts | 1 - 89 files changed, 1359 insertions(+), 1601 deletions(-) create mode 100644 backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/jpa/DatabaseDocumentCategoryRepository.java create mode 100644 backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/jpa/DatabaseDocumentTypeRepository.java create mode 100644 backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/jpa/DatabaseNormAbbreviationRepository.java rename backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/jpa/{JPADatabaseNormElementRepository.java => DatabaseNormElementRepository.java} (59%) create mode 100644 backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/jpa/DatabaseNormReferenceRepository.java rename backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/jpa/{JPADocumentTypeRepository.java => DatabaseRegionRepository.java} (64%) create mode 100644 backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/jpa/DocumentCategoryDTO.java create mode 100644 backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/jpa/DocumentTypeDTO.java delete mode 100644 backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/jpa/JPADocumentTypeDTO.java create mode 100644 backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/jpa/NormAbbreviationDTO.java rename backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/jpa/{JPANormElementDTO.java => NormElementDTO.java} (73%) create mode 100644 backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/jpa/NormReferenceDTO.java create mode 100644 backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/jpa/PostgresDocumentTypeRepositoryImpl.java create mode 100644 backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/jpa/PostgresNormAbbreviationRepositoryImpl.java rename backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/jpa/{JPAPostgresNormElementRepositoryImpl.java => PostgresNormElementRepositoryImpl.java} (75%) create mode 100644 backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/jpa/RegionDTO.java delete mode 100644 backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/r2dbc/DatabaseDocumentUnitNormRepository.java delete mode 100644 backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/r2dbc/DatabaseNormElementRepository.java delete mode 100644 backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/r2dbc/DocumentUnitNormDTO.java delete mode 100644 backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/r2dbc/NormElementDTO.java delete mode 100644 backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/r2dbc/lookuptable/DatabaseDocumentCategoryRepository.java delete mode 100644 backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/r2dbc/lookuptable/DatabaseDocumentTypeNewRepository.java delete mode 100644 backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/r2dbc/lookuptable/DatabaseDocumentTypeRepository.java delete mode 100644 backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/r2dbc/lookuptable/DatabaseNormAbbreviationDocumentTypeRepository.java delete mode 100644 backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/r2dbc/lookuptable/DatabaseNormAbbreviationRegionRepository.java delete mode 100644 backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/r2dbc/lookuptable/DatabaseNormAbbreviationRepository.java delete mode 100644 backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/r2dbc/lookuptable/DatabaseRegionRepository.java delete mode 100644 backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/r2dbc/lookuptable/DocumentCategoryDTO.java delete mode 100644 backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/r2dbc/lookuptable/DocumentTypeDTO.java delete mode 100644 backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/r2dbc/lookuptable/DocumentTypeNewDTO.java delete mode 100644 backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/r2dbc/lookuptable/NormAbbreviationDTO.java delete mode 100644 backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/r2dbc/lookuptable/NormAbbreviationDocumentTypeDTO.java delete mode 100644 backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/r2dbc/lookuptable/NormAbbreviationRegionDTO.java delete mode 100644 backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/r2dbc/lookuptable/PostgresDocumentTypeRepositoryImpl.java delete mode 100644 backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/r2dbc/lookuptable/PostgresNormAbbreviationRepositoryImpl.java delete mode 100644 backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/r2dbc/lookuptable/RegionDTO.java delete mode 100644 backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/transformer/DocumentTypeNewTransformer.java delete mode 100644 backend/src/main/java/de/bund/digitalservice/ris/caselaw/domain/lookuptable/DocumentTypeNew.java create mode 100644 backend/src/main/resources/db/migration/V0.129__caselaw_create_norm_abbreviation_migration_search_view.sql create mode 100644 backend/src/main/resources/db/migration/V0.130__caselaw_crate_document_type_id_migration.sql create mode 100644 backend/src/main/resources/db/migration/V0.131__caselaw_add_legacy_doc_unit_column_in_migration_norm_reference.sql delete mode 100644 backend/src/test/resources/db/create_extension.sql create mode 100644 backend/src/test/resources/db/create_migration_scheme_and_extensions.sql diff --git a/.talismanrc b/.talismanrc index 76ab243e30..54f5686801 100644 --- a/.talismanrc +++ b/.talismanrc @@ -21,7 +21,7 @@ fileignoreconfig: - filename: backend/src/test/kotlin/unit/application/service/GetFileServiceTest.kt checksum: 8133265c6f388df84a3e0f61050428e8628853e0ba80b432e4723750a34b781e - filename: compose.yaml - checksum: 0cf11aa3c7711e07ad50cc83cad9b4c5a2081e7400d949aa84a43b1c5354058e + checksum: cd08d156c78274d39b8db8f42af9696da21b9f6815c09fbbededa937709ff945 - filename: doc/norms/backend-api.yaml checksum: df4fa1f7e6d7023f9a7a98d1052c2b88c1785366962004b3165453edcd5bf4db - filename: doc/structurizr/workspace.json diff --git a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/LookupTableImporterController.java b/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/LookupTableImporterController.java index 946d1a6c03..7d7f66889d 100644 --- a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/LookupTableImporterController.java +++ b/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/LookupTableImporterController.java @@ -25,21 +25,6 @@ public LookupTableImporterController(LookupTableImporterService service) { this.service = service; } - // In Postman go to "Body", select "raw" and "XML" and paste the XML-contents. - // Can we use @RequestBody @Valid DocumentTypesXML directly instead of ByteBuffer? - - @PutMapping(value = "doktyp") - @PreAuthorize("isAuthenticated()") - public Mono> importDocumentTypeLookupTable( - @RequestBody ByteBuffer byteBuffer) { - return service - .importDocumentTypeLookupTable(byteBuffer) - .map(resultString -> ResponseEntity.status(HttpStatus.OK).body(resultString)) - .onErrorReturn( - ResponseEntity.internalServerError() - .body("Could not import the document type lookup table")); - } - @PutMapping(value = "gerichtdata") @PreAuthorize("isAuthenticated()") public Mono> importCourtLookupTable(@RequestBody ByteBuffer byteBuffer) { diff --git a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/LookupTableImporterService.java b/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/LookupTableImporterService.java index 2ce41dc939..fa125ba0a2 100644 --- a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/LookupTableImporterService.java +++ b/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/LookupTableImporterService.java @@ -1,8 +1,6 @@ package de.bund.digitalservice.ris.caselaw.adapter; import com.fasterxml.jackson.dataformat.xml.XmlMapper; -import de.bund.digitalservice.ris.caselaw.adapter.database.jpa.JPADocumentTypeDTO; -import de.bund.digitalservice.ris.caselaw.adapter.database.jpa.JPADocumentTypeRepository; import de.bund.digitalservice.ris.caselaw.adapter.database.jpa.JPAFieldOfLawDTO; import de.bund.digitalservice.ris.caselaw.adapter.database.jpa.JPAFieldOfLawLinkDTO; import de.bund.digitalservice.ris.caselaw.adapter.database.jpa.JPAFieldOfLawLinkRepository; @@ -17,7 +15,6 @@ import de.bund.digitalservice.ris.caselaw.domain.ServiceUtils; import de.bund.digitalservice.ris.caselaw.domain.lookuptable.citation.CitationsStyleXML; import de.bund.digitalservice.ris.caselaw.domain.lookuptable.court.CourtsXML; -import de.bund.digitalservice.ris.caselaw.domain.lookuptable.documenttype.DocumentTypesXML; import de.bund.digitalservice.ris.caselaw.domain.lookuptable.fieldoflaw.FieldOfLawXml; import de.bund.digitalservice.ris.caselaw.domain.lookuptable.fieldoflaw.FieldsOfLawXml; import de.bund.digitalservice.ris.caselaw.domain.lookuptable.state.StatesXML; @@ -44,8 +41,6 @@ @Service @Slf4j public class LookupTableImporterService { - - private final JPADocumentTypeRepository jpaDocumentTypeRepository; private final DatabaseCourtRepository databaseCourtRepository; private final StateRepository stateRepository; private final DatabaseCitationStyleRepository databaseCitationStyleRepository; @@ -55,13 +50,11 @@ public class LookupTableImporterService { Pattern.compile("\\p{Lu}{2}(-\\d{2})+(?![\\p{L}\\d-])"); public LookupTableImporterService( - JPADocumentTypeRepository jpaDocumentTypeRepository, DatabaseCourtRepository databaseCourtRepository, StateRepository stateRepository, DatabaseCitationStyleRepository databaseCitationStyleRepository, JPAFieldOfLawRepository jpaFieldOfLawRepository, JPAFieldOfLawLinkRepository jpaFieldOfLawLinkRepository) { - this.jpaDocumentTypeRepository = jpaDocumentTypeRepository; this.databaseCourtRepository = databaseCourtRepository; this.stateRepository = stateRepository; this.databaseCitationStyleRepository = databaseCitationStyleRepository; @@ -69,45 +62,6 @@ public LookupTableImporterService( this.jpaFieldOfLawLinkRepository = jpaFieldOfLawLinkRepository; } - @Transactional(transactionManager = "jpaTransactionManager") - public Mono importDocumentTypeLookupTable(ByteBuffer byteBuffer) { - XmlMapper mapper = new XmlMapper(); - DocumentTypesXML documentTypesXML; - try { - documentTypesXML = - mapper.readValue(ServiceUtils.byteBufferToArray(byteBuffer), DocumentTypesXML.class); - } catch (IOException e) { - throw new ResponseStatusException( - HttpStatus.NOT_ACCEPTABLE, "Could not map ByteBuffer-content to DocumentTypesXML", e); - } - - importDocumentTypeJPA(documentTypesXML); - - return Mono.just("Successfully imported the document type lookup table"); - } - - public void importDocumentTypeJPA(DocumentTypesXML documentTypesXML) { - List documentTypeDTOS = - documentTypesXML.getList().stream() - .map( - documentTypeXML -> - JPADocumentTypeDTO.builder() - .id(documentTypeXML.getId()) - .changeDateClient(documentTypeXML.getChangeDateClient()) - .changeIndicator(documentTypeXML.getChangeIndicator()) - .version(documentTypeXML.getVersion()) - .jurisShortcut(documentTypeXML.getJurisShortcut()) - .documentType(documentTypeXML.getDocumentType()) - .multiple(documentTypeXML.getMultiple()) - .label(documentTypeXML.getLabel()) - .superlabel1(documentTypeXML.getSuperlabel1()) - .superlabel2(documentTypeXML.getSuperlabel2()) - .build()) - .toList(); - - jpaDocumentTypeRepository.saveAll(documentTypeDTOS); - } - public Mono importCourtLookupTable(ByteBuffer byteBuffer) { XmlMapper mapper = new XmlMapper(); CourtsXML courtsXML; diff --git a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/NormAbbreviationController.java b/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/NormAbbreviationController.java index 1471cbb936..bfe537f944 100644 --- a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/NormAbbreviationController.java +++ b/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/NormAbbreviationController.java @@ -28,36 +28,34 @@ public NormAbbreviationController(NormAbbreviationService service) { @GetMapping @PreAuthorize("isAuthenticated()") - public Flux getAllNormAbbreviationsBySearchQuery( - @RequestParam(value = "q", required = false, defaultValue = "") String query, - @RequestParam(value = "sz", required = false) Integer size, - @RequestParam(value = "pg", required = false) Integer page) { - - return service.getNormAbbreviationBySearchQuery(query, size, page); + public Flux getAllNormAbbreviationsStartingWithExact( + @RequestParam(value = "q", required = false, defaultValue = "") String normAbbreviation, + @RequestParam(value = "sz", required = false, defaultValue = "30") Integer size, + @RequestParam(value = "pg", required = false, defaultValue = "0") Integer page) { + return Flux.fromIterable( + service.getNormAbbreviationsStartingWithExact(normAbbreviation, size, page)); } @GetMapping("/{uuid}") @PreAuthorize("isAuthenticated()") - public Mono getNormAbbreviationController(@PathVariable("uuid") UUID uuid) { - return service.getNormAbbreviationById(uuid); + public Mono getNormAbbreviationById(@PathVariable("uuid") UUID uuid) { + return Mono.just(service.getNormAbbreviationById(uuid)); } @GetMapping("/search") @PreAuthorize("isAuthenticated()") - public Mono> getAllNormAbbreviationsByAwesomeSearchQuery( + public Mono> getAllNormAbbreviationsContaining( @RequestParam(value = "q", required = false, defaultValue = "") String query, - @RequestParam(value = "sz", required = false) Integer size, - @RequestParam(value = "pg", required = false) Integer page) { - - return service.getNormAbbreviationByAwesomeSearchQuery(query, size, page); + @RequestParam(value = "sz", required = false, defaultValue = "30") Integer size, + @RequestParam(value = "pg", required = false, defaultValue = "0") Integer page) { + return Mono.just(service.findAllNormAbbreviationsContaining(query, size, page)); } @PutMapping("/refreshMaterializedViews") @PreAuthorize("isAuthenticated()") public Mono> refreshMaterializedViews() { - return service - .refreshMaterializedViews() - .thenReturn( - ResponseEntity.ok("Refreshed the materialized view 'norm_abbreviation_search'")); + service.refreshMaterializedViews(); + return Mono.just( + ResponseEntity.ok("Refreshed the materialized view 'norm_abbreviation_search_migration'")); } } diff --git a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/NormAbbreviationService.java b/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/NormAbbreviationService.java index 5e4266779c..e538cb561f 100644 --- a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/NormAbbreviationService.java +++ b/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/NormAbbreviationService.java @@ -5,8 +5,6 @@ import java.util.List; import java.util.UUID; import org.springframework.stereotype.Service; -import reactor.core.publisher.Flux; -import reactor.core.publisher.Mono; @Service public class NormAbbreviationService { @@ -16,33 +14,21 @@ public NormAbbreviationService(NormAbbreviationRepository repository) { this.repository = repository; } - public Mono getNormAbbreviationById(UUID uuid) { + public NormAbbreviation getNormAbbreviationById(UUID uuid) { return repository.findById(uuid); } - public Flux getNormAbbreviationBySearchQuery( + public List getNormAbbreviationsStartingWithExact( String query, Integer size, Integer page) { - - Integer pageOffset = null; - if (page != null && size != null) { - pageOffset = page * size; - } - - return repository.findBySearchQuery(query, size, pageOffset); + return repository.getNormAbbreviationsStartingWithExact(query, size, page); } - public Mono> getNormAbbreviationByAwesomeSearchQuery( + public List findAllNormAbbreviationsContaining( String query, Integer size, Integer page) { - - Integer pageOffset = null; - if (page != null && size != null) { - pageOffset = page * size; - } - - return repository.findByAwesomeSearchQuery(query, size, pageOffset); + return repository.findAllContainingOrderByAccuracy(query, size, page); } - public Mono refreshMaterializedViews() { - return repository.refreshMaterializedViews(); + public void refreshMaterializedViews() { + repository.refreshMaterializedViews(); } } diff --git a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/jpa/DatabaseDocumentCategoryRepository.java b/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/jpa/DatabaseDocumentCategoryRepository.java new file mode 100644 index 0000000000..b63bbc7c7a --- /dev/null +++ b/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/jpa/DatabaseDocumentCategoryRepository.java @@ -0,0 +1,12 @@ +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 DatabaseDocumentCategoryRepository + extends JpaRepository { + + DocumentCategoryDTO findFirstByLabel(String label); +} diff --git a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/jpa/DatabaseDocumentTypeRepository.java b/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/jpa/DatabaseDocumentTypeRepository.java new file mode 100644 index 0000000000..79acac249a --- /dev/null +++ b/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/jpa/DatabaseDocumentTypeRepository.java @@ -0,0 +1,38 @@ +package de.bund.digitalservice.ris.caselaw.adapter.database.jpa; + +import java.util.List; +import java.util.UUID; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.stereotype.Repository; + +/** */ +@Repository +public interface DatabaseDocumentTypeRepository extends JpaRepository { + + DocumentTypeDTO findFirstByAbbreviationAndCategory( + String jurisShortcut, DocumentCategoryDTO category); + + List findAllByCategoryOrderByAbbreviationAscLabelAsc( + DocumentCategoryDTO category); + + // see query explanation in CourtRepository, it's almost the same + @Query( + nativeQuery = true, + value = + "WITH label_added AS (SELECT *, " + + " UPPER(CONCAT(abbreviation, ' ', label)) AS concat" + + " from incremental_migration.document_type) " + + "SELECT *," + + " concat, " + + " CASE " + + " WHEN concat LIKE UPPER(:searchStr||'%') THEN 1 " + + " WHEN concat LIKE UPPER('% '||:searchStr||'%') THEN 2 " + + " WHEN concat LIKE UPPER('%-'||:searchStr||'%') THEN 2 " + + " ELSE 3 " + + " END AS weight " + + "FROM label_added " + + "WHERE concat LIKE UPPER('%'||:searchStr||'%') AND document_category_id = :category " + + "ORDER BY weight, concat") + List findCaselawBySearchStrAndCategory(String searchStr, UUID category); +} diff --git a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/jpa/DatabaseNormAbbreviationRepository.java b/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/jpa/DatabaseNormAbbreviationRepository.java new file mode 100644 index 0000000000..2f38c54674 --- /dev/null +++ b/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/jpa/DatabaseNormAbbreviationRepository.java @@ -0,0 +1,58 @@ +package de.bund.digitalservice.ris.caselaw.adapter.database.jpa; + +import jakarta.transaction.Transactional; +import java.util.List; +import java.util.UUID; +import org.springframework.context.annotation.Primary; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; +import org.springframework.stereotype.Repository; + +@Repository +@Primary +public interface DatabaseNormAbbreviationRepository + extends JpaRepository { + + List findByAbbreviationIgnoreCase(String abbreviation, PageRequest of); + + List findByAbbreviationStartsWithOrderByAbbreviation( + String query, PageRequest of); + + List findByOfficialLetterAbbreviationIgnoreCase( + String officialLetterAbbreviation, PageRequest of); + + List findByAbbreviationStartsWithIgnoreCase( + String abbreviation, PageRequest of); + + List findByOfficialLetterAbbreviationStartsWithIgnoreCase( + String officialLetterAbbreviation, PageRequest size); + + @Query( + value = + "select" + + " id," + + " abbreviation," + + " decision_date," + + " document_id," + + " document_number," + + " official_letter_abbreviation," + + " official_long_title," + + " official_short_title," + + " source," + + " region_id," + + " ts_rank_cd(weighted_vector, to_tsquery('german', '' || :tsQuery || '')) rank" + + " from norm_abbreviation_search_migration" + + " where weighted_vector @@ to_tsquery('german', '' || :tsQuery || '')" + + " order by rank desc" + + " limit :size" + + " offset :offset", + nativeQuery = true) + List findByRankWeightedVector(String tsQuery, Integer size, Integer offset); + + @Transactional + @Modifying + @Query(value = "REFRESH MATERIALIZED VIEW norm_abbreviation_search_migration", nativeQuery = true) + void refreshMaterializedViews(); +} diff --git a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/jpa/JPADatabaseNormElementRepository.java b/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/jpa/DatabaseNormElementRepository.java similarity index 59% rename from backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/jpa/JPADatabaseNormElementRepository.java rename to backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/jpa/DatabaseNormElementRepository.java index c6ef586136..1fb196e007 100644 --- a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/jpa/JPADatabaseNormElementRepository.java +++ b/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/jpa/DatabaseNormElementRepository.java @@ -7,14 +7,14 @@ import org.springframework.stereotype.Repository; @Repository -public interface JPADatabaseNormElementRepository extends JpaRepository { +public interface DatabaseNormElementRepository extends JpaRepository { @Query( value = "SELECT ne.id, ne.label, ne.has_number_designation, ne.norm_code " - + "FROM norm_element ne " - + "INNER JOIN document_category dc ON ne.document_category_id=dc.id " + + "FROM incremental_migration.norm_element ne " + + "INNER JOIN incremental_migration.document_category dc ON ne.document_category_id=dc.id " + "WHERE dc.label = 'R'", nativeQuery = true) - List findAllByDocumentCategoryLabelR(); + List findAllByDocumentCategoryLabelR(); } diff --git a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/jpa/DatabaseNormReferenceRepository.java b/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/jpa/DatabaseNormReferenceRepository.java new file mode 100644 index 0000000000..9289875fb2 --- /dev/null +++ b/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/jpa/DatabaseNormReferenceRepository.java @@ -0,0 +1,11 @@ +package de.bund.digitalservice.ris.caselaw.adapter.database.jpa; + +import java.util.List; +import java.util.UUID; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface DatabaseNormReferenceRepository extends JpaRepository { + List findAllByLegacyDocUnitIdOrderById(UUID documentationUnitId); +} diff --git a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/jpa/JPADocumentTypeRepository.java b/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/jpa/DatabaseRegionRepository.java similarity index 64% rename from backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/jpa/JPADocumentTypeRepository.java rename to backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/jpa/DatabaseRegionRepository.java index 70776a94eb..3ac7a354d1 100644 --- a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/jpa/JPADocumentTypeRepository.java +++ b/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/jpa/DatabaseRegionRepository.java @@ -1,7 +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 JPADocumentTypeRepository extends JpaRepository {} +public interface DatabaseRegionRepository extends JpaRepository {} diff --git a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/jpa/DocumentCategoryDTO.java b/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/jpa/DocumentCategoryDTO.java new file mode 100644 index 0000000000..a2e9356cb5 --- /dev/null +++ b/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/jpa/DocumentCategoryDTO.java @@ -0,0 +1,26 @@ +package de.bund.digitalservice.ris.caselaw.adapter.database.jpa; + +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.Id; +import jakarta.persistence.Table; +import java.util.UUID; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Getter +@Setter +@AllArgsConstructor +@NoArgsConstructor +@Builder +@Entity +@Table(name = "document_category", schema = "incremental_migration") +public class DocumentCategoryDTO { + @Id @GeneratedValue private UUID id; + + @Column private String label; +} diff --git a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/jpa/DocumentTypeDTO.java b/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/jpa/DocumentTypeDTO.java new file mode 100644 index 0000000000..032ec482c3 --- /dev/null +++ b/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/jpa/DocumentTypeDTO.java @@ -0,0 +1,44 @@ +package de.bund.digitalservice.ris.caselaw.adapter.database.jpa; + +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.Table; +import java.util.UUID; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; + +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +@Builder +@Entity +@ToString(onlyExplicitlyIncluded = true) +@Table(name = "document_type", schema = "incremental_migration") +public class DocumentTypeDTO { + @Id @GeneratedValue private UUID id; + + @Column private String abbreviation; + + @ManyToOne + @JoinColumn(name = "document_category_id") + private DocumentCategoryDTO category; + + @Column private String label; + + @Column(name = "super_label_1") + private String superLabel1; + + @Column(name = "super_label_2") + private String superLabel2; + + @Column private Boolean multiple; +} diff --git a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/jpa/JPADocumentTypeDTO.java b/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/jpa/JPADocumentTypeDTO.java deleted file mode 100644 index 2a012c5726..0000000000 --- a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/jpa/JPADocumentTypeDTO.java +++ /dev/null @@ -1,40 +0,0 @@ -package de.bund.digitalservice.ris.caselaw.adapter.database.jpa; - -import jakarta.persistence.Column; -import jakarta.persistence.Entity; -import jakarta.persistence.Id; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; - -@Data -@Builder -@NoArgsConstructor -@AllArgsConstructor -@Entity(name = "lookuptable_documenttype") -public class JPADocumentTypeDTO { - @Id private long id; - - @Column(name = "change_date_mail") - private String changeDateMail; - - @Column(name = "change_date_client") - private String changeDateClient; - - @Column(name = "change_indicator") - private char changeIndicator; - - private String version; - - @Column(name = "juris_shortcut") - private String jurisShortcut; - - @Column(name = "document_type") - private char documentType; - - private String multiple; - private String label; - private String superlabel1; - private String superlabel2; -} diff --git a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/jpa/NormAbbreviationDTO.java b/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/jpa/NormAbbreviationDTO.java new file mode 100644 index 0000000000..a596c0f5f1 --- /dev/null +++ b/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/jpa/NormAbbreviationDTO.java @@ -0,0 +1,97 @@ +package de.bund.digitalservice.ris.caselaw.adapter.database.jpa; + +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.FetchType; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.JoinTable; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.OneToMany; +import jakarta.persistence.Table; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Size; +import java.time.LocalDate; +import java.util.HashSet; +import java.util.Objects; +import java.util.Set; +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(name = "norm_abbreviation", schema = "incremental_migration") +public class NormAbbreviationDTO { + + @Id @GeneratedValue private UUID id; + + @Column + @Size(max = 255) + @NotBlank + private String abbreviation; + + @Column(name = "decision_date") + private LocalDate decisionDate; + + @Column(nullable = false, unique = true, name = "document_id") + @NotNull + private Long documentId; + + @Column(name = "document_number") + private String documentNumber; + + @OneToMany(fetch = FetchType.EAGER) + @JoinTable( + name = "norm_abbreviation_document_type", + schema = "incremental_migration", + joinColumns = @JoinColumn(name = "norm_abbreviation_id"), + inverseJoinColumns = @JoinColumn(name = "document_type_id")) + @Builder.Default + private Set documentTypeList = new HashSet<>(); + + @Column(name = "official_letter_abbreviation") + private String officialLetterAbbreviation; + + @Column(name = "official_long_title") + private String officialLongTitle; + + @Column(name = "official_short_title") + private String officialShortTitle; + + @ManyToOne(fetch = FetchType.EAGER) + @JoinTable( + name = "norm_abbreviation_region", + schema = "incremental_migration", + joinColumns = @JoinColumn(name = "norm_abbreviation_id"), + inverseJoinColumns = @JoinColumn(name = "region_id")) + private RegionDTO region; + + @Column + @Size(min = 1, max = 1) + private String source; + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + NormAbbreviationDTO that = (NormAbbreviationDTO) o; + + return Objects.equals(id, that.id); + } + + @Override + public int hashCode() { + return id != null ? id.hashCode() : 0; + } +} diff --git a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/jpa/JPANormElementDTO.java b/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/jpa/NormElementDTO.java similarity index 73% rename from backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/jpa/JPANormElementDTO.java rename to backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/jpa/NormElementDTO.java index 2dca646aaa..1445c0b0cb 100644 --- a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/jpa/JPANormElementDTO.java +++ b/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/jpa/NormElementDTO.java @@ -3,18 +3,22 @@ import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.Id; +import jakarta.persistence.Table; import java.util.UUID; import lombok.AllArgsConstructor; import lombok.Builder; -import lombok.Data; +import lombok.Getter; import lombok.NoArgsConstructor; +import lombok.Setter; -@Data +@Getter +@Setter @Builder @NoArgsConstructor @AllArgsConstructor @Entity -public class JPANormElementDTO { +@Table(name = "norm_element", schema = "incremental_migration") +public class NormElementDTO { @Id UUID id; private String label; diff --git a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/jpa/NormReferenceDTO.java b/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/jpa/NormReferenceDTO.java new file mode 100644 index 0000000000..f4874561eb --- /dev/null +++ b/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/jpa/NormReferenceDTO.java @@ -0,0 +1,47 @@ +package de.bund.digitalservice.ris.caselaw.adapter.database.jpa; + +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.FetchType; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.Table; +import java.time.LocalDate; +import java.util.UUID; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +@Builder +@Entity +@Table(name = "norm_reference", schema = "incremental_migration") +public class NormReferenceDTO { + + @Id @GeneratedValue UUID id; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "norm_abbreviation_id") + private NormAbbreviationDTO normAbbreviation; + + @Column(name = "single_norm") + String singleNorm; + + @Column(name = "date_of_version") + LocalDate dateOfVersion; + + @Column(name = "date_of_relevance") + String dateOfRelevance; + + @Column(name = "legacy_doc_unit_id") + UUID legacyDocUnitId; + + // @ManyToOne @NotNull DocumentUnitDTO documentUnit; +} diff --git a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/jpa/PostgresDocumentTypeRepositoryImpl.java b/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/jpa/PostgresDocumentTypeRepositoryImpl.java new file mode 100644 index 0000000000..70d557fc5b --- /dev/null +++ b/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/jpa/PostgresDocumentTypeRepositoryImpl.java @@ -0,0 +1,39 @@ +package de.bund.digitalservice.ris.caselaw.adapter.database.jpa; + +import de.bund.digitalservice.ris.caselaw.adapter.transformer.DocumentTypeTransformer; +import de.bund.digitalservice.ris.caselaw.domain.DocumentTypeRepository; +import de.bund.digitalservice.ris.caselaw.domain.lookuptable.documenttype.DocumentType; +import java.util.List; +import org.springframework.stereotype.Repository; + +@Repository +public class PostgresDocumentTypeRepositoryImpl implements DocumentTypeRepository { + private final DatabaseDocumentTypeRepository repository; + private final DatabaseDocumentCategoryRepository categoryRepository; + + public PostgresDocumentTypeRepositoryImpl( + DatabaseDocumentTypeRepository repository, + DatabaseDocumentCategoryRepository categoryRepository) { + this.repository = repository; + this.categoryRepository = categoryRepository; + } + + @Override + public List findCaselawBySearchStr(String searchString) { + return repository + .findCaselawBySearchStrAndCategory( + searchString, categoryRepository.findFirstByLabel("R").getId()) + .stream() + .map(DocumentTypeTransformer::transformDTO) + .toList(); + } + + @Override + public List findAllByDocumentTypeOrderByAbbreviationAscLabelAsc(char shortcut) { + return repository + .findAllByCategoryOrderByAbbreviationAscLabelAsc(categoryRepository.findFirstByLabel("R")) + .stream() + .map(DocumentTypeTransformer::transformDTO) + .toList(); + } +} diff --git a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/jpa/PostgresNormAbbreviationRepositoryImpl.java b/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/jpa/PostgresNormAbbreviationRepositoryImpl.java new file mode 100644 index 0000000000..f88a5c8e65 --- /dev/null +++ b/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/jpa/PostgresNormAbbreviationRepositoryImpl.java @@ -0,0 +1,108 @@ +package de.bund.digitalservice.ris.caselaw.adapter.database.jpa; + +import de.bund.digitalservice.ris.caselaw.adapter.transformer.NormAbbreviationTransformer; +import de.bund.digitalservice.ris.caselaw.domain.lookuptable.NormAbbreviation; +import de.bund.digitalservice.ris.caselaw.domain.lookuptable.NormAbbreviationRepository; +import java.util.List; +import java.util.UUID; +import org.springframework.data.domain.PageRequest; +import org.springframework.stereotype.Repository; + +@Repository +public class PostgresNormAbbreviationRepositoryImpl implements NormAbbreviationRepository { + + private final DatabaseNormAbbreviationRepository repository; + + public PostgresNormAbbreviationRepositoryImpl(DatabaseNormAbbreviationRepository repository) { + this.repository = repository; + } + + @Override + public NormAbbreviation findById(UUID id) { + return NormAbbreviationTransformer.transformDTO(repository.findById(id).orElse(null)); + } + + @Override + public List getNormAbbreviationsStartingWithExact( + String query, Integer size, Integer page) { + var list = + repository.findByAbbreviationStartsWithOrderByAbbreviation( + query, PageRequest.of(page, size)); + return list.stream().map(NormAbbreviationTransformer::transformDTO).toList(); + } + + @Override + public List findAllContainingOrderByAccuracy( + String query, Integer size, Integer page) { + + String cleanedQuery = + query + .trim() + .replace(",", "") + .replace(";", "") + .replace("(", "") + .replace(")", "") + .replace("*", "") + .replace("+", "") + .replace("-", "") + .replace(":", "") + .replace("/", " "); + String directInput = cleanedQuery.toLowerCase(); + String[] queryBlocks = cleanedQuery.split(" "); + StringBuilder tsQuery = new StringBuilder(); + for (int i = 0; i < queryBlocks.length; i++) { + if (queryBlocks[i].isBlank()) continue; + + if (i > 0) { + tsQuery.append(" & "); + } + + tsQuery.append(queryBlocks[i]).append(":*"); + } + + List results = + repository.findByAbbreviationIgnoreCase(directInput, PageRequest.of(page, size)); + + if (results.size() < size) { + var officialLetterAbbreviationExact = + repository.findByOfficialLetterAbbreviationIgnoreCase( + directInput, PageRequest.of(page, size)); + officialLetterAbbreviationExact.stream() + .filter(e -> results.size() < size && !results.contains(e)) + .forEach(results::add); + } + + if (results.size() < size) { + var abbreviationStartingWith = + repository.findByAbbreviationStartsWithIgnoreCase( + directInput, PageRequest.of(page, size)); + abbreviationStartingWith.stream() + .filter(e -> results.size() < size && !results.contains(e)) + .forEach(results::add); + } + + if (results.size() < size) { + var officialLetterAbbreviationStartingWith = + repository.findByOfficialLetterAbbreviationStartsWithIgnoreCase( + directInput, PageRequest.of(page, size)); + officialLetterAbbreviationStartingWith.stream() + .filter(e -> results.size() < size && !results.contains(e)) + .forEach(results::add); + } + + if (results.size() < size) { + var rankWeightedVector = + repository.findByRankWeightedVector(tsQuery.toString(), size, page * size); + rankWeightedVector.stream() + .filter(e -> results.size() < size && !results.contains(e)) + .forEach(results::add); + } + + return results.stream().map(NormAbbreviationTransformer::transformDTO).toList(); + } + + @Override + public void refreshMaterializedViews() { + repository.refreshMaterializedViews(); + } +} diff --git a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/jpa/JPAPostgresNormElementRepositoryImpl.java b/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/jpa/PostgresNormElementRepositoryImpl.java similarity index 75% rename from backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/jpa/JPAPostgresNormElementRepositoryImpl.java rename to backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/jpa/PostgresNormElementRepositoryImpl.java index 9e2e485b4f..042fdc2cca 100644 --- a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/jpa/JPAPostgresNormElementRepositoryImpl.java +++ b/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/jpa/PostgresNormElementRepositoryImpl.java @@ -6,12 +6,11 @@ import org.springframework.stereotype.Repository; @Repository -public class JPAPostgresNormElementRepositoryImpl implements NormElementRepository { +public class PostgresNormElementRepositoryImpl implements NormElementRepository { - private final JPADatabaseNormElementRepository normElementRepository; + private final DatabaseNormElementRepository normElementRepository; - public JPAPostgresNormElementRepositoryImpl( - JPADatabaseNormElementRepository normElementRepository) { + public PostgresNormElementRepositoryImpl(DatabaseNormElementRepository normElementRepository) { this.normElementRepository = normElementRepository; } diff --git a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/jpa/RegionDTO.java b/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/jpa/RegionDTO.java new file mode 100644 index 0000000000..055a0ff7f2 --- /dev/null +++ b/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/jpa/RegionDTO.java @@ -0,0 +1,28 @@ +package de.bund.digitalservice.ris.caselaw.adapter.database.jpa; + +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.Id; +import jakarta.persistence.Table; +import jakarta.validation.constraints.NotBlank; +import java.util.UUID; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +@Builder +@Entity +@Table(name = "region", schema = "incremental_migration") +public class RegionDTO { + + @Id @GeneratedValue private UUID id; + + @Column @NotBlank private String code; +} diff --git a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/r2dbc/DatabaseDocumentUnitMetadataRepository.java b/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/r2dbc/DatabaseDocumentUnitMetadataRepository.java index 18a5d56b0a..92ec3245af 100644 --- a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/r2dbc/DatabaseDocumentUnitMetadataRepository.java +++ b/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/r2dbc/DatabaseDocumentUnitMetadataRepository.java @@ -40,7 +40,7 @@ Flux searchByLinkedDocumentationUnit( String courtLocation, Instant decisionDate, Long[] docUnitIds, - Long docTypeId, + UUID docTypeId, Integer pageSize, Long offset); @@ -50,5 +50,5 @@ Mono countSearchByLinkedDocumentationUnit( String courtLocation, Instant decisionDate, Long[] docUnitIds, - Long docTypeId); + UUID docTypeId); } diff --git a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/r2dbc/DatabaseDocumentUnitNormRepository.java b/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/r2dbc/DatabaseDocumentUnitNormRepository.java deleted file mode 100644 index 2895769a25..0000000000 --- a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/r2dbc/DatabaseDocumentUnitNormRepository.java +++ /dev/null @@ -1,11 +0,0 @@ -package de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc; - -import org.springframework.data.r2dbc.repository.R2dbcRepository; -import org.springframework.stereotype.Repository; -import reactor.core.publisher.Flux; - -@Repository -public interface DatabaseDocumentUnitNormRepository - extends R2dbcRepository { - Flux findAllByDocumentUnitIdOrderById(Long documentationUnitId); -} diff --git a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/r2dbc/DatabaseNormElementRepository.java b/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/r2dbc/DatabaseNormElementRepository.java deleted file mode 100644 index 25c1104331..0000000000 --- a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/r2dbc/DatabaseNormElementRepository.java +++ /dev/null @@ -1,17 +0,0 @@ -package de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc; - -import org.springframework.data.r2dbc.repository.Query; -import org.springframework.data.r2dbc.repository.R2dbcRepository; -import org.springframework.stereotype.Repository; -import reactor.core.publisher.Flux; - -@Repository -public interface DatabaseNormElementRepository extends R2dbcRepository { - - @Query( - "SELECT ne.id, ne.label, ne.has_number_designation, ne.norm_code " - + "FROM norm_element ne " - + "INNER JOIN document_category dc ON ne.document_category_id=dc.id " - + "WHERE dc.label = 'R'") - Flux findAllByDocumentCategoryLabelR(); -} diff --git a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/r2dbc/DocumentUnitDTO.java b/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/r2dbc/DocumentUnitDTO.java index 7e6f887ff0..e810412a67 100644 --- a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/r2dbc/DocumentUnitDTO.java +++ b/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/r2dbc/DocumentUnitDTO.java @@ -1,5 +1,6 @@ package de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc; +import de.bund.digitalservice.ris.caselaw.adapter.database.jpa.NormReferenceDTO; import de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.lookuptable.FieldOfLawDTO; import de.bund.digitalservice.ris.caselaw.domain.ActiveCitation; import java.util.List; @@ -56,5 +57,5 @@ public class DocumentUnitDTO extends DocumentUnitMetadataDTO { @Transient List deviatingDecisionDates; @Transient List keywords; @Transient List fieldsOfLaw; - @Transient List norms; + @Transient List norms; } diff --git a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/r2dbc/DocumentUnitMetadataDTO.java b/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/r2dbc/DocumentUnitMetadataDTO.java index 19fb11a28e..375b1f8271 100644 --- a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/r2dbc/DocumentUnitMetadataDTO.java +++ b/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/r2dbc/DocumentUnitMetadataDTO.java @@ -1,8 +1,8 @@ package de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc; +import de.bund.digitalservice.ris.caselaw.adapter.database.jpa.DocumentTypeDTO; import de.bund.digitalservice.ris.caselaw.adapter.database.jpa.DocumentationOfficeDTO; import de.bund.digitalservice.ris.caselaw.adapter.database.jpa.ProcedureDTO; -import de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.lookuptable.DocumentTypeDTO; import de.bund.digitalservice.ris.caselaw.domain.DataSource; import de.bund.digitalservice.ris.caselaw.domain.DocumentUnitStatus; import java.time.Instant; @@ -41,7 +41,7 @@ public class DocumentUnitMetadataDTO { private String courtType; @Column("document_type_id") - private Long documentTypeId; + private UUID documentTypeId; @Transient private DocumentTypeDTO documentTypeDTO; diff --git a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/r2dbc/DocumentUnitNormDTO.java b/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/r2dbc/DocumentUnitNormDTO.java deleted file mode 100644 index 0416613317..0000000000 --- a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/r2dbc/DocumentUnitNormDTO.java +++ /dev/null @@ -1,28 +0,0 @@ -package de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc; - -import de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.lookuptable.NormAbbreviationDTO; -import java.time.Instant; -import java.util.UUID; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; -import org.springframework.data.annotation.Id; -import org.springframework.data.annotation.Transient; -import org.springframework.data.relational.core.mapping.Table; - -@Data -@Builder -@NoArgsConstructor -@AllArgsConstructor -@Table("document_unit_norm") -public class DocumentUnitNormDTO { - - @Id Long id; - Long documentUnitId; - UUID normAbbreviationUuid; - String singleNorm; - Instant dateOfVersion; - String dateOfRelevance; - @Transient NormAbbreviationDTO normAbbreviation; -} diff --git a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/r2dbc/NormElementDTO.java b/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/r2dbc/NormElementDTO.java deleted file mode 100644 index ee0cbb830e..0000000000 --- a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/r2dbc/NormElementDTO.java +++ /dev/null @@ -1,25 +0,0 @@ -package de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc; - -import java.util.UUID; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; -import org.springframework.data.annotation.Id; -import org.springframework.data.relational.core.mapping.Column; - -@Data -@Builder -@NoArgsConstructor -@AllArgsConstructor -public class NormElementDTO { - @Id UUID id; - - private String label; - - @Column("has_number_designation") - private boolean hasNumberDesignation; - - @Column("norm_code") - private String normCode; -} diff --git a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/r2dbc/PostgresDocumentUnitRepositoryImpl.java b/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/r2dbc/PostgresDocumentUnitRepositoryImpl.java index f0b78f41bc..8191f0943d 100644 --- a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/r2dbc/PostgresDocumentUnitRepositoryImpl.java +++ b/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/r2dbc/PostgresDocumentUnitRepositoryImpl.java @@ -1,21 +1,25 @@ package de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc; +import de.bund.digitalservice.ris.caselaw.adapter.database.jpa.DatabaseDocumentCategoryRepository; +import de.bund.digitalservice.ris.caselaw.adapter.database.jpa.DatabaseDocumentTypeRepository; import de.bund.digitalservice.ris.caselaw.adapter.database.jpa.DatabaseDocumentationOfficeRepository; +import de.bund.digitalservice.ris.caselaw.adapter.database.jpa.DatabaseNormAbbreviationRepository; +import de.bund.digitalservice.ris.caselaw.adapter.database.jpa.DatabaseNormReferenceRepository; import de.bund.digitalservice.ris.caselaw.adapter.database.jpa.DatabaseProcedureLinkRepository; import de.bund.digitalservice.ris.caselaw.adapter.database.jpa.DatabaseProcedureRepository; +import de.bund.digitalservice.ris.caselaw.adapter.database.jpa.DocumentTypeDTO; import de.bund.digitalservice.ris.caselaw.adapter.database.jpa.DocumentationOfficeDTO; import de.bund.digitalservice.ris.caselaw.adapter.database.jpa.DocumentationUnitSearchEntryDTO; +import de.bund.digitalservice.ris.caselaw.adapter.database.jpa.NormAbbreviationDTO; +import de.bund.digitalservice.ris.caselaw.adapter.database.jpa.NormReferenceDTO; +import de.bund.digitalservice.ris.caselaw.adapter.database.jpa.NormReferenceDTO.NormReferenceDTOBuilder; import de.bund.digitalservice.ris.caselaw.adapter.database.jpa.ProcedureDTO; import de.bund.digitalservice.ris.caselaw.adapter.database.jpa.ProcedureLinkDTO; import de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.DocumentUnitDTO.DocumentUnitDTOBuilder; import de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.lookuptable.CourtDTO; import de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.lookuptable.DatabaseCitationStyleRepository; import de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.lookuptable.DatabaseCourtRepository; -import de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.lookuptable.DatabaseDocumentTypeRepository; import de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.lookuptable.DatabaseFieldOfLawRepository; -import de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.lookuptable.DatabaseNormAbbreviationRepository; -import de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.lookuptable.DocumentTypeDTO; -import de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.lookuptable.NormAbbreviationDTO; import de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.lookuptable.StateDTO; import de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.lookuptable.StateRepository; import de.bund.digitalservice.ris.caselaw.adapter.transformer.ActiveCitationTransformer; @@ -80,14 +84,16 @@ public class PostgresDocumentUnitRepositoryImpl implements DocumentUnitRepositor private final DatabaseCourtRepository databaseCourtRepository; private final StateRepository stateRepository; private final DatabaseDocumentTypeRepository databaseDocumentTypeRepository; + private final DatabaseDocumentCategoryRepository databaseDocumentCategoryRepository; private final DatabaseFieldOfLawRepository fieldOfLawRepository; private final DatabaseDocumentUnitFieldsOfLawRepository documentUnitFieldsOfLawRepository; private final DatabaseKeywordRepository keywordRepository; - private final DatabaseDocumentUnitNormRepository documentUnitNormRepository; + private final DatabaseNormReferenceRepository documentUnitNormRepository; private final DatabaseDocumentationOfficeRepository documentationOfficeRepository; private final DatabaseDocumentUnitStatusRepository databaseDocumentUnitStatusRepository; - private final DatabaseNormAbbreviationRepository normAbbreviationRepository; private final DatabaseDocumentationUnitLinkRepository documentationUnitLinkRepository; + + private final DatabaseNormAbbreviationRepository normAbbreviationRepository; private final DatabaseCitationStyleRepository citationStyleRepository; private final DatabaseProcedureRepository procedureRepository; private final DatabaseProcedureLinkRepository procedureLinkRepository; @@ -103,13 +109,14 @@ public PostgresDocumentUnitRepositoryImpl( DatabaseCourtRepository databaseCourtRepository, StateRepository stateRepository, DatabaseDocumentTypeRepository databaseDocumentTypeRepository, + DatabaseDocumentCategoryRepository databaseDocumentCategoryRepository, DatabaseFieldOfLawRepository fieldOfLawRepository, DatabaseDocumentUnitFieldsOfLawRepository documentUnitFieldsOfLawRepository, DatabaseKeywordRepository keywordRepository, - DatabaseDocumentUnitNormRepository documentUnitNormRepository, + DatabaseNormReferenceRepository documentUnitNormRepository, DatabaseDocumentUnitStatusRepository databaseDocumentUnitStatusRepository, - DatabaseNormAbbreviationRepository normAbbreviationRepository, DatabaseDocumentationUnitLinkRepository documentationUnitLinkRepository, + DatabaseNormAbbreviationRepository normAbbreviationRepository, DatabaseCitationStyleRepository citationStyleRepository, DatabaseDocumentationOfficeRepository documentationOfficeRepository, DatabaseProcedureRepository procedureRepository, @@ -125,14 +132,15 @@ public PostgresDocumentUnitRepositoryImpl( this.databaseCourtRepository = databaseCourtRepository; this.stateRepository = stateRepository; this.databaseDocumentTypeRepository = databaseDocumentTypeRepository; + this.databaseDocumentCategoryRepository = databaseDocumentCategoryRepository; this.fieldOfLawRepository = fieldOfLawRepository; this.documentUnitFieldsOfLawRepository = documentUnitFieldsOfLawRepository; this.keywordRepository = keywordRepository; this.documentUnitNormRepository = documentUnitNormRepository; this.documentationOfficeRepository = documentationOfficeRepository; this.databaseDocumentUnitStatusRepository = databaseDocumentUnitStatusRepository; - this.normAbbreviationRepository = normAbbreviationRepository; this.documentationUnitLinkRepository = documentationUnitLinkRepository; + this.normAbbreviationRepository = normAbbreviationRepository; this.citationStyleRepository = citationStyleRepository; this.procedureRepository = procedureRepository; this.procedureLinkRepository = procedureLinkRepository; @@ -232,8 +240,10 @@ private Mono enrichDocumentType( return Mono.just(documentUnitDTO); } - return databaseDocumentTypeRepository - .findFirstByJurisShortcutAndDocumentType(documentType.jurisShortcut(), 'R') + return Mono.just( + databaseDocumentTypeRepository.findFirstByAbbreviationAndCategory( + documentType.jurisShortcut(), + databaseDocumentCategoryRepository.findFirstByLabel("R"))) .map( documentTypeDTO -> { if (!documentTypeDTO.getLabel().equals(documentType.label())) { @@ -350,36 +360,41 @@ public Mono saveFileNumbers( public Mono saveNorms( DocumentUnitDTO documentUnitDTO, DocumentUnit documentUnit) { - return documentUnitNormRepository - .findAllByDocumentUnitIdOrderById(documentUnitDTO.getId()) + return Flux.fromIterable( + documentUnitNormRepository.findAllByLegacyDocUnitIdOrderById(documentUnitDTO.getUuid())) .collectList() .flatMap( documentUnitNormDTOs -> { - List documentUnitNorms = new ArrayList<>(); if (documentUnit.contentRelatedIndexing() == null || documentUnit.contentRelatedIndexing().norms() == null) return Mono.just(documentUnitDTO); - documentUnitNorms.addAll(documentUnit.contentRelatedIndexing().norms()); + List documentUnitNorms = + new ArrayList<>(documentUnit.contentRelatedIndexing().norms()); AtomicInteger normIndex = new AtomicInteger(0); - List toSave = new ArrayList<>(); - List toDelete = new ArrayList<>(); + List toSave = new ArrayList<>(); + List toDelete = new ArrayList<>(); documentUnitNormDTOs.forEach( documentUnitNormDTO -> { int index = normIndex.getAndIncrement(); - UUID normAbbreviationId = null; if (index < documentUnitNorms.size()) { DocumentUnitNorm currentNorm = documentUnitNorms.get(index); - if (currentNorm.normAbbreviation() != null) { - normAbbreviationId = currentNorm.normAbbreviation().id(); + if (!isEmptyNorm(currentNorm)) { + documentUnitNormDTO.setId(currentNorm.id()); + documentUnitNormDTO.setSingleNorm(currentNorm.singleNorm()); + documentUnitNormDTO.setDateOfVersion(currentNorm.dateOfVersion()); + documentUnitNormDTO.setDateOfRelevance(currentNorm.dateOfRelevance()); + documentUnitNormDTO.setNormAbbreviation( + normAbbreviationRepository + .findById(currentNorm.normAbbreviation().id()) + .orElse(null)); + documentUnitNormDTO.setLegacyDocUnitId(documentUnitDTO.uuid); + toSave.add(documentUnitNormDTO); + } else { + toDelete.add(documentUnitNormDTO); } - documentUnitNormDTO.normAbbreviationUuid = normAbbreviationId; - documentUnitNormDTO.singleNorm = currentNorm.singleNorm(); - documentUnitNormDTO.dateOfVersion = currentNorm.dateOfVersion(); - documentUnitNormDTO.dateOfRelevance = currentNorm.dateOfRelevance(); - toSave.add(documentUnitNormDTO); } else { toDelete.add(documentUnitNormDTO); } @@ -391,28 +406,31 @@ public Mono saveNorms( if (isEmptyNorm(currentNorm)) { continue; } - UUID normAbbreviationId = null; - if (currentNorm.normAbbreviation() != null) { - normAbbreviationId = currentNorm.normAbbreviation().id(); - } - DocumentUnitNormDTO documentUnitNormDTO = - DocumentUnitNormDTO.builder() - .normAbbreviationUuid(normAbbreviationId) + + NormReferenceDTOBuilder builder = + NormReferenceDTO.builder() + .id(currentNorm.id()) .singleNorm(currentNorm.singleNorm()) .dateOfVersion(currentNorm.dateOfVersion()) .dateOfRelevance(currentNorm.dateOfRelevance()) - .documentUnitId(documentUnitDTO.getId()) - .build(); - toSave.add(documentUnitNormDTO); + .legacyDocUnitId(documentUnitDTO.getUuid()); + + if (currentNorm.normAbbreviation() != null + && currentNorm.normAbbreviation().id() != null) { + Optional normAbbreviationDTO = + normAbbreviationRepository.findById(currentNorm.normAbbreviation().id()); + + normAbbreviationDTO.ifPresent(builder::normAbbreviation); + } + + toSave.add(builder.build()); } - return documentUnitNormRepository - .deleteAll(toDelete) - .then( - documentUnitNormRepository - .saveAll(toSave) - .flatMapSequential(this::injectNormAbbreviation) - .collectList()) + documentUnitNormRepository.deleteAll(toDelete); + + return Flux.fromIterable(documentUnitNormRepository.saveAll(toSave)) + .flatMapSequential(this::injectNormAbbreviation) + .collectList() .map( savedNormList -> { documentUnitDTO.setNorms(savedNormList); @@ -1040,9 +1058,10 @@ private Mono injectDocumentType( if (documentUnitMetadataDTO.getDocumentTypeId() == null) { return Mono.just(documentUnitMetadataDTO); } - return databaseDocumentTypeRepository - .findById(documentUnitMetadataDTO.getDocumentTypeId()) - .defaultIfEmpty(DocumentTypeDTO.builder().build()) + return Mono.just( + databaseDocumentTypeRepository + .findById(documentUnitMetadataDTO.getDocumentTypeId()) + .orElse(DocumentTypeDTO.builder().build())) .map( documentTypeDTO -> { documentUnitMetadataDTO.setDocumentTypeDTO(documentTypeDTO); @@ -1083,8 +1102,8 @@ private Mono injectKeywords(DocumentUnitDTO documentUnitDTO) { } private Mono injectNorms(DocumentUnitDTO documentUnitDTO) { - return documentUnitNormRepository - .findAllByDocumentUnitIdOrderById(documentUnitDTO.getId()) + return Flux.fromIterable( + documentUnitNormRepository.findAllByLegacyDocUnitIdOrderById(documentUnitDTO.getUuid())) .flatMapSequential(this::injectNormAbbreviation) .collectList() .map( @@ -1094,20 +1113,8 @@ private Mono injectNorms(DocumentUnitDTO documentUnitDTO) { }); } - private Mono injectNormAbbreviation( - DocumentUnitNormDTO documentUnitNormDTO) { - if (documentUnitNormDTO.getNormAbbreviationUuid() == null) { - return Mono.just(documentUnitNormDTO); - } - - return normAbbreviationRepository - .findById(documentUnitNormDTO.getNormAbbreviationUuid()) - .defaultIfEmpty(NormAbbreviationDTO.builder().build()) - .map( - normAbbreviationDTO -> { - documentUnitNormDTO.setNormAbbreviation(normAbbreviationDTO); - return documentUnitNormDTO; - }); + private Mono injectNormAbbreviation(NormReferenceDTO normReferenceDTO) { + return Mono.just(normReferenceDTO); } private Mono injectDocumentationOffice( @@ -1187,7 +1194,7 @@ public Flux searchByLinkedDocumentationUnit( if (documentUnitDTOIdsViaFileNumber == null && linkedDocumentationUnit.getFileNumber() != null) return Flux.empty(); - Long documentTypeDTOId = tuple.getT2() == -1L ? null : tuple.getT2(); + UUID documentTypeDTOId = tuple.getT2().equals(new UUID(0, 0)) ? null : tuple.getT2(); if (documentTypeDTOId == null && linkedDocumentationUnit.getDocumentType() != null) return Flux.empty(); @@ -1220,7 +1227,7 @@ public Mono countSearchByLinkedDocumentationUnit( if (documentUnitDTOIdsViaFileNumber == null && linkedDocumentationUnit.getFileNumber() != null) return Mono.just(0L); - Long documentTypeDTOId = tuple.getT2() == -1L ? null : tuple.getT2(); + UUID documentTypeDTOId = tuple.getT2().equals(new UUID(0, 0)) ? null : tuple.getT2(); if (documentTypeDTOId == null && linkedDocumentationUnit.getDocumentType() != null) return Mono.just(0L); @@ -1256,15 +1263,16 @@ private Flux extractDocumentUnitDTOIdsViaFileNumber( .map(FileNumberDTO::getDocumentUnitId); } - private Mono extractDocumentTypeDTOId(LinkedDocumentationUnit linkedDocumentationUnit) { + private Mono extractDocumentTypeDTOId(LinkedDocumentationUnit linkedDocumentationUnit) { return Mono.justOrEmpty(linkedDocumentationUnit.getDocumentType()) .map(DocumentType::jurisShortcut) .flatMap( jurisShortcut -> - databaseDocumentTypeRepository.findFirstByJurisShortcutAndDocumentType( - jurisShortcut, 'R')) + Mono.justOrEmpty( + databaseDocumentTypeRepository.findFirstByAbbreviationAndCategory( + jurisShortcut, databaseDocumentCategoryRepository.findFirstByLabel("R")))) .mapNotNull(DocumentTypeDTO::getId) - .switchIfEmpty(Mono.just(-1L)); + .switchIfEmpty(Mono.just(new UUID(0, 0))); } private Long[] convertListToArrayOrReturnNull(List list) { @@ -1353,8 +1361,7 @@ private static Predicate[] getPredicates( builder.equal(root.get("documentationOfficeId"), documentationOfficeDTO.getId()); if (searchInput.status() != null && searchInput.status().withError()) { - Predicate statusWithError = - builder.equal(root.get("withError"), searchInput.status().withError()); + Predicate statusWithError = builder.equal(root.get("withError"), true); restrictions.add(builder.and(myDocOffice, statusWithError)); } diff --git a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/r2dbc/lookuptable/DatabaseDocumentCategoryRepository.java b/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/r2dbc/lookuptable/DatabaseDocumentCategoryRepository.java deleted file mode 100644 index ed0cb48c2d..0000000000 --- a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/r2dbc/lookuptable/DatabaseDocumentCategoryRepository.java +++ /dev/null @@ -1,7 +0,0 @@ -package de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.lookuptable; - -import java.util.UUID; -import org.springframework.data.r2dbc.repository.R2dbcRepository; - -public interface DatabaseDocumentCategoryRepository - extends R2dbcRepository {} diff --git a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/r2dbc/lookuptable/DatabaseDocumentTypeNewRepository.java b/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/r2dbc/lookuptable/DatabaseDocumentTypeNewRepository.java deleted file mode 100644 index 5729a4dcdb..0000000000 --- a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/r2dbc/lookuptable/DatabaseDocumentTypeNewRepository.java +++ /dev/null @@ -1,10 +0,0 @@ -package de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.lookuptable; - -import java.util.UUID; -import org.springframework.data.r2dbc.repository.R2dbcRepository; -import reactor.core.publisher.Flux; - -public interface DatabaseDocumentTypeNewRepository - extends R2dbcRepository { - Flux findAllById(UUID id); -} diff --git a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/r2dbc/lookuptable/DatabaseDocumentTypeRepository.java b/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/r2dbc/lookuptable/DatabaseDocumentTypeRepository.java deleted file mode 100644 index f9bebff52c..0000000000 --- a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/r2dbc/lookuptable/DatabaseDocumentTypeRepository.java +++ /dev/null @@ -1,34 +0,0 @@ -package de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.lookuptable; - -import org.springframework.data.r2dbc.repository.Query; -import org.springframework.data.r2dbc.repository.R2dbcRepository; -import org.springframework.stereotype.Repository; -import reactor.core.publisher.Flux; -import reactor.core.publisher.Mono; - -@Repository -public interface DatabaseDocumentTypeRepository extends R2dbcRepository { - - Mono findFirstByJurisShortcutAndDocumentType( - String jurisShortcut, char documentType); - - Flux findAllByDocumentTypeOrderByJurisShortcutAscLabelAsc(char documentType); - - // see query explanation in CourtRepository, it's almost the same - @Query( - "WITH label_added AS (SELECT *, " - + " UPPER(CONCAT(juris_shortcut, ' ', label)) AS concat" - + " from lookuptable_documenttype) " - + "SELECT *," - + " concat, " - + " CASE " - + " WHEN concat LIKE UPPER(:searchStr||'%') THEN 1 " - + " WHEN concat LIKE UPPER('% '||:searchStr||'%') THEN 2 " - + " WHEN concat LIKE UPPER('%-'||:searchStr||'%') THEN 2 " - + " ELSE 3 " - + " END AS weight " - + "FROM label_added " - + "WHERE concat LIKE UPPER('%'||:searchStr||'%') AND document_type = 'R' " - + "ORDER BY weight, concat") - Flux findCaselawBySearchStr(String searchStr); -} diff --git a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/r2dbc/lookuptable/DatabaseNormAbbreviationDocumentTypeRepository.java b/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/r2dbc/lookuptable/DatabaseNormAbbreviationDocumentTypeRepository.java deleted file mode 100644 index c34d004de9..0000000000 --- a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/r2dbc/lookuptable/DatabaseNormAbbreviationDocumentTypeRepository.java +++ /dev/null @@ -1,10 +0,0 @@ -package de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.lookuptable; - -import java.util.UUID; -import org.springframework.data.r2dbc.repository.R2dbcRepository; -import reactor.core.publisher.Flux; - -public interface DatabaseNormAbbreviationDocumentTypeRepository - extends R2dbcRepository { - Flux findAllByNormAbbreviationId(UUID normAbbreviationId); -} diff --git a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/r2dbc/lookuptable/DatabaseNormAbbreviationRegionRepository.java b/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/r2dbc/lookuptable/DatabaseNormAbbreviationRegionRepository.java deleted file mode 100644 index f0b0dc5566..0000000000 --- a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/r2dbc/lookuptable/DatabaseNormAbbreviationRegionRepository.java +++ /dev/null @@ -1,10 +0,0 @@ -package de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.lookuptable; - -import java.util.UUID; -import org.springframework.data.r2dbc.repository.R2dbcRepository; -import reactor.core.publisher.Flux; - -public interface DatabaseNormAbbreviationRegionRepository - extends R2dbcRepository { - Flux findAllByNormAbbreviationId(UUID normAbbreviationId); -} diff --git a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/r2dbc/lookuptable/DatabaseNormAbbreviationRepository.java b/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/r2dbc/lookuptable/DatabaseNormAbbreviationRepository.java deleted file mode 100644 index 72bc7e466d..0000000000 --- a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/r2dbc/lookuptable/DatabaseNormAbbreviationRepository.java +++ /dev/null @@ -1,106 +0,0 @@ -package de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.lookuptable; - -import java.util.UUID; -import org.springframework.data.r2dbc.repository.Query; -import org.springframework.data.r2dbc.repository.R2dbcRepository; -import reactor.core.publisher.Flux; -import reactor.core.publisher.Mono; - -public interface DatabaseNormAbbreviationRepository - extends R2dbcRepository { - - @Query("select * from norm_abbreviation limit :size") - Flux findAll(int size); - - @Query( - "select * from norm_abbreviation where abbreviation like :query||'%' order by abbreviation limit :size offset :pageOffset") - Flux findBySearchQuery(String query, Integer size, Integer pageOffset); - - @Query( - "select" - + " id," - + " abbreviation," - + " decision_date," - + " document_id," - + " document_number," - + " official_letter_abbreviation," - + " official_long_title," - + " official_short_title," - + " source" - + " from norm_abbreviation" - + " where lower(abbreviation) = :directInput" - + " limit :size") - Flux findByAwesomeSearchQuery_rank4(String directInput, Integer size); - - @Query( - "select" - + " id," - + " abbreviation," - + " decision_date," - + " document_id," - + " document_number," - + " official_letter_abbreviation," - + " official_long_title," - + " official_short_title," - + " source" - + " from norm_abbreviation" - + " where lower(official_letter_abbreviation) = :directInput" - + " limit :size") - Flux findByAwesomeSearchQuery_rank3(String directInput, Integer size); - - @Query( - "select" - + " id," - + " abbreviation," - + " decision_date," - + " document_id," - + " document_number," - + " official_letter_abbreviation," - + " official_long_title," - + " official_short_title," - + " source" - + " from norm_abbreviation" - + " where lower(abbreviation) like :directInput || '%'" - + " limit :size") - Flux findByAwesomeSearchQuery_rank2(String directInput, Integer size); - - @Query( - "select" - + " id," - + " abbreviation," - + " decision_date," - + " document_id," - + " document_number," - + " official_letter_abbreviation," - + " official_long_title," - + " official_short_title," - + " source" - + " from norm_abbreviation" - + " where lower(official_letter_abbreviation) like :directInput || '%'" - + " limit :size") - Flux findByAwesomeSearchQuery_rank1(String directInput, Integer size); - - @Query( - "select" - + " id," - + " abbreviation," - + " decision_date," - + " document_id," - + " document_number," - + " official_letter_abbreviation," - + " official_long_title," - + " official_short_title," - + " source," - + " ts_rank_cd(weighted_vector, to_tsquery('german', '' || :tsQuery || '')) rank" - + " from norm_abbreviation_search" - + " where weighted_vector @@ to_tsquery('german', '' || :tsQuery || '')" - + " order by rank desc" - + " limit :size") - Flux findByAwesomeSearchQuery_rankWeightedVector( - String tsQuery, Integer size); - - Mono findById(UUID normAbbreviationUuid); - - @Query("REFRESH MATERIALIZED VIEW norm_abbreviation_search") - Mono refreshMaterializedViews(); -} diff --git a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/r2dbc/lookuptable/DatabaseRegionRepository.java b/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/r2dbc/lookuptable/DatabaseRegionRepository.java deleted file mode 100644 index 845605ff4c..0000000000 --- a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/r2dbc/lookuptable/DatabaseRegionRepository.java +++ /dev/null @@ -1,6 +0,0 @@ -package de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.lookuptable; - -import java.util.UUID; -import org.springframework.data.r2dbc.repository.R2dbcRepository; - -public interface DatabaseRegionRepository extends R2dbcRepository {} diff --git a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/r2dbc/lookuptable/DocumentCategoryDTO.java b/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/r2dbc/lookuptable/DocumentCategoryDTO.java deleted file mode 100644 index af347c28e8..0000000000 --- a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/r2dbc/lookuptable/DocumentCategoryDTO.java +++ /dev/null @@ -1,27 +0,0 @@ -package de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.lookuptable; - -import java.util.UUID; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; -import org.springframework.data.annotation.Id; -import org.springframework.data.annotation.Transient; -import org.springframework.data.domain.Persistable; -import org.springframework.data.relational.core.mapping.Table; - -@Data -@NoArgsConstructor -@AllArgsConstructor -@Builder -@Table("document_category") -public class DocumentCategoryDTO implements Persistable { - @Id private UUID id; - private Character label; - @Transient private boolean newEntity; - - @Override - public boolean isNew() { - return id == null || newEntity; - } -} diff --git a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/r2dbc/lookuptable/DocumentTypeDTO.java b/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/r2dbc/lookuptable/DocumentTypeDTO.java deleted file mode 100644 index e4101375fa..0000000000 --- a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/r2dbc/lookuptable/DocumentTypeDTO.java +++ /dev/null @@ -1,37 +0,0 @@ -package de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.lookuptable; - -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; -import org.springframework.data.annotation.Id; -import org.springframework.data.annotation.Transient; -import org.springframework.data.domain.Persistable; -import org.springframework.data.relational.core.mapping.Table; - -@Data -@Builder -@NoArgsConstructor -@AllArgsConstructor -@Table("lookuptable_documenttype") -public class DocumentTypeDTO implements Persistable { - @Id Long id; - String changeDateMail; - String changeDateClient; - char changeIndicator; - String version; - String jurisShortcut; - char documentType; - String multiple; - String label; - String superlabel1; - String superlabel2; - - @Transient private boolean newEntry; - - @Override - @Transient - public boolean isNew() { - return this.newEntry || id == null; - } -} diff --git a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/r2dbc/lookuptable/DocumentTypeNewDTO.java b/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/r2dbc/lookuptable/DocumentTypeNewDTO.java deleted file mode 100644 index ce07d0773a..0000000000 --- a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/r2dbc/lookuptable/DocumentTypeNewDTO.java +++ /dev/null @@ -1,39 +0,0 @@ -package de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.lookuptable; - -import java.util.UUID; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; -import org.springframework.data.annotation.Id; -import org.springframework.data.annotation.Transient; -import org.springframework.data.domain.Persistable; -import org.springframework.data.relational.core.mapping.Column; -import org.springframework.data.relational.core.mapping.Table; - -@Data -@NoArgsConstructor -@AllArgsConstructor -@Builder -@Table("document_type") -public class DocumentTypeNewDTO implements Persistable { - @Id private UUID id; - private String abbreviation; - private String label; - private boolean multiple; - - @Column("super_label_1") - private String superLabel1; - - @Column("super_label_2") - private String superLabel2; - - private UUID documentCategoryId; - @Transient private Character categoryLabel; - @Transient private boolean newEntity; - - @Override - public boolean isNew() { - return id == null || newEntity; - } -} diff --git a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/r2dbc/lookuptable/NormAbbreviationDTO.java b/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/r2dbc/lookuptable/NormAbbreviationDTO.java deleted file mode 100644 index 5e7c0e9458..0000000000 --- a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/r2dbc/lookuptable/NormAbbreviationDTO.java +++ /dev/null @@ -1,38 +0,0 @@ -package de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.lookuptable; - -import java.time.LocalDate; -import java.util.List; -import java.util.UUID; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; -import org.springframework.data.annotation.Id; -import org.springframework.data.annotation.Transient; -import org.springframework.data.domain.Persistable; -import org.springframework.data.relational.core.mapping.Table; - -@Data -@NoArgsConstructor -@AllArgsConstructor -@Builder(toBuilder = true) -@Table("norm_abbreviation") -public class NormAbbreviationDTO implements Persistable { - @Id UUID id; - String abbreviation; - LocalDate decisionDate; - Integer documentId; - String documentNumber; - String officialLetterAbbreviation; - String officialLongTitle; - String officialShortTitle; - Character source; - @Transient List documentTypes; - @Transient List regions; - @Transient boolean newEntity; - - @Override - public boolean isNew() { - return id == null || newEntity; - } -} diff --git a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/r2dbc/lookuptable/NormAbbreviationDocumentTypeDTO.java b/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/r2dbc/lookuptable/NormAbbreviationDocumentTypeDTO.java deleted file mode 100644 index 77fdea6271..0000000000 --- a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/r2dbc/lookuptable/NormAbbreviationDocumentTypeDTO.java +++ /dev/null @@ -1,31 +0,0 @@ -package de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.lookuptable; - -import java.util.UUID; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; -import org.springframework.data.annotation.Transient; -import org.springframework.data.domain.Persistable; -import org.springframework.data.relational.core.mapping.Table; - -@Data -@NoArgsConstructor -@AllArgsConstructor -@Builder -@Table(name = "norm_abbreviation_document_type") -public class NormAbbreviationDocumentTypeDTO implements Persistable { - private UUID normAbbreviationId; - private UUID documentTypeId; - @Transient private boolean newEntity; - - @Override - public UUID getId() { - return null; - } - - @Override - public boolean isNew() { - return newEntity; - } -} diff --git a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/r2dbc/lookuptable/NormAbbreviationRegionDTO.java b/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/r2dbc/lookuptable/NormAbbreviationRegionDTO.java deleted file mode 100644 index 11596c3edd..0000000000 --- a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/r2dbc/lookuptable/NormAbbreviationRegionDTO.java +++ /dev/null @@ -1,31 +0,0 @@ -package de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.lookuptable; - -import java.util.UUID; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; -import org.springframework.data.annotation.Transient; -import org.springframework.data.domain.Persistable; -import org.springframework.data.relational.core.mapping.Table; - -@Data -@NoArgsConstructor -@AllArgsConstructor -@Builder -@Table("norm_abbreviation_region") -public class NormAbbreviationRegionDTO implements Persistable { - private UUID normAbbreviationId; - private UUID regionId; - @Transient private boolean newEntity; - - @Override - public UUID getId() { - return null; - } - - @Override - public boolean isNew() { - return newEntity; - } -} diff --git a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/r2dbc/lookuptable/PostgresDocumentTypeRepositoryImpl.java b/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/r2dbc/lookuptable/PostgresDocumentTypeRepositoryImpl.java deleted file mode 100644 index b6e453d818..0000000000 --- a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/r2dbc/lookuptable/PostgresDocumentTypeRepositoryImpl.java +++ /dev/null @@ -1,30 +0,0 @@ -package de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.lookuptable; - -import de.bund.digitalservice.ris.caselaw.adapter.transformer.DocumentTypeTransformer; -import de.bund.digitalservice.ris.caselaw.domain.DocumentTypeRepository; -import de.bund.digitalservice.ris.caselaw.domain.lookuptable.documenttype.DocumentType; -import org.springframework.stereotype.Repository; -import reactor.core.publisher.Flux; - -@Repository -public class PostgresDocumentTypeRepositoryImpl implements DocumentTypeRepository { - private final DatabaseDocumentTypeRepository repository; - - public PostgresDocumentTypeRepositoryImpl(DatabaseDocumentTypeRepository repository) { - this.repository = repository; - } - - @Override - public Flux findCaselawBySearchStr(String searchString) { - return repository - .findCaselawBySearchStr(searchString) - .map(DocumentTypeTransformer::transformDTO); - } - - @Override - public Flux findAllByDocumentTypeOrderByJurisShortcutAscLabelAsc(char shortcut) { - return repository - .findAllByDocumentTypeOrderByJurisShortcutAscLabelAsc(shortcut) - .map(DocumentTypeTransformer::transformDTO); - } -} diff --git a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/r2dbc/lookuptable/PostgresNormAbbreviationRepositoryImpl.java b/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/r2dbc/lookuptable/PostgresNormAbbreviationRepositoryImpl.java deleted file mode 100644 index 9133044d5a..0000000000 --- a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/r2dbc/lookuptable/PostgresNormAbbreviationRepositoryImpl.java +++ /dev/null @@ -1,201 +0,0 @@ -package de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.lookuptable; - -import de.bund.digitalservice.ris.caselaw.adapter.transformer.NormAbbreviationTransformer; -import de.bund.digitalservice.ris.caselaw.domain.lookuptable.NormAbbreviation; -import de.bund.digitalservice.ris.caselaw.domain.lookuptable.NormAbbreviationRepository; -import java.util.List; -import java.util.UUID; -import org.springframework.stereotype.Repository; -import reactor.core.publisher.Flux; -import reactor.core.publisher.Mono; - -@Repository -public class PostgresNormAbbreviationRepositoryImpl implements NormAbbreviationRepository { - private final DatabaseNormAbbreviationRepository repository; - private final DatabaseDocumentTypeNewRepository documentTypeRepository; - private final DatabaseNormAbbreviationDocumentTypeRepository - normAbbreviationDocumentTypeRepository; - private final DatabaseRegionRepository regionRepository; - private final DatabaseNormAbbreviationRegionRepository normAbbreviationRegionRepository; - private final DatabaseDocumentCategoryRepository documentCategoryRepository; - - public PostgresNormAbbreviationRepositoryImpl( - DatabaseNormAbbreviationRepository repository, - DatabaseDocumentTypeNewRepository documentTypeRepository, - DatabaseNormAbbreviationDocumentTypeRepository normAbbreviationDocumentTypeRepository, - DatabaseRegionRepository regionRepository, - DatabaseNormAbbreviationRegionRepository normAbbreviationRegionRepository, - DatabaseDocumentCategoryRepository documentCategoryRepository) { - - this.repository = repository; - this.documentTypeRepository = documentTypeRepository; - this.normAbbreviationDocumentTypeRepository = normAbbreviationDocumentTypeRepository; - this.regionRepository = regionRepository; - this.normAbbreviationRegionRepository = normAbbreviationRegionRepository; - this.documentCategoryRepository = documentCategoryRepository; - } - - @Override - public Mono findById(UUID id) { - return repository - .findById(id) - .flatMap(this::injectAdditionalInformation) - .map(NormAbbreviationTransformer::transformDTO); - } - - @Override - public Flux findBySearchQuery(String query, Integer size, Integer pageOffset) { - return repository - .findBySearchQuery(query, size, pageOffset) - .flatMapSequential(this::injectAdditionalInformation) - .map(NormAbbreviationTransformer::transformDTO); - } - - @Override - public Mono> findByAwesomeSearchQuery( - String query, Integer size, Integer page) { - String cleanedQuery = - query - .trim() - .replace(",", "") - .replace(";", "") - .replace("(", "") - .replace(")", "") - .replace("*", "") - .replace("+", "") - .replace("-", "") - .replace(":", "") - .replace("/", " "); - String directInput = cleanedQuery.toLowerCase(); - String[] queryBlocks = cleanedQuery.split(" "); - StringBuilder tsQuery = new StringBuilder(); - for (int i = 0; i < queryBlocks.length; i++) { - if (queryBlocks[i].isBlank()) continue; - - if (i > 0) { - tsQuery.append(" & "); - } - - tsQuery.append(queryBlocks[i]).append(":*"); - } - - return repository - .findByAwesomeSearchQuery_rank4(directInput, size) - .collectList() - .flatMap( - list -> { - if (list.size() < size) { - return repository - .findByAwesomeSearchQuery_rank3(directInput, size - list.size()) - .collectList() - .map( - rank3list -> { - rank3list.stream().filter(e -> !list.contains(e)).forEach(list::add); - return list; - }); - } - return Mono.just(list); - }) - .flatMap( - list -> { - if (list.size() < size) { - return repository - .findByAwesomeSearchQuery_rank2(directInput, size - list.size()) - .collectList() - .map( - rank2list -> { - rank2list.stream().filter(e -> !list.contains(e)).forEach(list::add); - return list; - }); - } - return Mono.just(list); - }) - .flatMap( - list -> { - if (list.size() < size) { - return repository - .findByAwesomeSearchQuery_rank1(directInput, size - list.size()) - .collectList() - .map( - rank1list -> { - rank1list.stream().filter(e -> !list.contains(e)).forEach(list::add); - return list; - }); - } - return Mono.just(list); - }) - .flatMap( - list -> { - if (list.size() < size) { - return repository - .findByAwesomeSearchQuery_rankWeightedVector( - tsQuery.toString(), size - list.size()) - .collectList() - .map( - rankWeightedList -> { - rankWeightedList.stream() - .filter(e -> !list.contains(e)) - .forEach(list::add); - return list; - }); - } - return Mono.just(list); - }) - .flatMap( - list -> - Flux.fromIterable(list) - .flatMapSequential( - normAbbreviationDTO -> - injectAdditionalInformation(normAbbreviationDTO) - .map(NormAbbreviationTransformer::transformDTO)) - .collectList()); - } - - @Override - public Mono refreshMaterializedViews() { - return repository.refreshMaterializedViews(); - } - - private Mono injectAdditionalInformation( - NormAbbreviationDTO normAbbreviationDTO) { - Mono> documentTypes = - normAbbreviationDocumentTypeRepository - .findAllByNormAbbreviationId(normAbbreviationDTO.getId()) - .flatMapSequential( - normAbbreviationDocumentTypeDTO -> - documentTypeRepository - .findById(normAbbreviationDocumentTypeDTO.getDocumentTypeId()) - .flatMap(this::injectCategoryLabel)) - .collectList(); - Mono> regions = - normAbbreviationRegionRepository - .findAllByNormAbbreviationId(normAbbreviationDTO.getId()) - .flatMapSequential( - normAbbreviationRegionDTO -> - regionRepository.findById(normAbbreviationRegionDTO.getRegionId())) - .collectList(); - - return Mono.zip(documentTypes, regions) - .map( - tuple -> { - normAbbreviationDTO.setDocumentTypes(tuple.getT1()); - normAbbreviationDTO.setRegions(tuple.getT2()); - - return normAbbreviationDTO; - }); - } - - private Mono injectCategoryLabel(DocumentTypeNewDTO documentTypeNewDTO) { - if (documentTypeNewDTO == null || documentTypeNewDTO.getDocumentCategoryId() == null) { - return Mono.just(documentTypeNewDTO); - } - - return documentCategoryRepository - .findById(documentTypeNewDTO.getDocumentCategoryId()) - .map( - documentCategoryDTO -> { - documentTypeNewDTO.setCategoryLabel(documentCategoryDTO.getLabel()); - return documentTypeNewDTO; - }); - } -} diff --git a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/r2dbc/lookuptable/RegionDTO.java b/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/r2dbc/lookuptable/RegionDTO.java deleted file mode 100644 index 10d71e5339..0000000000 --- a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/database/r2dbc/lookuptable/RegionDTO.java +++ /dev/null @@ -1,28 +0,0 @@ -package de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.lookuptable; - -import java.util.UUID; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; -import org.springframework.data.annotation.Id; -import org.springframework.data.annotation.Transient; -import org.springframework.data.domain.Persistable; -import org.springframework.data.relational.core.mapping.Table; - -@Data -@NoArgsConstructor -@AllArgsConstructor -@Builder -@Table("region") -public class RegionDTO implements Persistable { - @Id private UUID id; - private String code; - private String label; - @Transient private boolean newEntity; - - @Override - public boolean isNew() { - return id == null || newEntity; - } -} diff --git a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/transformer/DocumentTypeNewTransformer.java b/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/transformer/DocumentTypeNewTransformer.java deleted file mode 100644 index b754e4d770..0000000000 --- a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/transformer/DocumentTypeNewTransformer.java +++ /dev/null @@ -1,19 +0,0 @@ -package de.bund.digitalservice.ris.caselaw.adapter.transformer; - -import de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.lookuptable.DocumentTypeNewDTO; -import de.bund.digitalservice.ris.caselaw.domain.lookuptable.DocumentTypeNew; - -public class DocumentTypeNewTransformer { - private DocumentTypeNewTransformer() {} - - public static DocumentTypeNew transformDTO(DocumentTypeNewDTO documentTypeNewDTO) { - return DocumentTypeNew.builder() - .abbreviation(documentTypeNewDTO.getAbbreviation()) - .label(documentTypeNewDTO.getLabel()) - .multiple(documentTypeNewDTO.isMultiple()) - .superLabel1(documentTypeNewDTO.getSuperLabel1()) - .superLabel2(documentTypeNewDTO.getSuperLabel2()) - .categoryLabel(documentTypeNewDTO.getCategoryLabel()) - .build(); - } -} diff --git a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/transformer/DocumentTypeTransformer.java b/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/transformer/DocumentTypeTransformer.java index 9c917f83ea..3d9eaea994 100644 --- a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/transformer/DocumentTypeTransformer.java +++ b/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/transformer/DocumentTypeTransformer.java @@ -1,6 +1,6 @@ package de.bund.digitalservice.ris.caselaw.adapter.transformer; -import de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.lookuptable.DocumentTypeDTO; +import de.bund.digitalservice.ris.caselaw.adapter.database.jpa.DocumentTypeDTO; import de.bund.digitalservice.ris.caselaw.domain.lookuptable.documenttype.DocumentType; public class DocumentTypeTransformer { @@ -8,7 +8,7 @@ private DocumentTypeTransformer() {} public static DocumentType transformDTO(DocumentTypeDTO documentTypeDTO) { return DocumentType.builder() - .jurisShortcut(documentTypeDTO.getJurisShortcut()) + .jurisShortcut(documentTypeDTO.getAbbreviation()) .label(documentTypeDTO.getLabel()) .build(); } diff --git a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/transformer/DocumentUnitNormTransformer.java b/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/transformer/DocumentUnitNormTransformer.java index efa221bec2..57dfd163d4 100644 --- a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/transformer/DocumentUnitNormTransformer.java +++ b/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/transformer/DocumentUnitNormTransformer.java @@ -1,13 +1,14 @@ package de.bund.digitalservice.ris.caselaw.adapter.transformer; -import de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.DocumentUnitNormDTO; +import de.bund.digitalservice.ris.caselaw.adapter.database.jpa.NormReferenceDTO; import de.bund.digitalservice.ris.caselaw.domain.DocumentUnitNorm; public class DocumentUnitNormTransformer { private DocumentUnitNormTransformer() {} - public static DocumentUnitNorm transformToDomain(DocumentUnitNormDTO normDTO) { + public static DocumentUnitNorm transformToDomain(NormReferenceDTO normDTO) { return DocumentUnitNorm.builder() + .id(normDTO.getId()) .normAbbreviation(NormAbbreviationTransformer.transformDTO(normDTO.getNormAbbreviation())) .singleNorm(normDTO.getSingleNorm()) .dateOfVersion(normDTO.getDateOfVersion()) diff --git a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/transformer/DocumentUnitTransformer.java b/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/transformer/DocumentUnitTransformer.java index c1bf24255f..d5f7c0f886 100644 --- a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/transformer/DocumentUnitTransformer.java +++ b/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/transformer/DocumentUnitTransformer.java @@ -1,5 +1,6 @@ package de.bund.digitalservice.ris.caselaw.adapter.transformer; +import de.bund.digitalservice.ris.caselaw.adapter.database.jpa.DocumentTypeDTO; import de.bund.digitalservice.ris.caselaw.adapter.database.jpa.DocumentationOfficeDTO; import de.bund.digitalservice.ris.caselaw.adapter.database.jpa.ProcedureDTO; import de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.DeviatingDecisionDateDTO; @@ -9,7 +10,6 @@ import de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.FileNumberDTO; import de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.IncorrectCourtDTO; import de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.KeywordDTO; -import de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.lookuptable.DocumentTypeDTO; import de.bund.digitalservice.ris.caselaw.domain.ActiveCitation; import de.bund.digitalservice.ris.caselaw.domain.ContentRelatedIndexing; import de.bund.digitalservice.ris.caselaw.domain.CoreData; @@ -174,7 +174,7 @@ public static DocumentUnit transformMetadataToDomain( DocumentTypeDTO documentTypeDTO = documentUnitMetadataDTO.getDocumentTypeDTO(); if (documentTypeDTO != null) { documentType = - new DocumentType(documentTypeDTO.getJurisShortcut(), documentTypeDTO.getLabel()); + new DocumentType(documentTypeDTO.getAbbreviation(), documentTypeDTO.getLabel()); } List fileNumbers = null; @@ -237,7 +237,7 @@ public static DocumentUnit transformDTO(DocumentUnitDTO documentUnitDTO) { DocumentTypeDTO documentTypeDTO = documentUnitDTO.getDocumentTypeDTO(); if (documentTypeDTO != null) { documentType = - new DocumentType(documentTypeDTO.getJurisShortcut(), documentTypeDTO.getLabel()); + new DocumentType(documentTypeDTO.getAbbreviation(), documentTypeDTO.getLabel()); } List proceedingDecisions = null; diff --git a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/transformer/LinkedDocumentationUnitTransformer.java b/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/transformer/LinkedDocumentationUnitTransformer.java index b80f7b81cb..5b5a0dad64 100644 --- a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/transformer/LinkedDocumentationUnitTransformer.java +++ b/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/transformer/LinkedDocumentationUnitTransformer.java @@ -1,9 +1,9 @@ package de.bund.digitalservice.ris.caselaw.adapter.transformer; +import de.bund.digitalservice.ris.caselaw.adapter.database.jpa.DocumentTypeDTO; import de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.DocumentUnitException; import de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.DocumentUnitMetadataDTO; import de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.DocumentationUnitLinkDTO; -import de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.lookuptable.DocumentTypeDTO; import de.bund.digitalservice.ris.caselaw.domain.ActiveCitation; import de.bund.digitalservice.ris.caselaw.domain.CoreData; import de.bund.digitalservice.ris.caselaw.domain.DataSource; @@ -63,13 +63,13 @@ static Court getCourt(DocumentUnitMetadataDTO documentUnitMetadataDTO) { static DocumentType getDocumentTypeByDTO(DocumentTypeDTO documentTypeDTO) { if (documentTypeDTO == null - || (documentTypeDTO.getLabel() == null && documentTypeDTO.getJurisShortcut() == null)) { + || (documentTypeDTO.getLabel() == null && documentTypeDTO.getAbbreviation() == null)) { return null; } return DocumentType.builder() .label(documentTypeDTO.getLabel()) - .jurisShortcut(documentTypeDTO.getJurisShortcut()) + .jurisShortcut(documentTypeDTO.getAbbreviation()) .build(); } diff --git a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/transformer/NormAbbreviationTransformer.java b/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/transformer/NormAbbreviationTransformer.java index 0e37c958ba..9a40b0e41e 100644 --- a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/transformer/NormAbbreviationTransformer.java +++ b/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/transformer/NormAbbreviationTransformer.java @@ -1,9 +1,9 @@ package de.bund.digitalservice.ris.caselaw.adapter.transformer; -import de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.lookuptable.NormAbbreviationDTO; -import de.bund.digitalservice.ris.caselaw.domain.lookuptable.DocumentTypeNew; +import de.bund.digitalservice.ris.caselaw.adapter.database.jpa.NormAbbreviationDTO; import de.bund.digitalservice.ris.caselaw.domain.lookuptable.NormAbbreviation; import de.bund.digitalservice.ris.caselaw.domain.lookuptable.Region; +import de.bund.digitalservice.ris.caselaw.domain.lookuptable.documenttype.DocumentType; import java.time.ZoneId; import java.util.List; @@ -15,17 +15,16 @@ public static NormAbbreviation transformDTO(NormAbbreviationDTO normAbbreviation return null; } - List documentTypes = null; - if (normAbbreviationDTO.getDocumentTypes() != null) { + List documentTypes = null; + if (normAbbreviationDTO.getDocumentTypeList() != null) { documentTypes = - normAbbreviationDTO.getDocumentTypes().stream() - .map(DocumentTypeNewTransformer::transformDTO) + normAbbreviationDTO.getDocumentTypeList().stream() + .map(DocumentTypeTransformer::transformDTO) .toList(); } - List regions = null; - if (normAbbreviationDTO.getRegions() != null) { - regions = - normAbbreviationDTO.getRegions().stream().map(RegionTransformer::transformDTO).toList(); + Region region = null; + if (normAbbreviationDTO.getRegion() != null) { + region = RegionTransformer.transformDTO(normAbbreviationDTO.getRegion()); } return NormAbbreviation.builder() @@ -46,7 +45,7 @@ public static NormAbbreviation transformDTO(NormAbbreviationDTO normAbbreviation .officialShortTitle(normAbbreviationDTO.getOfficialShortTitle()) .source(normAbbreviationDTO.getSource()) .documentTypes(documentTypes) - .regions(regions) + .region(region) .build(); } } diff --git a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/transformer/RegionTransformer.java b/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/transformer/RegionTransformer.java index cf145ef1c4..056c06620a 100644 --- a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/transformer/RegionTransformer.java +++ b/backend/src/main/java/de/bund/digitalservice/ris/caselaw/adapter/transformer/RegionTransformer.java @@ -1,12 +1,12 @@ package de.bund.digitalservice.ris.caselaw.adapter.transformer; -import de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.lookuptable.RegionDTO; +import de.bund.digitalservice.ris.caselaw.adapter.database.jpa.RegionDTO; import de.bund.digitalservice.ris.caselaw.domain.lookuptable.Region; public class RegionTransformer { private RegionTransformer() {} public static Region transformDTO(RegionDTO regionDTO) { - return Region.builder().code(regionDTO.getCode()).label(regionDTO.getLabel()).build(); + return Region.builder().code(regionDTO.getCode()).build(); } } diff --git a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/domain/DocumentTypeRepository.java b/backend/src/main/java/de/bund/digitalservice/ris/caselaw/domain/DocumentTypeRepository.java index a5218e0129..a13eabd6af 100644 --- a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/domain/DocumentTypeRepository.java +++ b/backend/src/main/java/de/bund/digitalservice/ris/caselaw/domain/DocumentTypeRepository.java @@ -1,12 +1,12 @@ package de.bund.digitalservice.ris.caselaw.domain; import de.bund.digitalservice.ris.caselaw.domain.lookuptable.documenttype.DocumentType; +import java.util.List; import org.springframework.data.repository.NoRepositoryBean; -import reactor.core.publisher.Flux; @NoRepositoryBean public interface DocumentTypeRepository { - Flux findCaselawBySearchStr(String searchString); + List findCaselawBySearchStr(String searchString); - Flux findAllByDocumentTypeOrderByJurisShortcutAscLabelAsc(char shortcut); + List findAllByDocumentTypeOrderByAbbreviationAscLabelAsc(char shortcut); } diff --git a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/domain/DocumentUnitNorm.java b/backend/src/main/java/de/bund/digitalservice/ris/caselaw/domain/DocumentUnitNorm.java index d6a35b5b47..237919fc87 100644 --- a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/domain/DocumentUnitNorm.java +++ b/backend/src/main/java/de/bund/digitalservice/ris/caselaw/domain/DocumentUnitNorm.java @@ -2,15 +2,16 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import de.bund.digitalservice.ris.caselaw.domain.lookuptable.NormAbbreviation; -import java.time.Instant; +import java.time.LocalDate; +import java.util.UUID; import lombok.Builder; @Builder(toBuilder = true) // to ignore the validationErrors that the frontend might be sending along @JsonIgnoreProperties(ignoreUnknown = true) public record DocumentUnitNorm( + UUID id, NormAbbreviation normAbbreviation, - // @SingleNormConstraint String singleNorm, - Instant dateOfVersion, + LocalDate dateOfVersion, String dateOfRelevance) {} diff --git a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/domain/LookupTableService.java b/backend/src/main/java/de/bund/digitalservice/ris/caselaw/domain/LookupTableService.java index a9c237904e..a7b609ec58 100644 --- a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/domain/LookupTableService.java +++ b/backend/src/main/java/de/bund/digitalservice/ris/caselaw/domain/LookupTableService.java @@ -30,10 +30,12 @@ public LookupTableService( public Flux getCaselawDocumentTypes(Optional searchStr) { if (searchStr.isPresent() && !searchStr.get().isBlank()) { - return documentTypeRepository.findCaselawBySearchStr(searchStr.get().trim()); + return Flux.fromIterable( + documentTypeRepository.findCaselawBySearchStr(searchStr.get().trim())); } - return documentTypeRepository.findAllByDocumentTypeOrderByJurisShortcutAscLabelAsc('R'); + return Flux.fromIterable( + documentTypeRepository.findAllByDocumentTypeOrderByAbbreviationAscLabelAsc('R')); } public Flux getCourts(Optional searchStr) { diff --git a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/domain/lookuptable/DocumentTypeNew.java b/backend/src/main/java/de/bund/digitalservice/ris/caselaw/domain/lookuptable/DocumentTypeNew.java deleted file mode 100644 index c7f9f06f82..0000000000 --- a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/domain/lookuptable/DocumentTypeNew.java +++ /dev/null @@ -1,12 +0,0 @@ -package de.bund.digitalservice.ris.caselaw.domain.lookuptable; - -import lombok.Builder; - -@Builder -public record DocumentTypeNew( - String abbreviation, - String label, - boolean multiple, - String superLabel1, - String superLabel2, - Character categoryLabel) {} diff --git a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/domain/lookuptable/NormAbbreviation.java b/backend/src/main/java/de/bund/digitalservice/ris/caselaw/domain/lookuptable/NormAbbreviation.java index 7a1c707177..32ade7fa75 100644 --- a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/domain/lookuptable/NormAbbreviation.java +++ b/backend/src/main/java/de/bund/digitalservice/ris/caselaw/domain/lookuptable/NormAbbreviation.java @@ -1,5 +1,6 @@ package de.bund.digitalservice.ris.caselaw.domain.lookuptable; +import de.bund.digitalservice.ris.caselaw.domain.lookuptable.documenttype.DocumentType; import java.time.Instant; import java.util.List; import java.util.UUID; @@ -10,11 +11,11 @@ public record NormAbbreviation( UUID id, String abbreviation, Instant decisionDate, - Integer documentId, + Long documentId, String documentNumber, String officialLetterAbbreviation, String officialLongTitle, String officialShortTitle, - Character source, - List documentTypes, - List regions) {} + String source, + List documentTypes, + Region region) {} diff --git a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/domain/lookuptable/NormAbbreviationRepository.java b/backend/src/main/java/de/bund/digitalservice/ris/caselaw/domain/lookuptable/NormAbbreviationRepository.java index 72026159d4..fda97c847c 100644 --- a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/domain/lookuptable/NormAbbreviationRepository.java +++ b/backend/src/main/java/de/bund/digitalservice/ris/caselaw/domain/lookuptable/NormAbbreviationRepository.java @@ -3,16 +3,15 @@ import java.util.List; import java.util.UUID; import org.springframework.data.repository.NoRepositoryBean; -import reactor.core.publisher.Flux; -import reactor.core.publisher.Mono; @NoRepositoryBean public interface NormAbbreviationRepository { - public Mono findById(UUID id); + public NormAbbreviation findById(UUID id); - Flux findBySearchQuery(String query, Integer size, Integer page); + List getNormAbbreviationsStartingWithExact( + String query, Integer size, Integer page); - Mono> findByAwesomeSearchQuery(String query, Integer size, Integer page); + List findAllContainingOrderByAccuracy(String query, Integer size, Integer page); - Mono refreshMaterializedViews(); + void refreshMaterializedViews(); } diff --git a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/domain/lookuptable/Region.java b/backend/src/main/java/de/bund/digitalservice/ris/caselaw/domain/lookuptable/Region.java index c64e28bed1..7543e0deaf 100644 --- a/backend/src/main/java/de/bund/digitalservice/ris/caselaw/domain/lookuptable/Region.java +++ b/backend/src/main/java/de/bund/digitalservice/ris/caselaw/domain/lookuptable/Region.java @@ -3,4 +3,4 @@ import lombok.Builder; @Builder -public record Region(String code, String label) {} +public record Region(String code) {} diff --git a/backend/src/main/resources/application-local.yaml b/backend/src/main/resources/application-local.yaml index 4560057d25..7aeec277ef 100644 --- a/backend/src/main/resources/application-local.yaml +++ b/backend/src/main/resources/application-local.yaml @@ -27,6 +27,8 @@ spring: # properties: # hibernate: # format_sql: true +# jdbc: +# fetch_size: 10000 mail: exporter: response: diff --git a/backend/src/main/resources/db/migration/V0.129__caselaw_create_norm_abbreviation_migration_search_view.sql b/backend/src/main/resources/db/migration/V0.129__caselaw_create_norm_abbreviation_migration_search_view.sql new file mode 100644 index 0000000000..d517d04dc5 --- /dev/null +++ b/backend/src/main/resources/db/migration/V0.129__caselaw_create_norm_abbreviation_migration_search_view.sql @@ -0,0 +1,40 @@ +CREATE INDEX + IF NOT EXISTS norm_abbreviation_official_letter_gin_idx ON incremental_migration.norm_abbreviation USING gin (upper(official_letter_abbreviation) gin_trgm_ops); + +CREATE INDEX + IF NOT EXISTS norm_abbreviation_gin_idx ON incremental_migration.norm_abbreviation USING gin (upper(abbreviation) gin_trgm_ops); + +CREATE INDEX + IF NOT EXISTS norm_abbreviation_fs_idx ON incremental_migration.norm_abbreviation USING GIN ( + to_tsvector( + 'german', + coalesce(abbreviation, '') || ' ' || coalesce(official_long_title, '') || ' ' || coalesce(official_short_title, '') || ' ' || coalesce(official_letter_abbreviation, '') + ) + ); + +CREATE materialized VIEW IF NOT EXISTS + norm_abbreviation_search_migration AS +SELECT + na.*, + r.code, + r.id AS region_id, + setweight(to_tsvector('german', na.abbreviation), 'A') || setweight( + to_tsvector( + 'german', + coalesce(na.official_letter_abbreviation, '') + ), + 'B' + ) || setweight( + to_tsvector('german', coalesce(na.official_short_title, '')), + 'B' + ) || setweight( + to_tsvector('german', coalesce(na.official_long_title, '')), + 'B' + ) || setweight(to_tsvector('german', coalesce(r.code, '')), 'B') weighted_vector +FROM + incremental_migration.norm_abbreviation na + LEFT JOIN incremental_migration.norm_abbreviation_region nar ON na.id = nar.norm_abbreviation_id + LEFT JOIN incremental_migration.region r ON nar.region_id = r.id; + +CREATE INDEX + IF NOT EXISTS norm_abbreviation_search_migration_idx ON norm_abbreviation_search_migration USING GIN (weighted_vector); diff --git a/backend/src/main/resources/db/migration/V0.130__caselaw_crate_document_type_id_migration.sql b/backend/src/main/resources/db/migration/V0.130__caselaw_crate_document_type_id_migration.sql new file mode 100644 index 0000000000..1c54e5cc07 --- /dev/null +++ b/backend/src/main/resources/db/migration/V0.130__caselaw_crate_document_type_id_migration.sql @@ -0,0 +1,68 @@ +DROP VIEW + IF EXISTS search_documentation_unit; + +ALTER TABLE + doc_unit +DROP COLUMN IF EXISTS + document_type_id; + +ALTER TABLE + doc_unit +ADD COLUMN IF NOT EXISTS + document_type_id UUID; + +ALTER TABLE + doc_unit +ADD + CONSTRAINT fk_document_type FOREIGN KEY (document_type_id) REFERENCES incremental_migration.document_type (id) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE NO ACTION; + +create view + search_documentation_unit as ( + with + last_status as ( + select distinct + on (document_unit_id) publication_status, + with_error, + document_unit_id, + created_at + from + status + order by + document_unit_id desc, + created_at desc + ), + first_file_number as ( + select distinct + on (document_unit_id) id, + document_unit_id, + file_number.file_number + from + file_number + order by + document_unit_id desc, + id + ) + select + du.id, + du.uuid, + du.documentnumber as document_number, + du.data_source, + du.filename as file_name, + du.gerichtstyp as court_type, + du.gerichtssitz as court_location, + du.decision_date, + du.documentation_office_id, + s.publication_status, + s.with_error, + fn.file_number as first_file_number, + dt.abbreviation as document_type + from + doc_unit du + left outer join last_status s on du.uuid = s.document_unit_id + left outer join first_file_number fn on du.id = fn.document_unit_id + left outer join incremental_migration.document_type dt on du.document_type_id = dt.id + where + du.data_source in ('MIGRATION', 'NEURIS') + order by + du.id desc + ); diff --git a/backend/src/main/resources/db/migration/V0.131__caselaw_add_legacy_doc_unit_column_in_migration_norm_reference.sql b/backend/src/main/resources/db/migration/V0.131__caselaw_add_legacy_doc_unit_column_in_migration_norm_reference.sql new file mode 100644 index 0000000000..14f2bd56cf --- /dev/null +++ b/backend/src/main/resources/db/migration/V0.131__caselaw_add_legacy_doc_unit_column_in_migration_norm_reference.sql @@ -0,0 +1,4 @@ +ALTER TABLE + incremental_migration.norm_reference +ADD COLUMN IF NOT EXISTS + legacy_doc_unit_id uuid; diff --git a/backend/src/test/java/de/bund/digitalservice/ris/caselaw/adapter/LookupTableImporterControllerTest.java b/backend/src/test/java/de/bund/digitalservice/ris/caselaw/adapter/LookupTableImporterControllerTest.java index 43fa2be96b..ad9ab35cc8 100644 --- a/backend/src/test/java/de/bund/digitalservice/ris/caselaw/adapter/LookupTableImporterControllerTest.java +++ b/backend/src/test/java/de/bund/digitalservice/ris/caselaw/adapter/LookupTableImporterControllerTest.java @@ -31,22 +31,6 @@ class LookupTableImporterControllerTest { @MockBean private ReactiveClientRegistrationRepository clientRegistrationRepository; @MockBean private JdbcTemplate jdbcTemplate; - @Test - void testImportDocumentTypeLookupTable() { - when(service.importDocumentTypeLookupTable(any(ByteBuffer.class))).thenReturn(Mono.empty()); - - risWebTestClient - .withDefaultLogin() - .put() - .uri("/api/v1/caselaw/lookuptableimporter/doktyp") - .bodyValue(BodyInserters.fromValue(new byte[] {})) - .exchange() - .expectStatus() - .isOk(); - - verify(service, times(1)).importDocumentTypeLookupTable(any(ByteBuffer.class)); - } - @Test void testImportCourtLookupTable() { when(service.importCourtLookupTable(any(ByteBuffer.class))).thenReturn(Mono.empty()); diff --git a/backend/src/test/java/de/bund/digitalservice/ris/caselaw/domain/LookupTableImporterServiceTest.java b/backend/src/test/java/de/bund/digitalservice/ris/caselaw/domain/LookupTableImporterServiceTest.java index e96b59dda0..83cb30ec53 100644 --- a/backend/src/test/java/de/bund/digitalservice/ris/caselaw/domain/LookupTableImporterServiceTest.java +++ b/backend/src/test/java/de/bund/digitalservice/ris/caselaw/domain/LookupTableImporterServiceTest.java @@ -11,8 +11,6 @@ import static org.mockito.Mockito.when; import de.bund.digitalservice.ris.caselaw.adapter.LookupTableImporterService; -import de.bund.digitalservice.ris.caselaw.adapter.database.jpa.JPADocumentTypeDTO; -import de.bund.digitalservice.ris.caselaw.adapter.database.jpa.JPADocumentTypeRepository; import de.bund.digitalservice.ris.caselaw.adapter.database.jpa.JPAFieldOfLawDTO; import de.bund.digitalservice.ris.caselaw.adapter.database.jpa.JPAFieldOfLawLinkRepository; import de.bund.digitalservice.ris.caselaw.adapter.database.jpa.JPAFieldOfLawRepository; @@ -22,7 +20,6 @@ import de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.lookuptable.CourtDTO; import de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.lookuptable.DatabaseCitationStyleRepository; import de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.lookuptable.DatabaseCourtRepository; -import de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.lookuptable.DatabaseDocumentTypeRepository; import de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.lookuptable.DatabaseFieldOfLawRepository; import de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.lookuptable.StateDTO; import de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.lookuptable.StateRepository; @@ -49,9 +46,9 @@ class LookupTableImporterServiceTest { @SpyBean private LookupTableImporterService service; - @MockBean private DatabaseDocumentTypeRepository databaseDocumentTypeRepository; - - @MockBean private JPADocumentTypeRepository jpaDocumentTypeRepository; + @MockBean + private de.bund.digitalservice.ris.caselaw.adapter.database.jpa.DatabaseDocumentTypeRepository + databaseDocumentTypeRepository; @MockBean private DatabaseCourtRepository databaseCourtRepository; @@ -65,47 +62,6 @@ class LookupTableImporterServiceTest { @MockBean private JPAFieldOfLawLinkRepository jpaFieldOfLawLinkRepository; - @Test - void testImportDocumentTypeLookupTable() { - when(databaseDocumentTypeRepository.deleteAll()).thenReturn(Mono.empty()); - - String doctypesXml = - """ - - - - ÄN - N - Ja - Änderungsnorm - - """; - ByteBuffer byteBuffer = ByteBuffer.wrap(doctypesXml.getBytes()); - List documentTypeDTOs = - List.of( - JPADocumentTypeDTO.builder() - .id(1L) - .changeIndicator('N') - .version("1.0") - .jurisShortcut("ÄN") - .documentType('N') - .multiple("Ja") - .label("Änderungsnorm") - .build()); - - StepVerifier.create(service.importDocumentTypeLookupTable(byteBuffer)) - .consumeNextWith( - documentTypeDTO -> - assertEquals( - "Successfully imported the document type lookup table", documentTypeDTO)) - .verifyComplete(); - - verify(databaseDocumentTypeRepository, never()).deleteAll(); - verify(databaseDocumentTypeRepository, never()).saveAll(anyCollection()); - verify(jpaDocumentTypeRepository, atMostOnce()).deleteAll(); - verify(jpaDocumentTypeRepository, atMostOnce()).saveAll(documentTypeDTOs); - } - @Captor private ArgumentCaptor> courtDTOlistCaptor; @Test diff --git a/backend/src/test/java/de/bund/digitalservice/ris/caselaw/domain/LookupTableServiceTest.java b/backend/src/test/java/de/bund/digitalservice/ris/caselaw/domain/LookupTableServiceTest.java index ee0788eeca..fdf0b0f7a6 100644 --- a/backend/src/test/java/de/bund/digitalservice/ris/caselaw/domain/LookupTableServiceTest.java +++ b/backend/src/test/java/de/bund/digitalservice/ris/caselaw/domain/LookupTableServiceTest.java @@ -4,17 +4,19 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import de.bund.digitalservice.ris.caselaw.adapter.database.jpa.DatabaseDocumentCategoryRepository; +import de.bund.digitalservice.ris.caselaw.adapter.database.jpa.DatabaseDocumentTypeRepository; +import de.bund.digitalservice.ris.caselaw.adapter.database.jpa.DocumentCategoryDTO; +import de.bund.digitalservice.ris.caselaw.adapter.database.jpa.DocumentTypeDTO; +import de.bund.digitalservice.ris.caselaw.adapter.database.jpa.PostgresDocumentTypeRepositoryImpl; import de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.lookuptable.CitationStyleDTO; import de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.lookuptable.CourtDTO; import de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.lookuptable.DatabaseCitationStyleRepository; import de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.lookuptable.DatabaseCourtRepository; -import de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.lookuptable.DatabaseDocumentTypeRepository; -import de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.lookuptable.DocumentTypeDTO; import de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.lookuptable.FieldOfLawKeywordRepository; import de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.lookuptable.NormRepository; import de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.lookuptable.PostgresCitationStyleRepositoryImpl; import de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.lookuptable.PostgresCourtRepositoryImpl; -import de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.lookuptable.PostgresDocumentTypeRepositoryImpl; import de.bund.digitalservice.ris.caselaw.domain.lookuptable.citation.CitationStyle; import de.bund.digitalservice.ris.caselaw.domain.lookuptable.court.Court; import de.bund.digitalservice.ris.caselaw.domain.lookuptable.documenttype.DocumentType; @@ -42,6 +44,7 @@ class LookupTableServiceTest { @SpyBean private LookupTableService service; @MockBean private DatabaseDocumentTypeRepository databaseDocumentTypeRepository; + @MockBean private DatabaseDocumentCategoryRepository databaseDocumentCategoryRepository; @MockBean private DatabaseCourtRepository databaseCourtRepository; @MockBean private DatabaseCitationStyleRepository databaseCitationStyleRepository; @MockBean private FieldOfLawRepository fieldOfLawRepository; @@ -50,11 +53,14 @@ class LookupTableServiceTest { @Test void testGetDocumentTypes() { + var category = DocumentCategoryDTO.builder().id(UUID.randomUUID()).label("R").build(); + when(databaseDocumentCategoryRepository.findFirstByLabel("R")).thenReturn(category); + DocumentTypeDTO documentTypeDTO = DocumentTypeDTO.builder().build(); - documentTypeDTO.setJurisShortcut("ABC"); + documentTypeDTO.setAbbreviation("ABC"); documentTypeDTO.setLabel("LabelABC"); - when(databaseDocumentTypeRepository.findAllByDocumentTypeOrderByJurisShortcutAscLabelAsc('R')) - .thenReturn(Flux.just(documentTypeDTO)); + when(databaseDocumentTypeRepository.findAllByCategoryOrderByAbbreviationAscLabelAsc(category)) + .thenReturn(List.of(documentTypeDTO)); StepVerifier.create(service.getCaselawDocumentTypes(Optional.empty())) .consumeNextWith( @@ -66,7 +72,7 @@ void testGetDocumentTypes() { .verifyComplete(); verify(databaseDocumentTypeRepository) - .findAllByDocumentTypeOrderByJurisShortcutAscLabelAsc('R'); + .findAllByCategoryOrderByAbbreviationAscLabelAsc(category); } @Test diff --git a/backend/src/test/java/de/bund/digitalservice/ris/caselaw/integration/tests/ActiveCitationIntegrationTest.java b/backend/src/test/java/de/bund/digitalservice/ris/caselaw/integration/tests/ActiveCitationIntegrationTest.java index 49e98febbe..598b796215 100644 --- a/backend/src/test/java/de/bund/digitalservice/ris/caselaw/integration/tests/ActiveCitationIntegrationTest.java +++ b/backend/src/test/java/de/bund/digitalservice/ris/caselaw/integration/tests/ActiveCitationIntegrationTest.java @@ -12,7 +12,11 @@ import de.bund.digitalservice.ris.caselaw.adapter.DatabaseDocumentUnitStatusService; import de.bund.digitalservice.ris.caselaw.adapter.DocumentUnitController; import de.bund.digitalservice.ris.caselaw.adapter.DocxConverterService; +import de.bund.digitalservice.ris.caselaw.adapter.database.jpa.DatabaseDocumentCategoryRepository; +import de.bund.digitalservice.ris.caselaw.adapter.database.jpa.DatabaseDocumentTypeRepository; import de.bund.digitalservice.ris.caselaw.adapter.database.jpa.DatabaseDocumentationOfficeRepository; +import de.bund.digitalservice.ris.caselaw.adapter.database.jpa.DocumentCategoryDTO; +import de.bund.digitalservice.ris.caselaw.adapter.database.jpa.DocumentTypeDTO; import de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.DatabaseDocumentUnitRepository; import de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.DatabaseDocumentationUnitLinkRepository; import de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.DocumentUnitDTO; @@ -21,8 +25,6 @@ import de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.FileNumberRepository; import de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.PostgresDocumentUnitRepositoryImpl; import de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.PostgresPublicationReportRepositoryImpl; -import de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.lookuptable.DatabaseDocumentTypeRepository; -import de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.lookuptable.DocumentTypeDTO; import de.bund.digitalservice.ris.caselaw.config.FlywayConfig; import de.bund.digitalservice.ris.caselaw.config.PostgresConfig; import de.bund.digitalservice.ris.caselaw.config.PostgresJPAConfig; @@ -80,7 +82,8 @@ class ActiveCitationIntegrationTest { @Container static PostgreSQLContainer postgreSQLContainer = - new PostgreSQLContainer<>("postgres:14").withInitScript("db/create_extension.sql"); + new PostgreSQLContainer<>("postgres:14") + .withInitScript("db/create_migration_scheme_and_extensions.sql"); @DynamicPropertySource static void registerDynamicProperties(DynamicPropertyRegistry registry) { @@ -106,24 +109,33 @@ static void registerDynamicProperties(DynamicPropertyRegistry registry) { private static final String DOCUMENT_NUMBER_PREFIX = "XXRE20230000"; private static final String UUID_PREFIX = "88888888-4444-4444-4444-11111111111"; - private static final Long DOCUMENT_TYPE_ID_OFFSET = 111111L; private static final Instant TIMESTAMP = Instant.parse("2000-02-01T20:13:36.00Z"); private static final Instant DECISION_DATE = Instant.parse("1983-09-15T08:21:17.00Z"); private UUID docOfficeUuid; + private DocumentCategoryDTO category; + @Autowired private DatabaseDocumentCategoryRepository databaseDocumentCategoryRepository; + @BeforeEach void setUp() { when(userService.getDocumentationOffice(any(OidcUser.class))) .thenReturn(Mono.just(AuthUtils.buildDocOffice("DigitalService", "XX"))); docOfficeUuid = documentationOfficeRepository.findByLabel("DigitalService").getId(); + + category = databaseDocumentCategoryRepository.findFirstByLabel("R"); + if (category == null) { + category = + databaseDocumentCategoryRepository.saveAndFlush( + DocumentCategoryDTO.builder().label("R").build()); + } } @AfterEach void cleanUp() { linkRepository.deleteAll().block(); - documentTypeRepository.deleteAll().block(); repository.deleteAll().block(); + documentTypeRepository.deleteAll(); } @Test @@ -151,7 +163,7 @@ void testFindDocumentationUnit_withActiveCitation() { @Test void testUpdateDocumentationUnit_withNewActiveCitation() { prepareTestData(1, 0); - addDocumentTypeToDB(2); + var type = addDocumentTypeToDB(2); ActiveCitation activeCitation = generateActiveCitation(1, false); ActiveCitation newActiveCitationRequest = @@ -708,7 +720,7 @@ void testUpdateDocumentationUnit_removeAllValuesInEditableActiveCitation() { } private void prepareTestData(int realActiveCitationCount, int editableActiveCitationCount) { - addDocumentTypeToDB(0); + var type = addDocumentTypeToDB(0); DocumentUnitDTO parentDTO = DocumentUnitDTO.builder() @@ -717,7 +729,7 @@ private void prepareTestData(int realActiveCitationCount, int editableActiveCita .documentnumber(DOCUMENT_NUMBER_PREFIX + "0") .creationtimestamp(TIMESTAMP.plus(0, ChronoUnit.MINUTES)) .decisionDate(DECISION_DATE) - .documentTypeId(DOCUMENT_TYPE_ID_OFFSET) + .documentTypeId(type.getId()) .build(); DocumentUnitDTO savedParentDTO = repository.save(parentDTO).block(); @@ -741,7 +753,7 @@ private void prepareTestData(int realActiveCitationCount, int editableActiveCita } private void addActiveCitationToDB(int offset, boolean editable) { - addDocumentTypeToDB(offset); + var type = addDocumentTypeToDB(offset); DocumentUnitDTO activeCitationDTO = DocumentUnitDTO.builder() @@ -752,7 +764,7 @@ private void addActiveCitationToDB(int offset, boolean editable) { .decisionDate(DECISION_DATE.plus(offset * 10L, ChronoUnit.MINUTES)) .courtType("TestCourt #" + offset) .courtLocation("Berlin #" + offset) - .documentTypeId(DOCUMENT_TYPE_ID_OFFSET + offset) + .documentTypeId(type.getId()) .dateKnown(true) .dataSource(editable ? DataSource.ACTIVE_CITATION : DataSource.NEURIS) .build(); @@ -790,18 +802,16 @@ private void removeLink(int number) { linkRepository.delete(linkDTO).block(); } - private void addDocumentTypeToDB(int number) { + private DocumentTypeDTO addDocumentTypeToDB(int number) { DocumentTypeDTO documentTypeDTO = DocumentTypeDTO.builder() - .id(DOCUMENT_TYPE_ID_OFFSET + number) - .newEntry(true) - .jurisShortcut("D" + number) - .label("document type of DigitalService #" + number) - .documentType('R') - .changeIndicator('N') + .abbreviation("abbreviation" + number) + .label("R") + .category(category) + .multiple(true) .build(); - documentTypeRepository.save(documentTypeDTO).block(); + return documentTypeRepository.saveAndFlush(documentTypeDTO); } private ActiveCitation generateActiveCitation(int number, boolean editable) { @@ -818,10 +828,7 @@ private ActiveCitation generateActiveCitation(int number, boolean editable) { .decisionDate(DECISION_DATE.plus(number * 10L, ChronoUnit.MINUTES)) .documentNumber(DOCUMENT_NUMBER_PREFIX + number) .documentType( - DocumentType.builder() - .jurisShortcut("D" + number) - .label("document type of DigitalService #" + number) - .build()) + DocumentType.builder().jurisShortcut("abbreviation" + number).label("R").build()) .fileNumber("file number #" + number) .build(); } @@ -846,10 +853,7 @@ private DocumentUnit generateDocumentUnit(List activeCitations) .deviatingFileNumbers(Collections.emptyList()) .fileNumbers(List.of("file number #0")) .documentType( - DocumentType.builder() - .jurisShortcut("D0") - .label("document type of DigitalService #0") - .build()) + DocumentType.builder().jurisShortcut("abbreviation0").label("R").build()) .decisionDate(DECISION_DATE) .incorrectCourts(Collections.emptyList()) .documentationOffice(AuthUtils.buildDefaultDocOffice()) diff --git a/backend/src/test/java/de/bund/digitalservice/ris/caselaw/integration/tests/AuthIntegrationTest.java b/backend/src/test/java/de/bund/digitalservice/ris/caselaw/integration/tests/AuthIntegrationTest.java index 3368eea503..b4ea587e3d 100644 --- a/backend/src/test/java/de/bund/digitalservice/ris/caselaw/integration/tests/AuthIntegrationTest.java +++ b/backend/src/test/java/de/bund/digitalservice/ris/caselaw/integration/tests/AuthIntegrationTest.java @@ -36,7 +36,8 @@ class AuthIntegrationTest { @Container static PostgreSQLContainer postgreSQLContainer = - new PostgreSQLContainer<>("postgres:14").withInitScript("db/create_extension.sql"); + new PostgreSQLContainer<>("postgres:14") + .withInitScript("db/create_migration_scheme_and_extensions.sql"); @DynamicPropertySource static void registerDynamicProperties(DynamicPropertyRegistry registry) { diff --git a/backend/src/test/java/de/bund/digitalservice/ris/caselaw/integration/tests/DocumentUnitControllerAuthIntegrationTest.java b/backend/src/test/java/de/bund/digitalservice/ris/caselaw/integration/tests/DocumentUnitControllerAuthIntegrationTest.java index 6b142e0225..265e9aed20 100644 --- a/backend/src/test/java/de/bund/digitalservice/ris/caselaw/integration/tests/DocumentUnitControllerAuthIntegrationTest.java +++ b/backend/src/test/java/de/bund/digitalservice/ris/caselaw/integration/tests/DocumentUnitControllerAuthIntegrationTest.java @@ -77,7 +77,8 @@ class DocumentUnitControllerAuthIntegrationTest { @Container static PostgreSQLContainer postgreSQLContainer = - new PostgreSQLContainer<>("postgres:14").withInitScript("db/create_extension.sql"); + new PostgreSQLContainer<>("postgres:14") + .withInitScript("db/create_migration_scheme_and_extensions.sql"); @DynamicPropertySource static void registerDynamicProperties(DynamicPropertyRegistry registry) { diff --git a/backend/src/test/java/de/bund/digitalservice/ris/caselaw/integration/tests/DocumentUnitFieldOfLawIntegrationTest.java b/backend/src/test/java/de/bund/digitalservice/ris/caselaw/integration/tests/DocumentUnitFieldOfLawIntegrationTest.java index 6d42bd1210..afad25ee20 100644 --- a/backend/src/test/java/de/bund/digitalservice/ris/caselaw/integration/tests/DocumentUnitFieldOfLawIntegrationTest.java +++ b/backend/src/test/java/de/bund/digitalservice/ris/caselaw/integration/tests/DocumentUnitFieldOfLawIntegrationTest.java @@ -64,7 +64,8 @@ class DocumentUnitFieldOfLawIntegrationTest { @Container static PostgreSQLContainer postgreSQLContainer = - new PostgreSQLContainer<>("postgres:14").withInitScript("db/create_extension.sql"); + new PostgreSQLContainer<>("postgres:14") + .withInitScript("db/create_migration_scheme_and_extensions.sql"); @DynamicPropertySource static void registerDynamicProperties(DynamicPropertyRegistry registry) { diff --git a/backend/src/test/java/de/bund/digitalservice/ris/caselaw/integration/tests/DocumentUnitIntegrationTest.java b/backend/src/test/java/de/bund/digitalservice/ris/caselaw/integration/tests/DocumentUnitIntegrationTest.java index f3c7f7e46d..1ca861802f 100644 --- a/backend/src/test/java/de/bund/digitalservice/ris/caselaw/integration/tests/DocumentUnitIntegrationTest.java +++ b/backend/src/test/java/de/bund/digitalservice/ris/caselaw/integration/tests/DocumentUnitIntegrationTest.java @@ -18,7 +18,11 @@ import de.bund.digitalservice.ris.caselaw.adapter.DatabaseDocumentUnitStatusService; import de.bund.digitalservice.ris.caselaw.adapter.DocumentUnitController; import de.bund.digitalservice.ris.caselaw.adapter.DocxConverterService; +import de.bund.digitalservice.ris.caselaw.adapter.database.jpa.DatabaseDocumentCategoryRepository; +import de.bund.digitalservice.ris.caselaw.adapter.database.jpa.DatabaseDocumentTypeRepository; import de.bund.digitalservice.ris.caselaw.adapter.database.jpa.DatabaseDocumentationOfficeRepository; +import de.bund.digitalservice.ris.caselaw.adapter.database.jpa.DocumentCategoryDTO; +import de.bund.digitalservice.ris.caselaw.adapter.database.jpa.DocumentTypeDTO; import de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.DatabaseDeviatingDecisionDateRepository; import de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.DatabaseDocumentUnitMetadataRepository; import de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.DatabaseDocumentUnitRepository; @@ -37,8 +41,6 @@ import de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.PostgresPublicationReportRepositoryImpl; import de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.lookuptable.CourtDTO; import de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.lookuptable.DatabaseCourtRepository; -import de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.lookuptable.DatabaseDocumentTypeRepository; -import de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.lookuptable.DocumentTypeDTO; import de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.lookuptable.StateDTO; import de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.lookuptable.StateRepository; import de.bund.digitalservice.ris.caselaw.config.FlywayConfig; @@ -103,7 +105,8 @@ class DocumentUnitIntegrationTest { @Container static PostgreSQLContainer postgreSQLContainer = - new PostgreSQLContainer<>("postgres:14").withInitScript("db/create_extension.sql"); + new PostgreSQLContainer<>("postgres:14") + .withInitScript("db/create_migration_scheme_and_extensions.sql"); @DynamicPropertySource static void registerDynamicProperties(DynamicPropertyRegistry registry) { @@ -137,6 +140,7 @@ static void registerDynamicProperties(DynamicPropertyRegistry registry) { private final DocumentationOffice docOffice = buildDefaultDocOffice(); private UUID documentationOfficeUuid; + @Autowired private DatabaseDocumentCategoryRepository databaseDocumentCategoryRepository; @BeforeEach void setUp() { @@ -162,7 +166,7 @@ void cleanUp() { deviatingDecisionDateRepository.deleteAll().block(); incorrectCourtRepository.deleteAll().block(); repository.deleteAll().block(); - databaseDocumentTypeRepository.deleteAll().block(); + databaseDocumentTypeRepository.deleteAll(); documentUnitStatusRepository.deleteAll().block(); databasePublishReportRepository.deleteAll().block(); } @@ -611,30 +615,41 @@ private DocumentUnit testRegionFilledBasedOnCourt( @Test void testDocumentTypeToSetIdFromLookuptable() { + var categoryA = + databaseDocumentCategoryRepository.saveAndFlush( + DocumentCategoryDTO.builder().label("A").build()); + var categoryR = + databaseDocumentCategoryRepository.saveAndFlush( + DocumentCategoryDTO.builder().label("R").build()); + var categoryC = + databaseDocumentCategoryRepository.saveAndFlush( + DocumentCategoryDTO.builder().label("C").build()); + DocumentTypeDTO documentTypeDTOA = DocumentTypeDTO.builder() - .changeIndicator('c') - .jurisShortcut("ABC") - .documentType('A') - .label("ABC123") - .build(); - DocumentTypeDTO documentTypeDTOR = - DocumentTypeDTO.builder() - .changeIndicator('c') - .jurisShortcut("ABC") - .documentType('R') + .abbreviation("ABC") + .category(categoryA) .label("ABC123") + .multiple(true) .build(); DocumentTypeDTO documentTypeDTOC = DocumentTypeDTO.builder() - .changeIndicator('c') - .jurisShortcut("ABC") - .documentType('C') + .abbreviation("ABC") + .category(categoryC) .label("ABC123") + .multiple(true) .build(); - databaseDocumentTypeRepository.save(documentTypeDTOA).block(); - databaseDocumentTypeRepository.save(documentTypeDTOR).block(); - databaseDocumentTypeRepository.save(documentTypeDTOC).block(); + + databaseDocumentTypeRepository.saveAllAndFlush(List.of(documentTypeDTOA, documentTypeDTOC)); + + var documentTypeDTOR = + databaseDocumentTypeRepository.saveAndFlush( + DocumentTypeDTO.builder() + .abbreviation("ABC") + .category(categoryR) + .label("ABC123") + .multiple(true) + .build()); DocumentUnitDTO dto = DocumentUnitDTO.builder() @@ -654,7 +669,7 @@ void testDocumentTypeToSetIdFromLookuptable() { CoreData.builder() .documentType( DocumentType.builder() - .jurisShortcut(documentTypeDTOR.getJurisShortcut()) + .jurisShortcut(documentTypeDTOR.getAbbreviation()) .label(documentTypeDTOR.getLabel()) .build()) .documentationOffice(docOffice) @@ -676,23 +691,27 @@ void testDocumentTypeToSetIdFromLookuptable() { assertThat(response.getResponseBody().coreData().documentType().label()) .isEqualTo(documentTypeDTOR.getLabel()); assertThat(response.getResponseBody().coreData().documentType().jurisShortcut()) - .isEqualTo(documentTypeDTOR.getJurisShortcut()); + .isEqualTo(documentTypeDTOR.getAbbreviation()); }); List list = repository.findAll().collectList().block(); assertThat(list).hasSize(1); - assertThat(list.get(0).getDocumentTypeId()).isEqualTo(2L); + assertThat(list.get(0).getDocumentTypeId()).isEqualTo(documentTypeDTOR.getId()); assertThat(list.get(0).getDocumentTypeDTO()).isNull(); } @Test void testUndoSettingDocumentType() { + var docType = + databaseDocumentTypeRepository.saveAndFlush( + DocumentTypeDTO.builder().abbreviation("test").multiple(true).build()); + DocumentUnitDTO dto = DocumentUnitDTO.builder() .uuid(UUID.randomUUID()) .creationtimestamp(Instant.now()) .documentnumber("1234567890123") - .documentTypeId(123L) + .documentTypeId(docType.getId()) .documentationOfficeId(documentationOfficeUuid) .build(); repository.save(dto).block(); diff --git a/backend/src/test/java/de/bund/digitalservice/ris/caselaw/integration/tests/DocumentUnitKeywordIntegrationTest.java b/backend/src/test/java/de/bund/digitalservice/ris/caselaw/integration/tests/DocumentUnitKeywordIntegrationTest.java index fd62467467..9307866074 100644 --- a/backend/src/test/java/de/bund/digitalservice/ris/caselaw/integration/tests/DocumentUnitKeywordIntegrationTest.java +++ b/backend/src/test/java/de/bund/digitalservice/ris/caselaw/integration/tests/DocumentUnitKeywordIntegrationTest.java @@ -61,7 +61,8 @@ class DocumentUnitKeywordIntegrationTest { @Container static PostgreSQLContainer postgreSQLContainer = - new PostgreSQLContainer<>("postgres:14").withInitScript("db/create_extension.sql"); + new PostgreSQLContainer<>("postgres:14") + .withInitScript("db/create_migration_scheme_and_extensions.sql"); @DynamicPropertySource static void registerDynamicProperties(DynamicPropertyRegistry registry) { diff --git a/backend/src/test/java/de/bund/digitalservice/ris/caselaw/integration/tests/DocumentUnitListEntryIntegrationTest.java b/backend/src/test/java/de/bund/digitalservice/ris/caselaw/integration/tests/DocumentUnitListEntryIntegrationTest.java index 1acbf0ff27..1f09c24819 100644 --- a/backend/src/test/java/de/bund/digitalservice/ris/caselaw/integration/tests/DocumentUnitListEntryIntegrationTest.java +++ b/backend/src/test/java/de/bund/digitalservice/ris/caselaw/integration/tests/DocumentUnitListEntryIntegrationTest.java @@ -73,7 +73,8 @@ class DocumentUnitListEntryIntegrationTest { @Container static PostgreSQLContainer postgreSQLContainer = - new PostgreSQLContainer<>("postgres:14").withInitScript("db/create_extension.sql"); + new PostgreSQLContainer<>("postgres:14") + .withInitScript("db/create_migration_scheme_and_extensions.sql"); @DynamicPropertySource static void registerDynamicProperties(DynamicPropertyRegistry registry) { diff --git a/backend/src/test/java/de/bund/digitalservice/ris/caselaw/integration/tests/FieldOfLawIntegrationTest.java b/backend/src/test/java/de/bund/digitalservice/ris/caselaw/integration/tests/FieldOfLawIntegrationTest.java index 56cb1fe66c..cd1452aa19 100644 --- a/backend/src/test/java/de/bund/digitalservice/ris/caselaw/integration/tests/FieldOfLawIntegrationTest.java +++ b/backend/src/test/java/de/bund/digitalservice/ris/caselaw/integration/tests/FieldOfLawIntegrationTest.java @@ -48,7 +48,8 @@ class FieldOfLawIntegrationTest { @Container static PostgreSQLContainer postgreSQLContainer = - new PostgreSQLContainer<>("postgres:14").withInitScript("db/create_extension.sql"); + new PostgreSQLContainer<>("postgres:14") + .withInitScript("db/create_migration_scheme_and_extensions.sql"); @DynamicPropertySource static void registerDynamicProperties(DynamicPropertyRegistry registry) { diff --git a/backend/src/test/java/de/bund/digitalservice/ris/caselaw/integration/tests/HealthEndpointIntegrationTest.java b/backend/src/test/java/de/bund/digitalservice/ris/caselaw/integration/tests/HealthEndpointIntegrationTest.java index 2962f71846..26d3d25112 100644 --- a/backend/src/test/java/de/bund/digitalservice/ris/caselaw/integration/tests/HealthEndpointIntegrationTest.java +++ b/backend/src/test/java/de/bund/digitalservice/ris/caselaw/integration/tests/HealthEndpointIntegrationTest.java @@ -34,7 +34,8 @@ class HealthEndpointIntegrationTest { @Container static PostgreSQLContainer postgreSQLContainer = - new PostgreSQLContainer<>("postgres:14").withInitScript("db/create_extension.sql"); + new PostgreSQLContainer<>("postgres:14") + .withInitScript("db/create_migration_scheme_and_extensions.sql"); @Container static GenericContainer redis = diff --git a/backend/src/test/java/de/bund/digitalservice/ris/caselaw/integration/tests/LookupTableImporterIntegrationTest.java b/backend/src/test/java/de/bund/digitalservice/ris/caselaw/integration/tests/LookupTableImporterIntegrationTest.java index 362626a4ca..0d51798510 100644 --- a/backend/src/test/java/de/bund/digitalservice/ris/caselaw/integration/tests/LookupTableImporterIntegrationTest.java +++ b/backend/src/test/java/de/bund/digitalservice/ris/caselaw/integration/tests/LookupTableImporterIntegrationTest.java @@ -7,8 +7,6 @@ import de.bund.digitalservice.ris.caselaw.adapter.AuthService; import de.bund.digitalservice.ris.caselaw.adapter.LookupTableImporterController; import de.bund.digitalservice.ris.caselaw.adapter.LookupTableImporterService; -import de.bund.digitalservice.ris.caselaw.adapter.database.jpa.JPADocumentTypeDTO; -import de.bund.digitalservice.ris.caselaw.adapter.database.jpa.JPADocumentTypeRepository; import de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.lookuptable.CitationStyleDTO; import de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.lookuptable.CourtDTO; import de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.lookuptable.DatabaseCitationStyleRepository; @@ -59,7 +57,8 @@ class LookupTableImporterIntegrationTest { @Container static PostgreSQLContainer postgreSQLContainer = - new PostgreSQLContainer<>("postgres:14").withInitScript("db/create_extension.sql"); + new PostgreSQLContainer<>("postgres:14") + .withInitScript("db/create_migration_scheme_and_extensions.sql"); @DynamicPropertySource static void registerDynamicProperties(DynamicPropertyRegistry registry) { @@ -71,7 +70,6 @@ static void registerDynamicProperties(DynamicPropertyRegistry registry) { } @Autowired private RisWebTestClient risWebTestClient; - @Autowired private JPADocumentTypeRepository jpaDocumentTypeRepository; @Autowired private DatabaseCourtRepository databaseCourtRepository; @Autowired private DatabaseCitationStyleRepository databaseCitationStyleRepository; @Autowired private StateRepository stateRepository; @@ -89,51 +87,12 @@ static void registerDynamicProperties(DynamicPropertyRegistry registry) { @AfterEach void cleanUp() { - jpaDocumentTypeRepository.deleteAll(); databaseCourtRepository.deleteAll().block(); databaseCitationStyleRepository.deleteAll().block(); stateRepository.deleteAll().block(); fieldOfLawRepository.deleteAll().block(); // will cascade delete the other 3 repo-contents } - @Test - void shouldImportDocumentTypeLookupTableCorrectly() { - String doktypXml = - """ - - - - ÄN - N - Ja - Änderungsnorm - - """; - - risWebTestClient - .withDefaultLogin() - .put() - .uri("/api/v1/caselaw/lookuptableimporter/doktyp") - .bodyValue(doktypXml) - .exchange() - .expectStatus() - .isOk() - .expectBody(String.class) - .consumeWith( - response -> - assertThat(response.getResponseBody()) - .isEqualTo("Successfully imported the document type lookup table")); - - List list = jpaDocumentTypeRepository.findAll(); - assertThat(list).hasSize(1); - JPADocumentTypeDTO documentTypeDTO = list.get(0); - assertThat(documentTypeDTO.getId()).isEqualTo(7L); - assertThat(documentTypeDTO.getJurisShortcut()).isEqualTo("ÄN"); - assertThat(documentTypeDTO.getDocumentType()).isEqualTo('N'); - assertThat(documentTypeDTO.getMultiple()).isEqualTo("Ja"); - assertThat(documentTypeDTO.getLabel()).isEqualTo("Änderungsnorm"); - } - @Test void shouldImportCourtLookupTableCorrectly() { String gerichtdataXml = diff --git a/backend/src/test/java/de/bund/digitalservice/ris/caselaw/integration/tests/LookupTableIntegrationTest.java b/backend/src/test/java/de/bund/digitalservice/ris/caselaw/integration/tests/LookupTableIntegrationTest.java index 152ccafa8a..54791b68de 100644 --- a/backend/src/test/java/de/bund/digitalservice/ris/caselaw/integration/tests/LookupTableIntegrationTest.java +++ b/backend/src/test/java/de/bund/digitalservice/ris/caselaw/integration/tests/LookupTableIntegrationTest.java @@ -6,14 +6,14 @@ import de.bund.digitalservice.ris.caselaw.TestConfig; import de.bund.digitalservice.ris.caselaw.adapter.AuthService; import de.bund.digitalservice.ris.caselaw.adapter.LookupTableController; +import de.bund.digitalservice.ris.caselaw.adapter.database.jpa.DatabaseDocumentTypeRepository; +import de.bund.digitalservice.ris.caselaw.adapter.database.jpa.PostgresDocumentTypeRepositoryImpl; import de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.lookuptable.CitationStyleDTO; import de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.lookuptable.CourtDTO; import de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.lookuptable.DatabaseCitationStyleRepository; import de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.lookuptable.DatabaseCourtRepository; -import de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.lookuptable.DatabaseDocumentTypeRepository; import de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.lookuptable.PostgresCitationStyleRepositoryImpl; import de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.lookuptable.PostgresCourtRepositoryImpl; -import de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.lookuptable.PostgresDocumentTypeRepositoryImpl; import de.bund.digitalservice.ris.caselaw.config.FlywayConfig; import de.bund.digitalservice.ris.caselaw.config.PostgresConfig; import de.bund.digitalservice.ris.caselaw.config.PostgresJPAConfig; @@ -56,7 +56,8 @@ class LookupTableIntegrationTest { @Container static PostgreSQLContainer postgreSQLContainer = - new PostgreSQLContainer<>("postgres:14").withInitScript("db/create_extension.sql"); + new PostgreSQLContainer<>("postgres:14") + .withInitScript("db/create_migration_scheme_and_extensions.sql"); @DynamicPropertySource static void registerDynamicProperties(DynamicPropertyRegistry registry) { @@ -83,7 +84,7 @@ static void registerDynamicProperties(DynamicPropertyRegistry registry) { void cleanUp() { databaseCourtRepository.deleteAll().block(); databaseCitationStyleRepository.deleteAll().block(); - databaseDocumentTypeRepository.deleteAll().block(); + databaseDocumentTypeRepository.deleteAll(); } @Test diff --git a/backend/src/test/java/de/bund/digitalservice/ris/caselaw/integration/tests/NormAbbreviationIntegrationTest.java b/backend/src/test/java/de/bund/digitalservice/ris/caselaw/integration/tests/NormAbbreviationIntegrationTest.java index 71946708e1..f6777c6d3d 100644 --- a/backend/src/test/java/de/bund/digitalservice/ris/caselaw/integration/tests/NormAbbreviationIntegrationTest.java +++ b/backend/src/test/java/de/bund/digitalservice/ris/caselaw/integration/tests/NormAbbreviationIntegrationTest.java @@ -7,34 +7,33 @@ import de.bund.digitalservice.ris.caselaw.adapter.AuthService; import de.bund.digitalservice.ris.caselaw.adapter.NormAbbreviationController; import de.bund.digitalservice.ris.caselaw.adapter.NormAbbreviationService; -import de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.lookuptable.DatabaseDocumentCategoryRepository; -import de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.lookuptable.DatabaseDocumentTypeNewRepository; -import de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.lookuptable.DatabaseNormAbbreviationDocumentTypeRepository; -import de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.lookuptable.DatabaseNormAbbreviationRegionRepository; -import de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.lookuptable.DatabaseNormAbbreviationRepository; -import de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.lookuptable.DatabaseRegionRepository; -import de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.lookuptable.DocumentCategoryDTO; -import de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.lookuptable.DocumentTypeNewDTO; -import de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.lookuptable.NormAbbreviationDTO; -import de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.lookuptable.NormAbbreviationDocumentTypeDTO; -import de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.lookuptable.NormAbbreviationRegionDTO; -import de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.lookuptable.PostgresNormAbbreviationRepositoryImpl; -import de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.lookuptable.RegionDTO; +import de.bund.digitalservice.ris.caselaw.adapter.database.jpa.DatabaseDocumentCategoryRepository; +import de.bund.digitalservice.ris.caselaw.adapter.database.jpa.DatabaseDocumentTypeRepository; +import de.bund.digitalservice.ris.caselaw.adapter.database.jpa.DatabaseNormAbbreviationRepository; +import de.bund.digitalservice.ris.caselaw.adapter.database.jpa.DatabaseRegionRepository; +import de.bund.digitalservice.ris.caselaw.adapter.database.jpa.DocumentCategoryDTO; +import de.bund.digitalservice.ris.caselaw.adapter.database.jpa.DocumentTypeDTO; +import de.bund.digitalservice.ris.caselaw.adapter.database.jpa.NormAbbreviationDTO; +import de.bund.digitalservice.ris.caselaw.adapter.database.jpa.PostgresNormAbbreviationRepositoryImpl; +import de.bund.digitalservice.ris.caselaw.adapter.database.jpa.RegionDTO; import de.bund.digitalservice.ris.caselaw.config.FlywayConfig; import de.bund.digitalservice.ris.caselaw.config.PostgresConfig; +import de.bund.digitalservice.ris.caselaw.config.PostgresJPAConfig; import de.bund.digitalservice.ris.caselaw.config.SecurityConfig; import de.bund.digitalservice.ris.caselaw.domain.DocumentUnitService; import de.bund.digitalservice.ris.caselaw.domain.EmailPublishService; import de.bund.digitalservice.ris.caselaw.domain.UserService; -import de.bund.digitalservice.ris.caselaw.domain.lookuptable.DocumentTypeNew; import de.bund.digitalservice.ris.caselaw.domain.lookuptable.NormAbbreviation; import de.bund.digitalservice.ris.caselaw.domain.lookuptable.NormAbbreviation.NormAbbreviationBuilder; import de.bund.digitalservice.ris.caselaw.domain.lookuptable.Region; +import de.bund.digitalservice.ris.caselaw.domain.lookuptable.documenttype.DocumentType; import java.time.LocalDate; import java.time.Month; import java.time.ZoneId; import java.util.ArrayList; import java.util.List; +import java.util.Objects; +import java.util.Set; import java.util.UUID; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Test; @@ -52,6 +51,7 @@ NormAbbreviationService.class, FlywayConfig.class, PostgresConfig.class, + PostgresJPAConfig.class, PostgresNormAbbreviationRepositoryImpl.class, SecurityConfig.class, AuthService.class, @@ -59,34 +59,112 @@ }, controllers = {NormAbbreviationController.class}) class NormAbbreviationIntegrationTest { - private static final UUID NORM_ABBREVIATION_UUID_1 = - UUID.fromString("A1A1A1A1-2222-3333-4444-555555555555"); - private static final UUID NORM_ABBREVIATION_UUID_2 = - UUID.fromString("A2A2A2A2-2222-3333-4444-555555555555"); - private static final UUID NORM_ABBREVIATION_UUID_3 = - UUID.fromString("A3A3A3A3-2222-3333-4444-555555555555"); - private static final UUID NORM_ABBREVIATION_UUID_4 = - UUID.fromString("A4A4A4A4-2222-3333-4444-555555555555"); - private static final UUID NORM_ABBREVIATION_UUID_5 = - UUID.fromString("A5A5A5A5-2222-3333-4444-555555555555"); - private static final UUID NORM_ABBREVIATION_UUID_6 = - UUID.fromString("A6A6A6A6-2222-3333-4444-555555555555"); - private static final UUID NORM_ABBREVIATION_UUID_7 = - UUID.fromString("A7A7A7A7-2222-3333-4444-555555555555"); - private static final UUID DOCUMENT_TYPE_UUID_1 = - UUID.fromString("D1D1D1D1-2222-3333-4444-555555555555"); - private static final UUID DOCUMENT_TYPE_UUID_2 = - UUID.fromString("D2D2D2D2-2222-3333-4444-555555555555"); - private static final UUID DOCUMENT_CATEGORY_UUID_1 = - UUID.fromString("C1C1C1C1-2222-3333-4444-555555555555"); - private static final UUID DOCUMENT_CATEGORY_UUID_2 = - UUID.fromString("C2C2C2C2-2222-3333-4444-555555555555"); - private static final UUID REGION_UUID_1 = UUID.fromString("E1E1E1E1-2222-3333-4444-555555555555"); - private static final UUID REGION_UUID_2 = UUID.fromString("E2E2E2E2-2222-3333-4444-555555555555"); + private NormAbbreviationDTO abbreviation1 = + NormAbbreviationDTO.builder() + .abbreviation("norm abbreviation 1") + .decisionDate(LocalDate.of(2023, Month.MAY, 19)) + .documentId(1234L) + .documentNumber("document number 1") + .officialLetterAbbreviation("official letter abbreviation 1") + .officialLongTitle("official long title 1") + .officialShortTitle("official short title 1") + .source("S") + .build(); + + private NormAbbreviationDTO abbreviation2 = + NormAbbreviationDTO.builder() + .abbreviation("search query at the beginning") + .decisionDate(LocalDate.of(2023, Month.MAY, 20)) + .documentId(2345L) + .documentNumber("document number 2") + .officialLetterAbbreviation("official letter abbreviation 2") + .officialLongTitle("official long title 2") + .officialShortTitle("official short title 2") + .source("T") + .build(); + ; + private NormAbbreviationDTO abbreviation3 = + NormAbbreviationDTO.builder() + .abbreviation("in the middle the query search is located") + .decisionDate(LocalDate.of(2023, Month.MAY, 21)) + .documentId(3456L) + .documentNumber("document number 3") + .officialLetterAbbreviation("official letter abbreviation 3") + .officialLongTitle("official long title 3") + .officialShortTitle("official short title 3") + .source("U") + .build(); + private NormAbbreviationDTO abbreviation4 = + NormAbbreviationDTO.builder() + .abbreviation("SeaRch QueRY not in the right case") + .decisionDate(LocalDate.of(2023, Month.MAY, 22)) + .documentId(4567L) + .documentNumber("document number 4") + .officialLetterAbbreviation("official letter abbreviation 4") + .officialLongTitle("official long title 4") + .officialShortTitle("official short title 4") + .source("V") + .build(); + private NormAbbreviationDTO abbreviation5 = + NormAbbreviationDTO.builder() + .abbreviation("Search B") + .decisionDate(LocalDate.of(2023, Month.MAY, 23)) + .documentId(5678L) + .documentNumber("document number 5") + .officialLetterAbbreviation("official letter abbreviation 5") + .officialLongTitle("official long title 5") + .officialShortTitle("official short title 5") + .source("W") + .build(); + private NormAbbreviationDTO abbreviation6 = + NormAbbreviationDTO.builder() + .abbreviation("Search A") + .decisionDate(LocalDate.of(2023, Month.MAY, 24)) + .documentId(6789L) + .documentNumber("document number 6") + .officialLetterAbbreviation("official letter abbreviation 6") + .officialLongTitle("official long title 6") + .officialShortTitle("official short title 6") + .source("X") + .build(); + private NormAbbreviationDTO abbreviation7 = + NormAbbreviationDTO.builder() + .abbreviation("Search C") + .decisionDate(LocalDate.of(2023, Month.MAY, 25)) + .documentId(7890L) + .documentNumber("document number 7") + .officialLetterAbbreviation("official letter abbreviation 7") + .officialLongTitle("official long title 7") + .officialShortTitle("official short title 7") + .source("Y") + .build(); + private DocumentCategoryDTO documentCategoryDTO1 = + DocumentCategoryDTO.builder().label("L").build(); + private DocumentCategoryDTO documentCategoryDTO2 = + DocumentCategoryDTO.builder().label("M").build(); + private DocumentTypeDTO documentType1 = + DocumentTypeDTO.builder() + .abbreviation("document type abbreviation 1") + .label("document type label 1") + .multiple(false) + .superLabel1("super label 11") + .superLabel2("super label 21") + .build(); + private DocumentTypeDTO documentType2 = + DocumentTypeDTO.builder() + .abbreviation("document type abbreviation 2") + .label("document type label 2") + .multiple(false) + .superLabel1("super label 12") + .superLabel2("super label 22") + .build(); + private RegionDTO region1 = RegionDTO.builder().code("region code 1").build(); + private RegionDTO region2 = RegionDTO.builder().code("region code 2").build(); @Container static PostgreSQLContainer postgreSQLContainer = - new PostgreSQLContainer<>("postgres:14").withInitScript("db/create_extension.sql"); + new PostgreSQLContainer<>("postgres:14") + .withInitScript("db/create_migration_scheme_and_extensions.sql"); @DynamicPropertySource static void registerDynamicProperties(DynamicPropertyRegistry registry) { @@ -99,15 +177,10 @@ static void registerDynamicProperties(DynamicPropertyRegistry registry) { @Autowired private RisWebTestClient risWebTestClient; @Autowired private DatabaseNormAbbreviationRepository repository; - @Autowired private DatabaseDocumentTypeNewRepository documentTypeRepository; + @Autowired private DatabaseDocumentTypeRepository documentTypeRepository; @Autowired private DatabaseDocumentCategoryRepository documentCategoryRepository; @Autowired private DatabaseRegionRepository regionRepository; - @Autowired - private DatabaseNormAbbreviationDocumentTypeRepository normAbbreviationDocumentTypeRepository; - - @Autowired private DatabaseNormAbbreviationRegionRepository normAbbreviationRegionRepository; - @MockBean UserService userService; @MockBean private DocumentUnitService documentUnitService; @MockBean ReactiveClientRegistrationRepository clientRegistrationRepository; @@ -116,31 +189,30 @@ static void registerDynamicProperties(DynamicPropertyRegistry registry) { @AfterEach void cleanUp() { - normAbbreviationRegionRepository.deleteAll().block(); - normAbbreviationDocumentTypeRepository.deleteAll().block(); - repository.deleteAll().block(); - documentTypeRepository.deleteAll().block(); - documentCategoryRepository.deleteAll().block(); - regionRepository.deleteAll().block(); + repository.deleteAll(); + documentTypeRepository.deleteAll(); + documentCategoryRepository.deleteAll(); + regionRepository.deleteAll(); } @Test void testGetNormAbbreviationById_allValuesFilled() { generateLookupValues(); - linkDocumentType(DOCUMENT_TYPE_UUID_1); - linkRegion(REGION_UUID_1); + + repository.save( + abbreviation1.toBuilder().documentTypeList(Set.of(documentType1)).region(region2).build()); NormAbbreviation expectedNormAbbreviation = new NormAbbreviationTestBuilder() .getExpectedNormAbbreviation() - .addDocumentType(DOCUMENT_TYPE_UUID_1, 'L') - .addRegion(REGION_UUID_1) + .addDocumentType(documentType1.getId(), "L") + .setRegion(region2.getId()) .build(); risWebTestClient .withDefaultLogin() .get() - .uri("/api/v1/caselaw/normabbreviation/" + NORM_ABBREVIATION_UUID_1) + .uri("/api/v1/caselaw/normabbreviation/" + abbreviation1.getId()) .exchange() .expectStatus() .isOk() @@ -154,18 +226,19 @@ void testGetNormAbbreviationById_allValuesFilled() { @Test void testGetNormAbbreviationById_withoutLinkedDocumentType() { generateLookupValues(); - linkRegion(REGION_UUID_1); + + repository.save(abbreviation1.toBuilder().region(region1).build()); NormAbbreviation expectedNormAbbreviation = new NormAbbreviationTestBuilder() .getExpectedNormAbbreviation() - .addRegion(REGION_UUID_1) + .setRegion(region1.getId()) .build(); risWebTestClient .withDefaultLogin() .get() - .uri("/api/v1/caselaw/normabbreviation/" + NORM_ABBREVIATION_UUID_1) + .uri("/api/v1/caselaw/normabbreviation/" + abbreviation1.getId()) .exchange() .expectStatus() .isOk() @@ -179,18 +252,19 @@ void testGetNormAbbreviationById_withoutLinkedDocumentType() { @Test void testGetNormAbbreviationById_withoutLinkedRegion() { generateLookupValues(); - linkDocumentType(DOCUMENT_TYPE_UUID_1); + + repository.save(abbreviation1.toBuilder().documentTypeList(Set.of(documentType1)).build()); NormAbbreviation expectedNormAbbreviation = new NormAbbreviationTestBuilder() .getExpectedNormAbbreviation() - .addDocumentType(DOCUMENT_TYPE_UUID_1, 'L') + .addDocumentType(documentType1.getId(), "L") .build(); risWebTestClient .withDefaultLogin() .get() - .uri("/api/v1/caselaw/normabbreviation/" + NORM_ABBREVIATION_UUID_1) + .uri("/api/v1/caselaw/normabbreviation/" + abbreviation1.getId()) .exchange() .expectStatus() .isOk() @@ -211,7 +285,7 @@ void testGetNormAbbreviationById_withoutLinkedDocumentTypeAndRegion() { risWebTestClient .withDefaultLogin() .get() - .uri("/api/v1/caselaw/normabbreviation/" + NORM_ABBREVIATION_UUID_1) + .uri("/api/v1/caselaw/normabbreviation/" + abbreviation1.getId()) .exchange() .expectStatus() .isOk() @@ -225,31 +299,32 @@ void testGetNormAbbreviationById_withoutLinkedDocumentTypeAndRegion() { @Test void testGetNormAbbreviationById_withTwoLinkedDocumentTypesAndTwoRegions() { generateLookupValues(); - linkDocumentType(DOCUMENT_TYPE_UUID_1); - linkDocumentType(DOCUMENT_TYPE_UUID_2); - linkRegion(REGION_UUID_1); - linkRegion(REGION_UUID_2); + + repository.saveAndFlush( + abbreviation1.toBuilder() + .documentTypeList(Set.of(documentType1, documentType2)) + .region(region1) + .build()); NormAbbreviation expectedNormAbbreviation = new NormAbbreviationTestBuilder() .getExpectedNormAbbreviation() - .addDocumentType(DOCUMENT_TYPE_UUID_1, 'L') - .addDocumentType(DOCUMENT_TYPE_UUID_2, 'M') - .addRegion(REGION_UUID_1) - .addRegion(REGION_UUID_2) + .addDocumentType(documentType1.getId(), "L") + .addDocumentType(documentType2.getId(), "M") .build(); risWebTestClient .withDefaultLogin() .get() - .uri("/api/v1/caselaw/normabbreviation/" + NORM_ABBREVIATION_UUID_1) + .uri("/api/v1/caselaw/normabbreviation/" + abbreviation1.getId()) .exchange() .expectStatus() .isOk() .expectBody(NormAbbreviation.class) .consumeWith( response -> { - assertThat(response.getResponseBody()).isEqualTo(expectedNormAbbreviation); + assertThat(Objects.requireNonNull(response.getResponseBody()).documentTypes()) + .containsAll(expectedNormAbbreviation.documentTypes()); }); } @@ -260,7 +335,7 @@ void testGetNormAbbreviationBySearchQuery() { risWebTestClient .withDefaultLogin() .get() - .uri("/api/v1/caselaw/normabbreviation?q=search query") + .uri("/api/v1/caselaw/normabbreviation?q=search query at the beginning") .exchange() .expectStatus() .isOk() @@ -269,10 +344,25 @@ void testGetNormAbbreviationBySearchQuery() { response -> { assertThat(response.getResponseBody()) .extracting("id") - .containsExactly(NORM_ABBREVIATION_UUID_2); + .containsExactly(abbreviation2.getId()); }); } + @Test + void testGetNormAbbreviationBySearchQueryOnlySearchesStartWith() { + generateLookupValues(); + + risWebTestClient + .withDefaultLogin() + .get() + .uri("/api/v1/caselaw/normabbreviation?q=beginning") + .exchange() + .expectStatus() + .isOk() + .expectBody() + .json("[]", true); + } + @Test void testGetNormAbbreviationBySearchQuery_returnInTheRightOrder() { generateLookupValues(); @@ -290,14 +380,14 @@ void testGetNormAbbreviationBySearchQuery_returnInTheRightOrder() { assertThat(response.getResponseBody()) .extracting("id") .containsExactly( - NORM_ABBREVIATION_UUID_6, NORM_ABBREVIATION_UUID_5, NORM_ABBREVIATION_UUID_7); + abbreviation6.getId(), abbreviation5.getId(), abbreviation7.getId()); }); } @Test void testGetNormAbbreviationByAwesomeSearchQuery_returnInTheRightOrder() { generateLookupValues(); - repository.refreshMaterializedViews().block(); + repository.refreshMaterializedViews(); String query = "search query"; @@ -314,7 +404,7 @@ void testGetNormAbbreviationByAwesomeSearchQuery_returnInTheRightOrder() { assertThat(response.getResponseBody()) .extracting("id") .containsExactly( - NORM_ABBREVIATION_UUID_2, NORM_ABBREVIATION_UUID_4, NORM_ABBREVIATION_UUID_3); + abbreviation2.getId(), abbreviation4.getId(), abbreviation3.getId()); }); query = "letter abbreviation query"; @@ -331,215 +421,53 @@ void testGetNormAbbreviationByAwesomeSearchQuery_returnInTheRightOrder() { response -> { assertThat(response.getResponseBody()) .extracting("id") - .containsExactly( - NORM_ABBREVIATION_UUID_3, NORM_ABBREVIATION_UUID_2, NORM_ABBREVIATION_UUID_4); + .containsExactlyInAnyOrder( + abbreviation3.getId(), abbreviation2.getId(), abbreviation4.getId()); }); } private void generateLookupValues() { - NormAbbreviationDTO normAbbreviationDTO = - NormAbbreviationDTO.builder() - .id(NORM_ABBREVIATION_UUID_1) - .newEntity(true) - .abbreviation("norm abbreviation 1") - .decisionDate(LocalDate.of(2023, Month.MAY, 19)) - .documentId(1234) - .documentNumber("document number 1") - .officialLetterAbbreviation("official letter abbreviation 1") - .officialLongTitle("official long title 1") - .officialShortTitle("official short title 1") - .source('S') - .build(); - repository.save(normAbbreviationDTO).block(); - - normAbbreviationDTO = - NormAbbreviationDTO.builder() - .id(NORM_ABBREVIATION_UUID_2) - .newEntity(true) - .abbreviation("search query at the beginning") - .decisionDate(LocalDate.of(2023, Month.MAY, 20)) - .documentId(2345) - .documentNumber("document number 2") - .officialLetterAbbreviation("official letter abbreviation 2") - .officialLongTitle("official long title 2") - .officialShortTitle("official short title 2") - .source('T') - .build(); - repository.save(normAbbreviationDTO).block(); - - normAbbreviationDTO = - NormAbbreviationDTO.builder() - .id(NORM_ABBREVIATION_UUID_3) - .newEntity(true) - .abbreviation("in the middle the search query is located") - .decisionDate(LocalDate.of(2023, Month.MAY, 21)) - .documentId(3456) - .documentNumber("document number 3") - .officialLetterAbbreviation("official letter abbreviation 3") - .officialLongTitle("official long title 3") - .officialShortTitle("official short title 3") - .source('U') - .build(); - repository.save(normAbbreviationDTO).block(); - - normAbbreviationDTO = - NormAbbreviationDTO.builder() - .id(NORM_ABBREVIATION_UUID_4) - .newEntity(true) - .abbreviation("SeaRch QueRY not in the right case") - .decisionDate(LocalDate.of(2023, Month.MAY, 22)) - .documentId(4567) - .documentNumber("document number 4") - .officialLetterAbbreviation("official letter abbreviation 4") - .officialLongTitle("official long title 4") - .officialShortTitle("official short title 4") - .source('V') - .build(); - repository.save(normAbbreviationDTO).block(); - - normAbbreviationDTO = - NormAbbreviationDTO.builder() - .id(NORM_ABBREVIATION_UUID_5) - .newEntity(true) - .abbreviation("Search B") - .decisionDate(LocalDate.of(2023, Month.MAY, 23)) - .documentId(5678) - .documentNumber("document number 5") - .officialLetterAbbreviation("official letter abbreviation 5") - .officialLongTitle("official long title 5") - .officialShortTitle("official short title 5") - .source('W') - .build(); - repository.save(normAbbreviationDTO).block(); - - normAbbreviationDTO = - NormAbbreviationDTO.builder() - .id(NORM_ABBREVIATION_UUID_6) - .newEntity(true) - .abbreviation("Search A") - .decisionDate(LocalDate.of(2023, Month.MAY, 24)) - .documentId(6789) - .documentNumber("document number 6") - .officialLetterAbbreviation("official letter abbreviation 6") - .officialLongTitle("official long title 6") - .officialShortTitle("official short title 6") - .source('X') - .build(); - repository.save(normAbbreviationDTO).block(); - - normAbbreviationDTO = - NormAbbreviationDTO.builder() - .id(NORM_ABBREVIATION_UUID_7) - .newEntity(true) - .abbreviation("Search C") - .decisionDate(LocalDate.of(2023, Month.MAY, 25)) - .documentId(7890) - .documentNumber("document number 7") - .officialLetterAbbreviation("official letter abbreviation 7") - .officialLongTitle("official long title 7") - .officialShortTitle("official short title 7") - .source('Y') - .build(); - repository.save(normAbbreviationDTO).block(); - - DocumentCategoryDTO documentCategoryDTO = - DocumentCategoryDTO.builder() - .id(DOCUMENT_CATEGORY_UUID_1) - .newEntity(true) - .label('L') - .build(); - documentCategoryRepository.save(documentCategoryDTO).block(); - documentCategoryDTO = - DocumentCategoryDTO.builder() - .id(DOCUMENT_CATEGORY_UUID_2) - .newEntity(true) - .label('M') - .build(); - documentCategoryRepository.save(documentCategoryDTO).block(); - - DocumentTypeNewDTO documentTypeNewDTO = - DocumentTypeNewDTO.builder() - .id(DOCUMENT_TYPE_UUID_1) - .newEntity(true) - .abbreviation("document type abbreviation 1") - .label("document type label 1") - .multiple(false) - .superLabel1("super label 11") - .superLabel2("super label 21") - .documentCategoryId(DOCUMENT_CATEGORY_UUID_1) - .build(); - documentTypeRepository.save(documentTypeNewDTO).block(); - - documentTypeNewDTO = - DocumentTypeNewDTO.builder() - .id(DOCUMENT_TYPE_UUID_2) - .newEntity(true) - .abbreviation("document type abbreviation 2") - .label("document type label 2") - .multiple(false) - .superLabel1("super label 12") - .superLabel2("super label 22") - .documentCategoryId(DOCUMENT_CATEGORY_UUID_2) - .build(); - documentTypeRepository.save(documentTypeNewDTO).block(); - - RegionDTO regionDTO = - RegionDTO.builder() - .id(REGION_UUID_1) - .newEntity(true) - .code("region code 1") - .label("region label 1") - .build(); - regionRepository.save(regionDTO).block(); - - regionDTO = - RegionDTO.builder() - .id(REGION_UUID_2) - .newEntity(true) - .code("region code 2") - .label("region label 2") - .build(); - regionRepository.save(regionDTO).block(); - } - - private void linkDocumentType(UUID documentTypeUUID) { - NormAbbreviationDocumentTypeDTO normAbbreviationDocumentTypeDTO = - NormAbbreviationDocumentTypeDTO.builder() - .newEntity(true) - .normAbbreviationId(NORM_ABBREVIATION_UUID_1) - .documentTypeId(documentTypeUUID) - .build(); - normAbbreviationDocumentTypeRepository.save(normAbbreviationDocumentTypeDTO).block(); - } - - private void linkRegion(UUID regionUUID) { - NormAbbreviationRegionDTO normAbbreviationRegionDTO = - NormAbbreviationRegionDTO.builder() - .newEntity(true) - .normAbbreviationId(NORM_ABBREVIATION_UUID_1) - .regionId(regionUUID) - .build(); - normAbbreviationRegionRepository.save(normAbbreviationRegionDTO).block(); + documentCategoryDTO1 = documentCategoryRepository.save(documentCategoryDTO1); + documentCategoryDTO2 = documentCategoryRepository.save(documentCategoryDTO2); + documentCategoryRepository.flush(); + + documentType1.setCategory(documentCategoryDTO1); + documentType1 = documentTypeRepository.saveAndFlush(documentType1); + documentType2.setCategory(documentCategoryDTO2); + documentType2 = documentTypeRepository.saveAndFlush(documentType2); + documentTypeRepository.flush(); + + region1 = regionRepository.save(region1); + region2 = regionRepository.save(region2); + regionRepository.flush(); + + abbreviation1 = repository.save(abbreviation1); + abbreviation2 = repository.save(abbreviation2); + abbreviation3 = repository.save(abbreviation3); + abbreviation4 = repository.save(abbreviation4); + abbreviation5 = repository.save(abbreviation5); + abbreviation6 = repository.save(abbreviation6); + abbreviation7 = repository.save(abbreviation7); + repository.flush(); } private class NormAbbreviationTestBuilder { private final NormAbbreviationBuilder builder; - private final List regions; - private final List documentTypes; + private Region region; + private final List documentTypes; private NormAbbreviationTestBuilder() { this.builder = NormAbbreviation.builder(); - regions = new ArrayList<>(); documentTypes = new ArrayList<>(); } private NormAbbreviationTestBuilder getExpectedNormAbbreviation() { builder - .id(NORM_ABBREVIATION_UUID_1) + .id(abbreviation1.getId()) .abbreviation("norm abbreviation 1") - .documentId(1234) + .documentId(1234L) .documentNumber("document number 1") .decisionDate( LocalDate.of(2023, Month.MAY, 19) @@ -549,43 +477,39 @@ private NormAbbreviationTestBuilder getExpectedNormAbbreviation() { .officialLetterAbbreviation("official letter abbreviation 1") .officialShortTitle("official short title 1") .officialLongTitle("official long title 1") - .source('S'); + .source("S"); return this; } - private NormAbbreviationTestBuilder addRegion(UUID regionUuid) { - RegionDTO regionDTO = regionRepository.findById(regionUuid).block(); + private NormAbbreviationTestBuilder setRegion(UUID regionUuid) { + RegionDTO regionDTO = regionRepository.findById(regionUuid).orElse(null); if (regionDTO == null) { return this; } - regions.add(Region.builder().code(regionDTO.getCode()).label(regionDTO.getLabel()).build()); + region = Region.builder().code(regionDTO.getCode()).build(); return this; } private NormAbbreviationTestBuilder addDocumentType( - UUID documentTypeUuid, Character categoryLabel) { - DocumentTypeNewDTO documentTypeNewDTO = - documentTypeRepository.findById(documentTypeUuid).block(); + UUID documentTypeUuid, String categoryLabel) { + DocumentTypeDTO documentTypeNewDTO = + documentTypeRepository.findById(documentTypeUuid).orElse(null); if (documentTypeNewDTO == null) { return this; } documentTypes.add( - DocumentTypeNew.builder() - .abbreviation(documentTypeNewDTO.getAbbreviation()) + DocumentType.builder() + .jurisShortcut(documentTypeNewDTO.getAbbreviation()) .label(documentTypeNewDTO.getLabel()) - .multiple(documentTypeNewDTO.isMultiple()) - .superLabel1(documentTypeNewDTO.getSuperLabel1()) - .superLabel2(documentTypeNewDTO.getSuperLabel2()) - .categoryLabel(categoryLabel) .build()); return this; } private NormAbbreviation build() { - return builder.regions(regions).documentTypes(documentTypes).build(); + return builder.region(region).documentTypes(documentTypes).build(); } } } diff --git a/backend/src/test/java/de/bund/digitalservice/ris/caselaw/integration/tests/ProcedureIntegrationTest.java b/backend/src/test/java/de/bund/digitalservice/ris/caselaw/integration/tests/ProcedureIntegrationTest.java index 6d11795f7a..fb4ecd7594 100644 --- a/backend/src/test/java/de/bund/digitalservice/ris/caselaw/integration/tests/ProcedureIntegrationTest.java +++ b/backend/src/test/java/de/bund/digitalservice/ris/caselaw/integration/tests/ProcedureIntegrationTest.java @@ -78,7 +78,8 @@ class ProcedureIntegrationTest { @Container static PostgreSQLContainer postgreSQLContainer = - new PostgreSQLContainer<>("postgres:14").withInitScript("db/create_extension.sql"); + new PostgreSQLContainer<>("postgres:14") + .withInitScript("db/create_migration_scheme_and_extensions.sql"); @DynamicPropertySource static void registerDynamicProperties(DynamicPropertyRegistry registry) { diff --git a/backend/src/test/java/de/bund/digitalservice/ris/caselaw/integration/tests/ProceedingDecisionIntegrationTest.java b/backend/src/test/java/de/bund/digitalservice/ris/caselaw/integration/tests/ProceedingDecisionIntegrationTest.java index 2793de2ae1..5504e8f7d7 100644 --- a/backend/src/test/java/de/bund/digitalservice/ris/caselaw/integration/tests/ProceedingDecisionIntegrationTest.java +++ b/backend/src/test/java/de/bund/digitalservice/ris/caselaw/integration/tests/ProceedingDecisionIntegrationTest.java @@ -14,7 +14,11 @@ import de.bund.digitalservice.ris.caselaw.adapter.DocxConverterService; import de.bund.digitalservice.ris.caselaw.adapter.KeycloakUserService; import de.bund.digitalservice.ris.caselaw.adapter.ProceedingDecisionController; +import de.bund.digitalservice.ris.caselaw.adapter.database.jpa.DatabaseDocumentCategoryRepository; +import de.bund.digitalservice.ris.caselaw.adapter.database.jpa.DatabaseDocumentTypeRepository; import de.bund.digitalservice.ris.caselaw.adapter.database.jpa.DatabaseDocumentationOfficeRepository; +import de.bund.digitalservice.ris.caselaw.adapter.database.jpa.DocumentCategoryDTO; +import de.bund.digitalservice.ris.caselaw.adapter.database.jpa.DocumentTypeDTO; import de.bund.digitalservice.ris.caselaw.adapter.database.jpa.DocumentationOfficeDTO; import de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.DatabaseDocumentUnitMetadataRepository; import de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.DatabaseDocumentUnitRepository; @@ -29,8 +33,6 @@ import de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.FileNumberRepository; import de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.PostgresDocumentUnitRepositoryImpl; import de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.PostgresPublicationReportRepositoryImpl; -import de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.lookuptable.DatabaseDocumentTypeRepository; -import de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.lookuptable.DocumentTypeDTO; import de.bund.digitalservice.ris.caselaw.config.FlywayConfig; import de.bund.digitalservice.ris.caselaw.config.PostgresConfig; import de.bund.digitalservice.ris.caselaw.config.PostgresJPAConfig; @@ -86,7 +88,10 @@ class ProceedingDecisionIntegrationTest { @Container static PostgreSQLContainer postgreSQLContainer = - new PostgreSQLContainer<>("postgres:14").withInitScript("db/create_extension.sql"); + new PostgreSQLContainer<>("postgres:14") + .withInitScript("db/create_migration_scheme_and_extensions.sql"); + + private DocumentCategoryDTO category; @DynamicPropertySource static void registerDynamicProperties(DynamicPropertyRegistry registry) { @@ -116,11 +121,15 @@ static void registerDynamicProperties(DynamicPropertyRegistry registry) { private final DocumentationOffice docOffice = buildDefaultDocOffice(); private UUID documentationOfficeUuid; + @Autowired private DatabaseDocumentCategoryRepository databaseDocumentCategoryRepository; @BeforeEach void setUp() { documentationOfficeUuid = documentationOfficeRepository.findByLabel(docOffice.label()).getId(); doReturn(Mono.just(docOffice)).when(userService).getDocumentationOffice(any(OidcUser.class)); + category = + databaseDocumentCategoryRepository.saveAndFlush( + DocumentCategoryDTO.builder().label("R").build()); } @AfterEach @@ -130,9 +139,10 @@ void cleanUp() { repository.deleteAll().block(); metadataRepository.deleteAll().block(); fileNumberRepository.deleteAll().block(); - databaseDocumentTypeRepository.deleteAll().block(); + databaseDocumentTypeRepository.deleteAll(); statusRepository.deleteAll().block(); databasePublishReportRepository.deleteAll().block(); + databaseDocumentCategoryRepository.delete(category); } // This test is flaky if executed locally, but reliable in the pipeline @@ -593,6 +603,10 @@ void testSearchForDocumentUnitsByProceedingDecisionInput_onlyCourt_shouldMatchOn prepareDocumentUnitMetadataDTOs(); simulateAPICall( ProceedingDecision.builder().court(Court.builder().type("SomeCourt").build()).build()) + .consumeWith( + result -> { + System.out.println("result = " + result.toString()); + }) .jsonPath("$.content") .isNotEmpty() .jsonPath("$.content.length()") @@ -769,16 +783,25 @@ private DocumentUnitMetadataDTO createDocumentUnit( String documentOfficeLabel, DocumentUnitStatus status) { - Long documentTypeId = null; + UUID documentTypeId = null; if (documentTypeJurisShortcut != null) { - DocumentTypeDTO documentTypeDTO = - DocumentTypeDTO.builder() - .changeIndicator('a') - .documentType('R') - .label("ABC123") - .jurisShortcut(documentTypeJurisShortcut) - .build(); - documentTypeId = databaseDocumentTypeRepository.save(documentTypeDTO).block().getId(); + + var documentType = + databaseDocumentTypeRepository.findFirstByAbbreviationAndCategory( + documentTypeJurisShortcut, category); + + if (documentType == null) { + DocumentTypeDTO documentTypeDTO = + DocumentTypeDTO.builder() + .category(category) + .label("ABC123") + .multiple(true) + .abbreviation(documentTypeJurisShortcut) + .build(); + documentTypeId = databaseDocumentTypeRepository.saveAndFlush(documentTypeDTO).getId(); + } else { + documentTypeId = documentType.getId(); + } } DocumentationOfficeDTO documentOffice = diff --git a/backend/src/test/java/de/bund/digitalservice/ris/caselaw/integration/tests/PublishDocumentUnitIntegrationTest.java b/backend/src/test/java/de/bund/digitalservice/ris/caselaw/integration/tests/PublishDocumentUnitIntegrationTest.java index a0317bed43..97f9f0ece5 100644 --- a/backend/src/test/java/de/bund/digitalservice/ris/caselaw/integration/tests/PublishDocumentUnitIntegrationTest.java +++ b/backend/src/test/java/de/bund/digitalservice/ris/caselaw/integration/tests/PublishDocumentUnitIntegrationTest.java @@ -77,7 +77,8 @@ class PublishDocumentUnitIntegrationTest { @Container static PostgreSQLContainer postgreSQLContainer = - new PostgreSQLContainer<>("postgres:14").withInitScript("db/create_extension.sql"); + new PostgreSQLContainer<>("postgres:14") + .withInitScript("db/create_migration_scheme_and_extensions.sql"); @DynamicPropertySource static void registerDynamicProperties(DynamicPropertyRegistry registry) { diff --git a/backend/src/test/java/de/bund/digitalservice/ris/caselaw/integration/tests/SaveNormIntegrationTest.java b/backend/src/test/java/de/bund/digitalservice/ris/caselaw/integration/tests/SaveNormIntegrationTest.java index 8ad0e114f0..f8ee03d6a5 100644 --- a/backend/src/test/java/de/bund/digitalservice/ris/caselaw/integration/tests/SaveNormIntegrationTest.java +++ b/backend/src/test/java/de/bund/digitalservice/ris/caselaw/integration/tests/SaveNormIntegrationTest.java @@ -13,14 +13,14 @@ import de.bund.digitalservice.ris.caselaw.adapter.DocumentUnitController; import de.bund.digitalservice.ris.caselaw.adapter.DocxConverterService; import de.bund.digitalservice.ris.caselaw.adapter.database.jpa.DatabaseDocumentationOfficeRepository; -import de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.DatabaseDocumentUnitNormRepository; +import de.bund.digitalservice.ris.caselaw.adapter.database.jpa.DatabaseDocumentationUnitSearchRepository; +import de.bund.digitalservice.ris.caselaw.adapter.database.jpa.DatabaseNormAbbreviationRepository; +import de.bund.digitalservice.ris.caselaw.adapter.database.jpa.DatabaseNormReferenceRepository; +import de.bund.digitalservice.ris.caselaw.adapter.database.jpa.NormAbbreviationDTO; import de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.DatabaseDocumentUnitRepository; import de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.DocumentUnitDTO; -import de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.DocumentUnitNormDTO; import de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.PostgresDocumentUnitRepositoryImpl; import de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.PostgresPublicationReportRepositoryImpl; -import de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.lookuptable.DatabaseNormAbbreviationRepository; -import de.bund.digitalservice.ris.caselaw.adapter.database.r2dbc.lookuptable.NormAbbreviationDTO; import de.bund.digitalservice.ris.caselaw.config.FlywayConfig; import de.bund.digitalservice.ris.caselaw.config.PostgresConfig; import de.bund.digitalservice.ris.caselaw.config.PostgresJPAConfig; @@ -36,7 +36,6 @@ import de.bund.digitalservice.ris.caselaw.domain.lookuptable.NormAbbreviation; import java.time.Instant; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import java.util.Objects; import java.util.UUID; @@ -73,7 +72,8 @@ class SaveNormIntegrationTest { @Container static PostgreSQLContainer postgreSQLContainer = - new PostgreSQLContainer<>("postgres:14").withInitScript("db/create_extension.sql"); + new PostgreSQLContainer<>("postgres:14") + .withInitScript("db/create_migration_scheme_and_extensions.sql"); @DynamicPropertySource static void registerDynamicProperties(DynamicPropertyRegistry registry) { @@ -86,7 +86,7 @@ static void registerDynamicProperties(DynamicPropertyRegistry registry) { @Autowired private RisWebTestClient risWebTestClient; @Autowired private DatabaseDocumentUnitRepository repository; - @Autowired private DatabaseDocumentUnitNormRepository normRepository; + @Autowired private DatabaseNormReferenceRepository normRepository; @Autowired private DatabaseNormAbbreviationRepository normAbbreviationRepository; @Autowired private DatabaseDocumentationOfficeRepository documentationOfficeRepository; @@ -99,6 +99,9 @@ static void registerDynamicProperties(DynamicPropertyRegistry registry) { private final DocumentationOffice docOffice = buildDefaultDocOffice(); private UUID documentationOfficeUuid; + @Autowired + private DatabaseDocumentationUnitSearchRepository databaseDocumentationUnitSearchRepository; + @BeforeEach void setUp() { documentationOfficeUuid = documentationOfficeRepository.findByLabel(docOffice.label()).getId(); @@ -115,9 +118,9 @@ void setUp() { @AfterEach void cleanUp() { - normAbbreviationRepository.deleteAll().block(); - normRepository.deleteAll().block(); + normRepository.deleteAll(); repository.deleteAll().block(); + normAbbreviationRepository.deleteAll(); } // TODO: write a test for add a document type with a wrong shortcut @@ -137,13 +140,7 @@ void testSaveNorm_withoutNorm() { repository.save(dto).block(); - DocumentUnit documentUnitFromFrontend = - DocumentUnit.builder() - .uuid(uuid) - .creationtimestamp(creationTimestamp) - .documentNumber("1234567890123") - .coreData(CoreData.builder().documentationOffice(docOffice).build()) - .build(); + DocumentUnit documentUnitFromFrontend = generateDocumentationUnit(uuid, creationTimestamp); risWebTestClient .withDefaultLogin() @@ -158,7 +155,7 @@ void testSaveNorm_withoutNorm() { response -> { assertThat(response.getResponseBody()).isNotNull(); assertThat(response.getResponseBody().contentRelatedIndexing()).isNotNull(); - assertThat(response.getResponseBody().contentRelatedIndexing().norms()).isNull(); + assertThat(response.getResponseBody().contentRelatedIndexing().norms()).isEmpty(); }); } @@ -167,22 +164,27 @@ void testSaveNorm_withOneNormAndNoChange() { UUID uuid = UUID.randomUUID(); Instant creationTimestamp = Instant.now(); - DocumentUnitDTO dto = - DocumentUnitDTO.builder() - .uuid(uuid) - .creationtimestamp(creationTimestamp) - .documentnumber("1234567890123") - .documentationOfficeId(documentationOfficeUuid) - .build(); - DocumentUnitDTO savedDTO = repository.save(dto).block(); - addNormToDB(1, savedDTO.getId()); + repository + .save( + DocumentUnitDTO.builder() + .uuid(uuid) + .norms(new ArrayList<>()) + .creationtimestamp(creationTimestamp) + .documentnumber("1234567890124") + .documentationOfficeId(documentationOfficeUuid) + .build()) + .block(); + NormAbbreviationDTO normAbbreviation = addNormToDB(2352); DocumentUnit documentUnitFromFrontend = generateDocumentationUnit(uuid, creationTimestamp); - documentUnitFromFrontend = - addNormToDomain(documentUnitFromFrontend, generateDocumentationUnitNorm(1)); - DocumentUnitNorm norm1 = generateDocumentationUnitNorm(1); - List expectedNormList = generateNormList(norm1); + documentUnitFromFrontend + .contentRelatedIndexing() + .norms() + .add( + DocumentUnitNorm.builder() + .normAbbreviation(NormAbbreviation.builder().id(normAbbreviation.getId()).build()) + .build()); risWebTestClient .withDefaultLogin() @@ -197,8 +199,16 @@ void testSaveNorm_withOneNormAndNoChange() { response -> { assertThat(response.getResponseBody()).isNotNull(); assertThat(response.getResponseBody().contentRelatedIndexing()).isNotNull(); - assertThat(response.getResponseBody().contentRelatedIndexing().norms()) - .containsExactlyElementsOf(expectedNormList); + assertThat(response.getResponseBody().contentRelatedIndexing().norms()).hasSize(1); + assertThat( + response + .getResponseBody() + .contentRelatedIndexing() + .norms() + .get(0) + .normAbbreviation() + .id()) + .isEqualTo(normAbbreviation.getId()); }); } @@ -208,28 +218,29 @@ void testSaveNorm_RISDEV2185() { UUID uuid = UUID.randomUUID(); Instant creationTimestamp = Instant.now(); - DocumentUnitDTO dto = - DocumentUnitDTO.builder() - .uuid(uuid) - .creationtimestamp(creationTimestamp) - .documentnumber("1234567890123") - .documentationOfficeId(documentationOfficeUuid) - .build(); - DocumentUnitDTO savedDTO = repository.save(dto).block(); - addNormToDB(1, savedDTO.getId()); - addNormToDB(2, savedDTO.getId()); + repository + .save( + DocumentUnitDTO.builder() + .uuid(uuid) + .creationtimestamp(creationTimestamp) + .documentnumber("1234567890123") + .documentationOfficeId(documentationOfficeUuid) + .build()) + .block(); + var dbNormAbbreviation1 = addNormToDB(1); + var dbNormAbbreviation2 = addNormToDB(2); DocumentUnit documentUnitFromFrontend = generateDocumentationUnit(uuid, creationTimestamp); - documentUnitFromFrontend = - addNormToDomain(documentUnitFromFrontend, generateDocumentationUnitNorm(1)); - DocumentUnitNorm changedNorm = - generateDocumentationUnitNorm(2).toBuilder().normAbbreviation(null).build(); - documentUnitFromFrontend = addNormToDomain(documentUnitFromFrontend, changedNorm); - DocumentUnitNorm norm1 = generateDocumentationUnitNorm(1); + DocumentUnitNorm norm1 = + DocumentUnitNorm.builder() + .normAbbreviation(NormAbbreviation.builder().id(dbNormAbbreviation1.getId()).build()) + .build(); DocumentUnitNorm norm2 = - generateDocumentationUnitNorm(2).toBuilder().normAbbreviation(null).build(); - List expectedNormList = generateNormList(norm1, norm2); + DocumentUnitNorm.builder() + .normAbbreviation(NormAbbreviation.builder().id(dbNormAbbreviation2.getId()).build()) + .build(); + documentUnitFromFrontend.contentRelatedIndexing().norms().addAll(List.of(norm1, norm2)); risWebTestClient .withDefaultLogin() @@ -244,68 +255,43 @@ void testSaveNorm_RISDEV2185() { response -> { assertThat(response.getResponseBody()).isNotNull(); assertThat(response.getResponseBody().contentRelatedIndexing()).isNotNull(); - assertThat(response.getResponseBody().contentRelatedIndexing().norms()) - .containsExactlyElementsOf(expectedNormList); + assertThat( + response + .getResponseBody() + .contentRelatedIndexing() + .norms() + .get(0) + .normAbbreviation() + .id()) + .isEqualTo(dbNormAbbreviation1.getId()); + assertThat( + response + .getResponseBody() + .contentRelatedIndexing() + .norms() + .get(1) + .normAbbreviation() + .id()) + .isEqualTo(dbNormAbbreviation2.getId()); }); } - private List generateNormList(DocumentUnitNorm... norms) { - return new ArrayList<>(Arrays.asList(norms)); - } - private DocumentUnit generateDocumentationUnit(UUID uuid, Instant creationTimestamp) { return DocumentUnit.builder() .uuid(uuid) .creationtimestamp(creationTimestamp) .documentNumber("1234567890123") .coreData(CoreData.builder().documentationOffice(docOffice).build()) + .contentRelatedIndexing(ContentRelatedIndexing.builder().norms(new ArrayList<>()).build()) .build(); } - private void addNormToDB(int index, Long parentId) { + private NormAbbreviationDTO addNormToDB(int index) { NormAbbreviationDTO normAbbreviationDTO = NormAbbreviationDTO.builder() - .id(UUID.fromString("11111111-1111-1111-1111-11111111111" + index)) - .newEntity(true) .abbreviation("norm abbreviation " + index) - .documentId(index) + .documentId((long) index) .build(); - normAbbreviationRepository.save(normAbbreviationDTO).block(); - - DocumentUnitNormDTO normDTO = - DocumentUnitNormDTO.builder() - .documentUnitId(parentId) - .normAbbreviationUuid(UUID.fromString("11111111-1111-1111-1111-11111111111" + index)) - .build(); - normRepository.save(normDTO).block(); - } - - private DocumentUnit addNormToDomain(DocumentUnit documentUnit, DocumentUnitNorm norm) { - if (documentUnit.contentRelatedIndexing() == null) { - documentUnit = - documentUnit.toBuilder() - .contentRelatedIndexing( - ContentRelatedIndexing.builder().norms(new ArrayList<>()).build()) - .build(); - } else if (documentUnit.contentRelatedIndexing().norms() == null) { - ContentRelatedIndexing contentRelatedIndexing = documentUnit.contentRelatedIndexing(); - contentRelatedIndexing = contentRelatedIndexing.toBuilder().norms(new ArrayList<>()).build(); - documentUnit = - documentUnit.toBuilder().contentRelatedIndexing(contentRelatedIndexing).build(); - } - - documentUnit.contentRelatedIndexing().norms().add(norm); - return documentUnit; - } - - private DocumentUnitNorm generateDocumentationUnitNorm(int index) { - return DocumentUnitNorm.builder() - .normAbbreviation( - NormAbbreviation.builder() - .id(UUID.fromString("11111111-1111-1111-1111-11111111111" + index)) - .abbreviation("norm abbreviation " + index) - .documentId(index) - .build()) - .build(); + return normAbbreviationRepository.saveAndFlush(normAbbreviationDTO); } } diff --git a/backend/src/test/java/de/bund/digitalservice/ris/caselaw/integration/tests/SecurityIntegrationTest.java b/backend/src/test/java/de/bund/digitalservice/ris/caselaw/integration/tests/SecurityIntegrationTest.java index df88d0cc88..1e33358013 100644 --- a/backend/src/test/java/de/bund/digitalservice/ris/caselaw/integration/tests/SecurityIntegrationTest.java +++ b/backend/src/test/java/de/bund/digitalservice/ris/caselaw/integration/tests/SecurityIntegrationTest.java @@ -27,7 +27,8 @@ class SecurityIntegrationTest { @Container static PostgreSQLContainer postgreSQLContainer = - new PostgreSQLContainer<>("postgres:14").withInitScript("db/create_extension.sql"); + new PostgreSQLContainer<>("postgres:14") + .withInitScript("db/create_migration_scheme_and_extensions.sql"); @DynamicPropertySource static void registerDynamicProperties(DynamicPropertyRegistry registry) { diff --git a/backend/src/test/java/de/bund/digitalservice/ris/caselaw/integration/tests/SingleNormValidationIntegrationTest.java b/backend/src/test/java/de/bund/digitalservice/ris/caselaw/integration/tests/SingleNormValidationIntegrationTest.java index 2eabfbb7c9..a49a50a3cc 100644 --- a/backend/src/test/java/de/bund/digitalservice/ris/caselaw/integration/tests/SingleNormValidationIntegrationTest.java +++ b/backend/src/test/java/de/bund/digitalservice/ris/caselaw/integration/tests/SingleNormValidationIntegrationTest.java @@ -10,7 +10,7 @@ import de.bund.digitalservice.ris.caselaw.adapter.DocumentUnitController; import de.bund.digitalservice.ris.caselaw.adapter.DocxConverterService; import de.bund.digitalservice.ris.caselaw.adapter.database.jpa.DatabaseDocumentationOfficeRepository; -import de.bund.digitalservice.ris.caselaw.adapter.database.jpa.JPAPostgresNormElementRepositoryImpl; +import de.bund.digitalservice.ris.caselaw.adapter.database.jpa.PostgresNormElementRepositoryImpl; import de.bund.digitalservice.ris.caselaw.config.FlywayConfig; import de.bund.digitalservice.ris.caselaw.config.PostgresConfig; import de.bund.digitalservice.ris.caselaw.config.PostgresJPAConfig; @@ -62,7 +62,7 @@ SecurityConfig.class, AuthService.class, TestConfig.class, - JPAPostgresNormElementRepositoryImpl.class + PostgresNormElementRepositoryImpl.class }, controllers = {DocumentUnitController.class}) @Slf4j @@ -70,7 +70,8 @@ class SingleNormValidationIntegrationTest { @Container static PostgreSQLContainer postgreSQLContainer = - new PostgreSQLContainer<>("postgres:14").withInitScript("db/create_extension.sql"); + new PostgreSQLContainer<>("postgres:14") + .withInitScript("db/create_migration_scheme_and_extensions.sql"); @DynamicPropertySource static void registerDynamicProperties(DynamicPropertyRegistry registry) { diff --git a/backend/src/test/kotlin/integration/framework/adapter/output/database/PostgresTestcontainerIntegrationTest.kt b/backend/src/test/kotlin/integration/framework/adapter/output/database/PostgresTestcontainerIntegrationTest.kt index ea26585c3a..b0308a166e 100644 --- a/backend/src/test/kotlin/integration/framework/adapter/output/database/PostgresTestcontainerIntegrationTest.kt +++ b/backend/src/test/kotlin/integration/framework/adapter/output/database/PostgresTestcontainerIntegrationTest.kt @@ -30,7 +30,7 @@ open class PostgresTestcontainerIntegrationTest { withDatabaseName("testdb") withUsername("user") withPassword("password") - withInitScript("db/create_extension.sql") + withInitScript("db/create_migration_scheme_and_extensions.sql") start() } diff --git a/backend/src/test/resources/db/create_extension.sql b/backend/src/test/resources/db/create_extension.sql deleted file mode 100644 index eeee495167..0000000000 --- a/backend/src/test/resources/db/create_extension.sql +++ /dev/null @@ -1,2 +0,0 @@ -CREATE EXTENSION - "uuid-ossp"; diff --git a/backend/src/test/resources/db/create_migration_scheme_and_extensions.sql b/backend/src/test/resources/db/create_migration_scheme_and_extensions.sql new file mode 100644 index 0000000000..d64a53cbe4 --- /dev/null +++ b/backend/src/test/resources/db/create_migration_scheme_and_extensions.sql @@ -0,0 +1,124 @@ +CREATE SCHEMA + IF NOT EXISTS incremental_migration; + +CREATE EXTENSION + IF NOT EXISTS "uuid-ossp"; + +CREATE EXTENSION + IF NOT EXISTS "pg_trgm"; + +CREATE TABLE IF NOT EXISTS + incremental_migration.region ( + id uuid NOT NULL, + code character varying(255) COLLATE pg_catalog."default", + CONSTRAINT region_pkey PRIMARY KEY (id), + CONSTRAINT uc_region_code UNIQUE (code) + ); + +CREATE TABLE IF NOT EXISTS + incremental_migration.norm_abbreviation ( + id uuid NOT NULL, + abbreviation character varying(255) COLLATE pg_catalog."default" NOT NULL, + decision_date date, + document_id bigint NOT NULL, + document_number character varying(80) COLLATE pg_catalog."default", + official_letter_abbreviation character varying(255) COLLATE pg_catalog."default", + official_long_title text COLLATE pg_catalog."default", + official_short_title text COLLATE pg_catalog."default", + source character varying(1) COLLATE pg_catalog."default", + CONSTRAINT norm_abbreviation_pkey PRIMARY KEY (id), + CONSTRAINT uc_norm_abbreviation_document_id UNIQUE (document_id) + ); + +CREATE TABLE IF NOT EXISTS + incremental_migration.document_category ( + id uuid NOT NULL, + label character varying(1) COLLATE pg_catalog."default" NOT NULL, + CONSTRAINT document_category_pkey PRIMARY KEY (id), + CONSTRAINT uc_document_category_label UNIQUE (label) + ); + +CREATE TABLE IF NOT EXISTS + incremental_migration.document_type ( + id uuid NOT NULL, + abbreviation character varying(32) COLLATE pg_catalog."default", + label character varying(255) COLLATE pg_catalog."default", + multiple boolean NOT NULL DEFAULT false, + super_label_1 character varying(255) COLLATE pg_catalog."default", + super_label_2 character varying(255) COLLATE pg_catalog."default", + document_category_id uuid, + CONSTRAINT document_type_pkey PRIMARY KEY (id), + CONSTRAINT uc_abbreviation_document_category_id UNIQUE (abbreviation, document_category_id), + CONSTRAINT fk_document_category FOREIGN KEY (document_category_id) REFERENCES incremental_migration.document_category (id) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE NO ACTION + ); + +CREATE TABLE IF NOT EXISTS + incremental_migration.norm_abbreviation_document_type ( + norm_abbreviation_id uuid NOT NULL, + document_type_id uuid NOT NULL, + CONSTRAINT norm_abbreviation_document_type_pkey PRIMARY KEY (norm_abbreviation_id, document_type_id), + CONSTRAINT fk_document_type FOREIGN KEY (document_type_id) REFERENCES incremental_migration.document_type (id) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT fk_norm_abbreviation FOREIGN KEY (norm_abbreviation_id) REFERENCES incremental_migration.norm_abbreviation (id) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE NO ACTION + ); + +CREATE TABLE IF NOT EXISTS + incremental_migration.norm_abbreviation_region ( + norm_abbreviation_id uuid NOT NULL, + region_id uuid NOT NULL, + CONSTRAINT norm_abbreviation_region_pkey PRIMARY KEY (norm_abbreviation_id, region_id), + CONSTRAINT fk_norm_abbreviation FOREIGN KEY (norm_abbreviation_id) REFERENCES incremental_migration.norm_abbreviation (id) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT fk_region FOREIGN KEY (region_id) REFERENCES incremental_migration.region (id) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE NO ACTION + ); + +CREATE TABLE IF NOT EXISTS + incremental_migration.norm_element ( + id uuid NOT NULL, + label character varying(255) COLLATE pg_catalog."default" NOT NULL, + has_number_designation boolean NOT NULL DEFAULT false, + norm_code character varying(18) COLLATE pg_catalog."default", + juris_id integer NOT NULL, + document_category_id uuid, + CONSTRAINT norm_element_pkey PRIMARY KEY (id), + CONSTRAINT uc_norm_element_juris_id UNIQUE (juris_id), + CONSTRAINT fk_document_category FOREIGN KEY (document_category_id) REFERENCES incremental_migration.document_category (id) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE NO ACTION + ); + +create materialized view + norm_abbreviation_search_migration as +select + na.*, + r.code, + r.id as region_id, + setweight(to_tsvector('german', na.abbreviation), 'A') || setweight( + to_tsvector( + 'german', + coalesce(na.official_letter_abbreviation, '') + ), + 'B' + ) || setweight( + to_tsvector('german', coalesce(na.official_short_title, '')), + 'B' + ) || setweight( + to_tsvector('german', coalesce(na.official_long_title, '')), + 'B' + ) || setweight(to_tsvector('german', coalesce(r.code, '')), 'B') weighted_vector +from + incremental_migration.norm_abbreviation na + left join incremental_migration.norm_abbreviation_region nar on na.id = nar.norm_abbreviation_id + left join incremental_migration.region r on nar.region_id = r.id; + +CREATE INDEX + norm_abbreviation_search_migration_idx ON norm_abbreviation_search_migration USING GIN (weighted_vector); + +CREATE TABLE IF NOT EXISTS + incremental_migration.norm_reference ( + id uuid NOT NULL, + norm_abbreviation_raw_value character varying(1000) COLLATE pg_catalog."default", + single_norm character varying(255) COLLATE pg_catalog."default", + date_of_version date, + date_of_relevance character varying(255) COLLATE pg_catalog."default", + documentation_unit_id uuid, + norm_abbreviation_id uuid, + date_of_version_raw_value character varying(255) COLLATE pg_catalog."default", + legacy_doc_unit_id uuid + ) diff --git a/compose.yaml b/compose.yaml index e2d842cd92..6a08e14124 100644 --- a/compose.yaml +++ b/compose.yaml @@ -121,6 +121,7 @@ services: psql -e -U test "$${POSTGRES_DB}" -c "ALTER DEFAULT PRIVILEGES IN SCHEMA incremental_migration GRANT SELECT, INSERT, UPDATE, DELETE ON TABLES TO $${MIGRATION_USER_NAME}, $${POSTGRES_USER};" psql -U $${POSTGRES_USER} -d $${POSTGRES_DB} -c 'CREATE EXTENSION IF NOT EXISTS "uuid-ossp";' + psql -U $${POSTGRES_USER} -d $${POSTGRES_DB} -c 'CREATE EXTENSION IF NOT EXISTS pg_trgm;' wait healthcheck: test: ["CMD-SHELL", "pg_isready -U test -d neuris"] diff --git a/frontend/src/domain/normAbbreviation.ts b/frontend/src/domain/normAbbreviation.ts index 6f31ce58dc..9b18a79303 100644 --- a/frontend/src/domain/normAbbreviation.ts +++ b/frontend/src/domain/normAbbreviation.ts @@ -14,5 +14,4 @@ export type NormAbbreviation = { export type Region = { code: string - label: string }