From b374eb31a9607a96286f80efc6cdeec2b2fac36e Mon Sep 17 00:00:00 2001 From: OZGCloud <ozgcloud@mgm-tp.com> Date: Wed, 21 Dec 2022 10:23:00 +0100 Subject: [PATCH] OZG-3284 Map data and call semantik adapter --- .../formcycle-adapter-impl/pom.xml | 23 ++++++++++- .../formcycle/FormCycleFormDataMapper.java | 25 +++++++++++ .../eingang/formcycle/FormDataController.java | 14 +++++-- .../FormcycleAdapterApplication.java | 11 ++++- .../src/main/resources/application-local.yml | 10 ++++- .../src/main/resources/application.yml | 10 ++++- .../FormCycleFormDataMapperTest.java | 32 +++++++++++++++ .../FormCycleFormDataTestFactory.java | 20 +++++++++ .../FormCycleFormHeaderTestFactory.java | 20 +++++++++ .../FormCycleServiceKontoTestFactory.java | 15 +++++++ .../formcycle/FormDataControllerTest.java | 41 ++++++++++++++++--- .../src/main/protobuf/form-data.model.proto | 19 +++++---- formcycle-adapter/pom.xml | 20 ++++++++- .../FormCycleEngineBasedAdapter.java | 13 ++++++ .../FormCycleEngineBasedAdapterTest.java | 24 +++++++++++ 15 files changed, 274 insertions(+), 23 deletions(-) create mode 100644 formcycle-adapter/formcycle-adapter-impl/src/main/java/de/itvsh/kop/eingang/formcycle/FormCycleFormDataMapper.java create mode 100644 formcycle-adapter/formcycle-adapter-impl/src/test/java/de/itvsh/kop/eingang/formcycle/FormCycleFormDataMapperTest.java create mode 100644 formcycle-adapter/formcycle-adapter-impl/src/test/java/de/itvsh/kop/eingang/formcycle/FormCycleFormDataTestFactory.java create mode 100644 formcycle-adapter/formcycle-adapter-impl/src/test/java/de/itvsh/kop/eingang/formcycle/FormCycleFormHeaderTestFactory.java create mode 100644 formcycle-adapter/formcycle-adapter-impl/src/test/java/de/itvsh/kop/eingang/formcycle/FormCycleServiceKontoTestFactory.java create mode 100644 semantik-adapter/src/main/java/de/itvsh/kop/eingangsadapter/semantik/enginebased/formcycle/FormCycleEngineBasedAdapter.java create mode 100644 semantik-adapter/src/test/java/de/itvsh/kop/eingangsadapter/semantik/enginebased/formcycle/FormCycleEngineBasedAdapterTest.java diff --git a/formcycle-adapter/formcycle-adapter-impl/pom.xml b/formcycle-adapter/formcycle-adapter-impl/pom.xml index df115c8c8..156e71052 100644 --- a/formcycle-adapter/formcycle-adapter-impl/pom.xml +++ b/formcycle-adapter/formcycle-adapter-impl/pom.xml @@ -35,12 +35,29 @@ <artifactId>formcycle-adapter-impl</artifactId> <name>EM - Formcycle Adapter - Implementation</name> - + <properties> <formcycle-interface.version>1.0.0-SNAPSHOT</formcycle-interface.version> </properties> <dependencies> + <!--own project--> + <dependency> + <groupId>de.itvsh.ozg.pluto</groupId> + <artifactId>pluto-utils</artifactId> + </dependency> + <dependency> + <groupId>de.itvsh.ozg.pluto</groupId> + <artifactId>pluto-utils</artifactId> + <type>test-jar</type> + </dependency> + <dependency> + <groupId>de.itvsh.kop.eingangsadapter</groupId> + <artifactId>common</artifactId> + <type>test-jar</type> + </dependency> + + <!--spring--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> @@ -51,6 +68,10 @@ <artifactId>formcycle-adapter-interface</artifactId> <version>${formcycle-interface.version}</version> </dependency> + <dependency> + <groupId>de.itvsh.kop.eingangsadapter</groupId> + <artifactId>semantik-adapter</artifactId> + </dependency> </dependencies> <build> diff --git a/formcycle-adapter/formcycle-adapter-impl/src/main/java/de/itvsh/kop/eingang/formcycle/FormCycleFormDataMapper.java b/formcycle-adapter/formcycle-adapter-impl/src/main/java/de/itvsh/kop/eingang/formcycle/FormCycleFormDataMapper.java new file mode 100644 index 000000000..310d72889 --- /dev/null +++ b/formcycle-adapter/formcycle-adapter-impl/src/main/java/de/itvsh/kop/eingang/formcycle/FormCycleFormDataMapper.java @@ -0,0 +1,25 @@ +package de.itvsh.kop.eingang.formcycle; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; + +import de.itvsh.kop.eingangsadapter.common.formdata.FormData; +import de.itvsh.kop.eingangsadapter.formcycle.FormCycleFormData; +import de.itvsh.kop.pluto.common.grpc.GrpcFormDataMapper; + +@Mapper(uses = GrpcFormDataMapper.class) +public interface FormCycleFormDataMapper { + + @Mapping(target = "antragsteller", ignore = true) + @Mapping(target = "attachment", ignore = true) + @Mapping(target = "attachments", ignore = true) + @Mapping(target = "id", ignore = true) + @Mapping(target = "numberOfAttachments", ignore = true) + @Mapping(target = "numberOfRepresentations", ignore = true) + @Mapping(target = "representation", ignore = true) + @Mapping(target = "representations", ignore = true) + @Mapping(target = "zustaendigeStelle", ignore = true) + @Mapping(target = "header.formEngineName", constant = "FormCycle") + @Mapping(target = "header.createdAt", source = "header.receivedAt") + FormData toFormData(FormCycleFormData fcFormData); +} diff --git a/formcycle-adapter/formcycle-adapter-impl/src/main/java/de/itvsh/kop/eingang/formcycle/FormDataController.java b/formcycle-adapter/formcycle-adapter-impl/src/main/java/de/itvsh/kop/eingang/formcycle/FormDataController.java index fe89919f8..30c0492e0 100644 --- a/formcycle-adapter/formcycle-adapter-impl/src/main/java/de/itvsh/kop/eingang/formcycle/FormDataController.java +++ b/formcycle-adapter/formcycle-adapter-impl/src/main/java/de/itvsh/kop/eingang/formcycle/FormDataController.java @@ -7,15 +7,23 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import de.itvsh.kop.eingangsadapter.formcycle.ConfirmationResponse; -import de.itvsh.kop.eingangsadapter.formcycle.ProtobufFormData; +import de.itvsh.kop.eingangsadapter.formcycle.FormCycleFormData; +import de.itvsh.kop.eingangsadapter.semantik.SemantikAdapter; +import lombok.RequiredArgsConstructor; @Controller @ResponseBody @RequestMapping("formData") +@RequiredArgsConstructor class FormDataController { + private final FormCycleFormDataMapper mapper; + private final SemantikAdapter semantikAdapter; + @PostMapping(consumes = "application/protobuf", produces = "application/protobuf") - public ConfirmationResponse receiveFormData(@RequestBody ProtobufFormData formData) { - return ConfirmationResponse.newBuilder().setVorgangNummer("abc").build(); + public ConfirmationResponse receiveFormData(@RequestBody FormCycleFormData formData) { + semantikAdapter.processFormData(mapper.toFormData(formData)); + + return ConfirmationResponse.newBuilder().setVorgangNummer("TODO FILL ME").build(); } } diff --git a/formcycle-adapter/formcycle-adapter-impl/src/main/java/de/itvsh/kop/eingang/formcycle/FormcycleAdapterApplication.java b/formcycle-adapter/formcycle-adapter-impl/src/main/java/de/itvsh/kop/eingang/formcycle/FormcycleAdapterApplication.java index 3c51a5e52..a1769ce0a 100644 --- a/formcycle-adapter/formcycle-adapter-impl/src/main/java/de/itvsh/kop/eingang/formcycle/FormcycleAdapterApplication.java +++ b/formcycle-adapter/formcycle-adapter-impl/src/main/java/de/itvsh/kop/eingang/formcycle/FormcycleAdapterApplication.java @@ -4,12 +4,21 @@ import java.util.TimeZone; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.Bean; -@SpringBootApplication +import de.itvsh.kop.eingangsadapter.semantik.enginebased.EngineBasedSemantikAdapter; +import de.itvsh.kop.eingangsadapter.semantik.enginebased.formcycle.FormCycleEngineBasedAdapter; + +@SpringBootApplication(scanBasePackages = "de.itvsh.kop") public class FormcycleAdapterApplication { public static void main(String[] args) { TimeZone.setDefault(TimeZone.getTimeZone("UTC")); SpringApplication.run(FormcycleAdapterApplication.class, args); } + + @Bean + public EngineBasedSemantikAdapter engineBasedAdapter() { + return new FormCycleEngineBasedAdapter(); + } } diff --git a/formcycle-adapter/formcycle-adapter-impl/src/main/resources/application-local.yml b/formcycle-adapter/formcycle-adapter-impl/src/main/resources/application-local.yml index f3fa5ad3f..ee720c84d 100644 --- a/formcycle-adapter/formcycle-adapter-impl/src/main/resources/application-local.yml +++ b/formcycle-adapter/formcycle-adapter-impl/src/main/resources/application-local.yml @@ -1,3 +1,11 @@ +logging: + config: classpath:log4j2-local.xml + server: error: - include-stacktrace: always \ No newline at end of file + include-stacktrace: always + +kop: + adapter: + targetPlutoName: local + fallbackStrategy: DENY \ No newline at end of file diff --git a/formcycle-adapter/formcycle-adapter-impl/src/main/resources/application.yml b/formcycle-adapter/formcycle-adapter-impl/src/main/resources/application.yml index 0ce011207..4c77ae61a 100644 --- a/formcycle-adapter/formcycle-adapter-impl/src/main/resources/application.yml +++ b/formcycle-adapter/formcycle-adapter-impl/src/main/resources/application.yml @@ -3,6 +3,10 @@ logging: ROOT: WARN '[de.itvsh]': INFO +spring: + profiles: + include: formcycle + server: http2: enabled: true @@ -30,4 +34,8 @@ management: endpoints: web: exposure: - include: health,prometheus \ No newline at end of file + include: health,prometheus + +kop: + adapter: + routingStrategy: SINGLE \ No newline at end of file diff --git a/formcycle-adapter/formcycle-adapter-impl/src/test/java/de/itvsh/kop/eingang/formcycle/FormCycleFormDataMapperTest.java b/formcycle-adapter/formcycle-adapter-impl/src/test/java/de/itvsh/kop/eingang/formcycle/FormCycleFormDataMapperTest.java new file mode 100644 index 000000000..904b19da8 --- /dev/null +++ b/formcycle-adapter/formcycle-adapter-impl/src/test/java/de/itvsh/kop/eingang/formcycle/FormCycleFormDataMapperTest.java @@ -0,0 +1,32 @@ +package de.itvsh.kop.eingang.formcycle; + +import static org.assertj.core.api.Assertions.*; + +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; +import org.mapstruct.factory.Mappers; +import org.mockito.InjectMocks; +import org.mockito.Spy; + +import de.itvsh.kop.pluto.common.grpc.GrpcFormDataMapper; + +class FormCycleFormDataMapperTest { + + @InjectMocks + private FormCycleFormDataMapper mapper = Mappers.getMapper(FormCycleFormDataMapper.class); + + @Spy + private GrpcFormDataMapper formDataMapper = Mappers.getMapper(GrpcFormDataMapper.class); + + @Nested + class TestToFormData { + + @Test + void shouldMapHeader() { + var mapped = mapper.toFormData(FormCycleFormDataTestFactory.create()); + + assertThat(mapped.getHeader()).isNotNull(); + } + } + +} diff --git a/formcycle-adapter/formcycle-adapter-impl/src/test/java/de/itvsh/kop/eingang/formcycle/FormCycleFormDataTestFactory.java b/formcycle-adapter/formcycle-adapter-impl/src/test/java/de/itvsh/kop/eingang/formcycle/FormCycleFormDataTestFactory.java new file mode 100644 index 000000000..49d57631a --- /dev/null +++ b/formcycle-adapter/formcycle-adapter-impl/src/test/java/de/itvsh/kop/eingang/formcycle/FormCycleFormDataTestFactory.java @@ -0,0 +1,20 @@ +package de.itvsh.kop.eingang.formcycle; + +import de.itvsh.kop.eingangsadapter.formcycle.FormCycleFormData; +import de.itvsh.kop.eingangsadapter.formcycle.FormCycleFormData.Builder; +import de.itvsh.kop.pluto.common.grpc.GrpcFormDataTestFactory; + +class FormCycleFormDataTestFactory { + + static FormCycleFormData create() { + return createBuilder().build(); + } + + static Builder createBuilder() { + return FormCycleFormData.newBuilder() + .setHeader(FormCycleFormHeaderTestFactory.create()) + .setServiceKonto(FormCycleServiceKontoTestFactory.create()) + .setFormData(GrpcFormDataTestFactory.create()); + } + +} diff --git a/formcycle-adapter/formcycle-adapter-impl/src/test/java/de/itvsh/kop/eingang/formcycle/FormCycleFormHeaderTestFactory.java b/formcycle-adapter/formcycle-adapter-impl/src/test/java/de/itvsh/kop/eingang/formcycle/FormCycleFormHeaderTestFactory.java new file mode 100644 index 000000000..7b08d18b7 --- /dev/null +++ b/formcycle-adapter/formcycle-adapter-impl/src/test/java/de/itvsh/kop/eingang/formcycle/FormCycleFormHeaderTestFactory.java @@ -0,0 +1,20 @@ +package de.itvsh.kop.eingang.formcycle; + +import de.itvsh.kop.eingangsadapter.formcycle.FormCycleFormHeader; +import de.itvsh.kop.eingangsadapter.formcycle.FormCycleFormHeader.Builder; + +public class FormCycleFormHeaderTestFactory { + + static final String RECEIVED_AT = "2022-12-24T18:00:00Z"; + static final String FORM_NAME = "test form 1"; + + static FormCycleFormHeader create() { + return createBuilder().build(); + } + + static Builder createBuilder() { + return FormCycleFormHeader.newBuilder() + .setFormName(FORM_NAME) + .setReceivedAt(RECEIVED_AT); + } +} diff --git a/formcycle-adapter/formcycle-adapter-impl/src/test/java/de/itvsh/kop/eingang/formcycle/FormCycleServiceKontoTestFactory.java b/formcycle-adapter/formcycle-adapter-impl/src/test/java/de/itvsh/kop/eingang/formcycle/FormCycleServiceKontoTestFactory.java new file mode 100644 index 000000000..7c2366f53 --- /dev/null +++ b/formcycle-adapter/formcycle-adapter-impl/src/test/java/de/itvsh/kop/eingang/formcycle/FormCycleServiceKontoTestFactory.java @@ -0,0 +1,15 @@ +package de.itvsh.kop.eingang.formcycle; + +import de.itvsh.kop.eingangsadapter.formcycle.FormCycleServiceKonto; +import de.itvsh.kop.eingangsadapter.formcycle.FormCycleServiceKonto.Builder; + +public class FormCycleServiceKontoTestFactory { + + static FormCycleServiceKonto create() { + return createBuilder().build(); + } + + static Builder createBuilder() { + return FormCycleServiceKonto.newBuilder(); + } +} diff --git a/formcycle-adapter/formcycle-adapter-impl/src/test/java/de/itvsh/kop/eingang/formcycle/FormDataControllerTest.java b/formcycle-adapter/formcycle-adapter-impl/src/test/java/de/itvsh/kop/eingang/formcycle/FormDataControllerTest.java index 45cc2f972..cddf391ab 100644 --- a/formcycle-adapter/formcycle-adapter-impl/src/test/java/de/itvsh/kop/eingang/formcycle/FormDataControllerTest.java +++ b/formcycle-adapter/formcycle-adapter-impl/src/test/java/de/itvsh/kop/eingang/formcycle/FormDataControllerTest.java @@ -1,6 +1,8 @@ package de.itvsh.kop.eingang.formcycle; import static org.assertj.core.api.Assertions.*; +import static org.mockito.ArgumentMatchers.*; +import static org.mockito.Mockito.*; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; @@ -10,14 +12,16 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.mockito.InjectMocks; +import org.mockito.Mock; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.ResultActions; import org.springframework.test.web.servlet.setup.MockMvcBuilders; import de.itvsh.kop.eingang.formcycle.common.protobuf.ProtobufMessageConverter; +import de.itvsh.kop.eingangsadapter.common.formdata.FormData; +import de.itvsh.kop.eingangsadapter.common.formdata.FormDataTestFactory; import de.itvsh.kop.eingangsadapter.formcycle.ConfirmationResponse; -import de.itvsh.kop.eingangsadapter.formcycle.ProtobufFormData; -import de.itvsh.kop.eingangsadapter.formcycle.ProtobufFormHeader; +import de.itvsh.kop.eingangsadapter.semantik.SemantikAdapter; import lombok.SneakyThrows; class FormDataControllerTest { @@ -25,6 +29,11 @@ class FormDataControllerTest { @InjectMocks private FormDataController controller; + @Mock + private FormCycleFormDataMapper mapper; + @Mock + private SemantikAdapter semantikAdapter; + private MockMvc mockMvc; @BeforeEach @@ -36,6 +45,14 @@ class FormDataControllerTest { @Nested class ReceiveFormData { + + private FormData mappedFormData = FormDataTestFactory.create(); + + @BeforeEach + void init() { + when(mapper.toFormData(any())).thenReturn(mappedFormData); + } + @Test void shouldReturnSuccess() throws Exception { doPostRequest().andExpect(status().is2xxSuccessful()); @@ -47,7 +64,21 @@ class FormDataControllerTest { var confirmation = ConfirmationResponse.parseFrom( doPostRequest().andReturn().getResponse().getContentAsByteArray()); - assertThat(confirmation.getVorgangNummer()).isEqualTo("abc"); + assertThat(confirmation.getVorgangNummer()).isEqualTo("TODO FILL ME"); + } + + @Test + void shouldCallMapper() { + doPostRequest(); + + verify(mapper).toFormData(notNull()); + } + + @Test + void shouldCallSemantikAdapter() { + doPostRequest(); + + verify(semantikAdapter).processFormData(mappedFormData); } @SneakyThrows @@ -60,10 +91,8 @@ class FormDataControllerTest { @SneakyThrows static byte[] buildTestFormData() { - var header = ProtobufFormHeader.newBuilder().setFormName("test form 1").build(); - var formData = ProtobufFormData.newBuilder().setHeader(header).build(); var out = new ByteArrayOutputStream(); - formData.writeTo(out); + FormCycleFormDataTestFactory.create().writeTo(out); return out.toByteArray(); } diff --git a/formcycle-adapter/formcycle-adapter-interface/src/main/protobuf/form-data.model.proto b/formcycle-adapter/formcycle-adapter-interface/src/main/protobuf/form-data.model.proto index e689cff2a..11e41a6bd 100644 --- a/formcycle-adapter/formcycle-adapter-interface/src/main/protobuf/form-data.model.proto +++ b/formcycle-adapter/formcycle-adapter-interface/src/main/protobuf/form-data.model.proto @@ -25,7 +25,8 @@ syntax = "proto3"; package de.itvsh.kop.eingangsadapter.formcycle; -import "common.model.proto"; +/*import "common.model.proto";*/ +import "vorgangmodel.proto"; option java_multiple_files = true; option java_package = "de.itvsh.kop.eingangsadapter.formcycle"; @@ -35,24 +36,24 @@ message ConfirmationResponse { string vorgangNummer = 1; } -message ProtobufFormData { - ProtobufFormHeader header = 1; - ProtobufServiceKonto serviceKonto = 2; - de.itvsh.ozg.pluto.common.GrpcObject formData = 3; +message FormCycleFormData { + FormCycleFormHeader header = 1; + FormCycleServiceKonto serviceKonto = 2; + de.itvsh.ozg.pluto.vorgang.GrpcFormData formData = 3; } -message ProtobufFormHeader { +message FormCycleFormHeader { string receivedAt = 1; string formName = 2; string organisationsEinheitId = 3; } -message ProtobufServiceKonto { +message FormCycleServiceKonto { string type = 1; - ProtobufPostfachAddress address = 2; + FormCyclePostfachAddress address = 2; } -message ProtobufPostfachAddress { +message FormCyclePostfachAddress { string version = 1; string identifier = 2; } \ No newline at end of file diff --git a/formcycle-adapter/pom.xml b/formcycle-adapter/pom.xml index 5ad24b1af..6bb882554 100644 --- a/formcycle-adapter/pom.xml +++ b/formcycle-adapter/pom.xml @@ -45,6 +45,24 @@ <properties> <spring-boot.build-image.imageName>docker.ozg-sh.de/formcycle-adapter:build-latest</spring-boot.build-image.imageName> + + <pluto.version>1.3.0-SNAPSHOT</pluto.version> </properties> - + + <dependencyManagement> + <dependencies> + <dependency> + <groupId>de.itvsh.ozg.pluto</groupId> + <artifactId>pluto-utils</artifactId> + <version>${pluto.version}</version> + </dependency> + <dependency> + <groupId>de.itvsh.ozg.pluto</groupId> + <artifactId>pluto-utils</artifactId> + <version>${pluto.version}</version> + <type>test-jar</type> + <scope>test</scope> + </dependency> + </dependencies> + </dependencyManagement> </project> \ No newline at end of file diff --git a/semantik-adapter/src/main/java/de/itvsh/kop/eingangsadapter/semantik/enginebased/formcycle/FormCycleEngineBasedAdapter.java b/semantik-adapter/src/main/java/de/itvsh/kop/eingangsadapter/semantik/enginebased/formcycle/FormCycleEngineBasedAdapter.java new file mode 100644 index 000000000..94251e2f6 --- /dev/null +++ b/semantik-adapter/src/main/java/de/itvsh/kop/eingangsadapter/semantik/enginebased/formcycle/FormCycleEngineBasedAdapter.java @@ -0,0 +1,13 @@ +package de.itvsh.kop.eingangsadapter.semantik.enginebased.formcycle; + +import de.itvsh.kop.eingangsadapter.common.formdata.FormData; +import de.itvsh.kop.eingangsadapter.semantik.enginebased.EngineBasedSemantikAdapter; + +public class FormCycleEngineBasedAdapter implements EngineBasedSemantikAdapter { + + @Override + public FormData parseFormData(FormData formData) { + return formData; + } + +} diff --git a/semantik-adapter/src/test/java/de/itvsh/kop/eingangsadapter/semantik/enginebased/formcycle/FormCycleEngineBasedAdapterTest.java b/semantik-adapter/src/test/java/de/itvsh/kop/eingangsadapter/semantik/enginebased/formcycle/FormCycleEngineBasedAdapterTest.java new file mode 100644 index 000000000..4bf62f573 --- /dev/null +++ b/semantik-adapter/src/test/java/de/itvsh/kop/eingangsadapter/semantik/enginebased/formcycle/FormCycleEngineBasedAdapterTest.java @@ -0,0 +1,24 @@ +package de.itvsh.kop.eingangsadapter.semantik.enginebased.formcycle; + +import static org.assertj.core.api.Assertions.*; + +import org.junit.jupiter.api.Test; +import org.mockito.InjectMocks; + +import de.itvsh.kop.eingangsadapter.common.formdata.FormDataTestFactory; + +class FormCycleEngineBasedAdapterTest { + + @InjectMocks + private FormCycleEngineBasedAdapter adapter; + + @Test + void shouldUnprocessedData() { + var formData = FormDataTestFactory.create(); + + var result = adapter.parseFormData(formData); + + assertThat(result).isSameAs(formData); + } + +} -- GitLab