diff --git a/backend/src/main/java/de/bund/digitalservice/ris/norms/adapter/input/restapi/controller/TimeBoundaryController.java b/backend/src/main/java/de/bund/digitalservice/ris/norms/adapter/input/restapi/controller/TimeBoundaryController.java index 5d77f04a9..67d72d498 100644 --- a/backend/src/main/java/de/bund/digitalservice/ris/norms/adapter/input/restapi/controller/TimeBoundaryController.java +++ b/backend/src/main/java/de/bund/digitalservice/ris/norms/adapter/input/restapi/controller/TimeBoundaryController.java @@ -15,7 +15,7 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; -/** Controller for norm-related actions. */ +/** Controller for listing and managing time boundaries of a regelungstext. */ @RestController @RequestMapping( "/api/v1/norms/eli/bund/{agent}/{year}/{naturalIdentifier}/{pointInTime}/{version}/{language}/{subtype}/timeBoundaries" @@ -37,7 +37,7 @@ public TimeBoundaryController( } /** - * Retrieves time boundaries for a norm based on its ELI with an optional filtering by the eli of + * Retrieves time boundaries for a regelungstext based on its ELI with an optional filtering by the eli of * an amending law. * *

The method constructs an ELI from the provided path variables, queries the use case to @@ -62,7 +62,7 @@ public ResponseEntity> getTimeBoundaries( ) ) .orElseGet(() -> - loadTimeBoundariesUseCase.loadTimeBoundariesOfNorm( + loadTimeBoundariesUseCase.loadTimeBoundariesFromRegelungstext( new LoadTimeBoundariesUseCase.Query(eli) ) ) @@ -73,7 +73,7 @@ public ResponseEntity> getTimeBoundaries( } /** - * Updates time boundaries for a norm based on its ELI. + * Updates time boundaries for a regelungstext based on its ELI. * *

The method constructs an ELI from the provided path variables, queries the use case to * update time boundaries, and maps the resulting data to {@link TimeBoundarySchema}. If no data @@ -95,7 +95,7 @@ public ResponseEntity> updateTimeBoundaries( ) { return ResponseEntity.ok( updateTimeBoundariesUseCase - .updateTimeBoundariesOfNorm( + .updateTimeBoundariesOfRegelungstext( new UpdateTimeBoundariesUseCase.Query( eli, TimeBoundaryMapper.fromResponseSchema(timeBoundaries) diff --git a/backend/src/main/java/de/bund/digitalservice/ris/norms/application/port/input/LoadTimeBoundariesAmendedByUseCase.java b/backend/src/main/java/de/bund/digitalservice/ris/norms/application/port/input/LoadTimeBoundariesAmendedByUseCase.java index 0963203e6..76d7c4b3b 100644 --- a/backend/src/main/java/de/bund/digitalservice/ris/norms/application/port/input/LoadTimeBoundariesAmendedByUseCase.java +++ b/backend/src/main/java/de/bund/digitalservice/ris/norms/application/port/input/LoadTimeBoundariesAmendedByUseCase.java @@ -5,24 +5,24 @@ import java.util.List; /** - * Interface representing the use case for loading a list of {@link TimeBoundary} of a norm + * Interface representing the use case for loading a list of {@link TimeBoundary} of a regelungstext * containing passive mods. It will filter out those time boundaries that were introduced by the * given amending law. */ public interface LoadTimeBoundariesAmendedByUseCase { /** - * Retrieves a list of time boundaries related to the specified norm filtered by the amending law + * Retrieves a list of time boundaries related to the specified regelungstext filtered by the amending law * eli. * - * @param query The query containing the ELI (European Legislation Identifier) of the norm. - * @return A list of {@link TimeBoundary} entities related to the specified norm. + * @param query The query containing the ELI (European Legislation Identifier) of the regelungstext. + * @return A list of {@link TimeBoundary} entities related to the specified regelungstext. */ List loadTimeBoundariesAmendedBy(Query query); /** - * A record representing the parameters needed to query time boundaries related to a norm. + * A record representing the parameters needed to query time boundaries related to a regelungstext. * - * @param eli The ELI used to identify the norm in the query. + * @param eli The ELI used to identify the regelungstext in the query. * @param amendingLawEli The ELI of the amending law. */ record Query(DokumentExpressionEli eli, DokumentExpressionEli amendingLawEli) {} diff --git a/backend/src/main/java/de/bund/digitalservice/ris/norms/application/port/input/LoadTimeBoundariesUseCase.java b/backend/src/main/java/de/bund/digitalservice/ris/norms/application/port/input/LoadTimeBoundariesUseCase.java index f468b34e3..a7b3976b1 100644 --- a/backend/src/main/java/de/bund/digitalservice/ris/norms/application/port/input/LoadTimeBoundariesUseCase.java +++ b/backend/src/main/java/de/bund/digitalservice/ris/norms/application/port/input/LoadTimeBoundariesUseCase.java @@ -6,22 +6,22 @@ /** * Interface representing the use case for loading a list of {@link TimeBoundary}. Implementations - * of this interface should provide functionality to load all time boundaries related to a norm + * of this interface should provide functionality to load all time boundaries related to a regelungstext * based on a given query. */ public interface LoadTimeBoundariesUseCase { /** - * Retrieves a list of time boundaries related to the specified norm based on the provided query. + * Retrieves a list of time boundaries related to the specified regelungstext based on the provided query. * - * @param query The query containing the ELI (European Legislation Identifier) of the norm. - * @return A list of {@link TimeBoundary} entities related to the specified norm. + * @param query The query containing the ELI (European Legislation Identifier) of the regelungstext. + * @return A list of {@link TimeBoundary} entities related to the specified regelungstext. */ - List loadTimeBoundariesOfNorm(Query query); + List loadTimeBoundariesFromRegelungstext(Query query); /** - * A record representing the parameters needed to query time boundaries related to a norm. + * A record representing the parameters needed to query time boundaries related to a regelungstext. * - * @param eli The ELI used to identify the norm in the query. + * @param eli The ELI used to identify the regelungstext in the query. */ record Query(DokumentExpressionEli eli) {} } diff --git a/backend/src/main/java/de/bund/digitalservice/ris/norms/application/port/input/UpdateTimeBoundariesUseCase.java b/backend/src/main/java/de/bund/digitalservice/ris/norms/application/port/input/UpdateTimeBoundariesUseCase.java index fc6182355..916757b11 100644 --- a/backend/src/main/java/de/bund/digitalservice/ris/norms/application/port/input/UpdateTimeBoundariesUseCase.java +++ b/backend/src/main/java/de/bund/digitalservice/ris/norms/application/port/input/UpdateTimeBoundariesUseCase.java @@ -7,22 +7,22 @@ /** * Interface representing the use case for updating a list of {@link TimeBoundary}. Implementations - * of this interface should provide functionality to update all time boundaries related to a norm + * of this interface should provide functionality to update all time boundaries related to a regelungstext * based on a given query. */ public interface UpdateTimeBoundariesUseCase { /** - * Updates a list of time boundaries related to the specified norm based on the provided query. + * Updates a list of time boundaries related to the specified regelungstext based on the provided query. * - * @param query The query containing the ELI (European Legislation Identifier) of the norm. - * @return A list of {@link TimeBoundary} entities related to the specified norm. + * @param query The query containing the ELI (European Legislation Identifier) of the regelungstext. + * @return A list of {@link TimeBoundary} entities related to the specified regelungstext. */ - List updateTimeBoundariesOfNorm(Query query); + List updateTimeBoundariesOfRegelungstext(Query query); /** - * A record representing the parameters needed to update time boundaries related to a norm. + * A record representing the parameters needed to update time boundaries related to a regelungstext. * - * @param eli The ELI used to identify the norm in the query. + * @param eli The ELI used to identify the regelungstext in the query. * @param timeBoundaries The list of the changed time boundaries. */ record Query(DokumentExpressionEli eli, List timeBoundaries) {} diff --git a/backend/src/main/java/de/bund/digitalservice/ris/norms/application/service/TimeBoundaryService.java b/backend/src/main/java/de/bund/digitalservice/ris/norms/application/service/TimeBoundaryService.java index 65a8d7615..341865c36 100644 --- a/backend/src/main/java/de/bund/digitalservice/ris/norms/application/service/TimeBoundaryService.java +++ b/backend/src/main/java/de/bund/digitalservice/ris/norms/application/service/TimeBoundaryService.java @@ -30,14 +30,17 @@ public TimeBoundaryService(LoadNormPort loadNormPort, NormService normService) { } /** - * @param query The query containing the ELI (European Legislation Identifier) of the norm. + * @param query The query containing the ELI (European Legislation Identifier) of the regelungstext. * @return a List of TimeBoundaries */ @Override - public List loadTimeBoundariesOfNorm(LoadTimeBoundariesUseCase.Query query) { + public List loadTimeBoundariesFromRegelungstext( + LoadTimeBoundariesUseCase.Query query + ) { return loadNormPort .loadNorm(new LoadNormPort.Command(query.eli())) .orElseThrow(() -> new NormNotFoundException(query.eli().toString())) + .getRegelungstext1() .getTimeBoundaries(); } @@ -45,11 +48,12 @@ public List loadTimeBoundariesOfNorm(LoadTimeBoundariesUseCase.Que public List loadTimeBoundariesAmendedBy( LoadTimeBoundariesAmendedByUseCase.Query query ) { - final Norm norm = loadNormPort + final Regelungstext regelungstext = loadNormPort .loadNorm(new LoadNormPort.Command(query.eli())) - .orElseThrow(() -> new NormNotFoundException(query.eli().toString())); + .orElseThrow(() -> new NormNotFoundException(query.eli().toString())) + .getRegelungstext1(); - final List temporalGroupEidAmendedBy = norm + final List temporalGroupEidAmendedBy = regelungstext .getMeta() .getOrCreateAnalysis() .getPassiveModifications() @@ -67,25 +71,30 @@ public List loadTimeBoundariesAmendedBy( .filter(Objects::nonNull) .toList(); - final List temporalGroups = norm + final List temporalGroups = regelungstext .getMeta() .getTemporalData() .getTemporalGroups() .stream() .filter(f -> temporalGroupEidAmendedBy.contains(f.getEid())) .toList(); - return norm.getTimeBoundaries(temporalGroups); + return regelungstext.getTimeBoundaries(temporalGroups); } /** - * @param query The query containing the ELI (European Legislation Identifier) of the norm. + * @param query The query containing the ELI (European Legislation Identifier) of the regelungstext. * @return a List of TimeBoundaries */ @Override - public List updateTimeBoundariesOfNorm(UpdateTimeBoundariesUseCase.Query query) { + public List updateTimeBoundariesOfRegelungstext( + UpdateTimeBoundariesUseCase.Query query + ) { final Norm norm = loadNormPort .loadNorm(new LoadNormPort.Command(query.eli())) .orElseThrow(() -> new NormNotFoundException(query.eli().toString())); + + var regelungstext = norm.getRegelungstext1(); + // At first time boundaries that shall be deleted need to be selected // if we would delete first, there are cases where the next possible eId could not be safely // calculated @@ -94,28 +103,31 @@ public List updateTimeBoundariesOfNorm(UpdateTimeBoundariesUseCase // is being added. Then id3 could not be calculated. List timeBoundariesToDelete = selectTimeBoundariesToDelete( query.timeBoundaries(), - norm + regelungstext ); // Add TimeBoundaries where eid is null|empty - addTimeBoundaries(query.timeBoundaries(), norm); + addTimeBoundaries(query.timeBoundaries(), regelungstext); - deleteTimeBoundaries(timeBoundariesToDelete, norm); + deleteTimeBoundaries(timeBoundariesToDelete, regelungstext); - editTimeBoundaries(query.timeBoundaries(), norm); + editTimeBoundaries(query.timeBoundaries(), regelungstext); Map result = normService.updateNorm(norm); - return result.get(query.eli()).getTimeBoundaries(); + return result.get(query.eli()).getRegelungstext1().getTimeBoundaries(); } - private void editTimeBoundaries(List timeBoundaryChangeData, Norm norm) { + private void editTimeBoundaries( + List timeBoundaryChangeData, + Regelungstext regelungstext + ) { List datesToUpdate = timeBoundaryChangeData .stream() .filter(tb -> tb.eid() != null && !tb.eid().isEmpty()) .toList(); - List timeBoundariesToUpdate = norm + List timeBoundariesToUpdate = regelungstext .getTimeBoundaries() .stream() .filter(tb -> @@ -137,14 +149,14 @@ private void editTimeBoundaries(List timeBoundaryChangeD tb.setEventRefDate(newDate); }); - logChangeDataWithoutCorrespondingEidInXml(norm, datesToUpdate); + logChangeDataWithoutCorrespondingEidInXml(regelungstext, datesToUpdate); } private void logChangeDataWithoutCorrespondingEidInXml( - Norm norm, + Regelungstext regelungstext, List datesToUpdate ) { - List timeBoundaryEids = norm + List timeBoundaryEids = regelungstext .getTimeBoundaries() .stream() .map(TimeBoundary::getEventRefEid) @@ -165,24 +177,27 @@ private void logChangeDataWithoutCorrespondingEidInXml( } } - private void addTimeBoundaries(List timeBoundaryChangeData, Norm norm) { + private void addTimeBoundaries( + List timeBoundaryChangeData, + Regelungstext regelungstext + ) { timeBoundaryChangeData .stream() .filter(tb -> tb.eid() == null || tb.eid().isEmpty()) .map(TimeBoundaryChangeData::date) - .forEach(date -> norm.addTimeBoundary(date, EventRefType.GENERATION)); + .forEach(date -> regelungstext.addTimeBoundary(date, EventRefType.GENERATION)); } private List selectTimeBoundariesToDelete( List timeBoundaryChangeData, - Norm norm + Regelungstext regelungstext ) { List allChangeDateEids = timeBoundaryChangeData .stream() .map(TimeBoundaryChangeData::eid) .toList(); - List allEventRefEidsToDelete = norm + List allEventRefEidsToDelete = regelungstext .getTimeBoundaries() .stream() .map(TimeBoundary::getEventRefEid) @@ -197,8 +212,8 @@ private List selectTimeBoundariesToDelete( private void deleteTimeBoundaries( List timeBoundariesToDelete, - Norm norm + Regelungstext regelungstext ) { - timeBoundariesToDelete.forEach(norm::deleteTimeBoundary); + timeBoundariesToDelete.forEach(regelungstext::deleteTimeBoundary); } } diff --git a/backend/src/test/java/de/bund/digitalservice/ris/norms/adapter/input/restapi/controller/TimeBoundaryControllerTest.java b/backend/src/test/java/de/bund/digitalservice/ris/norms/adapter/input/restapi/controller/TimeBoundaryControllerTest.java index 81077008f..a27fb98ba 100644 --- a/backend/src/test/java/de/bund/digitalservice/ris/norms/adapter/input/restapi/controller/TimeBoundaryControllerTest.java +++ b/backend/src/test/java/de/bund/digitalservice/ris/norms/adapter/input/restapi/controller/TimeBoundaryControllerTest.java @@ -92,7 +92,8 @@ void getTimeBoundariesReturnsCorrectData() throws Exception { ) ); - when(loadTimeBoundariesUseCase.loadTimeBoundariesOfNorm(any())).thenReturn(timeBoundaries); + when(loadTimeBoundariesUseCase.loadTimeBoundariesFromRegelungstext(any())) + .thenReturn(timeBoundaries); // When // Then mockMvc @@ -104,7 +105,7 @@ void getTimeBoundariesReturnsCorrectData() throws Exception { .andExpect(jsonPath("$[0].temporalGroupEid", is("meta-1_geltzeiten-1_geltungszeitgr-1"))); verify(loadTimeBoundariesUseCase, times(1)) - .loadTimeBoundariesOfNorm(any(LoadTimeBoundariesUseCase.Query.class)); + .loadTimeBoundariesFromRegelungstext(any(LoadTimeBoundariesUseCase.Query.class)); } @Test @@ -206,7 +207,7 @@ void updateTimeBoundariesReturnsSuccess() throws Exception { ) ); - when(updateTimeBoundariesUseCase.updateTimeBoundariesOfNorm(any())) + when(updateTimeBoundariesUseCase.updateTimeBoundariesOfRegelungstext(any())) .thenReturn(timeBoundaries); // When // Then @@ -227,7 +228,7 @@ void updateTimeBoundariesReturnsSuccess() throws Exception { .andExpect(jsonPath("$[0].temporalGroupEid", is("meta-1_geltzeiten-1_geltungszeitgr-1"))); verify(updateTimeBoundariesUseCase, times(1)) - .updateTimeBoundariesOfNorm(any(UpdateTimeBoundariesUseCase.Query.class)); + .updateTimeBoundariesOfRegelungstext(any(UpdateTimeBoundariesUseCase.Query.class)); } @Test diff --git a/backend/src/test/java/de/bund/digitalservice/ris/norms/application/service/TimeBoundaryServiceTest.java b/backend/src/test/java/de/bund/digitalservice/ris/norms/application/service/TimeBoundaryServiceTest.java index 1f4a4c14b..0ef203f56 100644 --- a/backend/src/test/java/de/bund/digitalservice/ris/norms/application/service/TimeBoundaryServiceTest.java +++ b/backend/src/test/java/de/bund/digitalservice/ris/norms/application/service/TimeBoundaryServiceTest.java @@ -86,7 +86,7 @@ void itCallsLoadTimeBoundariesOfNormAndReturnsTimeBoundaries() { when(loadNormPort.loadNorm(any())).thenReturn(Optional.of(norm)); // When - var timeBoundaries = service.loadTimeBoundariesOfNorm( + var timeBoundaries = service.loadTimeBoundariesFromRegelungstext( new LoadTimeBoundariesUseCase.Query(eli) ); @@ -206,7 +206,7 @@ void itCallsLoadTimeBoundariesOfNormAndReturnsTimeBoundariesEmpty() { when(loadNormPort.loadNorm(any())).thenReturn(Optional.of(norm)); // When - var timeBoundaries = service.loadTimeBoundariesOfNorm( + var timeBoundaries = service.loadTimeBoundariesFromRegelungstext( new LoadTimeBoundariesUseCase.Query(eli) ); @@ -417,7 +417,7 @@ void itCallsUpdateTimeBoundariesOfNormAndReturnsTimeBoundariesNothingChanged() { LocalDate.parse("2023-12-30") ); - var result = service.updateTimeBoundariesOfNorm( + var result = service.updateTimeBoundariesOfRegelungstext( new UpdateTimeBoundariesUseCase.Query(eli, List.of(timeBoundaryChangeDataOldStays)) ); @@ -500,7 +500,7 @@ void itCallsUpdateTimeBoundariesOfNormAndReturnsTimeBoundariesNew() { LocalDate.parse("2024-01-02") ); - service.updateTimeBoundariesOfNorm( + service.updateTimeBoundariesOfRegelungstext( new UpdateTimeBoundariesUseCase.Query( eli, List.of(timeBoundaryChangeDataOldStays, timeBoundaryChangeDataNewDate) @@ -599,7 +599,7 @@ void itCallsUpdateTimeBoundariesOfNormAndReturnsTimeBoundariesDelete() { LocalDate.parse("2023-12-30") ); - service.updateTimeBoundariesOfNorm( + service.updateTimeBoundariesOfRegelungstext( new UpdateTimeBoundariesUseCase.Query(eli, List.of(timeBoundaryChangeDataOldStays)) ); @@ -674,7 +674,7 @@ void itChangesADate() { LocalDate.parse("1990-01-01") ); - service.updateTimeBoundariesOfNorm( + service.updateTimeBoundariesOfRegelungstext( new UpdateTimeBoundariesUseCase.Query( eli, List.of(timeBoundaryChangeDataNewDate1, timeBoundaryChangeDataNewDate2) @@ -758,7 +758,7 @@ void itChangesDateEIdNotFound() { LocalDate.parse("1970-01-01") ); - service.updateTimeBoundariesOfNorm( + service.updateTimeBoundariesOfRegelungstext( new UpdateTimeBoundariesUseCase.Query(eli, List.of(timeBoundaryChangeDataNewDate1)) );