diff --git a/backend/src/main/java/de/bund/digitalservice/ris/norms/adapter/output/database/mapper/ArticleMapper.java b/backend/src/main/java/de/bund/digitalservice/ris/norms/adapter/output/database/mapper/ArticleMapper.java index 8084bbb31..b36bd9b61 100644 --- a/backend/src/main/java/de/bund/digitalservice/ris/norms/adapter/output/database/mapper/ArticleMapper.java +++ b/backend/src/main/java/de/bund/digitalservice/ris/norms/adapter/output/database/mapper/ArticleMapper.java @@ -2,6 +2,7 @@ import de.bund.digitalservice.ris.norms.adapter.output.database.dto.ArticleDto; import de.bund.digitalservice.ris.norms.domain.entity.Article; +import java.util.Optional; /** Mapper class for converting between {@link ArticleDto} and {@link Article}. */ public class ArticleMapper { @@ -35,7 +36,8 @@ public static ArticleDto mapToDto(final Article article) { .enumeration(article.getEnumeration()) .eid(article.getEid()) .title(article.getTitle()) - .targetLawDto(TargetLawMapper.mapToDto(article.getTargetLaw())) + .targetLawDto( + Optional.ofNullable(article.getTargetLaw()).map(TargetLawMapper::mapToDto).orElse(null)) .build(); } } diff --git a/backend/src/main/java/de/bund/digitalservice/ris/norms/adapter/output/database/service/DBService.java b/backend/src/main/java/de/bund/digitalservice/ris/norms/adapter/output/database/service/DBService.java index f191312b9..e917087ca 100644 --- a/backend/src/main/java/de/bund/digitalservice/ris/norms/adapter/output/database/service/DBService.java +++ b/backend/src/main/java/de/bund/digitalservice/ris/norms/adapter/output/database/service/DBService.java @@ -1,11 +1,16 @@ package de.bund.digitalservice.ris.norms.adapter.output.database.service; +import de.bund.digitalservice.ris.norms.adapter.output.database.dto.AmendingLawDto; import de.bund.digitalservice.ris.norms.adapter.output.database.mapper.AmendingLawMapper; +import de.bund.digitalservice.ris.norms.adapter.output.database.mapper.ArticleMapper; import de.bund.digitalservice.ris.norms.adapter.output.database.repository.AmendingLawRepository; import de.bund.digitalservice.ris.norms.application.port.output.LoadAllAmendingLawsPort; import de.bund.digitalservice.ris.norms.application.port.output.LoadAmendingLawPort; +import de.bund.digitalservice.ris.norms.application.port.output.LoadArticlesPort; import de.bund.digitalservice.ris.norms.domain.entity.AmendingLaw; +import de.bund.digitalservice.ris.norms.domain.entity.Article; import jakarta.transaction.Transactional; +import java.util.Collections; import java.util.List; import java.util.Optional; import org.springframework.stereotype.Service; @@ -16,7 +21,7 @@ * Spring context. */ @Service -public class DBService implements LoadAmendingLawPort, LoadAllAmendingLawsPort { +public class DBService implements LoadAmendingLawPort, LoadAllAmendingLawsPort, LoadArticlesPort { private final AmendingLawRepository amendingLawRepository; @@ -26,7 +31,7 @@ public DBService(AmendingLawRepository amendingLawRepository) { @Override @Transactional - public Optional loadAmendingLawByEli(Command command) { + public Optional loadAmendingLawByEli(LoadAmendingLawPort.Command command) { return amendingLawRepository .findByEli(command.eli()) .map(AmendingLawMapper::mapToDomainWithArticles); @@ -38,4 +43,15 @@ public List loadAllAmendingLaws() { .map(AmendingLawMapper::mapToDomain) .toList(); } + + @Override + public List
loadArticlesByAmendingLaw(LoadArticlesPort.Command command) { + final Optional amendingLawDtoOptional = + amendingLawRepository.findByEli(command.eli()); + return amendingLawDtoOptional + .map( + amendingLawDto -> + amendingLawDto.getArticleDtos().stream().map(ArticleMapper::mapToDomain).toList()) + .orElse(Collections.emptyList()); + } } diff --git a/backend/src/main/java/de/bund/digitalservice/ris/norms/application/port/output/LoadArticlesPort.java b/backend/src/main/java/de/bund/digitalservice/ris/norms/application/port/output/LoadArticlesPort.java new file mode 100644 index 000000000..1f863a3ac --- /dev/null +++ b/backend/src/main/java/de/bund/digitalservice/ris/norms/application/port/output/LoadArticlesPort.java @@ -0,0 +1,26 @@ +package de.bund.digitalservice.ris.norms.application.port.output; + +import de.bund.digitalservice.ris.norms.domain.entity.Article; +import java.util.List; + +/** Port interface for loading all articles of a given amending law from the storage. */ +public interface LoadArticlesPort { + + /** + * Loads all {@link Article}s available in the system of a given amending law. + * + * @param command The command specifying the ELI to identify the amending law of the articles to + * be loaded. + * @return A {@link List} of {@link Article}, which may be empty if no articles are found. + */ + List
loadArticlesByAmendingLaw(final Command command); + + /** + * A record representing the command for loading articles. The command includes the ELI (European + * Legislation Identifier) to identify the amending law. + * + * @param eli The ELI (European Legislation Identifier) used to identify the amending law in the + * command. + */ + record Command(String eli) {} +} diff --git a/backend/src/main/java/de/bund/digitalservice/ris/norms/application/service/AmendingLawService.java b/backend/src/main/java/de/bund/digitalservice/ris/norms/application/service/AmendingLawService.java index 278e1d21b..95c9333ca 100644 --- a/backend/src/main/java/de/bund/digitalservice/ris/norms/application/service/AmendingLawService.java +++ b/backend/src/main/java/de/bund/digitalservice/ris/norms/application/service/AmendingLawService.java @@ -7,10 +7,10 @@ import de.bund.digitalservice.ris.norms.application.port.input.LoadTargetLawUseCase; import de.bund.digitalservice.ris.norms.application.port.output.LoadAllAmendingLawsPort; import de.bund.digitalservice.ris.norms.application.port.output.LoadAmendingLawPort; +import de.bund.digitalservice.ris.norms.application.port.output.LoadArticlesPort; import de.bund.digitalservice.ris.norms.domain.entity.AmendingLaw; import de.bund.digitalservice.ris.norms.domain.entity.Article; import de.bund.digitalservice.ris.norms.domain.entity.TargetLaw; -import java.util.Collections; import java.util.List; import java.util.Optional; import org.springframework.stereotype.Service; @@ -30,6 +30,7 @@ public class AmendingLawService private final LoadAmendingLawPort loadAmendingLawPort; private final LoadAllAmendingLawsPort loadAllAmendingLawsPort; + private final LoadArticlesPort loadArticlesPort; /** * Constructs a new {@link AmendingLawService} instance. @@ -38,9 +39,12 @@ public class AmendingLawService * @param loadAllAmendingLawsPort The port for loading all amending laws. */ public AmendingLawService( - LoadAmendingLawPort loadAmendingLawPort, LoadAllAmendingLawsPort loadAllAmendingLawsPort) { + LoadAmendingLawPort loadAmendingLawPort, + LoadAllAmendingLawsPort loadAllAmendingLawsPort, + LoadArticlesPort loadArticlesPort) { this.loadAmendingLawPort = loadAmendingLawPort; this.loadAllAmendingLawsPort = loadAllAmendingLawsPort; + this.loadArticlesPort = loadArticlesPort; } @Override @@ -60,7 +64,7 @@ public Optional
loadArticle(final LoadArticleUseCase.Query query) { @Override public List
loadArticlesOfAmendingLaw(final LoadArticlesUseCase.Query query) { - return Collections.emptyList(); + return loadArticlesPort.loadArticlesByAmendingLaw(new LoadArticlesPort.Command(query.eli())); } @Override diff --git a/backend/src/test/java/de/bund/digitalservice/ris/norms/application/service/AmendingLawServiceTest.java b/backend/src/test/java/de/bund/digitalservice/ris/norms/application/service/AmendingLawServiceTest.java index f9a01b68f..afa3344ee 100644 --- a/backend/src/test/java/de/bund/digitalservice/ris/norms/application/service/AmendingLawServiceTest.java +++ b/backend/src/test/java/de/bund/digitalservice/ris/norms/application/service/AmendingLawServiceTest.java @@ -11,6 +11,7 @@ import de.bund.digitalservice.ris.norms.application.port.input.LoadAmendingLawUseCase; import de.bund.digitalservice.ris.norms.application.port.output.LoadAllAmendingLawsPort; import de.bund.digitalservice.ris.norms.application.port.output.LoadAmendingLawPort; +import de.bund.digitalservice.ris.norms.application.port.output.LoadArticlesPort; import de.bund.digitalservice.ris.norms.domain.entity.AmendingLaw; import java.time.LocalDate; import java.util.List; @@ -20,15 +21,19 @@ class AmendingLawServiceTest { + final LoadAmendingLawPort loadAmendingLawAdapter = mock(LoadAmendingLawPort.class); + final LoadAllAmendingLawsPort loadAllAmendingLawsAdapter = mock(LoadAllAmendingLawsPort.class); + + final LoadArticlesPort loadArticlesPort = mock(LoadArticlesPort.class); + + final AmendingLawService service = + new AmendingLawService(loadAmendingLawAdapter, loadAllAmendingLawsAdapter, loadArticlesPort); + @Test void itCallsLoadAmendingLawByEliUsingInputQueryEli() { // Given final String eli = "someEli"; - final LoadAmendingLawPort loadAmendingLawAdapter = mock(LoadAmendingLawPort.class); - final LoadAllAmendingLawsPort loadAllAmendingLawsAdapter = mock(LoadAllAmendingLawsPort.class); - final AmendingLawService service = - new AmendingLawService(loadAmendingLawAdapter, loadAllAmendingLawsAdapter); final LoadAmendingLawUseCase.Query query = new LoadAmendingLawUseCase.Query(eli); when(loadAmendingLawAdapter.loadAmendingLawByEli(any())).thenReturn(Optional.empty()); @@ -44,11 +49,7 @@ void itCallsLoadAmendingLawByEliUsingInputQueryEli() { void canLoadAmendingLawByEliIfAdapterFindsOne() { // Given final String eli = "someEli"; - final LoadAmendingLawPort loadAmendingLawAdapter = mock(LoadAmendingLawPort.class); - final LoadAllAmendingLawsPort loadAllAmendingLawAdapter = mock(LoadAllAmendingLawsPort.class); - final AmendingLawService service = - new AmendingLawService(loadAmendingLawAdapter, loadAllAmendingLawAdapter); final LoadAmendingLawUseCase.Query query = new LoadAmendingLawUseCase.Query(eli); final String printAnnouncementGazette = "someGazette"; @@ -82,11 +83,7 @@ void canLoadAmendingLawByEliIfAdapterFindsOne() { void canNotLoadAmendingLawByEliIfAdapterDoesNotFindOne() { // Given final String eli = "someEli"; - final LoadAmendingLawPort loadAmendingLawAdapter = mock(LoadAmendingLawPort.class); - final LoadAllAmendingLawsPort loadAllAmendingLawsAdapter = mock(LoadAllAmendingLawsPort.class); - final AmendingLawService service = - new AmendingLawService(loadAmendingLawAdapter, loadAllAmendingLawsAdapter); final LoadAmendingLawUseCase.Query query = new LoadAmendingLawUseCase.Query(eli); when(loadAmendingLawAdapter.loadAmendingLawByEli(any())).thenReturn(Optional.empty()); @@ -100,11 +97,6 @@ void canNotLoadAmendingLawByEliIfAdapterDoesNotFindOne() { @Test void canLoadAllAmendingLaws() { // Given - final LoadAmendingLawPort loadAmendingLawAdapter = mock(LoadAmendingLawPort.class); - final LoadAllAmendingLawsPort loadAllAmendingLawsAdapter = mock(LoadAllAmendingLawsPort.class); - final AmendingLawService service = - new AmendingLawService(loadAmendingLawAdapter, loadAllAmendingLawsAdapter); - final String eli = "eli/bund/bgbl-1/1953/s225/2017-03-15/1/deu/regelungstext-1"; final String printAnnouncementGazette = "someGazette"; final LocalDate publicationDate = LocalDate.now(); diff --git a/backend/src/test/java/de/bund/digitalservice/ris/norms/integration/adapter/input/restapi/AmendingLawControllerIntegrationTest.java b/backend/src/test/java/de/bund/digitalservice/ris/norms/integration/adapter/input/restapi/AmendingLawControllerIntegrationTest.java index 86f09d4bf..37fe4d743 100644 --- a/backend/src/test/java/de/bund/digitalservice/ris/norms/integration/adapter/input/restapi/AmendingLawControllerIntegrationTest.java +++ b/backend/src/test/java/de/bund/digitalservice/ris/norms/integration/adapter/input/restapi/AmendingLawControllerIntegrationTest.java @@ -38,6 +38,7 @@ void itCallsAmendingLawServiceAndReturnsAmendingLaw() throws Exception { final String digitalAnnouncementMedium = "medium123"; final String digitalAnnouncementEdition = "edition123"; final String title = "title"; + final String xml = ""; // When final AmendingLaw amendingLaw = @@ -49,6 +50,7 @@ void itCallsAmendingLawServiceAndReturnsAmendingLaw() throws Exception { .digitalAnnouncementMedium(digitalAnnouncementMedium) .digitalAnnouncementEdition(digitalAnnouncementEdition) .title(title) + .xml(xml) .build(); amendingLawRepository.save(AmendingLawMapper.mapToDto(amendingLaw)); @@ -78,6 +80,7 @@ void itLoadsAllAmendingLawsAndReturnsSuccessfully() throws Exception { final String digitalAnnouncementMedium = "medium123"; final String digitalAnnouncementEdition = "edition123"; final String title1 = "title1"; + final String xml1 = "1"; final String eli2 = "eli2"; final String printAnnouncementGazette2 = "someGazette2"; @@ -86,6 +89,7 @@ void itLoadsAllAmendingLawsAndReturnsSuccessfully() throws Exception { final String digitalAnnouncementMedium2 = "medium1232"; final String digitalAnnouncementEdition2 = "edition1232"; final String title2 = "title2"; + final String xml2 = "2"; final AmendingLaw amendingLaw1 = AmendingLaw.builder() @@ -96,6 +100,7 @@ void itLoadsAllAmendingLawsAndReturnsSuccessfully() throws Exception { .digitalAnnouncementMedium(digitalAnnouncementMedium) .digitalAnnouncementEdition(digitalAnnouncementEdition) .title(title1) + .xml(xml1) .build(); final AmendingLaw amendingLaw2 = @@ -107,6 +112,7 @@ void itLoadsAllAmendingLawsAndReturnsSuccessfully() throws Exception { .digitalAnnouncementMedium(digitalAnnouncementMedium2) .digitalAnnouncementEdition(digitalAnnouncementEdition2) .title(title2) + .xml(xml2) .build(); amendingLawRepository.saveAll(