Skip to content

Commit

Permalink
Revert "Revert "Revert "Use migration schema for norm abbreviation (#791
Browse files Browse the repository at this point in the history
)"""

This reverts commit 464d92f.
  • Loading branch information
HPrinz committed Oct 26, 2023
1 parent a622e0c commit 189afa0
Show file tree
Hide file tree
Showing 87 changed files with 1,601 additions and 1,317 deletions.
4 changes: 1 addition & 3 deletions .talismanrc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ fileignoreconfig:
- filename: backend/src/test/kotlin/unit/application/service/GetFileServiceTest.kt
checksum: 8133265c6f388df84a3e0f61050428e8628853e0ba80b432e4723750a34b781e
- filename: compose.yaml
checksum: a9899cbf98e5d6402d4a8f1844445b36d0426dc189b5a323bdac3d1eec25d37a
checksum: 584e16667713a8c96c693069408ed50f10e46afcd5cbd2f43ea937ccfffab94e
- filename: doc/norms/backend-api.yaml
checksum: df4fa1f7e6d7023f9a7a98d1052c2b88c1785366962004b3165453edcd5bf4db
- filename: doc/structurizr/workspace.json
Expand All @@ -41,5 +41,3 @@ allowed_patterns:
- KEYWORD
threshold: medium
version: "1.0"
threshold: medium
version: "1.0"
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,21 @@ 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<ResponseEntity<String>> 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<ResponseEntity<String>> importCourtLookupTable(@RequestBody ByteBuffer byteBuffer) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
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;
Expand All @@ -15,6 +17,7 @@
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;
Expand All @@ -41,6 +44,8 @@
@Service
@Slf4j
public class LookupTableImporterService {

private final JPADocumentTypeRepository jpaDocumentTypeRepository;
private final DatabaseCourtRepository databaseCourtRepository;
private final StateRepository stateRepository;
private final DatabaseCitationStyleRepository databaseCitationStyleRepository;
Expand All @@ -50,18 +55,59 @@ 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;
this.jpaFieldOfLawRepository = jpaFieldOfLawRepository;
this.jpaFieldOfLawLinkRepository = jpaFieldOfLawLinkRepository;
}

@Transactional(transactionManager = "jpaTransactionManager")
public Mono<String> 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<JPADocumentTypeDTO> 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<String> importCourtLookupTable(ByteBuffer byteBuffer) {
XmlMapper mapper = new XmlMapper();
CourtsXML courtsXML;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,34 +28,36 @@ public NormAbbreviationController(NormAbbreviationService service) {

@GetMapping
@PreAuthorize("isAuthenticated()")
public Flux<NormAbbreviation> 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));
public Flux<NormAbbreviation> 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);
}

@GetMapping("/{uuid}")
@PreAuthorize("isAuthenticated()")
public Mono<NormAbbreviation> getNormAbbreviationById(@PathVariable("uuid") UUID uuid) {
return Mono.just(service.getNormAbbreviationById(uuid));
public Mono<NormAbbreviation> getNormAbbreviationController(@PathVariable("uuid") UUID uuid) {
return service.getNormAbbreviationById(uuid);
}

@GetMapping("/search")
@PreAuthorize("isAuthenticated()")
public Mono<List<NormAbbreviation>> getAllNormAbbreviationsContaining(
public Mono<List<NormAbbreviation>> getAllNormAbbreviationsByAwesomeSearchQuery(
@RequestParam(value = "q", required = false, defaultValue = "") String query,
@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));
@RequestParam(value = "sz", required = false) Integer size,
@RequestParam(value = "pg", required = false) Integer page) {

return service.getNormAbbreviationByAwesomeSearchQuery(query, size, page);
}

@PutMapping("/refreshMaterializedViews")
@PreAuthorize("isAuthenticated()")
public Mono<ResponseEntity<String>> refreshMaterializedViews() {
service.refreshMaterializedViews();
return Mono.just(
ResponseEntity.ok("Refreshed the materialized view 'norm_abbreviation_search_migration'"));
return service
.refreshMaterializedViews()
.thenReturn(
ResponseEntity.ok("Refreshed the materialized view 'norm_abbreviation_search'"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
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 {
Expand All @@ -14,21 +16,33 @@ public NormAbbreviationService(NormAbbreviationRepository repository) {
this.repository = repository;
}

public NormAbbreviation getNormAbbreviationById(UUID uuid) {
public Mono<NormAbbreviation> getNormAbbreviationById(UUID uuid) {
return repository.findById(uuid);
}

public List<NormAbbreviation> getNormAbbreviationsStartingWithExact(
public Flux<NormAbbreviation> getNormAbbreviationBySearchQuery(
String query, Integer size, Integer page) {
return repository.getNormAbbreviationsStartingWithExact(query, size, page);

Integer pageOffset = null;
if (page != null && size != null) {
pageOffset = page * size;
}

return repository.findBySearchQuery(query, size, pageOffset);
}

public List<NormAbbreviation> findAllNormAbbreviationsContaining(
public Mono<List<NormAbbreviation>> getNormAbbreviationByAwesomeSearchQuery(
String query, Integer size, Integer page) {
return repository.findAllContainingOrderByAccuracy(query, size, page);

Integer pageOffset = null;
if (page != null && size != null) {
pageOffset = page * size;
}

return repository.findByAwesomeSearchQuery(query, size, pageOffset);
}

public void refreshMaterializedViews() {
repository.refreshMaterializedViews();
public Mono<Void> refreshMaterializedViews() {
return repository.refreshMaterializedViews();
}
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 189afa0

Please sign in to comment.