From 1215d66040cb6becb8a98385b624235430b05170 Mon Sep 17 00:00:00 2001 From: Paulo Gomes da Cruz Junior Date: Wed, 10 Jan 2024 10:56:10 -0800 Subject: [PATCH 01/14] fix(FSADT1-1101): updating mail configuration on test --- .github/workflows/merge-main.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/merge-main.yml b/.github/workflows/merge-main.yml index 3a2f169e39..d522507a8b 100644 --- a/.github/workflows/merge-main.yml +++ b/.github/workflows/merge-main.yml @@ -258,8 +258,8 @@ jobs: parameters: -p ZONE=${{ env.ZONE }} -p NAME=${{ github.event.repository.name }} -p PROMOTE=${{ github.repository }}/backend:${{ env.ZONE }} - -p CHES_TOKEN_URL='https://test.loginproxy.gov.bc.ca/auth/realms/comsvcauth/protocol/openid-connect/token' - -p CHES_API_URL='https://ches-test.api.gov.bc.ca/api/v1/email' + -p CHES_TOKEN_URL='https://loginproxy.gov.bc.ca/auth/realms/comsvcauth/protocol/openid-connect/token' + -p CHES_API_URL='https://ches.api.gov.bc.ca/api/v1/email' -p BCREGISTRY_URI='https://bcregistry-prod.apigee.net' -p COGNITO_REGION=ca-central-1 -p COGNITO_COOKIE_DOMAIN=gov.bc.ca From d81601f488c7e574b259fefb69d2d4d4d9cbe958 Mon Sep 17 00:00:00 2001 From: Paulo Gomes da Cruz Junior Date: Wed, 10 Jan 2024 11:42:21 -0800 Subject: [PATCH 02/14] fix(FSADT1-1059): adding corporation to list --- backend/src/main/java/ca/bc/gov/app/ApplicationConstant.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/main/java/ca/bc/gov/app/ApplicationConstant.java b/backend/src/main/java/ca/bc/gov/app/ApplicationConstant.java index 81c3c410a2..b097d6774c 100644 --- a/backend/src/main/java/ca/bc/gov/app/ApplicationConstant.java +++ b/backend/src/main/java/ca/bc/gov/app/ApplicationConstant.java @@ -93,6 +93,6 @@ left join nrfc.province_code pc on (pc.province_code = sl.province_code and pc.c public static final String ID_TOKEN = "idToken"; public static final String ACCESS_TOKEN = "accessToken"; public static final List AVAILABLE_CLIENT_TYPES = List.of("A", "I", "S", "SP", "RSP", - "USP", "BC", "GP"); + "USP", "BC", "GP","C"); } From 8a7a099465b5eaf8a499faefe1854aad0e5768d0 Mon Sep 17 00:00:00 2001 From: Paulo Gomes da Cruz Junior Date: Wed, 10 Jan 2024 12:08:40 -0800 Subject: [PATCH 03/14] fix(FSADT1-1106): moving copy emails to bcc --- .../main/java/ca/bc/gov/app/service/ches/ChesService.java | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/backend/src/main/java/ca/bc/gov/app/service/ches/ChesService.java b/backend/src/main/java/ca/bc/gov/app/service/ches/ChesService.java index 6117b2b831..b30d66cfa5 100644 --- a/backend/src/main/java/ca/bc/gov/app/service/ches/ChesService.java +++ b/backend/src/main/java/ca/bc/gov/app/service/ches/ChesService.java @@ -82,10 +82,6 @@ public Mono sendEmail(String templateName, Map variables, Integer emailLogId) { - List emails = new ArrayList<>(); - emails.add(emailAddress); - emails.addAll(configuration.getChes().getCopyEmail()); - String processedSubject = configuration.getCognito().getEnvironment().equalsIgnoreCase("prod") ? subject @@ -93,7 +89,7 @@ public Mono sendEmail(String templateName, return this .buildTemplate(templateName, variables) - .map(body -> new ChesRequestDto(emails, body)) + .map(body -> new ChesRequestDto(List.of(emailAddress), body)) .flatMap(chesRequestDto -> this .sendEmail(chesRequestDto, processedSubject) @@ -212,7 +208,7 @@ public Mono sendEmail(ChesRequestDto requestContent, String subject) { .map(request -> new ChesMailRequest( null, - null, + configuration.getChes().getCopyEmail(), ChesMailBodyType.HTML, request.emailBody(), null, From 219dd90ae1395b5fe204bc4e26dcf0156a54d4bb Mon Sep 17 00:00:00 2001 From: Paulo Gomes da Cruz Junior Date: Wed, 10 Jan 2024 12:12:32 -0800 Subject: [PATCH 04/14] fix(FSADT1-1106): fixing ches copy mail list --- backend/openshift.deploy.yml | 5 +++++ common/openshift.init.yml | 1 + 2 files changed, 6 insertions(+) diff --git a/backend/openshift.deploy.yml b/backend/openshift.deploy.yml index abe7ffae51..1a3fb6af27 100644 --- a/backend/openshift.deploy.yml +++ b/backend/openshift.deploy.yml @@ -125,6 +125,11 @@ objects: value: ${CHES_API_URL} - name: POSTGRESQL_HOST value: ${NAME}-${ZONE}-database + - name: CHES_COPY_EMAIL + valueFrom: + secretKeyRef: + name: ${NAME}-${ZONE} + key: ches-mail-copy - name: POSTGRESQL_DATABASE valueFrom: secretKeyRef: diff --git a/common/openshift.init.yml b/common/openshift.init.yml index 5a5c5d7d6e..2129ebf51f 100644 --- a/common/openshift.init.yml +++ b/common/openshift.init.yml @@ -120,6 +120,7 @@ objects: cognito-environment: ${COGNITO_ENVIRONMENT} cognito-redirect-uri: ${COGNITO_REDIRECT_URI} cognito-logout-uri: ${COGNITO_LOGOUT_URI} + ches-mail-copy: ${CHES_MAIL_COPY} - apiVersion: networking.k8s.io/v1 kind: NetworkPolicy metadata: From 928553a80af03efe31f0184047e01e06c057d206 Mon Sep 17 00:00:00 2001 From: Paulo Gomes da Cruz Junior Date: Wed, 10 Jan 2024 14:54:14 -0800 Subject: [PATCH 05/14] chore: adding logs to track down mail message --- .../app/service/client/ClientSubmissionLoadingService.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/processor/src/main/java/ca/bc/gov/app/service/client/ClientSubmissionLoadingService.java b/processor/src/main/java/ca/bc/gov/app/service/client/ClientSubmissionLoadingService.java index 46ae337474..be4933d2a0 100644 --- a/processor/src/main/java/ca/bc/gov/app/service/client/ClientSubmissionLoadingService.java +++ b/processor/src/main/java/ca/bc/gov/app/service/client/ClientSubmissionLoadingService.java @@ -76,9 +76,13 @@ public Mono> sendNotification(Message message) return submissionDetailRepository .findBySubmissionId(message.getPayload()) + .doOnNext( + submission -> log.info("Loaded submission details for mail purpose {}", submission)) .flatMap(details -> contactRepository .findFirstBySubmissionId(message.getPayload()) + .doOnNext(submissionContact -> log.info( + "Loaded submission contact details for mail purpose {}", submissionContact)) .map(submissionContact -> new EmailRequestDto( details.getIncorporationNumber(), From cc23ce4191b3ca03364e8862022ad0edfb0228b1 Mon Sep 17 00:00:00 2001 From: Paulo Gomes da Cruz Junior Date: Wed, 10 Jan 2024 15:40:02 -0800 Subject: [PATCH 06/14] feat(FSADT1-1101): changing birthdate to be localdatetime --- legacy/src/main/java/ca/bc/gov/app/dto/ForestClientDto.java | 4 ++-- .../main/java/ca/bc/gov/app/entity/ForestClientEntity.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/legacy/src/main/java/ca/bc/gov/app/dto/ForestClientDto.java b/legacy/src/main/java/ca/bc/gov/app/dto/ForestClientDto.java index 5c4074676e..f717ae9703 100644 --- a/legacy/src/main/java/ca/bc/gov/app/dto/ForestClientDto.java +++ b/legacy/src/main/java/ca/bc/gov/app/dto/ForestClientDto.java @@ -1,6 +1,6 @@ package ca.bc.gov.app.dto; -import java.time.LocalDate; +import java.time.LocalDateTime; public record ForestClientDto( String clientNumber, @@ -9,7 +9,7 @@ public record ForestClientDto( String legalMiddleName, String clientStatusCode, String clientTypeCode, - LocalDate birthdate, + LocalDateTime birthdate, String clientIdTypeCode, String clientIdentification, String registryCompanyTypeCode, diff --git a/legacy/src/main/java/ca/bc/gov/app/entity/ForestClientEntity.java b/legacy/src/main/java/ca/bc/gov/app/entity/ForestClientEntity.java index cf59f6967c..7199f3eae7 100644 --- a/legacy/src/main/java/ca/bc/gov/app/entity/ForestClientEntity.java +++ b/legacy/src/main/java/ca/bc/gov/app/entity/ForestClientEntity.java @@ -40,7 +40,7 @@ public class ForestClientEntity { @Column("CLIENT_TYPE_CODE") private String clientTypeCode; @Column("BIRTHDATE") - private LocalDate birthdate; + private LocalDateTime birthdate; @Column("CLIENT_ID_TYPE_CODE") private String clientIdTypeCode; @Column("CLIENT_IDENTIFICATION ") From f52480c1061f4be430fefdbc26fede860c436a15 Mon Sep 17 00:00:00 2001 From: Paulo Gomes da Cruz Junior Date: Wed, 10 Jan 2024 15:50:04 -0800 Subject: [PATCH 07/14] feat(FSADT1-1101): fixing birthdate --- .../main/java/ca/bc/gov/app/dto/ForestClientDto.java | 4 ++-- .../gov/app/mappers/AbstractForestClientMapper.java | 11 +++++++++++ .../ca/bc/gov/app/mappers/ForestClientMapper.java | 10 ++++++++++ .../java/ca/bc/gov/app/service/ClientService.java | 2 +- 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/legacy/src/main/java/ca/bc/gov/app/dto/ForestClientDto.java b/legacy/src/main/java/ca/bc/gov/app/dto/ForestClientDto.java index f717ae9703..5c4074676e 100644 --- a/legacy/src/main/java/ca/bc/gov/app/dto/ForestClientDto.java +++ b/legacy/src/main/java/ca/bc/gov/app/dto/ForestClientDto.java @@ -1,6 +1,6 @@ package ca.bc.gov.app.dto; -import java.time.LocalDateTime; +import java.time.LocalDate; public record ForestClientDto( String clientNumber, @@ -9,7 +9,7 @@ public record ForestClientDto( String legalMiddleName, String clientStatusCode, String clientTypeCode, - LocalDateTime birthdate, + LocalDate birthdate, String clientIdTypeCode, String clientIdentification, String registryCompanyTypeCode, diff --git a/legacy/src/main/java/ca/bc/gov/app/mappers/AbstractForestClientMapper.java b/legacy/src/main/java/ca/bc/gov/app/mappers/AbstractForestClientMapper.java index a7228e3ac8..09ac0a4284 100644 --- a/legacy/src/main/java/ca/bc/gov/app/mappers/AbstractForestClientMapper.java +++ b/legacy/src/main/java/ca/bc/gov/app/mappers/AbstractForestClientMapper.java @@ -1,5 +1,6 @@ package ca.bc.gov.app.mappers; +import java.time.LocalDate; import java.time.LocalDateTime; import java.util.Objects; import org.mapstruct.InheritInverseConfiguration; @@ -28,4 +29,14 @@ default Long initialRevision(Object value) { return Objects.isNull(value) || !(value instanceof Long) ? 1L : (Long) value; } + @Named("LocalDateTimeDateQualifier") + default LocalDate toLocalDate(LocalDateTime date) { + return date == null ? null : date.toLocalDate(); + } + + @Named("LocalDateDateTimeQualifier") + default LocalDateTime toLocalDateTime(LocalDate date) { + return date == null ? null : date.atStartOfDay(); + } + } diff --git a/legacy/src/main/java/ca/bc/gov/app/mappers/ForestClientMapper.java b/legacy/src/main/java/ca/bc/gov/app/mappers/ForestClientMapper.java index 612895511c..f6a5336453 100644 --- a/legacy/src/main/java/ca/bc/gov/app/mappers/ForestClientMapper.java +++ b/legacy/src/main/java/ca/bc/gov/app/mappers/ForestClientMapper.java @@ -44,6 +44,11 @@ public interface ForestClientMapper extends source = "clientNumber", qualifiedByName = "InitialRevisionQualifier" ) + @Mapping( + target = "birthdate", + source = "birthdate", + qualifiedByName = "LocalDateDateTimeQualifier" + ) ForestClientEntity toEntity(ForestClientDto dto); @Override @@ -52,5 +57,10 @@ public interface ForestClientMapper extends target= "orgUnit", qualifiedByName = "InitialRevisionQualifier" ) + @Mapping( + target = "birthdate", + source = "birthdate", + qualifiedByName = "LocalDateTimeDateQualifier" + ) ForestClientDto toDto(ForestClientEntity entity); } diff --git a/legacy/src/main/java/ca/bc/gov/app/service/ClientService.java b/legacy/src/main/java/ca/bc/gov/app/service/ClientService.java index 93dd2a0f81..fb5ee1e933 100644 --- a/legacy/src/main/java/ca/bc/gov/app/service/ClientService.java +++ b/legacy/src/main/java/ca/bc/gov/app/service/ClientService.java @@ -55,7 +55,7 @@ private Mono locateClient( .findByIndividual( entity.getLegalFirstName(), entity.getClientName(), - entity.getBirthdate().atStartOfDay() + entity.getBirthdate() ) .map(client -> false) // means you can't create it .defaultIfEmpty(true) From 4cdd3de4da952edf92e60834711e278e9b6b3a03 Mon Sep 17 00:00:00 2001 From: Paulo Gomes da Cruz Junior Date: Fri, 12 Jan 2024 09:53:42 -0800 Subject: [PATCH 08/14] fix(FSADT1-1101|FSADT1-1103|FSADT1-1113|FSADT1-118FSADT1-1106): fixing email for processing --- .../main/resources/templates/rejection.html | 4 +- processor/pom.xml | 982 +++++++++--------- .../ca/bc/gov/app/ApplicationConstant.java | 24 +- .../ca/bc/gov/app/ProcessorApplication.java | 10 +- .../GlobalServiceConfiguration.java | 4 +- .../ProcessorIntegrationConfiguration.java | 188 ---- .../ca/bc/gov/app/dto/MessagingWrapper.java | 22 + .../app/repository/SubmissionRepository.java | 20 + ...ClientSubmissionAutoProcessingService.java | 74 +- .../ClientSubmissionLoadingService.java | 162 ++- .../client/ClientSubmissionMailService.java | 28 +- .../ClientSubmissionProcessingService.java | 140 +-- .../LegacyAbstractPersistenceService.java | 220 ++-- .../LegacyClientPersistenceService.java | 40 +- .../LegacyIndividualPersistenceService.java | 37 +- .../service/legacy/LegacyLoadingService.java | 49 +- .../legacy/LegacyPersistenceService.java | 58 ++ .../LegacyRegisteredSPPersistenceService.java | 47 +- ...egacyUnregisteredSPPersistenceService.java | 37 +- .../service/processor/ProcessorService.java | 129 +++ .../ca/bc/gov/app/util/ProcessorUtil.java | 11 - .../app/service/ProcessorIntegrationTest.java | 10 +- ...nAutoProcessingServiceIntegrationTest.java | 60 +- .../ClientSubmissionLoadingServiceTest.java | 57 +- .../ClientSubmissionMailServiceTest.java | 43 +- ...ssionProcessingServiceIntegrationTest.java | 168 +-- ...ractPersistenceServiceIntegrationTest.java | 16 +- .../LegacyAbstractPersistenceServiceTest.java | 241 ++--- .../LegacyClientPersistenceServiceTest.java | 47 +- ...egacyIndividualPersistenceServiceTest.java | 46 +- .../legacy/LegacyLoadingServiceTest.java | 43 +- ...acyRegisteredSPPersistenceServiceTest.java | 106 +- ...yUnregisteredSPPersistenceServiceTest.java | 43 +- .../ca/bc/gov/app/util/ProcessorUtilTest.java | 28 +- 34 files changed, 1373 insertions(+), 1821 deletions(-) delete mode 100644 processor/src/main/java/ca/bc/gov/app/configuration/ProcessorIntegrationConfiguration.java create mode 100644 processor/src/main/java/ca/bc/gov/app/dto/MessagingWrapper.java create mode 100644 processor/src/main/java/ca/bc/gov/app/service/legacy/LegacyPersistenceService.java create mode 100644 processor/src/main/java/ca/bc/gov/app/service/processor/ProcessorService.java diff --git a/backend/src/main/resources/templates/rejection.html b/backend/src/main/resources/templates/rejection.html index f24d89568d..cb1d3a82f7 100644 --- a/backend/src/main/resources/templates/rejection.html +++ b/backend/src/main/resources/templates/rejection.html @@ -18,10 +18,10 @@
 

- Your application for a client number can't go ahead because ${name} + Your application for a client number can't go ahead because ${business.name} already has one.

-

The number is ${number}. Be sure to keep it for your records.

+

${reason}

 

diff --git a/processor/pom.xml b/processor/pom.xml index b70a841a0d..ffa3595b5a 100644 --- a/processor/pom.xml +++ b/processor/pom.xml @@ -1,499 +1,493 @@ - 4.0.0 - - org.springframework.boot - spring-boot-starter-parent - 3.2.0 - - - - ca.bc.gov.nrs - nr-forest-client-processor - 0.0.1-SNAPSHOT - nr-forest-client-processor - Forest Client Background Processor + xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 3.2.0 + + + + ca.bc.gov.nrs + nr-forest-client-processor + 0.0.1-SNAPSHOT + nr-forest-client-processor + Forest Client Background Processor + - - Apache License, Version 2.0 - https://www.apache.org/licenses/LICENSE-2.0.txt - repo - - - - UTF-8 - UTF-8 - 17 - 17 - 3.10.1 - ${java.version} - ${java.version} - true - false - true - true - ${project.build.directory}/coverage-reports - ${maven.build.timestamp} - yyyy-MM-dd HH:mm:ss - 1.19.1 - 5.9.1 - 1.9.1 - 3.24.2 - ${project.version} - + + Apache License, Version 2.0 + https://www.apache.org/licenses/LICENSE-2.0.txt + repo + + + + + UTF-8 + UTF-8 + 17 + 17 + 3.10.1 + ${java.version} + ${java.version} + true + false + true + true + ${project.build.directory}/coverage-reports + ${maven.build.timestamp} + yyyy-MM-dd HH:mm:ss + 1.19.1 + 5.9.1 + 1.9.1 + 3.24.2 + ${project.version} + + - - org.springframework.boot - spring-boot-starter-actuator - - - org.springframework.boot - spring-boot-starter-data-r2dbc - - - org.springframework.boot - spring-boot-starter-integration - - - org.springframework.boot - spring-boot-starter-webflux - - - org.springframework.integration - spring-integration-r2dbc - - - org.springframework.boot - spring-boot-starter-validation - - - org.springframework.boot - spring-boot-starter-aop - - - io.micrometer - micrometer-registry-prometheus - - - org.postgresql - postgresql - runtime - - - org.postgresql - r2dbc-postgresql - - - org.projectlombok - lombok - true - - - org.apache.commons - commons-lang3 - - - org.springframework.boot - spring-boot-starter-test - test - - - io.projectreactor - reactor-test - test - - - org.junit.jupiter - junit-jupiter-params - test - - - org.awaitility - awaitility - test - - - org.springframework.integration - spring-integration-test - test - - - org.testcontainers - junit-jupiter - test - - - org.testcontainers - postgresql - test - - - org.testcontainers - r2dbc - test - - - org.flywaydb - flyway-core - 9.16.3 - test - - - org.springframework - spring-jdbc - test - - - org.wiremock - wiremock-standalone - 3.3.1 - test - - - - - - org.testcontainers - testcontainers-bom - ${testcontainers.version} - pom - import - - - org.yaml - snakeyaml - 2.2 - - - io.projectreactor.netty - reactor-netty-http - 1.1.13 - - - - - - - true - src/main/resources - - application* - - - - - - org.apache.maven.plugins - maven-resources-plugin - 3.1.0 - - - org.graalvm.buildtools - native-maven-plugin - - - org.springframework.boot - spring-boot-maven-plugin - - - - org.projectlombok - lombok - - - - - - org.apache.maven.plugins - maven-failsafe-plugin - 3.2.2 - - - integration-tests - - integration-test - verify - - - @{argLine} - false - ${skip.integration.tests} - - **/*IntegrationTest.java - - - - - - - org.apache.maven.plugins - maven-surefire-plugin - 3.2.2 - - @{argLine} - ${skip.unit.tests} - - **/*IntegrationTest.java - - - - cucumber.junit-platform.naming-strategy=long - - - - - - org.jacoco - jacoco-maven-plugin - 0.8.11 - - ${jacoco.skip} - - **/configuration/** - **/exception/** - **/dto/** - **/entity/** - **/repository/** - **/*$*Builder* - **/BootApplication* - - - - - pre-unit-test - - prepare-agent - - - ${jacoco.output.data}/jacoco-ut.exec - - - - post-unit-test - test - - report - - - ${jacoco.output.data}/jacoco-ut.exec - ${jacoco.output.data}/jacoco-ut - - - - pre-integration-test - pre-integration-test - - prepare-agent-integration - - - ${jacoco.output.data}/jacoco-it.exec - - - - post-integration-test - post-integration-test - - report-integration - - - ${jacoco.output.data}/jacoco-it.exec - ${jacoco.output.data}/jacoco-it - - - - merge-unit-and-integration - post-integration-test - - merge - - - - - ${jacoco.output.data} - - *.exec - - - - ${project.build.directory}/jacoco.exec - - - - merged-reports - post-integration-test - - report - - - ${project.build.directory}/jacoco.exec - ${jacoco.output.data}/merged-test-report - - - - coverage-check - - check - - - - - BUNDLE - - - LINE - COVEREDRATIO - 80% - - - - - - - - - - org.apache.maven.plugins - maven-javadoc-plugin - 3.6.2 - - 8 - Javadoc Documentation for ${project.name} ${project.version} - - ${project.name} ${project.version} - - - - - org.apache.maven.plugins - maven-enforcer-plugin - 3.4.1 - - - default-cli - - enforce - - - - - - [3.2,) - Invalid Maven version. It should be at least 3.2 - - - 17 - Invalid Java Version. It should be at least 17 - - - - central - spring-milestones - - - central - spring-milestones - - - - No Snapshots Allowed in releases! - true - - - - - - - - - org.apache.maven.plugins - maven-checkstyle-plugin - 3.3.1 - - ${checkstyle.skip} - google_checks.xml - true - true - false - - - - validate - validate - - check - - - - - - org.cyclonedx - cyclonedx-maven-plugin - 2.7.10 - - - validate - - makeAggregateBom - - - - - ${checkstyle.skip} - application - all - bom - - - - nr-forest-client-processor - - - - dev - - - all-tests - - all-tests - false - false - false - - - - integration-test - - integration-test - false - true - - - - macos - - - mac - aarch64 - - - - - io.netty - netty-resolver-dns-native-macos - osx-aarch_64 - - - - - native - - native - true - true - - - + + org.springframework.boot + spring-boot-starter-webflux + + + org.springframework.boot + spring-boot-starter-actuator + + + org.springframework.boot + spring-boot-starter-data-r2dbc + + + org.springframework.boot + spring-boot-starter-aop + + + io.micrometer + micrometer-registry-prometheus + + + org.postgresql + postgresql + runtime + + + org.postgresql + r2dbc-postgresql + + + org.projectlombok + lombok + true + + + org.apache.commons + commons-lang3 + + + org.springframework.boot + spring-boot-starter-test + test + + + io.projectreactor + reactor-test + test + + + org.junit.jupiter + junit-jupiter-params + test + + + org.awaitility + awaitility + test + + + org.testcontainers + junit-jupiter + test + + + org.testcontainers + postgresql + test + + + org.testcontainers + r2dbc + test + + + org.flywaydb + flyway-core + 9.16.3 + test + + + org.springframework + spring-jdbc + test + + + org.wiremock + wiremock-standalone + 3.3.1 + test + + + + + + + org.testcontainers + testcontainers-bom + ${testcontainers.version} + pom + import + + + org.yaml + snakeyaml + 2.2 + + + io.projectreactor.netty + reactor-netty-http + 1.1.13 + + + + + + + + true + src/main/resources + + application* + + + + + + org.apache.maven.plugins + maven-resources-plugin + 3.1.0 + + + org.graalvm.buildtools + native-maven-plugin + + + org.springframework.boot + spring-boot-maven-plugin + + + + org.projectlombok + lombok + + + + + + org.apache.maven.plugins + maven-failsafe-plugin + 3.2.2 + + + integration-tests + + integration-test + verify + + + @{argLine} + false + ${skip.integration.tests} + + **/*IntegrationTest.java + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 3.2.2 + + @{argLine} + ${skip.unit.tests} + + **/*IntegrationTest.java + + + + cucumber.junit-platform.naming-strategy=long + + + + + + org.jacoco + jacoco-maven-plugin + 0.8.11 + + ${jacoco.skip} + + **/configuration/** + **/exception/** + **/dto/** + **/entity/** + **/repository/** + **/*$*Builder* + **/BootApplication* + + + + + pre-unit-test + + prepare-agent + + + ${jacoco.output.data}/jacoco-ut.exec + + + + post-unit-test + test + + report + + + ${jacoco.output.data}/jacoco-ut.exec + ${jacoco.output.data}/jacoco-ut + + + + pre-integration-test + pre-integration-test + + prepare-agent-integration + + + ${jacoco.output.data}/jacoco-it.exec + + + + post-integration-test + post-integration-test + + report-integration + + + ${jacoco.output.data}/jacoco-it.exec + ${jacoco.output.data}/jacoco-it + + + + merge-unit-and-integration + post-integration-test + + merge + + + + + ${jacoco.output.data} + + *.exec + + + + ${project.build.directory}/jacoco.exec + + + + merged-reports + post-integration-test + + report + + + ${project.build.directory}/jacoco.exec + ${jacoco.output.data}/merged-test-report + + + + coverage-check + + check + + + + + BUNDLE + + + LINE + COVEREDRATIO + 80% + + + + + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 3.6.2 + + 8 + Javadoc Documentation for ${project.name} ${project.version} + + ${project.name} ${project.version} + + + + + org.apache.maven.plugins + maven-enforcer-plugin + 3.4.1 + + + default-cli + + enforce + + + + + + [3.2,) + Invalid Maven version. It should be at least 3.2 + + + 17 + Invalid Java Version. It should be at least 17 + + + + central + spring-milestones + + + central + spring-milestones + + + + No Snapshots Allowed in releases! + true + + + + + + + + + org.apache.maven.plugins + maven-checkstyle-plugin + 3.3.1 + + ${checkstyle.skip} + google_checks.xml + true + true + false + + + + validate + validate + + check + + + + + + org.cyclonedx + cyclonedx-maven-plugin + 2.7.10 + + + validate + + makeAggregateBom + + + + + ${checkstyle.skip} + application + all + bom + + + + nr-forest-client-processor + + + + + dev + + + all-tests + + all-tests + false + false + false + + + + integration-test + + integration-test + false + true + + + + macos + + + mac + aarch64 + + + + + io.netty + netty-resolver-dns-native-macos + osx-aarch_64 + + + + + native + + native + true + true + + + + \ No newline at end of file diff --git a/processor/src/main/java/ca/bc/gov/app/ApplicationConstant.java b/processor/src/main/java/ca/bc/gov/app/ApplicationConstant.java index 84c074912c..2656e8c90e 100644 --- a/processor/src/main/java/ca/bc/gov/app/ApplicationConstant.java +++ b/processor/src/main/java/ca/bc/gov/app/ApplicationConstant.java @@ -9,30 +9,17 @@ @NoArgsConstructor(access = AccessLevel.PRIVATE) public final class ApplicationConstant { + public static final String POSTGRES_ATTRIBUTE_SCHEMA = "nrfc"; - public static final String SUBMISSION_POSTPROCESSOR_CHANNEL = "submissionCompletedChannel"; - public static final String NOTIFICATION_PROCESSING_CHANNEL = "notificationProcessingChannel"; - public static final String SUBMISSION_COMPLETION_CHANNEL = "submissionCompletionChannel"; - public static final String SUBMISSION_LEGACY_CHANNEL = "saveToLegacyChannel"; - public static final String SUBMISSION_LIST_CHANNEL = "submissionListChannel"; - public static final String MATCH_CHECKING_CHANNEL = "matchCheckingChannel"; - public static final String FORWARD_CHANNEL = "forwardChannel"; public static final String AUTO_APPROVE_CHANNEL = "autoApproveChannel"; public static final String REVIEW_CHANNEL = "reviewChannel"; - public static final String SUBMISSION_MAIL_CHANNEL = "submissionMailChannel"; - public static final String SUBMISSION_LEGACY_CLIENT_CHANNEL = "submissionLegacyClientChannel"; - public static final String SUBMISSION_LEGACY_CLIENT_PERSIST_CHANNEL = "submissionLegacyClientPersistChannel"; - public static final String SUBMISSION_LEGACY_LOCATION_CHANNEL = "submissionLegacyLocationChannel"; - public static final String SUBMISSION_LEGACY_CONTACT_CHANNEL = "submissionLegacyContactChannel"; - public static final String SUBMISSION_LEGACY_NOTIFY_CHANNEL = "submissionLegacyNotifyChannel"; public static final String SUBMISSION_ID = "submission-id"; public static final String SUBMISSION_STATUS = "submission-status"; public static final String SUBMISSION_CLIENTID = "submission-clientid"; public static final String SUBMISSION_TYPE = "submission-type-code"; public static final String SUBMISSION_NAME = "submission-name"; - public static final String SUBMISSION_MESSAGE_SOURCE = "submissionMessages"; - public static final String PROCESSED_MESSAGE_SOURCE = "processedMessage"; + public static final String CREATED_BY = "createdBy"; public static final String UPDATED_BY = "updatedBy"; public static final String FOREST_CLIENT_NUMBER = "forestClientNumber"; @@ -44,16 +31,13 @@ public final class ApplicationConstant { public static final String PROCESSOR_USER_NAME = "IDIR\\OTTOMATED"; public static final long ORG_UNIT = 70L; public static final String LOCATION_CODE = "locationCode"; - public static final String SUBMISSION_MAIL_BUILD_CHANNEL = "submissionMailBuildChannel"; public static final String CLIENT_TYPE_CODE = "CLIENT_TYPE_CODE"; - public static final String SUBMISSION_LEGACY_INDIVIDUAL_CHANNEL = "submissionLegacyIndividualChannel"; - public static final String SUBMISSION_LEGACY_USP_CHANNEL = "submissionLegacyUSPChannel"; - public static final String SUBMISSION_LEGACY_RSP_CHANNEL = "submissionLegacyRSPChannel"; - public static final String SUBMISSION_LEGACY_OTHER_CHANNEL = "submissionLegacyOtherChannel"; public static final String CLIENT_SUBMITTER_NAME = "client-submitter-name"; public static final String MATCH_PARAM_NAME = "corporationName"; + public static final String MATCHING_REASON = "matching-reason"; + public static final BcRegistryDocumentRequestBodyDto BUSINESS_SUMMARY_FILING_HISTORY = new BcRegistryDocumentRequestBodyDto( diff --git a/processor/src/main/java/ca/bc/gov/app/ProcessorApplication.java b/processor/src/main/java/ca/bc/gov/app/ProcessorApplication.java index 7421358dcd..4940e4a126 100644 --- a/processor/src/main/java/ca/bc/gov/app/ProcessorApplication.java +++ b/processor/src/main/java/ca/bc/gov/app/ProcessorApplication.java @@ -2,14 +2,14 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.integration.config.EnableIntegration; +import org.springframework.scheduling.annotation.EnableScheduling; @SpringBootApplication -@EnableIntegration +@EnableScheduling public class ProcessorApplication { - public static void main(String[] args) { - SpringApplication.run(ProcessorApplication.class, args); - } + public static void main(String[] args) { + SpringApplication.run(ProcessorApplication.class, args); + } } diff --git a/processor/src/main/java/ca/bc/gov/app/configuration/GlobalServiceConfiguration.java b/processor/src/main/java/ca/bc/gov/app/configuration/GlobalServiceConfiguration.java index 1ee8560363..4b44c9ed23 100644 --- a/processor/src/main/java/ca/bc/gov/app/configuration/GlobalServiceConfiguration.java +++ b/processor/src/main/java/ca/bc/gov/app/configuration/GlobalServiceConfiguration.java @@ -5,15 +5,13 @@ import org.springframework.aot.hint.annotation.RegisterReflectionForBinding; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.messaging.Message; import org.springframework.web.reactive.function.client.WebClient; @Configuration @Slf4j @RegisterReflectionForBinding({ SubmissionInformationDto.class, - Integer.class, - Message.class + Integer.class }) public class GlobalServiceConfiguration { diff --git a/processor/src/main/java/ca/bc/gov/app/configuration/ProcessorIntegrationConfiguration.java b/processor/src/main/java/ca/bc/gov/app/configuration/ProcessorIntegrationConfiguration.java deleted file mode 100644 index 3c5ec8d8c8..0000000000 --- a/processor/src/main/java/ca/bc/gov/app/configuration/ProcessorIntegrationConfiguration.java +++ /dev/null @@ -1,188 +0,0 @@ -package ca.bc.gov.app.configuration; - -import ca.bc.gov.app.ApplicationConstant; -import java.time.Duration; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.data.r2dbc.core.R2dbcEntityTemplate; -import org.springframework.integration.channel.FluxMessageChannel; -import org.springframework.integration.dsl.IntegrationFlow; -import org.springframework.integration.dsl.Pollers; -import org.springframework.integration.r2dbc.inbound.R2dbcMessageSource; - -@Configuration -public class ProcessorIntegrationConfiguration { - - @Bean - public FluxMessageChannel submissionListChannel() { - return new FluxMessageChannel(); - } - - @Bean - public FluxMessageChannel matchCheckingChannel() { - return new FluxMessageChannel(); - } - - @Bean - public FluxMessageChannel forwardChannel() { - return new FluxMessageChannel(); - } - - @Bean - public FluxMessageChannel autoApproveChannel() { - return new FluxMessageChannel(); - } - - @Bean - public FluxMessageChannel reviewChannel() { - return new FluxMessageChannel(); - } - - @Bean - public FluxMessageChannel saveToLegacy() { - return new FluxMessageChannel(); - } - - @Bean - public FluxMessageChannel submissionMail() { - return new FluxMessageChannel(); - } - - @Bean - public FluxMessageChannel submissionCompletedChannel() { - return new FluxMessageChannel(); - } - - @Bean - public FluxMessageChannel notificationProcessingChannel() { - return new FluxMessageChannel(); - } - - @Bean - public FluxMessageChannel submissionCompletionChannel() { - return new FluxMessageChannel(); - } - - - @Bean - public FluxMessageChannel submissionLegacyClientChannel() { - return new FluxMessageChannel(); - } - - @Bean - public FluxMessageChannel submissionLegacyLocationChannel() { - return new FluxMessageChannel(); - } - - @Bean - public FluxMessageChannel submissionLegacyContactChannel() { - return new FluxMessageChannel(); - } - - @Bean - public FluxMessageChannel submissionLegacyAggregateChannel() { - return new FluxMessageChannel(); - } - - @Bean - public FluxMessageChannel submissionLegacyNotifyChannel() { - return new FluxMessageChannel(); - } - - @Bean - public FluxMessageChannel submissionLegacyClientPersistChannel() { - return new FluxMessageChannel(); - } - - @Bean - public FluxMessageChannel submissionLegacyIndividualChannel() { - return new FluxMessageChannel(); - } - - @Bean - public FluxMessageChannel submissionLegacyUSPChannel() { - return new FluxMessageChannel(); - } - - @Bean - public FluxMessageChannel submissionLegacyRSPChannel() { - return new FluxMessageChannel(); - } - - @Bean - public FluxMessageChannel submissionLegacyOtherChannel() { - return new FluxMessageChannel(); - } - - @Bean - public FluxMessageChannel submissionMailChannel() { - return new FluxMessageChannel(); - } - - - @Bean - public R2dbcMessageSource submissionMessages(R2dbcEntityTemplate r2dbcEntityTemplate) { - final String submissionIdQuery = """ - SELECT nrfc.submission.submission_id - FROM nrfc.submission - WHERE nrfc.submission.submission_type_code = 'SPP'"""; - - R2dbcMessageSource template = new R2dbcMessageSource( - r2dbcEntityTemplate, - submissionIdQuery - ); - template.setPayloadType(Integer.class); - template.setExpectSingleResult(false); - return template; - } - - @Bean - public R2dbcMessageSource processedMessage(R2dbcEntityTemplate r2dbcEntityTemplate) { - final String submissionIdQuery = """ - SELECT nrfc.submission.submission_id - FROM nrfc.submission - LEFT JOIN nrfc.submission_matching_detail - ON nrfc.submission_matching_detail.submission_id = nrfc.submission.submission_id - WHERE - nrfc.submission.submission_status_code in ('R','A') - AND ( nrfc.submission_matching_detail.submission_matching_processed is null or - nrfc.submission_matching_detail.submission_matching_processed = false)"""; - - R2dbcMessageSource template = new R2dbcMessageSource( - r2dbcEntityTemplate, - submissionIdQuery - ); - template.setPayloadType(Integer.class); - template.setExpectSingleResult(false); - return template; - } - - @Bean - public IntegrationFlow processingIntegrationFlow( - @Value("${ca.bc.gov.nrs.processor.poolTime:1M}") Duration poolingTime, - @Qualifier(ApplicationConstant.SUBMISSION_LIST_CHANNEL) FluxMessageChannel inputChannel, - @Qualifier(ApplicationConstant.SUBMISSION_MESSAGE_SOURCE) R2dbcMessageSource messageSource - ) { - return IntegrationFlow - .from(messageSource, adapter -> adapter.poller(Pollers.fixedDelay(poolingTime))) - .split() - .channel(inputChannel) - .get(); - } - - @Bean - public IntegrationFlow notifyingIntegrationFlow( - @Value("${ca.bc.gov.nrs.processor.poolTime:1M}") Duration poolingTime, - @Qualifier(ApplicationConstant.SUBMISSION_POSTPROCESSOR_CHANNEL) FluxMessageChannel inputChannel, - @Qualifier(ApplicationConstant.PROCESSED_MESSAGE_SOURCE) R2dbcMessageSource messageSource - ) { - return IntegrationFlow - .from(messageSource, adapter -> adapter.poller(Pollers.fixedDelay(poolingTime))) - .split() - .channel(inputChannel) - .get(); - } - -} diff --git a/processor/src/main/java/ca/bc/gov/app/dto/MessagingWrapper.java b/processor/src/main/java/ca/bc/gov/app/dto/MessagingWrapper.java new file mode 100644 index 0000000000..2f87e00c8c --- /dev/null +++ b/processor/src/main/java/ca/bc/gov/app/dto/MessagingWrapper.java @@ -0,0 +1,22 @@ +package ca.bc.gov.app.dto; + +import java.util.HashMap; +import java.util.Map; + +public record MessagingWrapper( + T payload, + Map parameters +) { + + public MessagingWrapper(T payload, Map parameters) { + this.payload = payload; + this.parameters = new HashMap<>(parameters); + } + + + public MessagingWrapper withParameter(String key, Object value) { + this.parameters.put(key, value); + return this; + } + +} diff --git a/processor/src/main/java/ca/bc/gov/app/repository/SubmissionRepository.java b/processor/src/main/java/ca/bc/gov/app/repository/SubmissionRepository.java index 4eade01c49..45d680bd41 100644 --- a/processor/src/main/java/ca/bc/gov/app/repository/SubmissionRepository.java +++ b/processor/src/main/java/ca/bc/gov/app/repository/SubmissionRepository.java @@ -2,6 +2,7 @@ import ca.bc.gov.app.entity.SubmissionEntity; import ca.bc.gov.app.entity.SubmissionTypeCodeEnum; +import org.springframework.data.r2dbc.repository.Query; import org.springframework.data.repository.reactive.ReactiveCrudRepository; import org.springframework.stereotype.Repository; import reactor.core.publisher.Flux; @@ -9,4 +10,23 @@ @Repository public interface SubmissionRepository extends ReactiveCrudRepository { Flux findBySubmissionType(SubmissionTypeCodeEnum submissionType); + + @Query(""" + SELECT nrfc.submission.submission_id + FROM nrfc.submission + WHERE nrfc.submission.submission_type_code = 'SPP'""" + ) + Flux loadProcessingSubmissions(); + + @Query(""" + SELECT nrfc.submission.submission_id + FROM nrfc.submission + LEFT JOIN nrfc.submission_matching_detail + ON nrfc.submission_matching_detail.submission_id = nrfc.submission.submission_id + WHERE + nrfc.submission.submission_status_code in ('R','A') + AND ( nrfc.submission_matching_detail.submission_matching_processed is null or + nrfc.submission_matching_detail.submission_matching_processed = false)""" + ) + Flux loadProcessedSubmissions(); } diff --git a/processor/src/main/java/ca/bc/gov/app/service/client/ClientSubmissionAutoProcessingService.java b/processor/src/main/java/ca/bc/gov/app/service/client/ClientSubmissionAutoProcessingService.java index 4b669dc66a..0372de52ef 100644 --- a/processor/src/main/java/ca/bc/gov/app/service/client/ClientSubmissionAutoProcessingService.java +++ b/processor/src/main/java/ca/bc/gov/app/service/client/ClientSubmissionAutoProcessingService.java @@ -1,8 +1,8 @@ package ca.bc.gov.app.service.client; import ca.bc.gov.app.ApplicationConstant; -import ca.bc.gov.app.dto.EmailRequestDto; import ca.bc.gov.app.dto.MatcherResult; +import ca.bc.gov.app.dto.MessagingWrapper; import ca.bc.gov.app.entity.SubmissionMatchDetailEntity; import ca.bc.gov.app.entity.SubmissionStatusEnum; import ca.bc.gov.app.entity.SubmissionTypeCodeEnum; @@ -11,43 +11,32 @@ import java.time.LocalDateTime; import java.util.List; import java.util.Map; -import java.util.Objects; import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.integration.annotation.ServiceActivator; -import org.springframework.integration.support.MessageBuilder; -import org.springframework.messaging.Message; import org.springframework.stereotype.Service; import reactor.core.publisher.Mono; +/** + * This class is responsible for processing the submission and persisting the data on oracle. It + * does through a few steps that are interconnected. + */ @Service @RequiredArgsConstructor @Slf4j -/** - * This class is responsible for processing the submission and persisting the data on oracle. - * It does through a few steps that are interconnected. - */ public class ClientSubmissionAutoProcessingService { private final SubmissionRepository submissionRepository; private final SubmissionMatchDetailRepository submissionMatchDetailRepository; /** - * This method is responsible for marking the submission as approved - * and sending to the nexty step. + * This method is responsible for marking the submission as approved and sending to the nexty + * step. */ - @ServiceActivator( - inputChannel = ApplicationConstant.AUTO_APPROVE_CHANNEL, - outputChannel = ApplicationConstant.SUBMISSION_POSTPROCESSOR_CHANNEL, - async = "true" - ) - public Mono> approved(Message> message) { + public Mono> approved(MessagingWrapper> message) { int submissionId = - Objects.requireNonNull( - message.getHeaders() - .get(ApplicationConstant.SUBMISSION_ID, Integer.class) - ); + (int) message.parameters() + .get(ApplicationConstant.SUBMISSION_ID); return persistData(submissionId, SubmissionTypeCodeEnum.AAC) .doOnNext(id -> log.info("Request {} was approved", id)) @@ -61,52 +50,36 @@ public Mono> approved(Message> message) { entity.getMatchingField() ) ) - .thenReturn(MessageBuilder - .withPayload(submissionId) - .setHeader(ApplicationConstant.SUBMISSION_TYPE, SubmissionTypeCodeEnum.AAC) - .build() - ); + .thenReturn(new MessagingWrapper<>(submissionId,Map.of())); } - /** * This method is responsible for marking the submission as processed */ - @ServiceActivator( - inputChannel = ApplicationConstant.SUBMISSION_COMPLETION_CHANNEL, - outputChannel = ApplicationConstant.SUBMISSION_MAIL_CHANNEL, - async = "true" - ) - public Mono> completeProcessing(Message message) { + public Mono completeProcessing(Integer submissionId) { return submissionMatchDetailRepository - .findBySubmissionId( - message.getHeaders().get(ApplicationConstant.SUBMISSION_ID, Integer.class)) + .findBySubmissionId(submissionId) .doOnNext(entity -> entity.setProcessed(true)) .doOnNext(entity -> entity.setUpdatedAt(LocalDateTime.now())) .flatMap(submissionMatchDetailRepository::save) - .thenReturn(message); + .thenReturn(submissionId); } /** * This method is responsible for marking the submission as reviewed */ - @ServiceActivator( - inputChannel = ApplicationConstant.REVIEW_CHANNEL, - outputChannel = ApplicationConstant.SUBMISSION_MAIL_BUILD_CHANNEL, - async = "true" - ) - public Mono> reviewed(Message> message) { + public Mono> reviewed(MessagingWrapper> message) { return persistData( - message.getHeaders().get(ApplicationConstant.SUBMISSION_ID, Integer.class), + (int) message.parameters().get(ApplicationConstant.SUBMISSION_ID), SubmissionTypeCodeEnum.RNC ) .doOnNext(id -> log.info("Request {} was put into review", id)) .flatMap(this::loadFirstOrNew) .doOnNext(entity -> entity.setMatchers( message - .getPayload() + .payload() .stream() .collect(Collectors.toMap(MatcherResult::fieldName, MatcherResult::value)) ) @@ -120,14 +93,15 @@ public Mono> reviewed(Message> message) { ) .doOnNext(entity -> log.info("Request {} was put into review", - message.getHeaders().get(ApplicationConstant.SUBMISSION_ID, Integer.class) + message.parameters().get(ApplicationConstant.SUBMISSION_ID) ) ) - .map(entity -> MessageBuilder - .withPayload(entity.getSubmissionId()) - .copyHeaders(message.getHeaders()) - .setHeader(ApplicationConstant.SUBMISSION_TYPE, SubmissionTypeCodeEnum.RNC) - .build() + .map(entity -> + new MessagingWrapper<>( + entity.getSubmissionId(), + message.parameters() + ) + .withParameter(ApplicationConstant.SUBMISSION_STATUS, SubmissionStatusEnum.N) ); } diff --git a/processor/src/main/java/ca/bc/gov/app/service/client/ClientSubmissionLoadingService.java b/processor/src/main/java/ca/bc/gov/app/service/client/ClientSubmissionLoadingService.java index be4933d2a0..9b6ba88671 100644 --- a/processor/src/main/java/ca/bc/gov/app/service/client/ClientSubmissionLoadingService.java +++ b/processor/src/main/java/ca/bc/gov/app/service/client/ClientSubmissionLoadingService.java @@ -2,16 +2,15 @@ import ca.bc.gov.app.ApplicationConstant; import ca.bc.gov.app.dto.EmailRequestDto; +import ca.bc.gov.app.dto.MessagingWrapper; import ca.bc.gov.app.dto.SubmissionInformationDto; +import ca.bc.gov.app.entity.SubmissionStatusEnum; import ca.bc.gov.app.repository.SubmissionContactRepository; import ca.bc.gov.app.repository.SubmissionDetailRepository; import java.util.Map; import java.util.Objects; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.integration.annotation.ServiceActivator; -import org.springframework.integration.support.MessageBuilder; -import org.springframework.messaging.Message; import org.springframework.stereotype.Service; import reactor.core.publisher.Mono; @@ -27,16 +26,11 @@ public class ClientSubmissionLoadingService { private final SubmissionDetailRepository submissionDetailRepository; private final SubmissionContactRepository contactRepository; - /** * Load the submission details to be processed later on */ - @ServiceActivator( - inputChannel = ApplicationConstant.SUBMISSION_LIST_CHANNEL, - outputChannel = ApplicationConstant.MATCH_CHECKING_CHANNEL, - async = "true" - ) - public Mono> loadSubmissionDetails(Integer submissionId) { + public Mono> loadSubmissionDetails( + Integer submissionId) { return submissionDetailRepository @@ -54,33 +48,34 @@ public Mono> loadSubmissionDetails(Integer sub ) //Build a message with our dto and pass the submission Id as header - .map(event -> - MessageBuilder - .withPayload(event) - .setHeader(ApplicationConstant.SUBMISSION_ID, submissionId) - .build() + .map(event -> new MessagingWrapper<>( + event, + Map.of(ApplicationConstant.SUBMISSION_ID, submissionId) + ) ); } + public Mono buildMailMessage( + MessagingWrapper message + ) { - /** - * Build the email request dto to be sent to the email service - */ - @ServiceActivator( - inputChannel = ApplicationConstant.SUBMISSION_MAIL_BUILD_CHANNEL, - outputChannel = ApplicationConstant.SUBMISSION_MAIL_CHANNEL, - async = "true" - ) - public Mono> sendNotification(Message message) { + if (message + .parameters() + .get(ApplicationConstant.SUBMISSION_STATUS) == null + ) { + return Mono.empty(); + } + //TODO: read from config + String clientAdminTeamEmail = "clientadminteamemail@email.ca"; return submissionDetailRepository - .findBySubmissionId(message.getPayload()) + .findBySubmissionId(message.payload()) .doOnNext( submission -> log.info("Loaded submission details for mail purpose {}", submission)) .flatMap(details -> contactRepository - .findFirstBySubmissionId(message.getPayload()) + .findFirstBySubmissionId(message.payload()) .doOnNext(submissionContact -> log.info( "Loaded submission contact details for mail purpose {}", submissionContact)) .map(submissionContact -> @@ -89,25 +84,110 @@ public Mono> sendNotification(Message message) details.getOrganizationName(), submissionContact.getUserId(), submissionContact.getFirstName(), - submissionContact.getEmailAddress(), - "approval", - "Success", - Map.of( - "userName", submissionContact.getFirstName(), - "business", Map.of( - "name", details.getOrganizationName(), - "clientNumber", Objects.toString(details.getClientNumber(), "") - ) + isClientAdminEmail(message) + ? + clientAdminTeamEmail + : + submissionContact.getEmailAddress(), + getTemplate(message), + getSubject(message, details.getOrganizationName()), + getParameter( + message, + submissionContact.getFirstName(), + details.getOrganizationName(), + Objects.toString(details.getClientNumber(), ""), + String.valueOf( + message.parameters().get(ApplicationConstant.MATCHING_REASON)), + message.payload() ) ) ) - ) - .map(emailRequestDto -> - MessageBuilder - .withPayload(emailRequestDto) - .copyHeaders(message.getHeaders()) - .build() ); } + private boolean isClientAdminEmail(MessagingWrapper message) { + return SubmissionStatusEnum.N.equals( + message + .parameters() + .get(ApplicationConstant.SUBMISSION_STATUS) + ); + } + + private String getTemplate(MessagingWrapper message) { + return switch ((SubmissionStatusEnum) message.parameters() + .get(ApplicationConstant.SUBMISSION_STATUS)) { + case A -> "approval"; + case R -> "rejection"; + default -> "revision"; + }; + } + + private String getSubject( + MessagingWrapper message, + String businessName + ) { + return switch ((SubmissionStatusEnum) message.parameters() + .get(ApplicationConstant.SUBMISSION_STATUS)) { + case A -> "Client number submission for " + businessName + " was approved"; + case R -> "Client number submission for " + businessName + " was rejected"; + default -> businessName + " submission requires review"; + }; + } + + private Map getParameter( + MessagingWrapper message, + String username, + String businessName, + String clientNumber, + String reason, + Integer submissionId + ) { + return switch ((SubmissionStatusEnum) message.parameters() + .get(ApplicationConstant.SUBMISSION_STATUS)) { + case A -> approvalParameters(username, businessName, clientNumber); + case R -> rejectionParameters(username, businessName, clientNumber, reason); + default -> revisionParameters(username, submissionId); + }; + } + + private Map revisionParameters( + String username, + Integer submissionId + ) { + return Map.of( + "userName", username, + "submission", submissionId + ); + } + + private Map approvalParameters( + String username, + String businessName, + String clientNumber + ) { + return Map.of( + "userName", username, + "business", Map.of( + "name", businessName, + "clientNumber", clientNumber + ) + ); + } + + private Map rejectionParameters( + String username, + String businessName, + String clientNumber, + String reason + ) { + return Map.of( + "userName", username, + "reason", reason, + "business", Map.of( + "name", businessName, + "clientNumber", clientNumber + ) + ); + } + } diff --git a/processor/src/main/java/ca/bc/gov/app/service/client/ClientSubmissionMailService.java b/processor/src/main/java/ca/bc/gov/app/service/client/ClientSubmissionMailService.java index c742038283..b3655831ef 100644 --- a/processor/src/main/java/ca/bc/gov/app/service/client/ClientSubmissionMailService.java +++ b/processor/src/main/java/ca/bc/gov/app/service/client/ClientSubmissionMailService.java @@ -1,13 +1,8 @@ package ca.bc.gov.app.service.client; -import ca.bc.gov.app.ApplicationConstant; import ca.bc.gov.app.dto.EmailRequestDto; -import ca.bc.gov.app.entity.SubmissionTypeCodeEnum; -import java.util.Objects; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.integration.annotation.ServiceActivator; -import org.springframework.messaging.Message; import org.springframework.stereotype.Service; import org.springframework.web.reactive.function.client.WebClient; import reactor.core.publisher.Mono; @@ -19,21 +14,22 @@ public class ClientSubmissionMailService { private final WebClient forestClientApi; - @ServiceActivator(inputChannel = ApplicationConstant.SUBMISSION_MAIL_CHANNEL) - public void sendMail(Message mailMessage) { + /*@ServiceActivator(inputChannel = ApplicationConstant.SUBMISSION_MAIL_CHANNEL)*/ + public Mono sendMail(EmailRequestDto mailMessage) { log.info("Sending email to {} {} -> {}", - mailMessage.getPayload().email(), - mailMessage.getPayload().subject(), - mailMessage.getPayload().variables() + mailMessage.email(), + mailMessage.subject(), + mailMessage.variables() ); - forestClientApi - .post() - .uri("/ches/email") - .body(Mono.just(mailMessage.getPayload()), EmailRequestDto.class) - .exchangeToMono(clientResponse -> clientResponse.bodyToMono(Void.class)) - .subscribe(source -> log.info("Email sent to {}", mailMessage.getPayload().email())); + return + forestClientApi + .post() + .uri("/ches/email") + .body(Mono.just(mailMessage), EmailRequestDto.class) + .exchangeToMono(clientResponse -> clientResponse.bodyToMono(Void.class)) + .doOnNext(source -> log.info("Email sent to {}", mailMessage.email())); } diff --git a/processor/src/main/java/ca/bc/gov/app/service/client/ClientSubmissionProcessingService.java b/processor/src/main/java/ca/bc/gov/app/service/client/ClientSubmissionProcessingService.java index 8b0491a5c0..2dc252beec 100644 --- a/processor/src/main/java/ca/bc/gov/app/service/client/ClientSubmissionProcessingService.java +++ b/processor/src/main/java/ca/bc/gov/app/service/client/ClientSubmissionProcessingService.java @@ -1,23 +1,15 @@ package ca.bc.gov.app.service.client; import ca.bc.gov.app.ApplicationConstant; -import ca.bc.gov.app.dto.EmailRequestDto; +import ca.bc.gov.app.dto.MessagingWrapper; import ca.bc.gov.app.entity.SubmissionMatchDetailEntity; -import ca.bc.gov.app.entity.SubmissionStatusEnum; -import ca.bc.gov.app.repository.SubmissionContactRepository; import ca.bc.gov.app.repository.SubmissionDetailRepository; import ca.bc.gov.app.repository.SubmissionMatchDetailRepository; import ca.bc.gov.app.repository.SubmissionRepository; -import ca.bc.gov.app.util.ProcessorUtil; -import java.util.Map; import java.util.Optional; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; -import org.springframework.integration.annotation.ServiceActivator; -import org.springframework.integration.support.MessageBuilder; -import org.springframework.messaging.Message; -import org.springframework.messaging.MessageHeaders; import org.springframework.stereotype.Service; import reactor.core.publisher.Mono; @@ -29,21 +21,14 @@ public class ClientSubmissionProcessingService { private final SubmissionDetailRepository submissionDetailRepository; private final SubmissionRepository submissionRepository; private final SubmissionMatchDetailRepository submissionMatchDetailRepository; - private final SubmissionContactRepository contactRepository; - /** * This method will process the submission and send the notification to the user. */ - @ServiceActivator( - inputChannel = ApplicationConstant.SUBMISSION_POSTPROCESSOR_CHANNEL, - outputChannel = ApplicationConstant.NOTIFICATION_PROCESSING_CHANNEL, - async = "true" - ) - public Mono> processSubmission( - Message submissionMessage + public Mono> processSubmission( + MessagingWrapper submissionMessage ) { - Integer submissionId = submissionMessage.getPayload(); + Integer submissionId = submissionMessage.payload(); return submissionRepository @@ -57,118 +42,25 @@ public Mono> processSubmission( .findBySubmissionId(submissionId) .defaultIfEmpty(SubmissionMatchDetailEntity.builder().build()) .map(matching -> - MessageBuilder - .withPayload(matching) - .copyHeaders(submissionMessage.getHeaders()) - .setHeader(ApplicationConstant.SUBMISSION_ID, submissionId) - .setHeader(ApplicationConstant.SUBMISSION_STATUS, + new MessagingWrapper<>( + matching, + submissionMessage.parameters() + ) + .withParameter(ApplicationConstant.SUBMISSION_ID, submissionId) + .withParameter(ApplicationConstant.SUBMISSION_STATUS, event.getSubmissionStatus()) - .setHeader(ApplicationConstant.SUBMISSION_CLIENTID, + .withParameter(ApplicationConstant.SUBMISSION_CLIENTID, Optional.ofNullable(details.getClientNumber()) .orElse(StringUtils.EMPTY)) - .setHeader(ApplicationConstant.SUBMISSION_NAME, + .withParameter(ApplicationConstant.SUBMISSION_NAME, details.getOrganizationName()) - - .build() + .withParameter(ApplicationConstant.MATCHING_REASON, + matching.getMatchingMessage()) + .withParameter(ApplicationConstant.CLIENT_TYPE_CODE, + details.getClientTypeCode()) ) ) ); } - - /** - * This method will process the submission and send the notification to the user. - */ - @SuppressWarnings("java:S1452") - @ServiceActivator( - inputChannel = ApplicationConstant.NOTIFICATION_PROCESSING_CHANNEL, - outputChannel = ApplicationConstant.FORWARD_CHANNEL, - async = "true" - ) - public Mono> notificationProcessing(Message message) { - - SubmissionStatusEnum status = ProcessorUtil.readHeader(message, - ApplicationConstant.SUBMISSION_STATUS, - SubmissionStatusEnum.class) - .orElse(SubmissionStatusEnum.R); - - Integer submissionId = ProcessorUtil.readHeader(message, ApplicationConstant.SUBMISSION_ID, - Integer.class).orElse(0); - - if (SubmissionStatusEnum.A.equals(status)) { - - log.info("Submission {} was approved", submissionId); - - return Mono - .just( - MessageBuilder - .withPayload(submissionId) - .copyHeaders(message.getHeaders()) - .setReplyChannelName(ApplicationConstant.SUBMISSION_LEGACY_CHANNEL) - .setHeader( - "output-channel", - ApplicationConstant.SUBMISSION_LEGACY_CHANNEL - ) - .setHeader(MessageHeaders.REPLY_CHANNEL, - ApplicationConstant.SUBMISSION_LEGACY_CHANNEL) - .build() - ); - - } - - log.info("Submission {} was rejected", submissionId); - - return - submissionMatchDetailRepository - .findBySubmissionId(submissionId) - .map(SubmissionMatchDetailEntity::getMatchingMessage) - .flatMap(matchingReason -> - submissionDetailRepository - .findBySubmissionId(submissionId) - .flatMap(submissionDetails -> - contactRepository - .findFirstBySubmissionId(submissionId) - .map(submissionContact -> - new EmailRequestDto( - submissionDetails.getIncorporationNumber(), - submissionDetails.getOrganizationName(), - submissionContact.getUserId(), - submissionContact.getFirstName(), - submissionContact.getEmailAddress(), - "rejection", - "Failure", - Map.of( - "userName", submissionContact.getFirstName(), - "name", submissionDetails.getOrganizationName(), - "reason", matchingReason - ) - ) - ) - ) - ) - .map(emailRequestDto -> - MessageBuilder - .withPayload(emailRequestDto) - .copyHeaders(message.getHeaders()) - .setReplyChannelName(ApplicationConstant.SUBMISSION_COMPLETION_CHANNEL) - .setHeader(ApplicationConstant.SUBMISSION_ID, submissionId) - .setHeader( - "output-channel", - ApplicationConstant.SUBMISSION_COMPLETION_CHANNEL - ) - .setHeader(MessageHeaders.REPLY_CHANNEL, - ApplicationConstant.SUBMISSION_COMPLETION_CHANNEL) - .build() - ); - } - - @ServiceActivator(inputChannel = ApplicationConstant.SUBMISSION_MAIL_BUILD_CHANNEL,async = "true") - public void updateMatch(Message message) { - submissionMatchDetailRepository - .findBySubmissionId(message.getPayload()) - .map(match -> match.withProcessed(true)) - .flatMap(submissionMatchDetailRepository::save) - .subscribe(match -> log.info("Updated match for submission {}", match.getSubmissionId())); - } - } diff --git a/processor/src/main/java/ca/bc/gov/app/service/legacy/LegacyAbstractPersistenceService.java b/processor/src/main/java/ca/bc/gov/app/service/legacy/LegacyAbstractPersistenceService.java index c2fd9a0478..9895f4e2fb 100644 --- a/processor/src/main/java/ca/bc/gov/app/service/legacy/LegacyAbstractPersistenceService.java +++ b/processor/src/main/java/ca/bc/gov/app/service/legacy/LegacyAbstractPersistenceService.java @@ -1,27 +1,22 @@ package ca.bc.gov.app.service.legacy; import ca.bc.gov.app.ApplicationConstant; +import ca.bc.gov.app.dto.MessagingWrapper; import ca.bc.gov.app.dto.legacy.ForestClientContactDto; import ca.bc.gov.app.dto.legacy.ForestClientDto; import ca.bc.gov.app.entity.SubmissionDetailEntity; import ca.bc.gov.app.entity.SubmissionLocationEntity; -import ca.bc.gov.app.entity.SubmissionTypeCodeEnum; import ca.bc.gov.app.repository.SubmissionContactRepository; import ca.bc.gov.app.repository.SubmissionDetailRepository; import ca.bc.gov.app.repository.SubmissionLocationContactRepository; import ca.bc.gov.app.repository.SubmissionLocationRepository; import ca.bc.gov.app.repository.SubmissionRepository; -import ca.bc.gov.app.util.ProcessorUtil; import java.util.function.Function; import lombok.Getter; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.RegExUtils; import org.apache.commons.lang3.StringUtils; -import org.springframework.integration.annotation.ServiceActivator; -import org.springframework.integration.support.MessageBuilder; -import org.springframework.messaging.Message; -import org.springframework.messaging.MessageHeaders; import org.springframework.stereotype.Service; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -43,75 +38,62 @@ public abstract class LegacyAbstractPersistenceService { private final SubmissionLocationContactRepository locationContactRepository; private final LegacyService legacyService; - abstract Mono> generateForestClient(Message message); + abstract Mono> generateForestClient( + MessagingWrapper message); abstract boolean filterByType(String clientTypeCode); - abstract String getNextChannel(); - - /** * Loads the submission from the database and prepares the message for next step. */ - @ServiceActivator( - inputChannel = ApplicationConstant.SUBMISSION_LEGACY_CHANNEL, - outputChannel = ApplicationConstant.SUBMISSION_LEGACY_CLIENT_CHANNEL, - async = "true" - ) - public Mono> loadSubmission(Message message) { + public Mono> loadSubmission(MessagingWrapper message) { return submissionRepository - .findById(message.getPayload()) + .findById(message.payload()) .doOnNext(submission -> log.info("Loaded submission for persistence on oracle {}", submission.getSubmissionId()) ) - .map(submission -> MessageBuilder - .fromMessage(message) - .setHeader(ApplicationConstant.SUBMISSION_ID, message.getPayload()) - .setHeader(ApplicationConstant.CREATED_BY, submission.getCreatedBy()) - .setHeader(ApplicationConstant.UPDATED_BY, submission.getUpdatedBy()) - .build() + .map(submission -> + new MessagingWrapper( + message.payload(), + message.parameters() + ) + .withParameter(ApplicationConstant.SUBMISSION_ID, message.payload()) + .withParameter(ApplicationConstant.CREATED_BY, submission.getCreatedBy()) + .withParameter(ApplicationConstant.UPDATED_BY, submission.getUpdatedBy()) ); } - /** * Checks if the client number exists for that submission and prepares the message for next step. * The next step will be identified and handled by individual channels */ - @ServiceActivator( - inputChannel = ApplicationConstant.SUBMISSION_LEGACY_CLIENT_CHANNEL, - outputChannel = ApplicationConstant.FORWARD_CHANNEL, //Dummy channel name - async = "true" - ) - public Mono> checkClientData(Message message) { + public Mono> checkClientData(MessagingWrapper message) { return submissionDetailRepository - .findBySubmissionId(message.getPayload()) + .findBySubmissionId(message.payload()) .doOnNext( submissionDetail -> log.info( "Loaded submission detail for persistence on oracle {} {} {}", - message.getPayload(), + message.payload(), submissionDetail.getOrganizationName(), submissionDetail.getIncorporationNumber() ) ) - .filter(submissionDetail -> filterByType(submissionDetail.getClientTypeCode())) .flatMap(submissionDetail -> contactRepository - .findFirstBySubmissionId(message.getPayload()) + .findFirstBySubmissionId(message.payload()) + .map(contact -> contact.getFirstName() + " " + contact.getLastName()) .map(contact -> - MessageBuilder - .withPayload(message.getPayload()) - .copyHeaders(message.getHeaders()) - .setHeader(ApplicationConstant.SUBMISSION_ID, message.getPayload()) - .setHeader(ApplicationConstant.CLIENT_TYPE_CODE, + new MessagingWrapper<>( + message.parameters().get(ApplicationConstant.FOREST_CLIENT_NUMBER) + .toString(), + message.parameters() + ) + .withParameter(ApplicationConstant.CLIENT_TYPE_CODE, submissionDetail.getClientTypeCode()) - .setHeader(ApplicationConstant.CLIENT_SUBMITTER_NAME, - contact.getFirstName() + " " + contact.getLastName()) - .setReplyChannelName(getNextChannel()) - .setHeader("output-channel", getNextChannel()) - .setHeader(MessageHeaders.REPLY_CHANNEL, getNextChannel()) - .build() + .withParameter(ApplicationConstant.CLIENT_SUBMITTER_NAME, + contact + ) ) ); } @@ -119,34 +101,25 @@ public Mono> checkClientData(Message message) { /** * Creates a client if does not exist on oracle and get back the client number. */ - @ServiceActivator( - inputChannel = ApplicationConstant.SUBMISSION_LEGACY_CLIENT_PERSIST_CHANNEL, - outputChannel = ApplicationConstant.SUBMISSION_LEGACY_LOCATION_CHANNEL, - async = "true" - ) - public Mono> createForestClient(Message message) { - - if (!filterByType( - message.getHeaders().get(ApplicationConstant.CLIENT_TYPE_CODE, String.class))) { - return Mono.empty(); - } + public Mono> createForestClient( + MessagingWrapper message) { log.info("Creating Forest Client {} {}", - message.getHeaders().get(ApplicationConstant.FOREST_CLIENT_NAME), - message.getPayload().clientNumber() + message.parameters().get(ApplicationConstant.FOREST_CLIENT_NAME), + message.payload().clientNumber() ); return // Create the client legacyService - .createClient(message.getPayload()) + .createClient(message.payload()) // Create the doing business as IF exists .flatMap(clientNumber -> createClientDoingBusinessAs(message, clientNumber)) // Updates the submission detail with the client number .flatMap(clientNumber -> submissionDetailRepository .findBySubmissionId( - message.getHeaders().get(ApplicationConstant.SUBMISSION_ID, Integer.class) + (Integer) message.parameters().get(ApplicationConstant.SUBMISSION_ID) ) .map(submissionDetail -> submissionDetail.withClientNumber(clientNumber)) .flatMap(submissionDetailRepository::save) @@ -155,17 +128,16 @@ public Mono> createForestClient(Message messag .doOnNext(forestClientNumber -> log.info( "Saved forest client {} {}", - message.getPayload(), + message.payload(), forestClientNumber ) ) .map(forestClientNumber -> - MessageBuilder - .withPayload( - message.getHeaders().get(ApplicationConstant.SUBMISSION_ID, Integer.class)) - .copyHeaders(message.getHeaders()) - .setHeader(ApplicationConstant.FOREST_CLIENT_NUMBER, forestClientNumber) - .build() + new MessagingWrapper<>( + (Integer) message.parameters().get(ApplicationConstant.SUBMISSION_ID), + message.parameters() + ) + .withParameter(ApplicationConstant.FOREST_CLIENT_NUMBER, forestClientNumber) ); } @@ -176,25 +148,15 @@ public Mono> createForestClient(Message messag * @param message A message containing the submission id * @return A flux of messages containing the submission id and the location id */ - @ServiceActivator( - inputChannel = ApplicationConstant.SUBMISSION_LEGACY_LOCATION_CHANNEL, - outputChannel = ApplicationConstant.SUBMISSION_LEGACY_CONTACT_CHANNEL, - async = "true" - ) - public Flux> createLocations(Message message) { - - if (!filterByType( - message.getHeaders().get(ApplicationConstant.CLIENT_TYPE_CODE, String.class))) { - return Flux.empty(); - } + public Flux> createLocations(MessagingWrapper message) { Flux data = locationRepository.findBySubmissionId( - message.getPayload() + message.payload() ) .doOnNext(submissionLocation -> log.info( "Loaded submission location for persistence on oracle {} {} {}", - message.getPayload(), + message.payload(), submissionLocation.getName(), submissionLocation.getSubmissionLocationId() ) @@ -217,20 +179,20 @@ public Flux> createLocations(Message message) { "Proceeding with location {}/{} of submission id {}", index, count, - message.getPayload() + message.payload() ) ) .map(count -> - MessageBuilder - .fromMessage(message) - .copyHeaders(message.getHeaders()) - .setHeader(ApplicationConstant.LOCATION_CODE, - String.format("%02d", index)) - .setHeader(ApplicationConstant.LOCATION_ID, + new MessagingWrapper<>( + message.payload(), + message.parameters() + ) + .withParameter(ApplicationConstant.LOCATION_ID, detail.getSubmissionLocationId()) - .setHeader(ApplicationConstant.TOTAL, count) - .setHeader(ApplicationConstant.INDEX, index) - .build() + .withParameter(ApplicationConstant.LOCATION_CODE, + String.format("%02d", index)) + .withParameter(ApplicationConstant.TOTAL, count) + .withParameter(ApplicationConstant.INDEX, index) ) ) ) @@ -242,21 +204,12 @@ public Flux> createLocations(Message message) { * Creates a contact if does not exist on oracle. It first checks for an existing entry and if it * does not have, create it. */ - @ServiceActivator( - inputChannel = ApplicationConstant.SUBMISSION_LEGACY_CONTACT_CHANNEL, - outputChannel = ApplicationConstant.SUBMISSION_LEGACY_NOTIFY_CHANNEL, - async = "true" - ) - public Mono> createContact(Message message) { + public Mono> createContact(MessagingWrapper message) { - if (!filterByType( - message.getHeaders().get(ApplicationConstant.CLIENT_TYPE_CODE, String.class))) { - return Mono.empty(); - } // Load all contacts for this location return locationContactRepository .findBySubmissionLocationId( - message.getHeaders().get(ApplicationConstant.LOCATION_ID, Integer.class) + (Integer) message.parameters().get(ApplicationConstant.LOCATION_ID) ) // Load the contact detail .flatMap(locationContact -> @@ -267,17 +220,17 @@ public Mono> createContact(Message message) { .doOnNext(submissionContact -> log.info( "Loaded submission contact for persistence on oracle {} {} {} {}", - message.getPayload(), + message.payload(), submissionContact.getFirstName(), submissionContact.getLastName(), - message.getHeaders().get(ApplicationConstant.LOCATION_CODE, String.class) + message.parameters().get(ApplicationConstant.LOCATION_CODE) ) ) // Convert it to a DTO .map(submissionContact -> new ForestClientContactDto( getClientNumber(message), - message.getHeaders().get(ApplicationConstant.LOCATION_CODE, String.class), + message.parameters().get(ApplicationConstant.LOCATION_CODE).toString(), submissionContact.getContactTypeCode(), String.format("%s %s", submissionContact.getFirstName(), submissionContact.getLastName()).toUpperCase(), @@ -297,43 +250,6 @@ public Mono> createContact(Message message) { .thenReturn(message); } - - /** - * Sends a notification to the user that the submission has been processed - */ - @ServiceActivator( - inputChannel = ApplicationConstant.SUBMISSION_LEGACY_NOTIFY_CHANNEL, - outputChannel = ApplicationConstant.SUBMISSION_MAIL_BUILD_CHANNEL, - async = "true" - ) - public Mono> sendNotification(Message message) { - - if (!filterByType( - message.getHeaders().get(ApplicationConstant.CLIENT_TYPE_CODE, String.class))) { - return Mono.empty(); - } - - Long total = message.getHeaders().get(ApplicationConstant.TOTAL, Long.class); - Long index = message.getHeaders().get(ApplicationConstant.INDEX, Long.class); - - if ((total == null || index == null) || ((total - 1) > index)) { - log.info("Skipping notification for submission {} until last location is processed", - message.getHeaders().get(ApplicationConstant.SUBMISSION_ID, Integer.class) - ); - return Mono.empty(); - } - - log.info("Sending notification for submission {}", - message.getHeaders().get(ApplicationConstant.SUBMISSION_ID, Integer.class) - ); - return Mono.just( - MessageBuilder - .fromMessage(message) - .setHeader(ApplicationConstant.SUBMISSION_TYPE, SubmissionTypeCodeEnum.RAC) - .build() - ); - } - protected ForestClientDto getBaseForestClient(String createdBy, String updatedBy) { return new ForestClientDto( @@ -355,19 +271,12 @@ protected ForestClientDto getBaseForestClient(String createdBy, String updatedBy ); } - protected String getUser(Message message, String headerName) { - return ProcessorUtil - .readHeader( - message, - headerName, - String.class - ) - .orElse(ApplicationConstant.PROCESSOR_USER_NAME); + protected String getUser(MessagingWrapper message, String headerName) { + return message.parameters().get(headerName).toString(); } - private String getClientNumber(Message message) { - return ProcessorUtil.readHeader(message, ApplicationConstant.FOREST_CLIENT_NUMBER, String.class) - .orElse(StringUtils.EMPTY); + private String getClientNumber(MessagingWrapper message) { + return message.parameters().get(ApplicationConstant.FOREST_CLIENT_NUMBER).toString(); } private boolean isRegisteredSoleProprietorship(ForestClientDto forestClient) { @@ -375,19 +284,18 @@ private boolean isRegisteredSoleProprietorship(ForestClientDto forestClient) { forestClient.clientIdTypeCode(), "BCRE"); } - private Mono createClientDoingBusinessAs(Message message, + private Mono createClientDoingBusinessAs(MessagingWrapper message, String clientNumber) { return Mono .just(clientNumber) .filter( - forestClientNumber -> isRegisteredSoleProprietorship(message.getPayload()) + forestClientNumber -> isRegisteredSoleProprietorship(message.payload()) ) .flatMap(forestClientNumber -> legacyService .createDoingBusinessAs( forestClientNumber, - message.getHeaders().get(ApplicationConstant.FOREST_CLIENT_NAME, - String.class), + message.parameters().get(ApplicationConstant.FOREST_CLIENT_NAME).toString(), getUser(message, ApplicationConstant.CREATED_BY), getUser(message, ApplicationConstant.UPDATED_BY) ) diff --git a/processor/src/main/java/ca/bc/gov/app/service/legacy/LegacyClientPersistenceService.java b/processor/src/main/java/ca/bc/gov/app/service/legacy/LegacyClientPersistenceService.java index 3a17348e28..049e35fd22 100644 --- a/processor/src/main/java/ca/bc/gov/app/service/legacy/LegacyClientPersistenceService.java +++ b/processor/src/main/java/ca/bc/gov/app/service/legacy/LegacyClientPersistenceService.java @@ -2,6 +2,7 @@ package ca.bc.gov.app.service.legacy; import ca.bc.gov.app.ApplicationConstant; +import ca.bc.gov.app.dto.MessagingWrapper; import ca.bc.gov.app.dto.legacy.ForestClientDto; import ca.bc.gov.app.repository.SubmissionContactRepository; import ca.bc.gov.app.repository.SubmissionDetailRepository; @@ -12,9 +13,6 @@ import java.util.List; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; -import org.springframework.integration.annotation.ServiceActivator; -import org.springframework.integration.support.MessageBuilder; -import org.springframework.messaging.Message; import org.springframework.stereotype.Service; import reactor.core.publisher.Mono; @@ -51,23 +49,15 @@ boolean filterByType(String clientTypeCode) { } @Override - String getNextChannel() { - return ApplicationConstant.SUBMISSION_LEGACY_OTHER_CHANNEL; - } - - @ServiceActivator( - inputChannel = ApplicationConstant.SUBMISSION_LEGACY_OTHER_CHANNEL, - outputChannel = ApplicationConstant.SUBMISSION_LEGACY_CLIENT_PERSIST_CHANNEL, - async = "true" - ) - @Override - public Mono> generateForestClient(Message message) { + public Mono> generateForestClient( + MessagingWrapper message) { return getSubmissionDetailRepository() .findBySubmissionId( - message - .getHeaders() - .get(ApplicationConstant.SUBMISSION_ID, Integer.class) + (Integer) + message + .parameters() + .get(ApplicationConstant.SUBMISSION_ID) ) .map(submissionDetail -> getBaseForestClient( @@ -87,23 +77,23 @@ public Mono> generateForestClient(Message messa .withCorpRegnNmbr( ProcessorUtil.extractNumbers(submissionDetail.getIncorporationNumber()) ) - .withClientNumber(message.getHeaders() - .get(ApplicationConstant.FOREST_CLIENT_NUMBER, String.class)) + .withClientNumber(message.parameters() + .get(ApplicationConstant.FOREST_CLIENT_NUMBER).toString()) ) .map(forestClient -> - MessageBuilder - .withPayload(forestClient) - .copyHeaders(message.getHeaders()) - .setHeader(ApplicationConstant.FOREST_CLIENT_NAME, + new MessagingWrapper<>( + forestClient, + message.parameters() + ) + .withParameter(ApplicationConstant.FOREST_CLIENT_NAME, forestClient.clientName() ) - .setHeader(ApplicationConstant.INCORPORATION_NUMBER, + .withParameter(ApplicationConstant.INCORPORATION_NUMBER, String.join(StringUtils.EMPTY, forestClient.registryCompanyTypeCode(), forestClient.corpRegnNmbr() ) ) - .build() ); } diff --git a/processor/src/main/java/ca/bc/gov/app/service/legacy/LegacyIndividualPersistenceService.java b/processor/src/main/java/ca/bc/gov/app/service/legacy/LegacyIndividualPersistenceService.java index 84361bd6db..ebb1267d98 100644 --- a/processor/src/main/java/ca/bc/gov/app/service/legacy/LegacyIndividualPersistenceService.java +++ b/processor/src/main/java/ca/bc/gov/app/service/legacy/LegacyIndividualPersistenceService.java @@ -2,6 +2,7 @@ package ca.bc.gov.app.service.legacy; import ca.bc.gov.app.ApplicationConstant; +import ca.bc.gov.app.dto.MessagingWrapper; import ca.bc.gov.app.dto.legacy.ForestClientDto; import ca.bc.gov.app.repository.SubmissionContactRepository; import ca.bc.gov.app.repository.SubmissionDetailRepository; @@ -11,9 +12,6 @@ import ca.bc.gov.app.util.ProcessorUtil; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; -import org.springframework.integration.annotation.ServiceActivator; -import org.springframework.integration.support.MessageBuilder; -import org.springframework.messaging.Message; import org.springframework.stereotype.Service; import reactor.core.publisher.Mono; @@ -49,27 +47,19 @@ boolean filterByType(String clientTypeCode) { return StringUtils.equalsIgnoreCase(clientTypeCode, "I"); } - @Override - String getNextChannel() { - return ApplicationConstant.SUBMISSION_LEGACY_INDIVIDUAL_CHANNEL; - } - /** * Generate the individual to be persisted into forest client database. */ - @ServiceActivator( - inputChannel = ApplicationConstant.SUBMISSION_LEGACY_INDIVIDUAL_CHANNEL, - outputChannel = ApplicationConstant.SUBMISSION_LEGACY_CLIENT_PERSIST_CHANNEL, - async = "true" - ) @Override - public Mono> generateForestClient(Message message) { + public Mono> generateForestClient( + MessagingWrapper message) { return getSubmissionDetailRepository() .findBySubmissionId( - message - .getHeaders() - .get(ApplicationConstant.SUBMISSION_ID, Integer.class) + (Integer) + message + .parameters() + .get(ApplicationConstant.SUBMISSION_ID) ) .map(detailEntity -> getBaseForestClient( @@ -91,22 +81,19 @@ public Mono> generateForestClient(Message messa .withClientIdentification( getUser(message, ApplicationConstant.CREATED_BY).replace("bcsc\\", StringUtils.EMPTY)) - .withClientNumber(message.getHeaders() - .get(ApplicationConstant.FOREST_CLIENT_NUMBER, String.class)) + .withClientNumber(message.parameters() + .get(ApplicationConstant.FOREST_CLIENT_NUMBER).toString()) ) .map(forestClient -> - MessageBuilder - .withPayload(forestClient) - .copyHeaders(message.getHeaders()) - .setHeader(ApplicationConstant.FOREST_CLIENT_NAME, + new MessagingWrapper<>(forestClient, message.parameters()) + .withParameter(ApplicationConstant.FOREST_CLIENT_NAME, String.join(" ", forestClient.legalFirstName(), forestClient.clientName() ) ) - .setHeader(ApplicationConstant.INCORPORATION_NUMBER, + .withParameter(ApplicationConstant.INCORPORATION_NUMBER, "not applicable") - .build() ); } diff --git a/processor/src/main/java/ca/bc/gov/app/service/legacy/LegacyLoadingService.java b/processor/src/main/java/ca/bc/gov/app/service/legacy/LegacyLoadingService.java index 08a3c88cb1..f2b866cb32 100644 --- a/processor/src/main/java/ca/bc/gov/app/service/legacy/LegacyLoadingService.java +++ b/processor/src/main/java/ca/bc/gov/app/service/legacy/LegacyLoadingService.java @@ -2,17 +2,13 @@ import ca.bc.gov.app.ApplicationConstant; import ca.bc.gov.app.dto.MatcherResult; +import ca.bc.gov.app.dto.MessagingWrapper; import ca.bc.gov.app.dto.SubmissionInformationDto; import ca.bc.gov.app.matchers.ProcessorMatcher; import java.util.List; -import java.util.function.Function; +import java.util.Map; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.BooleanUtils; -import org.springframework.integration.annotation.ServiceActivator; -import org.springframework.integration.support.MessageBuilder; -import org.springframework.messaging.Message; -import org.springframework.messaging.MessageHeaders; import org.springframework.stereotype.Service; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -24,36 +20,24 @@ public class LegacyLoadingService { private final List matchers; - @ServiceActivator( - inputChannel = ApplicationConstant.MATCH_CHECKING_CHANNEL, - outputChannel = ApplicationConstant.FORWARD_CHANNEL, - async = "true" - ) - public Mono>> matchCheck( - Message eventMono + public Mono>> matchCheck( + MessagingWrapper eventMono ) { - - Function replier = - value -> BooleanUtils.toString( - value, - ApplicationConstant.AUTO_APPROVE_CHANNEL, - ApplicationConstant.REVIEW_CHANNEL - ); - return - validateSubmission(eventMono.getPayload()) + validateSubmission(eventMono.payload()) .map(matchList -> - MessageBuilder - .withPayload(matchList) - .setReplyChannelName(replier.apply(matchList.isEmpty())) - .setHeader("output-channel", replier.apply(matchList.isEmpty())) - .setHeader(MessageHeaders.REPLY_CHANNEL, replier.apply(matchList.isEmpty())) - .setHeader("submission-id",eventMono.getHeaders().get("submission-id")) - .build() + new MessagingWrapper<>( + matchList, + Map.of( + ApplicationConstant.SUBMISSION_STATUS, matchList.isEmpty(), + ApplicationConstant.SUBMISSION_ID, + eventMono.parameters().get(ApplicationConstant.SUBMISSION_ID) + ) + ) ); } - public Mono> validateSubmission(SubmissionInformationDto message) { + private Mono> validateSubmission(SubmissionInformationDto message) { return Flux .fromIterable(matchers) .filter(matcher -> matcher.enabled(message)) @@ -64,9 +48,4 @@ public Mono> validateSubmission(SubmissionInformationDto mes .collectList(); } - @ServiceActivator(inputChannel = ApplicationConstant.FORWARD_CHANNEL) - public Message> approved(Message> eventMono) { - return eventMono; - } - } diff --git a/processor/src/main/java/ca/bc/gov/app/service/legacy/LegacyPersistenceService.java b/processor/src/main/java/ca/bc/gov/app/service/legacy/LegacyPersistenceService.java new file mode 100644 index 0000000000..93a3c54077 --- /dev/null +++ b/processor/src/main/java/ca/bc/gov/app/service/legacy/LegacyPersistenceService.java @@ -0,0 +1,58 @@ +package ca.bc.gov.app.service.legacy; + +import ca.bc.gov.app.ApplicationConstant; +import ca.bc.gov.app.dto.MessagingWrapper; +import ca.bc.gov.app.entity.SubmissionMatchDetailEntity; +import java.util.List; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; + +@Service +@Slf4j +@RequiredArgsConstructor +public class LegacyPersistenceService { + + private final List persistenceServices; + + public Mono> persist( + MessagingWrapper message) { + return + Flux + .fromStream(persistenceServices.stream()) + .filter(service -> service.filterByType( + message.parameters().get(ApplicationConstant.SUBMISSION_TYPE).toString() + ) + ) + .next() + .flatMap(service -> + service + .loadSubmission( + new MessagingWrapper<>( + (Integer) message.parameters().get(ApplicationConstant.SUBMISSION_ID), + message.parameters() + ) + ) + .flatMap(service::checkClientData) + .flatMap(service::generateForestClient) + .flatMap(service::createForestClient) + .flatMap(submission -> + service + .createLocations(submission) + .flatMap(service::createContact) + .collectList() + ) + ) + .map(submissionList -> + new MessagingWrapper<>( + (Integer) submissionList.get(0).parameters() + .get(ApplicationConstant.SUBMISSION_ID), + submissionList.get(0).parameters() + ) + ); + + } + +} diff --git a/processor/src/main/java/ca/bc/gov/app/service/legacy/LegacyRegisteredSPPersistenceService.java b/processor/src/main/java/ca/bc/gov/app/service/legacy/LegacyRegisteredSPPersistenceService.java index b5e3a636a6..8c434d4cf4 100644 --- a/processor/src/main/java/ca/bc/gov/app/service/legacy/LegacyRegisteredSPPersistenceService.java +++ b/processor/src/main/java/ca/bc/gov/app/service/legacy/LegacyRegisteredSPPersistenceService.java @@ -2,6 +2,7 @@ package ca.bc.gov.app.service.legacy; import ca.bc.gov.app.ApplicationConstant; +import ca.bc.gov.app.dto.MessagingWrapper; import ca.bc.gov.app.dto.bcregistry.BcRegistryPartyDto; import ca.bc.gov.app.dto.legacy.ForestClientDto; import ca.bc.gov.app.repository.SubmissionContactRepository; @@ -14,9 +15,6 @@ import java.util.Optional; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; -import org.springframework.integration.annotation.ServiceActivator; -import org.springframework.integration.support.MessageBuilder; -import org.springframework.messaging.Message; import org.springframework.stereotype.Service; import reactor.core.publisher.Mono; import reactor.util.function.Tuple2; @@ -59,24 +57,16 @@ boolean filterByType(String clientTypeCode) { } @Override - String getNextChannel() { - return ApplicationConstant.SUBMISSION_LEGACY_RSP_CHANNEL; - } - - @ServiceActivator( - inputChannel = ApplicationConstant.SUBMISSION_LEGACY_RSP_CHANNEL, - outputChannel = ApplicationConstant.SUBMISSION_LEGACY_CLIENT_PERSIST_CHANNEL, - async = "true" - ) - @Override - public Mono> generateForestClient(Message message) { + public Mono> generateForestClient( + MessagingWrapper message) { return getSubmissionDetailRepository() .findBySubmissionId( - message - .getHeaders() - .get(ApplicationConstant.SUBMISSION_ID, Integer.class) + (Integer) + message + .parameters() + .get(ApplicationConstant.SUBMISSION_ID) ) .map(submissionDetail -> getBaseForestClient( @@ -126,9 +116,10 @@ public Mono> generateForestClient(Message messa getContactRepository() //Get all contacts for the submission .findBySubmissionId( - message - .getHeaders() - .get(ApplicationConstant.SUBMISSION_ID, Integer.class) + (Integer) + message + .parameters() + .get(ApplicationConstant.SUBMISSION_ID) ) //Handle as a flux with the index .index() @@ -148,26 +139,26 @@ public Mono> generateForestClient(Message messa .withClientName(contact[1]) .withClientTypeCode("I") .withClientIdTypeCode("BCRE") - .withClientNumber(message.getHeaders() - .get(ApplicationConstant.FOREST_CLIENT_NUMBER, String.class)) + .withClientNumber(message.parameters() + .get(ApplicationConstant.FOREST_CLIENT_NUMBER).toString()) ) ) .map(forestClient -> - MessageBuilder - .withPayload(forestClient) - .copyHeaders(message.getHeaders()) - .setHeader(ApplicationConstant.FOREST_CLIENT_NAME, + new MessagingWrapper<>( + forestClient, + message.parameters() + ) + .withParameter(ApplicationConstant.FOREST_CLIENT_NAME, forestClient .clientComment() .split("and company name ")[1] ) - .setHeader(ApplicationConstant.INCORPORATION_NUMBER, + .withParameter(ApplicationConstant.INCORPORATION_NUMBER, String.join(StringUtils.EMPTY, forestClient.registryCompanyTypeCode(), forestClient.corpRegnNmbr() ) ) - .build() ); } diff --git a/processor/src/main/java/ca/bc/gov/app/service/legacy/LegacyUnregisteredSPPersistenceService.java b/processor/src/main/java/ca/bc/gov/app/service/legacy/LegacyUnregisteredSPPersistenceService.java index 8193587e8a..3b0129efbe 100644 --- a/processor/src/main/java/ca/bc/gov/app/service/legacy/LegacyUnregisteredSPPersistenceService.java +++ b/processor/src/main/java/ca/bc/gov/app/service/legacy/LegacyUnregisteredSPPersistenceService.java @@ -2,6 +2,7 @@ package ca.bc.gov.app.service.legacy; import ca.bc.gov.app.ApplicationConstant; +import ca.bc.gov.app.dto.MessagingWrapper; import ca.bc.gov.app.dto.legacy.ForestClientDto; import ca.bc.gov.app.repository.SubmissionContactRepository; import ca.bc.gov.app.repository.SubmissionDetailRepository; @@ -13,9 +14,6 @@ import java.util.stream.Stream; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; -import org.springframework.integration.annotation.ServiceActivator; -import org.springframework.integration.support.MessageBuilder; -import org.springframework.messaging.Message; import org.springframework.stereotype.Service; import reactor.core.publisher.Mono; @@ -52,11 +50,6 @@ boolean filterByType(String clientTypeCode) { return StringUtils.equalsIgnoreCase(clientTypeCode, "USP"); } - @Override - String getNextChannel() { - return ApplicationConstant.SUBMISSION_LEGACY_USP_CHANNEL; - } - /** * This method is responsible for generating the forest client for unregistered sole * proprietorship. @@ -64,19 +57,16 @@ String getNextChannel() { * @param message - the message containing the submission id. * @return - the forest client. */ - @ServiceActivator( - inputChannel = ApplicationConstant.SUBMISSION_LEGACY_USP_CHANNEL, - outputChannel = ApplicationConstant.SUBMISSION_LEGACY_CLIENT_PERSIST_CHANNEL, - async = "true" - ) @Override - public Mono> generateForestClient(Message message) { + public Mono> generateForestClient( + MessagingWrapper message) { return getSubmissionDetailRepository() .findBySubmissionId( - message - .getHeaders() - .get(ApplicationConstant.SUBMISSION_ID, Integer.class) + (Integer) + message + .parameters() + .get(ApplicationConstant.SUBMISSION_ID) ) .map(detail -> getBaseForestClient( @@ -94,8 +84,8 @@ public Mono> generateForestClient(Message messa getUser(message, ApplicationConstant.CLIENT_SUBMITTER_NAME) + " submitted the sole proprietor with data acquired from Business BCeID") .withClientTypeCode("I") - .withClientNumber(message.getHeaders() - .get(ApplicationConstant.FOREST_CLIENT_NUMBER, String.class)) + .withClientNumber(message.parameters() + .get(ApplicationConstant.FOREST_CLIENT_NUMBER).toString()) ) .doOnNext(forestClient -> log.info("Generated forest client for USP {}", @@ -103,10 +93,8 @@ public Mono> generateForestClient(Message messa ) ) .map(forestClient -> - MessageBuilder - .withPayload(forestClient) - .copyHeaders(message.getHeaders()) - .setHeader(ApplicationConstant.FOREST_CLIENT_NAME, + new MessagingWrapper<>(forestClient, message.parameters()) + .withParameter(ApplicationConstant.FOREST_CLIENT_NAME, Stream.of( forestClient.legalFirstName(), forestClient.legalMiddleName(), @@ -115,9 +103,8 @@ public Mono> generateForestClient(Message messa .filter(StringUtils::isNotBlank) .collect(Collectors.joining(" ")) ) - .setHeader(ApplicationConstant.INCORPORATION_NUMBER, + .withParameter(ApplicationConstant.INCORPORATION_NUMBER, "not applicable") - .build() ); } diff --git a/processor/src/main/java/ca/bc/gov/app/service/processor/ProcessorService.java b/processor/src/main/java/ca/bc/gov/app/service/processor/ProcessorService.java new file mode 100644 index 0000000000..fbda7a117d --- /dev/null +++ b/processor/src/main/java/ca/bc/gov/app/service/processor/ProcessorService.java @@ -0,0 +1,129 @@ +package ca.bc.gov.app.service.processor; + +import ca.bc.gov.app.ApplicationConstant; +import ca.bc.gov.app.dto.MessagingWrapper; +import ca.bc.gov.app.entity.SubmissionStatusEnum; +import ca.bc.gov.app.repository.SubmissionRepository; +import ca.bc.gov.app.service.client.ClientSubmissionAutoProcessingService; +import ca.bc.gov.app.service.client.ClientSubmissionLoadingService; +import ca.bc.gov.app.service.client.ClientSubmissionMailService; +import ca.bc.gov.app.service.client.ClientSubmissionProcessingService; +import ca.bc.gov.app.service.legacy.LegacyLoadingService; +import ca.bc.gov.app.service.legacy.LegacyPersistenceService; +import java.util.Map; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Service; +import reactor.core.publisher.Mono; + +@Service +@RequiredArgsConstructor +@Slf4j +public class ProcessorService { + + private final SubmissionRepository submissionRepository; + private final ClientSubmissionLoadingService submissionLoadingService; + private final LegacyLoadingService legacyLoadingService; + private final ClientSubmissionAutoProcessingService autoProcessingService; + private final ClientSubmissionProcessingService submissionProcessingService; + private final ClientSubmissionMailService mailService; + private final LegacyPersistenceService legacyPersistenceService; + + @Scheduled(fixedDelay = 30000) + public void submissionMessages() { + log.info("Starting submission processing"); + //Load submission + submissionRepository + .loadProcessingSubmissions() + .doOnNext(submission -> log.info("Loading submission for processing {}", submission)) + //Load details + .flatMap(submissionLoadingService::loadSubmissionDetails) + .doOnNext(submission -> log.info("Submission loaded, checking for matches {}", + submission.parameters().get( + ApplicationConstant.SUBMISSION_ID)) + ) + //Check matches + .flatMap(legacyLoadingService::matchCheck) + .doOnNext( + submission -> + log.info("Submission matches checked {} {}", + submission.parameters().get(ApplicationConstant.SUBMISSION_ID), + submission.parameters().get(ApplicationConstant.SUBMISSION_STATUS) + ) + ) + //Mark as approved or for review + .flatMap(submission -> + Mono.just(submission) + //If is true, means no matches, so auto-approved + .filter(submissionStatus -> Boolean.TRUE.equals(submissionStatus.parameters().get( + ApplicationConstant.SUBMISSION_STATUS)) + ) + .flatMap(autoProcessingService::approved) + //If filter is false, means there are matches, so send to manual review + .switchIfEmpty(autoProcessingService.reviewed(submission)) + ) + .doOnNext(submission -> log.info("Submission processed {} as {}", + submission.payload(), + submission.parameters().get(ApplicationConstant.SUBMISSION_TYPE) + ) + ) + //Build mail message and send it + .flatMap(submissionLoadingService::buildMailMessage) + .doOnNext(message -> log.info("Email ready to be sent {}", message)) + .flatMap(mailService::sendMail) + .subscribe(); + } + + @Scheduled(fixedDelay = 30000, initialDelay = 10000) + public void processedMessages() { + //Load the submissions that were processed + submissionRepository + .loadProcessedSubmissions() + //Little wrapper to make it easier to pass around + .map(submission -> + new MessagingWrapper<>( + submission, + Map.of(ApplicationConstant.SUBMISSION_ID, submission) + ) + ) + .doOnNext(submission -> log.info("Loaded submission for processing {}", submission)) + //Process the submission by loading some information + .flatMap(submissionProcessingService::processSubmission) + .doOnNext(submission -> log.info("Submission loaded for post processing {}", submission)) + .flatMap(message -> + Mono + .just(message) + //If the submission is approved or auto approved, go save on oracle + .filter(submission -> + SubmissionStatusEnum.A.equals( + submission.parameters() + .get(ApplicationConstant.SUBMISSION_STATUS) + ) + ) + .flatMap(legacyPersistenceService::persist) + //If rejected, just send the email + .defaultIfEmpty( + new MessagingWrapper<>( + (Integer) message.parameters().get(ApplicationConstant.SUBMISSION_ID), + message.parameters() + ) + ) + + .flatMap(submission -> + autoProcessingService + .completeProcessing(submission.payload()) + .map(id -> new MessagingWrapper<>(id, submission.parameters())) + ) + + ) + .doOnNext(submission -> log.info("Submission post processed {}, building message", submission)) + .flatMap(submissionLoadingService::buildMailMessage) + .doOnNext(message -> log.info("Email ready to be sent {}", message)) + .flatMap(mailService::sendMail) + .subscribe(); + + + } + +} diff --git a/processor/src/main/java/ca/bc/gov/app/util/ProcessorUtil.java b/processor/src/main/java/ca/bc/gov/app/util/ProcessorUtil.java index a212a2da3e..d299bc1ac7 100644 --- a/processor/src/main/java/ca/bc/gov/app/util/ProcessorUtil.java +++ b/processor/src/main/java/ca/bc/gov/app/util/ProcessorUtil.java @@ -1,25 +1,14 @@ package ca.bc.gov.app.util; -import java.util.Optional; import java.util.regex.Matcher; import java.util.regex.Pattern; import lombok.AccessLevel; import lombok.NoArgsConstructor; import org.apache.commons.lang3.StringUtils; -import org.springframework.messaging.Message; @NoArgsConstructor(access = AccessLevel.PRIVATE) public class ProcessorUtil { - @SuppressWarnings("unchecked:java:S3740") - public static Optional readHeader( - Message message, - String headerName, - Class clazz - ) { - return Optional.ofNullable(message.getHeaders().get(headerName, clazz)); - } - public static String extractLetters(String input) { Pattern pattern = Pattern.compile("[A-Z]+"); return getStringFromPattern(input, pattern); diff --git a/processor/src/test/java/ca/bc/gov/app/service/ProcessorIntegrationTest.java b/processor/src/test/java/ca/bc/gov/app/service/ProcessorIntegrationTest.java index 9889b0bce6..164b653c05 100644 --- a/processor/src/test/java/ca/bc/gov/app/service/ProcessorIntegrationTest.java +++ b/processor/src/test/java/ca/bc/gov/app/service/ProcessorIntegrationTest.java @@ -1,3 +1,4 @@ +/* package ca.bc.gov.app.service; import static com.github.tomakehurst.wiremock.client.WireMock.get; @@ -78,13 +79,16 @@ void test() { await() .alias("Match by incorporation number") - .atMost(Duration.ofSeconds(5)) - .untilAsserted(() -> wireMockExtension.verify(getRequestedFor(urlPathEqualTo("/api/search/match")))); + .atMost(Duration.ofSeconds(5)) + .untilAsserted( + () -> wireMockExtension.verify(getRequestedFor(urlPathEqualTo("/api/search/match")))); await() .alias("Match by incorporation number") .atMost(Duration.ofSeconds(5)) - .untilAsserted(() -> wireMockExtension.verify(getRequestedFor(urlPathEqualTo("/api/search/incorporationOrName")))); + .untilAsserted(() -> wireMockExtension.verify( + getRequestedFor(urlPathEqualTo("/api/search/incorporationOrName")))); } } +*/ diff --git a/processor/src/test/java/ca/bc/gov/app/service/client/ClientSubmissionAutoProcessingServiceIntegrationTest.java b/processor/src/test/java/ca/bc/gov/app/service/client/ClientSubmissionAutoProcessingServiceIntegrationTest.java index d9e9ff6e19..2df2b04a38 100644 --- a/processor/src/test/java/ca/bc/gov/app/service/client/ClientSubmissionAutoProcessingServiceIntegrationTest.java +++ b/processor/src/test/java/ca/bc/gov/app/service/client/ClientSubmissionAutoProcessingServiceIntegrationTest.java @@ -1,6 +1,5 @@ package ca.bc.gov.app.service.client; -import static ca.bc.gov.app.TestConstants.EMAIL_REQUEST; import static org.assertj.core.api.Assertions.as; import static org.assertj.core.api.AssertionsForClassTypes.assertThat; import static org.awaitility.Awaitility.await; @@ -11,6 +10,7 @@ import ca.bc.gov.app.ApplicationConstant; import ca.bc.gov.app.dto.MatcherResult; +import ca.bc.gov.app.dto.MessagingWrapper; import ca.bc.gov.app.entity.SubmissionEntity; import ca.bc.gov.app.entity.SubmissionMatchDetailEntity; import ca.bc.gov.app.extensions.AbstractTestContainer; @@ -19,14 +19,13 @@ import java.time.Duration; import java.util.ArrayList; import java.util.List; +import java.util.Map; import org.assertj.core.api.InstanceOfAssertFactories; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.mock.mockito.SpyBean; -import org.springframework.integration.support.MessageBuilder; -import org.springframework.messaging.Message; import reactor.test.StepVerifier; @DisplayName("Integrated Test | Client Service") @@ -48,13 +47,13 @@ void shouldApproveSubmission() { service .approved( - MessageBuilder - .withPayload(matchers) - .setHeader(ApplicationConstant.SUBMISSION_ID, 1) - .build() + new MessagingWrapper<>( + matchers, + Map.of(ApplicationConstant.SUBMISSION_ID, 1) + ) ) .as(StepVerifier::create) - .assertNext(message -> Assertions.assertEquals(Integer.valueOf(1), message.getPayload())) + .assertNext(message -> Assertions.assertEquals(Integer.valueOf(1), message.payload())) .verifyComplete(); await() @@ -77,12 +76,7 @@ void shouldApproveSubmission() { void shouldCompleteProcessing() { service - .completeProcessing( - MessageBuilder - .withPayload(EMAIL_REQUEST) - .setHeader(ApplicationConstant.SUBMISSION_ID, 2) - .build() - ) + .completeProcessing(2) .as(StepVerifier::create) .expectNextCount(1) .verifyComplete(); @@ -110,29 +104,27 @@ void shouldReviewSubmission() { List matchers = new ArrayList<>(); - Message> message = MessageBuilder - .withPayload(matchers) - .setHeader(ApplicationConstant.SUBMISSION_ID, 1) - .build(); - + MessagingWrapper> message = new MessagingWrapper<>( + matchers, Map.of(ApplicationConstant.SUBMISSION_ID, 1) + ); service .reviewed(message) .as(StepVerifier::create) - .assertNext( received -> - assertThat(received) - .isNotNull() - .isInstanceOf(Message.class) - .hasFieldOrPropertyWithValue("payload", 1) - .hasFieldOrProperty("headers") - .extracting(Message::getHeaders, as(InstanceOfAssertFactories.MAP)) - .isNotNull() - .isNotEmpty() - .containsKey("id") - .containsKey("timestamp") - .containsEntry(ApplicationConstant.SUBMISSION_ID, 1) - ) - .verifyComplete(); + .assertNext(received -> + assertThat(received) + .isNotNull() + .isInstanceOf(MessagingWrapper.class) + .hasFieldOrPropertyWithValue("payload", 1) + .hasFieldOrProperty("parameters") + .extracting(MessagingWrapper::parameters, as(InstanceOfAssertFactories.MAP)) + .isNotNull() + .isNotEmpty() + .containsKey("id") + .containsKey("timestamp") + .containsEntry(ApplicationConstant.SUBMISSION_ID, 1) + ) + .verifyComplete(); await() .alias("Submission lookup") @@ -158,4 +150,4 @@ void shouldReviewSubmission() { } -} \ No newline at end of file +} diff --git a/processor/src/test/java/ca/bc/gov/app/service/client/ClientSubmissionLoadingServiceTest.java b/processor/src/test/java/ca/bc/gov/app/service/client/ClientSubmissionLoadingServiceTest.java index 5fa719e432..468b563540 100644 --- a/processor/src/test/java/ca/bc/gov/app/service/client/ClientSubmissionLoadingServiceTest.java +++ b/processor/src/test/java/ca/bc/gov/app/service/client/ClientSubmissionLoadingServiceTest.java @@ -2,20 +2,17 @@ import static org.assertj.core.api.Assertions.as; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import ca.bc.gov.app.ApplicationConstant; import ca.bc.gov.app.TestConstants; -import ca.bc.gov.app.entity.SubmissionTypeCodeEnum; +import ca.bc.gov.app.dto.MessagingWrapper; import ca.bc.gov.app.repository.SubmissionContactRepository; import ca.bc.gov.app.repository.SubmissionDetailRepository; import org.assertj.core.api.InstanceOfAssertFactories; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import org.springframework.integration.support.MessageBuilder; -import org.springframework.messaging.Message; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; @@ -26,7 +23,8 @@ class ClientSubmissionLoadingServiceTest { mock(SubmissionDetailRepository.class); private final SubmissionContactRepository contactRepository = mock(SubmissionContactRepository.class); - private final ClientSubmissionLoadingService service = new ClientSubmissionLoadingService(submissionDetailRepository,contactRepository); + private final ClientSubmissionLoadingService service = new ClientSubmissionLoadingService( + submissionDetailRepository, contactRepository); @Test @@ -42,10 +40,10 @@ void shouldLoadSubmissionIntoMessage() { .assertNext(message -> assertThat(message) .isNotNull() - .isInstanceOf(Message.class) + .isInstanceOf(MessagingWrapper.class) .hasFieldOrPropertyWithValue("payload", TestConstants.SUBMISSION_INFORMATION) - .hasFieldOrProperty("headers") - .extracting(Message::getHeaders, as(InstanceOfAssertFactories.MAP)) + .hasFieldOrProperty("parameters") + .extracting(MessagingWrapper::parameters, as(InstanceOfAssertFactories.MAP)) .isNotNull() .isNotEmpty() .containsKey("id") @@ -56,46 +54,5 @@ void shouldLoadSubmissionIntoMessage() { } - @Test - @DisplayName("should send notification") - void shouldSendNotification(){ - - when(submissionDetailRepository.findBySubmissionId(any())) - .thenReturn(Mono.just(TestConstants.SUBMISSION_DETAIL.withClientNumber("00001000"))); - when(contactRepository.findFirstBySubmissionId(any())) - .thenReturn(Mono.just(TestConstants.SUBMISSION_CONTACT)); - - - - service - .sendNotification( - MessageBuilder - .withPayload(1) - .setHeader(ApplicationConstant.SUBMISSION_ID, 1) - .setHeader(ApplicationConstant.SUBMISSION_TYPE, SubmissionTypeCodeEnum.AAC) - .setHeader(ApplicationConstant.FOREST_CLIENT_NAME, "Test") - .setHeader(ApplicationConstant.FOREST_CLIENT_NUMBER, "00001000") - .build() - ) - .as(StepVerifier::create) - .assertNext(message -> - assertThat(message) - .isNotNull() - .isInstanceOf(Message.class) - .hasFieldOrPropertyWithValue("payload", TestConstants.EMAIL_REQUEST_DTO) - .hasFieldOrProperty("headers") - .extracting(Message::getHeaders, as(InstanceOfAssertFactories.MAP)) - .isNotNull() - .isNotEmpty() - .containsKey("id") - .containsKey("timestamp") - .containsEntry(ApplicationConstant.SUBMISSION_ID, 1) - .containsEntry(ApplicationConstant.SUBMISSION_TYPE, SubmissionTypeCodeEnum.AAC) - .containsEntry(ApplicationConstant.FOREST_CLIENT_NAME, "Test") - .containsEntry(ApplicationConstant.FOREST_CLIENT_NUMBER, "00001000") - ) - .verifyComplete(); - } - -} \ No newline at end of file +} diff --git a/processor/src/test/java/ca/bc/gov/app/service/client/ClientSubmissionMailServiceTest.java b/processor/src/test/java/ca/bc/gov/app/service/client/ClientSubmissionMailServiceTest.java index a5ffe5b0d8..e1932c9935 100644 --- a/processor/src/test/java/ca/bc/gov/app/service/client/ClientSubmissionMailServiceTest.java +++ b/processor/src/test/java/ca/bc/gov/app/service/client/ClientSubmissionMailServiceTest.java @@ -9,9 +9,7 @@ import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; import static org.awaitility.Awaitility.await; -import ca.bc.gov.app.ApplicationConstant; import ca.bc.gov.app.TestConstants; -import ca.bc.gov.app.entity.SubmissionTypeCodeEnum; import com.github.tomakehurst.wiremock.junit5.WireMockExtension; import java.time.Duration; import org.junit.jupiter.api.BeforeAll; @@ -19,8 +17,8 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; import org.springframework.http.MediaType; -import org.springframework.integration.support.MessageBuilder; import org.springframework.web.reactive.function.client.WebClient; +import reactor.test.StepVerifier; @DisplayName("Unit Test | Client Submission Mail Service") class ClientSubmissionMailServiceTest { @@ -45,35 +43,32 @@ public static void setUp() { @Test @DisplayName("send an email") void shouldSendEmail() { - service.sendMail( - MessageBuilder - .withPayload(TestConstants.EMAIL_REQUEST) - .build() - ); + service + .sendMail(TestConstants.EMAIL_REQUEST) + .as(StepVerifier::create) + .verifyComplete(); await() .alias("Email sent") .atMost(Duration.ofSeconds(2)) - .untilAsserted(() -> { - wireMockExtension - .verify( - postRequestedFor(urlEqualTo("/ches/email")) - .withHeader("Content-Type", containing(MediaType.APPLICATION_JSON_VALUE)) - .withRequestBody(equalToJson(TestConstants.EMAIL_REQUEST_JSON) - ) - ); - }); + .untilAsserted(() -> + wireMockExtension + .verify( + postRequestedFor(urlEqualTo("/ches/email")) + .withHeader("Content-Type", containing(MediaType.APPLICATION_JSON_VALUE)) + .withRequestBody(equalToJson(TestConstants.EMAIL_REQUEST_JSON) + ) + ) + ); } @Test @DisplayName("preview email on review") void shouldPreventReviewMails() { - service.sendMail( - MessageBuilder - .withPayload(TestConstants.EMAIL_REQUEST) - .setHeader(ApplicationConstant.SUBMISSION_TYPE, SubmissionTypeCodeEnum.RNC) - .build() - ); + service + .sendMail(TestConstants.EMAIL_REQUEST) + .as(StepVerifier::create) + .verifyComplete(); await() .alias("Email sent") @@ -90,4 +85,4 @@ void shouldPreventReviewMails() { }); } -} \ No newline at end of file +} diff --git a/processor/src/test/java/ca/bc/gov/app/service/client/ClientSubmissionProcessingServiceIntegrationTest.java b/processor/src/test/java/ca/bc/gov/app/service/client/ClientSubmissionProcessingServiceIntegrationTest.java index ab16b27cf1..6bc7f711bc 100644 --- a/processor/src/test/java/ca/bc/gov/app/service/client/ClientSubmissionProcessingServiceIntegrationTest.java +++ b/processor/src/test/java/ca/bc/gov/app/service/client/ClientSubmissionProcessingServiceIntegrationTest.java @@ -1,36 +1,25 @@ package ca.bc.gov.app.service.client; -import static org.awaitility.Awaitility.await; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.atLeastOnce; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import ca.bc.gov.app.ApplicationConstant; -import ca.bc.gov.app.dto.EmailRequestDto; -import ca.bc.gov.app.entity.SubmissionContactEntity; +import ca.bc.gov.app.dto.MessagingWrapper; import ca.bc.gov.app.entity.SubmissionDetailEntity; import ca.bc.gov.app.entity.SubmissionEntity; import ca.bc.gov.app.entity.SubmissionMatchDetailEntity; import ca.bc.gov.app.entity.SubmissionStatusEnum; -import ca.bc.gov.app.repository.SubmissionContactRepository; import ca.bc.gov.app.repository.SubmissionDetailRepository; import ca.bc.gov.app.repository.SubmissionMatchDetailRepository; import ca.bc.gov.app.repository.SubmissionRepository; -import java.time.Duration; import java.util.Map; import java.util.stream.Stream; import org.apache.commons.lang3.StringUtils; import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; -import org.springframework.integration.support.MessageBuilder; -import org.springframework.messaging.Message; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; @@ -42,13 +31,10 @@ class ClientSubmissionProcessingServiceIntegrationTest { private final SubmissionRepository submissionRepository = mock(SubmissionRepository.class); private final SubmissionMatchDetailRepository submissionMatchDetailRepository = mock( SubmissionMatchDetailRepository.class); - private final SubmissionContactRepository contactRepository = mock( - SubmissionContactRepository.class); private final ClientSubmissionProcessingService service = new ClientSubmissionProcessingService( submissionDetailRepository, submissionRepository, - submissionMatchDetailRepository, - contactRepository + submissionMatchDetailRepository ); @ParameterizedTest @@ -58,40 +44,36 @@ void shouldLoadSubmission( Mono submission, Mono submissionDetail, Mono submissionMatchDetail, - Message expected + MessagingWrapper expected ) { when(submissionDetailRepository.findBySubmissionId(1)).thenReturn(submissionDetail); when(submissionRepository.findById(1)).thenReturn(submission); when(submissionMatchDetailRepository.findBySubmissionId(1)).thenReturn(submissionMatchDetail); - StepVerifier.FirstStep> test = + StepVerifier.FirstStep> test = service - .processSubmission( - MessageBuilder - .withPayload(1) - .build() - ) + .processSubmission(new MessagingWrapper<>(1, Map.of())) .as(StepVerifier::create); if (expected != null) { test.assertNext(message -> { - assertEquals(expected.getPayload(), message.getPayload()); + assertEquals(expected.payload(), message.payload()); assertEquals( - expected.getHeaders().get(ApplicationConstant.SUBMISSION_ID), - message.getHeaders().get(ApplicationConstant.SUBMISSION_ID) + expected.parameters().get(ApplicationConstant.SUBMISSION_ID), + message.parameters().get(ApplicationConstant.SUBMISSION_ID) ); assertEquals( - expected.getHeaders().get(ApplicationConstant.SUBMISSION_STATUS), - message.getHeaders().get(ApplicationConstant.SUBMISSION_STATUS) + expected.parameters().get(ApplicationConstant.SUBMISSION_STATUS), + message.parameters().get(ApplicationConstant.SUBMISSION_STATUS) ); assertEquals( - expected.getHeaders().get(ApplicationConstant.SUBMISSION_CLIENTID), - message.getHeaders().get(ApplicationConstant.SUBMISSION_CLIENTID) + expected.parameters().get(ApplicationConstant.SUBMISSION_CLIENTID), + message.parameters().get(ApplicationConstant.SUBMISSION_CLIENTID) ); assertEquals( - expected.getHeaders().get(ApplicationConstant.SUBMISSION_NAME), - message.getHeaders().get(ApplicationConstant.SUBMISSION_NAME) + expected.parameters().get(ApplicationConstant.SUBMISSION_NAME), + message.parameters().get(ApplicationConstant.SUBMISSION_NAME) ); }) .verifyComplete(); @@ -102,56 +84,6 @@ void shouldLoadSubmission( } - @ParameterizedTest - @MethodSource("notification") - @DisplayName("notification is sent") - void shouldNotify( - SubmissionStatusEnum statusEnum, - Mono contact, - Mono detail, - Mono match, - Object response - ) { - - when(contactRepository.findFirstBySubmissionId(1)).thenReturn(contact); - when(submissionDetailRepository.findBySubmissionId(1)).thenReturn(detail); - when(submissionMatchDetailRepository.findBySubmissionId(1)).thenReturn(match); - - service - .notificationProcessing( - MessageBuilder - .withPayload(SubmissionMatchDetailEntity.builder().build()) - .setHeader(ApplicationConstant.SUBMISSION_STATUS, statusEnum) - .setHeader(ApplicationConstant.SUBMISSION_ID, 1) - .build() - ) - .as(StepVerifier::create) - .assertNext(message -> - assertEquals(response, message.getPayload()) - ) - .verifyComplete(); - } - - @Test - @DisplayName("update match") - void shouldUpdateMatch() { - when(submissionMatchDetailRepository.findBySubmissionId(1)) - .thenReturn(Mono.just(SubmissionMatchDetailEntity.builder().build())); - service - .updateMatch(MessageBuilder.withPayload(1).build()); - - await() - .alias("Submission matches") - .atMost(Duration.ofSeconds(5)) - .untilAsserted(() -> { - verify(submissionMatchDetailRepository, atLeastOnce()) - .save(any(SubmissionMatchDetailEntity.class)); - verify(submissionMatchDetailRepository, atLeastOnce()) - .findBySubmissionId(eq(1)); - } - ); - } - private static Stream submissionLoads() { return Stream.of( @@ -166,13 +98,15 @@ private static Stream submissionLoads() { SubmissionEntity.builder().submissionStatus(SubmissionStatusEnum.N).build()), Mono.just(SubmissionDetailEntity.builder().organizationName("TEST").build()), Mono.empty(), - MessageBuilder - .withPayload(SubmissionMatchDetailEntity.builder().build()) - .setHeader(ApplicationConstant.SUBMISSION_ID, 1) - .setHeader(ApplicationConstant.SUBMISSION_STATUS, SubmissionStatusEnum.N) - .setHeader(ApplicationConstant.SUBMISSION_CLIENTID, StringUtils.EMPTY) - .setHeader(ApplicationConstant.SUBMISSION_NAME, "TEST") - .build() + new MessagingWrapper<>( + SubmissionMatchDetailEntity.builder().build(), + Map.of( + ApplicationConstant.SUBMISSION_ID, 1, + ApplicationConstant.SUBMISSION_STATUS, SubmissionStatusEnum.N, + ApplicationConstant.SUBMISSION_CLIENTID, StringUtils.EMPTY, + ApplicationConstant.SUBMISSION_NAME, "TEST" + ) + ) ), Arguments.of( @@ -180,54 +114,18 @@ private static Stream submissionLoads() { SubmissionEntity.builder().submissionStatus(SubmissionStatusEnum.N).build()), Mono.just(SubmissionDetailEntity.builder().organizationName("TEST").build()), Mono.just(SubmissionMatchDetailEntity.builder().build()), - MessageBuilder - .withPayload(SubmissionMatchDetailEntity.builder().build()) - .setHeader(ApplicationConstant.SUBMISSION_ID, 1) - .setHeader(ApplicationConstant.SUBMISSION_STATUS, SubmissionStatusEnum.N) - .setHeader(ApplicationConstant.SUBMISSION_CLIENTID, StringUtils.EMPTY) - .setHeader(ApplicationConstant.SUBMISSION_NAME, "TEST") - .build() + new MessagingWrapper<>( + SubmissionMatchDetailEntity.builder().build(), + Map.of( + ApplicationConstant.SUBMISSION_ID, 1, + ApplicationConstant.SUBMISSION_STATUS, SubmissionStatusEnum.N, + ApplicationConstant.SUBMISSION_CLIENTID, StringUtils.EMPTY, + ApplicationConstant.SUBMISSION_NAME, "TEST" + ) + ) ) ); } - private static Stream notification() { - return - Stream - .of( - Arguments.of( - SubmissionStatusEnum.A, - Mono.empty(), - Mono.empty(), - Mono.empty(), - 1 - ), - Arguments.of( - SubmissionStatusEnum.R, - Mono.just(SubmissionContactEntity.builder().userId("uid1").firstName("Test") - .emailAddress("Mail") - .build()), - Mono.just(SubmissionDetailEntity.builder().organizationName("TEST") - .incorporationNumber("XX012345").build()), - Mono.just( - SubmissionMatchDetailEntity.builder().matchingMessage("Test").build()), - new EmailRequestDto( - "XX012345", - "TEST", - "uid1", - "Test", - "Mail", - "rejection", - "Failure", - Map.of( - "userName", "Test", - "name", "TEST", - "reason", "Test" - ) - ) - ) - ); - } - -} \ No newline at end of file +} diff --git a/processor/src/test/java/ca/bc/gov/app/service/legacy/LegacyAbstractPersistenceServiceIntegrationTest.java b/processor/src/test/java/ca/bc/gov/app/service/legacy/LegacyAbstractPersistenceServiceIntegrationTest.java index 92ddb9cf56..3fed850534 100644 --- a/processor/src/test/java/ca/bc/gov/app/service/legacy/LegacyAbstractPersistenceServiceIntegrationTest.java +++ b/processor/src/test/java/ca/bc/gov/app/service/legacy/LegacyAbstractPersistenceServiceIntegrationTest.java @@ -4,11 +4,12 @@ import static org.assertj.core.api.Assertions.assertThat; import ca.bc.gov.app.ApplicationConstant; +import ca.bc.gov.app.dto.MessagingWrapper; import ca.bc.gov.app.extensions.AbstractTestContainer; +import java.util.Map; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.integration.support.MessageBuilder; import reactor.test.StepVerifier; @DisplayName("Integration Test | Legacy Persistence Service") @@ -22,26 +23,23 @@ class LegacyAbstractPersistenceServiceIntegrationTest extends AbstractTestContai void shouldLoadSubmissions() { service - .loadSubmission(MessageBuilder - .withPayload(2) - .build() - ) + .loadSubmission(new MessagingWrapper<>(2, Map.of())) .as(StepVerifier::create) .assertNext(message -> { assertThat(message) .isNotNull() .hasFieldOrPropertyWithValue("payload", 2); - assertThat(message.getHeaders().get(ApplicationConstant.SUBMISSION_ID)) + assertThat(message.parameters().get(ApplicationConstant.SUBMISSION_ID)) .isNotNull() .isInstanceOf(Integer.class) .isEqualTo(2); - assertThat(message.getHeaders().get(ApplicationConstant.CREATED_BY)) + assertThat(message.parameters().get(ApplicationConstant.CREATED_BY)) .isNotNull() .isInstanceOf(String.class); - assertThat(message.getHeaders().get(ApplicationConstant.UPDATED_BY)) + assertThat(message.parameters().get(ApplicationConstant.UPDATED_BY)) .isNotNull() .isInstanceOf(String.class); @@ -50,4 +48,4 @@ void shouldLoadSubmissions() { } -} \ No newline at end of file +} diff --git a/processor/src/test/java/ca/bc/gov/app/service/legacy/LegacyAbstractPersistenceServiceTest.java b/processor/src/test/java/ca/bc/gov/app/service/legacy/LegacyAbstractPersistenceServiceTest.java index 92240ae5a8..1a4ffdc99c 100644 --- a/processor/src/test/java/ca/bc/gov/app/service/legacy/LegacyAbstractPersistenceServiceTest.java +++ b/processor/src/test/java/ca/bc/gov/app/service/legacy/LegacyAbstractPersistenceServiceTest.java @@ -10,6 +10,7 @@ import static org.mockito.Mockito.when; import ca.bc.gov.app.ApplicationConstant; +import ca.bc.gov.app.dto.MessagingWrapper; import ca.bc.gov.app.entity.SubmissionContactEntity; import ca.bc.gov.app.entity.SubmissionDetailEntity; import ca.bc.gov.app.entity.SubmissionLocationContactEntity; @@ -19,13 +20,13 @@ import ca.bc.gov.app.repository.SubmissionLocationContactRepository; import ca.bc.gov.app.repository.SubmissionLocationRepository; import ca.bc.gov.app.repository.SubmissionRepository; +import java.util.Map; import java.util.stream.Stream; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; -import org.springframework.integration.support.MessageBuilder; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; @@ -78,16 +79,18 @@ void shouldCreateLocations(boolean locationExisted) { service .createLocations( - MessageBuilder - .withPayload(2) - .setHeader(ApplicationConstant.SUBMISSION_ID, 2) - .setHeader(ApplicationConstant.CREATED_BY, ApplicationConstant.PROCESSOR_USER_NAME) - .setHeader(ApplicationConstant.UPDATED_BY, ApplicationConstant.PROCESSOR_USER_NAME) - .setHeader(ApplicationConstant.FOREST_CLIENT_NUMBER, "00000000") - .setHeader(ApplicationConstant.FOREST_CLIENT_NAME, "STAR DOT STAR VENTURES") - .setHeader(ApplicationConstant.INCORPORATION_NUMBER, "FM0159297") - .setHeader(ApplicationConstant.CLIENT_TYPE_CODE, "C") - .build() + new MessagingWrapper<>( + 2, + Map.of( + ApplicationConstant.SUBMISSION_ID, 2, + ApplicationConstant.CREATED_BY, ApplicationConstant.PROCESSOR_USER_NAME, + ApplicationConstant.UPDATED_BY, ApplicationConstant.PROCESSOR_USER_NAME, + ApplicationConstant.FOREST_CLIENT_NUMBER, "00000000", + ApplicationConstant.FOREST_CLIENT_NAME, "STAR DOT STAR VENTURES", + ApplicationConstant.INCORPORATION_NUMBER, "FM0159297", + ApplicationConstant.CLIENT_TYPE_CODE, "C" + ) + ) ) .as(StepVerifier::create) .assertNext(message -> { @@ -95,50 +98,50 @@ void shouldCreateLocations(boolean locationExisted) { .isNotNull() .hasFieldOrPropertyWithValue("payload", 2); - assertThat(message.getHeaders().get(ApplicationConstant.SUBMISSION_ID)) + assertThat(message.parameters().get(ApplicationConstant.SUBMISSION_ID)) .isNotNull() .isInstanceOf(Integer.class) .isEqualTo(2); - assertThat(message.getHeaders().get(ApplicationConstant.CREATED_BY)) + assertThat(message.parameters().get(ApplicationConstant.CREATED_BY)) .isNotNull() .isInstanceOf(String.class); - assertThat(message.getHeaders().get(ApplicationConstant.UPDATED_BY)) + assertThat(message.parameters().get(ApplicationConstant.UPDATED_BY)) .isNotNull() .isInstanceOf(String.class); - assertThat(message.getHeaders().get(ApplicationConstant.FOREST_CLIENT_NAME)) + assertThat(message.parameters().get(ApplicationConstant.FOREST_CLIENT_NAME)) .isNotNull() .isInstanceOf(String.class) .isEqualTo("STAR DOT STAR VENTURES"); - assertThat(message.getHeaders().get(ApplicationConstant.INCORPORATION_NUMBER)) + assertThat(message.parameters().get(ApplicationConstant.INCORPORATION_NUMBER)) .isNotNull() .isInstanceOf(String.class) .isEqualTo("FM0159297"); - assertThat(message.getHeaders().get(ApplicationConstant.FOREST_CLIENT_NUMBER)) + assertThat(message.parameters().get(ApplicationConstant.FOREST_CLIENT_NUMBER)) .isNotNull() .isInstanceOf(String.class) .isEqualTo("00000000"); - assertThat(message.getHeaders().get(ApplicationConstant.LOCATION_CODE)) + assertThat(message.parameters().get(ApplicationConstant.LOCATION_CODE)) .isNotNull() .isInstanceOf(String.class) .isEqualTo("00"); - assertThat(message.getHeaders().get(ApplicationConstant.LOCATION_ID)) + assertThat(message.parameters().get(ApplicationConstant.LOCATION_ID)) .isNotNull() .isInstanceOf(Integer.class) .isEqualTo(1); - assertThat(message.getHeaders().get(ApplicationConstant.TOTAL)) + assertThat(message.parameters().get(ApplicationConstant.TOTAL)) .isNotNull() .isInstanceOf(Long.class) .isEqualTo(1L); - assertThat(message.getHeaders().get(ApplicationConstant.INDEX)) + assertThat(message.parameters().get(ApplicationConstant.INDEX)) .isNotNull() .isInstanceOf(Long.class) .isEqualTo(0L); @@ -177,21 +180,23 @@ void shouldCreateContacts(boolean contactExisted) { when(legacyService.createContact(any())) .thenReturn(Mono.just("00000000")); + Map params = Map.of( + ApplicationConstant.SUBMISSION_ID, 2, + ApplicationConstant.CREATED_BY, ApplicationConstant.PROCESSOR_USER_NAME, + ApplicationConstant.UPDATED_BY, ApplicationConstant.PROCESSOR_USER_NAME, + ApplicationConstant.FOREST_CLIENT_NUMBER, "00000000", + ApplicationConstant.FOREST_CLIENT_NAME, "STAR DOT STAR VENTURES", + ApplicationConstant.INCORPORATION_NUMBER, "FM0159297", + ApplicationConstant.LOCATION_CODE, "00", + ApplicationConstant.LOCATION_ID, 1, + ApplicationConstant.CLIENT_TYPE_CODE, "C" + ); + service.createContact( - MessageBuilder - .withPayload(2) - .setHeader(ApplicationConstant.SUBMISSION_ID, 2) - .setHeader(ApplicationConstant.CREATED_BY, ApplicationConstant.PROCESSOR_USER_NAME) - .setHeader(ApplicationConstant.UPDATED_BY, ApplicationConstant.PROCESSOR_USER_NAME) - .setHeader(ApplicationConstant.FOREST_CLIENT_NUMBER, "00000000") - .setHeader(ApplicationConstant.FOREST_CLIENT_NAME, "STAR DOT STAR VENTURES") - .setHeader(ApplicationConstant.INCORPORATION_NUMBER, "FM0159297") - .setHeader(ApplicationConstant.LOCATION_CODE, "00") - .setHeader(ApplicationConstant.LOCATION_ID, 1) - .setHeader(ApplicationConstant.TOTAL, 1L) - .setHeader(ApplicationConstant.INDEX, 0L) - .setHeader(ApplicationConstant.CLIENT_TYPE_CODE, "C") - .build() + new MessagingWrapper<>( + 2, + params + ) ) .as(StepVerifier::create) .assertNext(message -> { @@ -199,89 +204,48 @@ void shouldCreateContacts(boolean contactExisted) { .isNotNull() .hasFieldOrPropertyWithValue("payload", 2); - assertThat(message.getHeaders().get(ApplicationConstant.SUBMISSION_ID)) + assertThat(message.parameters().get(ApplicationConstant.SUBMISSION_ID)) .isNotNull() .isInstanceOf(Integer.class) .isEqualTo(2); - assertThat(message.getHeaders().get(ApplicationConstant.CREATED_BY)) + assertThat(message.parameters().get(ApplicationConstant.CREATED_BY)) .isNotNull() .isInstanceOf(String.class); - assertThat(message.getHeaders().get(ApplicationConstant.UPDATED_BY)) + assertThat(message.parameters().get(ApplicationConstant.UPDATED_BY)) .isNotNull() .isInstanceOf(String.class); - assertThat(message.getHeaders().get(ApplicationConstant.FOREST_CLIENT_NAME)) + assertThat(message.parameters().get(ApplicationConstant.FOREST_CLIENT_NAME)) .isNotNull() .isInstanceOf(String.class) .isEqualTo("STAR DOT STAR VENTURES"); - assertThat(message.getHeaders().get(ApplicationConstant.INCORPORATION_NUMBER)) + assertThat(message.parameters().get(ApplicationConstant.INCORPORATION_NUMBER)) .isNotNull() .isInstanceOf(String.class) .isEqualTo("FM0159297"); - assertThat(message.getHeaders().get(ApplicationConstant.FOREST_CLIENT_NUMBER)) + assertThat(message.parameters().get(ApplicationConstant.FOREST_CLIENT_NUMBER)) .isNotNull() .isInstanceOf(String.class) .isEqualTo("00000000"); - assertThat(message.getHeaders().get(ApplicationConstant.LOCATION_CODE)) + assertThat(message.parameters().get(ApplicationConstant.LOCATION_CODE)) .isNotNull() .isInstanceOf(String.class) .isEqualTo("00"); - assertThat(message.getHeaders().get(ApplicationConstant.LOCATION_ID)) + assertThat(message.parameters().get(ApplicationConstant.LOCATION_ID)) .isNotNull() .isInstanceOf(Integer.class) .isEqualTo(1); - assertThat(message.getHeaders().get(ApplicationConstant.TOTAL)) - .isNotNull() - .isInstanceOf(Long.class) - .isEqualTo(1L); - - assertThat(message.getHeaders().get(ApplicationConstant.INDEX)) - .isNotNull() - .isInstanceOf(Long.class) - .isEqualTo(0L); - }) .verifyComplete(); } - @Test - @DisplayName("send email") - void shouldSendEmail() { - - service - .sendNotification( - MessageBuilder - .withPayload(2) - .setHeader(ApplicationConstant.SUBMISSION_ID, 2) - .setHeader(ApplicationConstant.CREATED_BY, ApplicationConstant.PROCESSOR_USER_NAME) - .setHeader(ApplicationConstant.UPDATED_BY, ApplicationConstant.PROCESSOR_USER_NAME) - .setHeader(ApplicationConstant.FOREST_CLIENT_NUMBER, "00000000") - .setHeader(ApplicationConstant.FOREST_CLIENT_NAME, "STAR DOT STAR VENTURES") - .setHeader(ApplicationConstant.INCORPORATION_NUMBER, "FM0159297") - .setHeader(ApplicationConstant.LOCATION_CODE, "00") - .setHeader(ApplicationConstant.LOCATION_ID, 1) - .setHeader(ApplicationConstant.TOTAL, 1L) - .setHeader(ApplicationConstant.INDEX, 0L) - .setHeader(ApplicationConstant.CLIENT_TYPE_CODE, "C") - .build() - ) - .as(StepVerifier::create) - .assertNext(mailMessage -> - assertThat(mailMessage.getPayload()) - .isNotNull() - .isInstanceOf(Integer.class) - .isEqualTo(2L) - ) - .verifyComplete(); - } - @ParameterizedTest @MethodSource("clientData") @DisplayName("check client data") @@ -315,12 +279,14 @@ void shouldCheckClientData( service .checkClientData( - MessageBuilder - .withPayload(2) - .setHeader(ApplicationConstant.SUBMISSION_ID, 2) - .setHeader(ApplicationConstant.CREATED_BY, ApplicationConstant.PROCESSOR_USER_NAME) - .setHeader(ApplicationConstant.UPDATED_BY, ApplicationConstant.PROCESSOR_USER_NAME) - .build() + new MessagingWrapper<>( + 2, + Map.of( + ApplicationConstant.SUBMISSION_ID, 2, + ApplicationConstant.CREATED_BY, ApplicationConstant.PROCESSOR_USER_NAME, + ApplicationConstant.UPDATED_BY, ApplicationConstant.PROCESSOR_USER_NAME + ) + ) ) .as(StepVerifier::create) .assertNext(message -> { @@ -328,29 +294,29 @@ void shouldCheckClientData( .isNotNull() .hasFieldOrPropertyWithValue("payload", 2); - assertThat(message.getHeaders().get(ApplicationConstant.SUBMISSION_ID)) + assertThat(message.parameters().get(ApplicationConstant.SUBMISSION_ID)) .as("submission id") .isNotNull() .isInstanceOf(Integer.class) .isEqualTo(2); - assertThat(message.getHeaders().get(ApplicationConstant.CREATED_BY)) + assertThat(message.parameters().get(ApplicationConstant.CREATED_BY)) .as("created by") .isNotNull() .isInstanceOf(String.class); - assertThat(message.getHeaders().get(ApplicationConstant.UPDATED_BY)) + assertThat(message.parameters().get(ApplicationConstant.UPDATED_BY)) .as("updated by") .isNotNull() .isInstanceOf(String.class); - assertThat(message.getHeaders().get(ApplicationConstant.CLIENT_TYPE_CODE)) + assertThat(message.parameters().get(ApplicationConstant.CLIENT_TYPE_CODE)) .as("client type code") .isNotNull() .isInstanceOf(String.class) .isEqualTo(clientTypeCode); - assertThat(message.getHeaders().get(ApplicationConstant.CLIENT_SUBMITTER_NAME)) + assertThat(message.parameters().get(ApplicationConstant.CLIENT_SUBMITTER_NAME)) .as("client submitter name") .isNotNull() .isInstanceOf(String.class) @@ -380,18 +346,19 @@ void shouldCreateClient() { when(legacyService.createClient(any())) .thenReturn(Mono.just("00000000")); - service .createForestClient( - MessageBuilder - .withPayload(CLIENT_ENTITY) - .setHeader(ApplicationConstant.SUBMISSION_ID, 2) - .setHeader(ApplicationConstant.CREATED_BY, ApplicationConstant.PROCESSOR_USER_NAME) - .setHeader(ApplicationConstant.UPDATED_BY, ApplicationConstant.PROCESSOR_USER_NAME) - .setHeader(ApplicationConstant.CLIENT_TYPE_CODE, "C") - .setHeader(ApplicationConstant.FOREST_CLIENT_NUMBER, "00000000") - .setHeader(ApplicationConstant.FOREST_CLIENT_NAME, "CHAMPAGNE SUPERNOVA") - .build() + new MessagingWrapper<>( + CLIENT_ENTITY, + Map.of( + ApplicationConstant.SUBMISSION_ID, 2, + ApplicationConstant.CREATED_BY, ApplicationConstant.PROCESSOR_USER_NAME, + ApplicationConstant.UPDATED_BY, ApplicationConstant.PROCESSOR_USER_NAME, + ApplicationConstant.CLIENT_TYPE_CODE, "C", + ApplicationConstant.FOREST_CLIENT_NUMBER, "00000000", + ApplicationConstant.FOREST_CLIENT_NAME, "CHAMPAGNE SUPERNOVA" + ) + ) ) .as(StepVerifier::create) .assertNext(message -> { @@ -400,7 +367,7 @@ void shouldCreateClient() { .isNotNull() .hasFieldOrPropertyWithValue("payload", 2); - assertThat(message.getHeaders().get(ApplicationConstant.FOREST_CLIENT_NUMBER)) + assertThat(message.parameters().get(ApplicationConstant.FOREST_CLIENT_NUMBER)) .as("forest client number") .isNotNull() .isInstanceOf(String.class) @@ -417,15 +384,19 @@ void shouldTryToCreateClient(String type) { service .createForestClient( - MessageBuilder - .withPayload(CLIENT_ENTITY) - .setHeader(ApplicationConstant.SUBMISSION_ID, 2) - .setHeader(ApplicationConstant.CREATED_BY, ApplicationConstant.PROCESSOR_USER_NAME) - .setHeader(ApplicationConstant.UPDATED_BY, ApplicationConstant.PROCESSOR_USER_NAME) - .setHeader(ApplicationConstant.CLIENT_TYPE_CODE, type) - .setHeader(ApplicationConstant.FOREST_CLIENT_NUMBER, "00000000") - .setHeader(ApplicationConstant.FOREST_CLIENT_NAME, "CHAMPAGNE SUPERNOVA") - .build() + new MessagingWrapper<>( + CLIENT_ENTITY, + Map.of( + ApplicationConstant.SUBMISSION_ID, 2, + ApplicationConstant.CREATED_BY, + ApplicationConstant.PROCESSOR_USER_NAME, + ApplicationConstant.UPDATED_BY, + ApplicationConstant.PROCESSOR_USER_NAME, + ApplicationConstant.CLIENT_TYPE_CODE, type, + ApplicationConstant.FOREST_CLIENT_NUMBER, "00000000", + ApplicationConstant.FOREST_CLIENT_NAME, "CHAMPAGNE SUPERNOVA" + ) + ) ) .as(StepVerifier::create) .verifyComplete(); @@ -437,15 +408,17 @@ void shouldTryToCreateClient(String type) { void shouldTryToCreateContact(String type) { service .createContact( - MessageBuilder - .withPayload(1) - .setHeader(ApplicationConstant.SUBMISSION_ID, 2) - .setHeader(ApplicationConstant.CREATED_BY, ApplicationConstant.PROCESSOR_USER_NAME) - .setHeader(ApplicationConstant.UPDATED_BY, ApplicationConstant.PROCESSOR_USER_NAME) - .setHeader(ApplicationConstant.CLIENT_TYPE_CODE, type) - .setHeader(ApplicationConstant.FOREST_CLIENT_NUMBER, "00000000") - .setHeader(ApplicationConstant.FOREST_CLIENT_NAME, "CHAMPAGNE SUPERNOVA") - .build() + new MessagingWrapper<>( + 1, + Map.of( + ApplicationConstant.SUBMISSION_ID, 2, + ApplicationConstant.CREATED_BY, ApplicationConstant.PROCESSOR_USER_NAME, + ApplicationConstant.UPDATED_BY, ApplicationConstant.PROCESSOR_USER_NAME, + ApplicationConstant.CLIENT_TYPE_CODE, type, + ApplicationConstant.FOREST_CLIENT_NUMBER, "00000000", + ApplicationConstant.FOREST_CLIENT_NAME, "CHAMPAGNE SUPERNOVA" + ) + ) ) .as(StepVerifier::create) .verifyComplete(); @@ -457,15 +430,17 @@ void shouldTryToCreateContact(String type) { void shouldTryToCreateLocation(String type) { service .createLocations( - MessageBuilder - .withPayload(1) - .setHeader(ApplicationConstant.SUBMISSION_ID, 2) - .setHeader(ApplicationConstant.CREATED_BY, ApplicationConstant.PROCESSOR_USER_NAME) - .setHeader(ApplicationConstant.UPDATED_BY, ApplicationConstant.PROCESSOR_USER_NAME) - .setHeader(ApplicationConstant.CLIENT_TYPE_CODE, type) - .setHeader(ApplicationConstant.FOREST_CLIENT_NUMBER, "00000000") - .setHeader(ApplicationConstant.FOREST_CLIENT_NAME, "CHAMPAGNE SUPERNOVA") - .build() + new MessagingWrapper<>( + 1, + Map.of( + ApplicationConstant.SUBMISSION_ID, 2, + ApplicationConstant.CREATED_BY, ApplicationConstant.PROCESSOR_USER_NAME, + ApplicationConstant.UPDATED_BY, ApplicationConstant.PROCESSOR_USER_NAME, + ApplicationConstant.CLIENT_TYPE_CODE, type, + ApplicationConstant.FOREST_CLIENT_NUMBER, "00000000", + ApplicationConstant.FOREST_CLIENT_NAME, "CHAMPAGNE SUPERNOVA" + ) + ) ) .as(StepVerifier::create) .verifyComplete(); diff --git a/processor/src/test/java/ca/bc/gov/app/service/legacy/LegacyClientPersistenceServiceTest.java b/processor/src/test/java/ca/bc/gov/app/service/legacy/LegacyClientPersistenceServiceTest.java index 322a59916f..ad81d9c40b 100644 --- a/processor/src/test/java/ca/bc/gov/app/service/legacy/LegacyClientPersistenceServiceTest.java +++ b/processor/src/test/java/ca/bc/gov/app/service/legacy/LegacyClientPersistenceServiceTest.java @@ -7,21 +7,20 @@ import static org.mockito.Mockito.when; import ca.bc.gov.app.ApplicationConstant; -import ca.bc.gov.app.dto.legacy.ForestClientDto; +import ca.bc.gov.app.dto.MessagingWrapper; import ca.bc.gov.app.entity.SubmissionDetailEntity; import ca.bc.gov.app.repository.SubmissionContactRepository; import ca.bc.gov.app.repository.SubmissionDetailRepository; import ca.bc.gov.app.repository.SubmissionLocationContactRepository; import ca.bc.gov.app.repository.SubmissionLocationRepository; import ca.bc.gov.app.repository.SubmissionRepository; +import java.util.Map; import java.util.stream.Stream; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; -import org.springframework.data.r2dbc.core.ReactiveInsertOperation.ReactiveInsert; -import org.springframework.integration.support.MessageBuilder; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; @@ -55,17 +54,9 @@ void shouldFilterByType(String type, boolean expected) { assertEquals(expected, service.filterByType(type)); } - @Test - @DisplayName("get next channel") - void shouldGetNextChannel() { - assertEquals(ApplicationConstant.SUBMISSION_LEGACY_OTHER_CHANNEL, service.getNextChannel()); - } - - @Test @DisplayName("create forest client") void shouldCreateForestClient() { - ReactiveInsert reactiveInsert = mock(ReactiveInsert.class); SubmissionDetailEntity entity = SubmissionDetailEntity.builder() .submissionId(2) @@ -82,14 +73,16 @@ void shouldCreateForestClient() { service .generateForestClient( - MessageBuilder - .withPayload("00000001") - .setHeader(ApplicationConstant.SUBMISSION_ID, 2) - .setHeader(ApplicationConstant.FOREST_CLIENT_NUMBER, "00000001") - .setHeader(ApplicationConstant.CREATED_BY, ApplicationConstant.PROCESSOR_USER_NAME) - .setHeader(ApplicationConstant.UPDATED_BY, ApplicationConstant.PROCESSOR_USER_NAME) - .setHeader(ApplicationConstant.CLIENT_SUBMITTER_NAME, "Jhon Snow") - .build() + new MessagingWrapper<>( + "00000001", + Map.of( + ApplicationConstant.SUBMISSION_ID, 2, + ApplicationConstant.FOREST_CLIENT_NUMBER, "00000001", + ApplicationConstant.CREATED_BY, ApplicationConstant.PROCESSOR_USER_NAME, + ApplicationConstant.UPDATED_BY, ApplicationConstant.PROCESSOR_USER_NAME, + ApplicationConstant.CLIENT_SUBMITTER_NAME, "Jhon Snow" + ) + ) ) .as(StepVerifier::create) .assertNext(message -> { @@ -97,7 +90,7 @@ void shouldCreateForestClient() { .isNotNull() .hasFieldOrProperty("payload"); - assertThat(message.getPayload()) + assertThat(message.parameters()) .isNotNull() .hasFieldOrPropertyWithValue("clientName", "STAR DOT STAR VENTURES") .hasFieldOrPropertyWithValue("clientTypeCode", "C") @@ -107,30 +100,30 @@ void shouldCreateForestClient() { .hasFieldOrPropertyWithValue("clientComment", "Jhon Snow submitted the client details acquired from BC Registry FM0159297"); - assertThat(message.getHeaders().get(ApplicationConstant.SUBMISSION_ID)) + assertThat(message.parameters().get(ApplicationConstant.SUBMISSION_ID)) .isNotNull() .isInstanceOf(Integer.class) .isEqualTo(2); - assertThat(message.getHeaders().get(ApplicationConstant.CREATED_BY)) + assertThat(message.parameters().get(ApplicationConstant.CREATED_BY)) .isNotNull() .isInstanceOf(String.class); - assertThat(message.getHeaders().get(ApplicationConstant.UPDATED_BY)) + assertThat(message.parameters().get(ApplicationConstant.UPDATED_BY)) .isNotNull() .isInstanceOf(String.class); - assertThat(message.getHeaders().get(ApplicationConstant.FOREST_CLIENT_NAME)) + assertThat(message.parameters().get(ApplicationConstant.FOREST_CLIENT_NAME)) .isNotNull() .isInstanceOf(String.class) .isEqualTo("STAR DOT STAR VENTURES"); - assertThat(message.getHeaders().get(ApplicationConstant.INCORPORATION_NUMBER)) + assertThat(message.parameters().get(ApplicationConstant.INCORPORATION_NUMBER)) .isNotNull() .isInstanceOf(String.class) .isEqualTo("FM0159297"); - assertThat(message.getHeaders().get(ApplicationConstant.FOREST_CLIENT_NUMBER)) + assertThat(message.parameters().get(ApplicationConstant.FOREST_CLIENT_NUMBER)) .isNotNull() .isInstanceOf(String.class) .isEqualTo("00000001"); @@ -148,4 +141,4 @@ private static Stream byType() { ); } -} \ No newline at end of file +} diff --git a/processor/src/test/java/ca/bc/gov/app/service/legacy/LegacyIndividualPersistenceServiceTest.java b/processor/src/test/java/ca/bc/gov/app/service/legacy/LegacyIndividualPersistenceServiceTest.java index f345880a55..cd94307a06 100644 --- a/processor/src/test/java/ca/bc/gov/app/service/legacy/LegacyIndividualPersistenceServiceTest.java +++ b/processor/src/test/java/ca/bc/gov/app/service/legacy/LegacyIndividualPersistenceServiceTest.java @@ -7,19 +7,20 @@ import static org.mockito.Mockito.when; import ca.bc.gov.app.ApplicationConstant; +import ca.bc.gov.app.dto.MessagingWrapper; import ca.bc.gov.app.entity.SubmissionDetailEntity; import ca.bc.gov.app.repository.SubmissionContactRepository; import ca.bc.gov.app.repository.SubmissionDetailRepository; import ca.bc.gov.app.repository.SubmissionLocationContactRepository; import ca.bc.gov.app.repository.SubmissionLocationRepository; import ca.bc.gov.app.repository.SubmissionRepository; +import java.util.Map; import java.util.stream.Stream; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; -import org.springframework.integration.support.MessageBuilder; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; @@ -54,15 +55,6 @@ void shouldFilterByType(String type, boolean expected) { assertEquals(expected, service.filterByType(type)); } - - @Test - @DisplayName("get next channel") - void shouldGetNextChannel() { - assertEquals(ApplicationConstant.SUBMISSION_LEGACY_INDIVIDUAL_CHANNEL, - service.getNextChannel()); - } - - @Test @DisplayName("create forest client") void shouldCreateForestClient() { @@ -81,14 +73,16 @@ void shouldCreateForestClient() { service .generateForestClient( - MessageBuilder - .withPayload("00000001") - .setHeader(ApplicationConstant.SUBMISSION_ID, 2) - .setHeader(ApplicationConstant.FOREST_CLIENT_NUMBER, "00000001") - .setHeader(ApplicationConstant.CREATED_BY, ApplicationConstant.PROCESSOR_USER_NAME) - .setHeader(ApplicationConstant.UPDATED_BY, ApplicationConstant.PROCESSOR_USER_NAME) - .setHeader(ApplicationConstant.CLIENT_SUBMITTER_NAME, "Jhon Snow") - .build() + new MessagingWrapper<>( + "00000001", + Map.of( + ApplicationConstant.SUBMISSION_ID, 2, + ApplicationConstant.FOREST_CLIENT_NUMBER, "00000001", + ApplicationConstant.CREATED_BY, ApplicationConstant.PROCESSOR_USER_NAME, + ApplicationConstant.UPDATED_BY, ApplicationConstant.PROCESSOR_USER_NAME, + ApplicationConstant.CLIENT_SUBMITTER_NAME, "Jhon Snow" + ) + ) ) .as(StepVerifier::create) .assertNext(message -> { @@ -96,7 +90,7 @@ void shouldCreateForestClient() { .isNotNull() .hasFieldOrProperty("payload"); - assertThat(message.getPayload()) + assertThat(message.payload()) .isNotNull() .hasFieldOrPropertyWithValue("clientName", "BAXTER") .hasFieldOrPropertyWithValue("legalFirstName", "JAMES") @@ -108,30 +102,30 @@ void shouldCreateForestClient() { .hasFieldOrPropertyWithValue("clientIdentification", ApplicationConstant.PROCESSOR_USER_NAME); - assertThat(message.getHeaders().get(ApplicationConstant.SUBMISSION_ID)) + assertThat(message.parameters().get(ApplicationConstant.SUBMISSION_ID)) .isNotNull() .isInstanceOf(Integer.class) .isEqualTo(2); - assertThat(message.getHeaders().get(ApplicationConstant.CREATED_BY)) + assertThat(message.parameters().get(ApplicationConstant.CREATED_BY)) .isNotNull() .isInstanceOf(String.class); - assertThat(message.getHeaders().get(ApplicationConstant.UPDATED_BY)) + assertThat(message.parameters().get(ApplicationConstant.UPDATED_BY)) .isNotNull() .isInstanceOf(String.class); - assertThat(message.getHeaders().get(ApplicationConstant.FOREST_CLIENT_NAME)) + assertThat(message.parameters().get(ApplicationConstant.FOREST_CLIENT_NAME)) .isNotNull() .isInstanceOf(String.class) .isEqualTo("JAMES BAXTER"); - assertThat(message.getHeaders().get(ApplicationConstant.INCORPORATION_NUMBER)) + assertThat(message.parameters().get(ApplicationConstant.INCORPORATION_NUMBER)) .isNotNull() .isInstanceOf(String.class) .isEqualTo("not applicable"); - assertThat(message.getHeaders().get(ApplicationConstant.FOREST_CLIENT_NUMBER)) + assertThat(message.parameters().get(ApplicationConstant.FOREST_CLIENT_NUMBER)) .isNotNull() .isInstanceOf(String.class) .isEqualTo("00000001"); @@ -149,4 +143,4 @@ private static Stream byType() { ); } -} \ No newline at end of file +} diff --git a/processor/src/test/java/ca/bc/gov/app/service/legacy/LegacyLoadingServiceTest.java b/processor/src/test/java/ca/bc/gov/app/service/legacy/LegacyLoadingServiceTest.java index 2ee352462e..e9eec8e5d9 100644 --- a/processor/src/test/java/ca/bc/gov/app/service/legacy/LegacyLoadingServiceTest.java +++ b/processor/src/test/java/ca/bc/gov/app/service/legacy/LegacyLoadingServiceTest.java @@ -2,44 +2,30 @@ import static org.assertj.core.api.Assertions.as; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.*; import ca.bc.gov.app.ApplicationConstant; import ca.bc.gov.app.TestConstants; import ca.bc.gov.app.dto.MatcherResult; +import ca.bc.gov.app.dto.MessagingWrapper; import ca.bc.gov.app.dto.SubmissionInformationDto; import ca.bc.gov.app.matchers.ProcessorMatcher; -import java.util.ArrayList; import java.util.List; +import java.util.Map; import java.util.stream.Stream; import org.assertj.core.api.InstanceOfAssertFactories; import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; -import org.springframework.integration.support.MessageBuilder; -import org.springframework.messaging.Message; -import org.springframework.messaging.MessageHeaders; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; @DisplayName("Unit Test | Legacy Service") class LegacyLoadingServiceTest { - private final LegacyLoadingService service = new LegacyLoadingService(List.of(new TestProcessorMatcher())); + private final LegacyLoadingService service = new LegacyLoadingService( + List.of(new TestProcessorMatcher())); - @Test - @DisplayName("Forward it") - void shouldJustForwardMessage() { - List matchers = new ArrayList<>(); - Message> message = MessageBuilder - .withPayload(matchers) - .setHeader(ApplicationConstant.SUBMISSION_ID, 1) - .build(); - - assertEquals(message, service.approved(message)); - } @ParameterizedTest @MethodSource("matchCheck") @@ -47,24 +33,23 @@ void shouldJustForwardMessage() { void shouldCheckAndMatch(SubmissionInformationDto input, String responseChannel) { service .matchCheck( - MessageBuilder - .withPayload(input) - .setHeader(ApplicationConstant.SUBMISSION_ID, 1) - .build() + new MessagingWrapper<>( + input, + Map.of(ApplicationConstant.SUBMISSION_ID, 1) + ) ) .as(StepVerifier::create) .assertNext(message -> assertThat(message) .isNotNull() - .isInstanceOf(Message.class) + .isInstanceOf(MessagingWrapper.class) .hasFieldOrProperty("payload") - .hasFieldOrProperty("headers") - .extracting(Message::getHeaders, as(InstanceOfAssertFactories.MAP)) + .hasFieldOrProperty("parameters") + .extracting(MessagingWrapper::parameters, as(InstanceOfAssertFactories.MAP)) .isNotNull() .isNotEmpty() .containsKey("id") .containsKey("timestamp") - .containsEntry(MessageHeaders.REPLY_CHANNEL, responseChannel) .containsEntry(ApplicationConstant.SUBMISSION_ID, 1) ) .verifyComplete(); @@ -84,7 +69,7 @@ private static Stream matchCheck() { ); } - private static class TestProcessorMatcher implements ProcessorMatcher{ + private static class TestProcessorMatcher implements ProcessorMatcher { @Override public boolean enabled(SubmissionInformationDto submission) { @@ -101,9 +86,9 @@ public Mono matches(SubmissionInformationDto submission) { return Mono .just(submission.goodStanding()) .filter(value -> value.equalsIgnoreCase("N")) - .map(value -> new MatcherResult("test",value)); + .map(value -> new MatcherResult("test", value)); } } -} \ No newline at end of file +} diff --git a/processor/src/test/java/ca/bc/gov/app/service/legacy/LegacyRegisteredSPPersistenceServiceTest.java b/processor/src/test/java/ca/bc/gov/app/service/legacy/LegacyRegisteredSPPersistenceServiceTest.java index 4b3a0fa934..521ed19294 100644 --- a/processor/src/test/java/ca/bc/gov/app/service/legacy/LegacyRegisteredSPPersistenceServiceTest.java +++ b/processor/src/test/java/ca/bc/gov/app/service/legacy/LegacyRegisteredSPPersistenceServiceTest.java @@ -9,6 +9,7 @@ import ca.bc.gov.app.ApplicationConstant; import ca.bc.gov.app.TestConstants; +import ca.bc.gov.app.dto.MessagingWrapper; import ca.bc.gov.app.entity.SubmissionDetailEntity; import ca.bc.gov.app.repository.SubmissionContactRepository; import ca.bc.gov.app.repository.SubmissionDetailRepository; @@ -16,6 +17,7 @@ import ca.bc.gov.app.repository.SubmissionLocationRepository; import ca.bc.gov.app.repository.SubmissionRepository; import ca.bc.gov.app.service.bcregistry.BcRegistryService; +import java.util.Map; import java.util.stream.Stream; import org.assertj.core.api.Assertions; import org.junit.jupiter.api.DisplayName; @@ -23,7 +25,6 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; -import org.springframework.integration.support.MessageBuilder; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; @@ -59,12 +60,6 @@ void shouldFilterByType(String type, boolean expected) { assertEquals(expected, service.filterByType(type)); } - @Test - @DisplayName("get next channel") - void shouldGetNextChannel() { - assertEquals(ApplicationConstant.SUBMISSION_LEGACY_RSP_CHANNEL, service.getNextChannel()); - } - @Test @DisplayName("create forest client") void shouldCreateForestClient() { @@ -90,14 +85,16 @@ void shouldCreateForestClient() { service .generateForestClient( - MessageBuilder - .withPayload("00000001") - .setHeader(ApplicationConstant.SUBMISSION_ID, 2) - .setHeader(ApplicationConstant.FOREST_CLIENT_NUMBER, "00000001") - .setHeader(ApplicationConstant.CREATED_BY, ApplicationConstant.PROCESSOR_USER_NAME) - .setHeader(ApplicationConstant.UPDATED_BY, ApplicationConstant.PROCESSOR_USER_NAME) - .setHeader(ApplicationConstant.CLIENT_SUBMITTER_NAME, "Jhon Snow") - .build() + new MessagingWrapper<>( + "00000001", + Map.of( + ApplicationConstant.SUBMISSION_ID, 2, + ApplicationConstant.FOREST_CLIENT_NUMBER, "00000001", + ApplicationConstant.CREATED_BY, ApplicationConstant.PROCESSOR_USER_NAME, + ApplicationConstant.UPDATED_BY, ApplicationConstant.PROCESSOR_USER_NAME, + ApplicationConstant.CLIENT_SUBMITTER_NAME, "Jhon Snow" + ) + ) ) .as(StepVerifier::create) .assertNext(message -> { @@ -105,7 +102,7 @@ void shouldCreateForestClient() { .isNotNull() .hasFieldOrProperty("payload"); - assertThat(message.getPayload()) + assertThat(message.payload()) .isNotNull() .hasFieldOrPropertyWithValue("clientName", "BAXTER") .hasFieldOrPropertyWithValue("legalFirstName", "JAMES") @@ -125,30 +122,30 @@ void shouldCreateForestClient() { .hasFieldOrPropertyWithValue("clientTypeCode", "I") .hasFieldOrPropertyWithValue("clientNumber", "00000001"); - assertThat(message.getHeaders().get(ApplicationConstant.SUBMISSION_ID)) + assertThat(message.parameters().get(ApplicationConstant.SUBMISSION_ID)) .isNotNull() .isInstanceOf(Integer.class) .isEqualTo(2); - assertThat(message.getHeaders().get(ApplicationConstant.CREATED_BY)) + assertThat(message.parameters().get(ApplicationConstant.CREATED_BY)) .isNotNull() .isInstanceOf(String.class); - assertThat(message.getHeaders().get(ApplicationConstant.UPDATED_BY)) + assertThat(message.parameters().get(ApplicationConstant.UPDATED_BY)) .isNotNull() .isInstanceOf(String.class); - assertThat(message.getHeaders().get(ApplicationConstant.FOREST_CLIENT_NAME)) + assertThat(message.parameters().get(ApplicationConstant.FOREST_CLIENT_NAME)) .isNotNull() .isInstanceOf(String.class) .isEqualTo("BAXTER CORP"); - assertThat(message.getHeaders().get(ApplicationConstant.INCORPORATION_NUMBER)) + assertThat(message.parameters().get(ApplicationConstant.INCORPORATION_NUMBER)) .isNotNull() .isInstanceOf(String.class) .isEqualTo("FM00184546"); - assertThat(message.getHeaders().get(ApplicationConstant.FOREST_CLIENT_NUMBER)) + assertThat(message.parameters().get(ApplicationConstant.FOREST_CLIENT_NUMBER)) .isNotNull() .isInstanceOf(String.class) .isEqualTo("00000001"); @@ -182,14 +179,16 @@ void shouldCreateForestClientWhenNoBcRegData() { service .generateForestClient( - MessageBuilder - .withPayload("00000001") - .setHeader(ApplicationConstant.SUBMISSION_ID, 2) - .setHeader(ApplicationConstant.FOREST_CLIENT_NUMBER, "00000001") - .setHeader(ApplicationConstant.CREATED_BY, ApplicationConstant.PROCESSOR_USER_NAME) - .setHeader(ApplicationConstant.UPDATED_BY, ApplicationConstant.PROCESSOR_USER_NAME) - .setHeader(ApplicationConstant.CLIENT_SUBMITTER_NAME, "Jhon Snow") - .build() + new MessagingWrapper<>( + "00000001", + Map.of( + ApplicationConstant.SUBMISSION_ID, 2, + ApplicationConstant.FOREST_CLIENT_NUMBER, "00000001", + ApplicationConstant.CREATED_BY, ApplicationConstant.PROCESSOR_USER_NAME, + ApplicationConstant.UPDATED_BY, ApplicationConstant.PROCESSOR_USER_NAME, + ApplicationConstant.CLIENT_SUBMITTER_NAME, "Jhon Snow" + ) + ) ) .as(StepVerifier::create) .assertNext(message -> { @@ -197,7 +196,7 @@ void shouldCreateForestClientWhenNoBcRegData() { .isNotNull() .hasFieldOrProperty("payload"); - assertThat(message.getPayload()) + assertThat(message.payload()) .isNotNull() .hasFieldOrPropertyWithValue("clientName", "BAXTER") .hasFieldOrPropertyWithValue("legalFirstName", "JAMES") @@ -217,30 +216,30 @@ void shouldCreateForestClientWhenNoBcRegData() { .hasFieldOrPropertyWithValue("clientTypeCode", "I") .hasFieldOrPropertyWithValue("clientNumber", "00000001"); - assertThat(message.getHeaders().get(ApplicationConstant.SUBMISSION_ID)) + assertThat(message.parameters().get(ApplicationConstant.SUBMISSION_ID)) .isNotNull() .isInstanceOf(Integer.class) .isEqualTo(2); - assertThat(message.getHeaders().get(ApplicationConstant.CREATED_BY)) + assertThat(message.parameters().get(ApplicationConstant.CREATED_BY)) .isNotNull() .isInstanceOf(String.class); - assertThat(message.getHeaders().get(ApplicationConstant.UPDATED_BY)) + assertThat(message.parameters().get(ApplicationConstant.UPDATED_BY)) .isNotNull() .isInstanceOf(String.class); - assertThat(message.getHeaders().get(ApplicationConstant.FOREST_CLIENT_NAME)) + assertThat(message.parameters().get(ApplicationConstant.FOREST_CLIENT_NAME)) .isNotNull() .isInstanceOf(String.class) .isEqualTo("BAXTER CORP"); - assertThat(message.getHeaders().get(ApplicationConstant.INCORPORATION_NUMBER)) + assertThat(message.parameters().get(ApplicationConstant.INCORPORATION_NUMBER)) .isNotNull() .isInstanceOf(String.class) .isEqualTo("FM00184546"); - assertThat(message.getHeaders().get(ApplicationConstant.FOREST_CLIENT_NUMBER)) + assertThat(message.parameters().get(ApplicationConstant.FOREST_CLIENT_NUMBER)) .isNotNull() .isInstanceOf(String.class) .isEqualTo("00000001"); @@ -273,21 +272,22 @@ void shouldCreateClient() { service .createForestClient( - MessageBuilder - .withPayload( - TestConstants - .CLIENT_ENTITY - .withClientTypeCode("I") - .withClientIdTypeCode("BCRE") + new MessagingWrapper<>( + TestConstants + .CLIENT_ENTITY + .withClientTypeCode("I") + .withClientIdTypeCode("BCRE") + , + Map.of( + ApplicationConstant.SUBMISSION_ID, 2, + ApplicationConstant.CREATED_BY, ApplicationConstant.PROCESSOR_USER_NAME, + ApplicationConstant.UPDATED_BY, ApplicationConstant.PROCESSOR_USER_NAME, + ApplicationConstant.CLIENT_TYPE_CODE, "RSP", + ApplicationConstant.FOREST_CLIENT_NUMBER, "00000000", + ApplicationConstant.FOREST_CLIENT_NAME, "CHAMPAGNE SUPERNOVA", + ApplicationConstant.CLIENT_SUBMITTER_NAME, "Jhon Snow" ) - .setHeader(ApplicationConstant.SUBMISSION_ID, 2) - .setHeader(ApplicationConstant.CREATED_BY, ApplicationConstant.PROCESSOR_USER_NAME) - .setHeader(ApplicationConstant.UPDATED_BY, ApplicationConstant.PROCESSOR_USER_NAME) - .setHeader(ApplicationConstant.CLIENT_TYPE_CODE, "RSP") - .setHeader(ApplicationConstant.FOREST_CLIENT_NUMBER, "00000000") - .setHeader(ApplicationConstant.FOREST_CLIENT_NAME, "CHAMPAGNE SUPERNOVA") - .setHeader(ApplicationConstant.CLIENT_SUBMITTER_NAME, "Jhon Snow") - .build() + ) ) .as(StepVerifier::create) .assertNext(message -> { @@ -296,7 +296,7 @@ void shouldCreateClient() { .isNotNull() .hasFieldOrPropertyWithValue("payload", 2); - Assertions.assertThat(message.getHeaders().get(ApplicationConstant.FOREST_CLIENT_NUMBER)) + Assertions.assertThat(message.parameters().get(ApplicationConstant.FOREST_CLIENT_NUMBER)) .as("forest client number") .isNotNull() .isInstanceOf(String.class) @@ -315,4 +315,4 @@ private static Stream byType() { ); } -} \ No newline at end of file +} diff --git a/processor/src/test/java/ca/bc/gov/app/service/legacy/LegacyUnregisteredSPPersistenceServiceTest.java b/processor/src/test/java/ca/bc/gov/app/service/legacy/LegacyUnregisteredSPPersistenceServiceTest.java index 9c897fd192..78027ae194 100644 --- a/processor/src/test/java/ca/bc/gov/app/service/legacy/LegacyUnregisteredSPPersistenceServiceTest.java +++ b/processor/src/test/java/ca/bc/gov/app/service/legacy/LegacyUnregisteredSPPersistenceServiceTest.java @@ -7,12 +7,14 @@ import static org.mockito.Mockito.when; import ca.bc.gov.app.ApplicationConstant; +import ca.bc.gov.app.dto.MessagingWrapper; import ca.bc.gov.app.entity.SubmissionDetailEntity; import ca.bc.gov.app.repository.SubmissionContactRepository; import ca.bc.gov.app.repository.SubmissionDetailRepository; import ca.bc.gov.app.repository.SubmissionLocationContactRepository; import ca.bc.gov.app.repository.SubmissionLocationRepository; import ca.bc.gov.app.repository.SubmissionRepository; +import java.util.Map; import java.util.stream.Stream; import org.apache.commons.lang3.StringUtils; import org.junit.jupiter.api.DisplayName; @@ -20,7 +22,6 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; -import org.springframework.integration.support.MessageBuilder; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; @@ -55,12 +56,6 @@ void shouldFilterByType(String type, boolean expected) { assertEquals(expected, service.filterByType(type)); } - @Test - @DisplayName("get next channel") - void shouldGetNextChannel() { - assertEquals(ApplicationConstant.SUBMISSION_LEGACY_USP_CHANNEL, service.getNextChannel()); - } - @Test @DisplayName("create forest client") void shouldCreateForestClient() { @@ -79,14 +74,16 @@ void shouldCreateForestClient() { service .generateForestClient( - MessageBuilder - .withPayload("00000001") - .setHeader(ApplicationConstant.SUBMISSION_ID, 2) - .setHeader(ApplicationConstant.FOREST_CLIENT_NUMBER, "00000001") - .setHeader(ApplicationConstant.CREATED_BY, ApplicationConstant.PROCESSOR_USER_NAME) - .setHeader(ApplicationConstant.UPDATED_BY, ApplicationConstant.PROCESSOR_USER_NAME) - .setHeader(ApplicationConstant.CLIENT_SUBMITTER_NAME, "Jhon Snow") - .build() + new MessagingWrapper<>( + "00000001", + Map.of( + ApplicationConstant.SUBMISSION_ID, 2, + ApplicationConstant.FOREST_CLIENT_NUMBER, "00000001", + ApplicationConstant.CREATED_BY, ApplicationConstant.PROCESSOR_USER_NAME, + ApplicationConstant.UPDATED_BY, ApplicationConstant.PROCESSOR_USER_NAME, + ApplicationConstant.CLIENT_SUBMITTER_NAME, "Jhon Snow" + ) + ) ) .as(StepVerifier::create) .assertNext(message -> { @@ -94,7 +91,7 @@ void shouldCreateForestClient() { .isNotNull() .hasFieldOrProperty("payload"); - assertThat(message.getPayload()) + assertThat(message.payload()) .isNotNull() .hasFieldOrPropertyWithValue("clientName", "BAXTER") .hasFieldOrPropertyWithValue("legalFirstName", "JAMES") @@ -104,30 +101,30 @@ void shouldCreateForestClient() { .hasFieldOrPropertyWithValue("clientTypeCode", "I") .hasFieldOrPropertyWithValue("clientNumber", "00000001"); - assertThat(message.getHeaders().get(ApplicationConstant.SUBMISSION_ID)) + assertThat(message.parameters().get(ApplicationConstant.SUBMISSION_ID)) .isNotNull() .isInstanceOf(Integer.class) .isEqualTo(2); - assertThat(message.getHeaders().get(ApplicationConstant.CREATED_BY)) + assertThat(message.parameters().get(ApplicationConstant.CREATED_BY)) .isNotNull() .isInstanceOf(String.class); - assertThat(message.getHeaders().get(ApplicationConstant.UPDATED_BY)) + assertThat(message.parameters().get(ApplicationConstant.UPDATED_BY)) .isNotNull() .isInstanceOf(String.class); - assertThat(message.getHeaders().get(ApplicationConstant.FOREST_CLIENT_NAME)) + assertThat(message.parameters().get(ApplicationConstant.FOREST_CLIENT_NAME)) .isNotNull() .isInstanceOf(String.class) .isEqualTo("JAMES BAXTER"); - assertThat(message.getHeaders().get(ApplicationConstant.INCORPORATION_NUMBER)) + assertThat(message.parameters().get(ApplicationConstant.INCORPORATION_NUMBER)) .isNotNull() .isInstanceOf(String.class) .isEqualTo("not applicable"); - assertThat(message.getHeaders().get(ApplicationConstant.FOREST_CLIENT_NUMBER)) + assertThat(message.parameters().get(ApplicationConstant.FOREST_CLIENT_NUMBER)) .isNotNull() .isInstanceOf(String.class) .isEqualTo("00000001"); @@ -145,4 +142,4 @@ private static Stream byType() { ); } -} \ No newline at end of file +} diff --git a/processor/src/test/java/ca/bc/gov/app/util/ProcessorUtilTest.java b/processor/src/test/java/ca/bc/gov/app/util/ProcessorUtilTest.java index c93b9f777d..224ce304e0 100644 --- a/processor/src/test/java/ca/bc/gov/app/util/ProcessorUtilTest.java +++ b/processor/src/test/java/ca/bc/gov/app/util/ProcessorUtilTest.java @@ -1,6 +1,5 @@ package ca.bc.gov.app.util; -import java.util.Optional; import java.util.stream.Stream; import org.apache.commons.lang3.StringUtils; import org.junit.jupiter.api.Assertions; @@ -8,27 +7,10 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; -import org.springframework.integration.support.MessageBuilder; @DisplayName("Unit Test | Processor Util") class ProcessorUtilTest { - - @ParameterizedTest(name = "should read header {0} and get {1}") - @MethodSource("readHeader") - @DisplayName("should read header") - void shouldReadHeader(String headerName, Optional expected) { - Assertions - .assertEquals(expected, ProcessorUtil - .readHeader( - MessageBuilder - .withPayload("test") - .setHeader("pizza", "cheese") - .build(), - headerName, - String.class)); - } - @ParameterizedTest(name = "should extract letters from {0} and get {1}") @MethodSource("extract") @DisplayName("should extract letters") @@ -50,14 +32,6 @@ void shouldSplitName(String input, String[] expected) { Assertions.assertArrayEquals(expected, ProcessorUtil.splitName(input)); } - private static Stream readHeader() { - return Stream.of( - Arguments.of("party", Optional.empty()), - Arguments.of("pizza", Optional.of("cheese")), - Arguments.of(StringUtils.EMPTY, Optional.empty()) - ); - } - private static Stream extract() { return Stream.of( Arguments.of("ABC1234", "ABC", "1234"), @@ -103,4 +77,4 @@ private static Stream splitName() { ); } -} \ No newline at end of file +} From e533439d70ba376b48e467f1726d9459d6951f05 Mon Sep 17 00:00:00 2001 From: Paulo Gomes da Cruz Junior Date: Fri, 12 Jan 2024 10:01:50 -0800 Subject: [PATCH 09/14] fix(FSADT1-1101|FSADT1-1103|FSADT1-1113|FSADT1-118FSADT1-1106): fixing email for processing --- processor/pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/processor/pom.xml b/processor/pom.xml index ffa3595b5a..ef2119be8f 100644 --- a/processor/pom.xml +++ b/processor/pom.xml @@ -59,11 +59,11 @@ org.springframework.boot spring-boot-starter-data-r2dbc - + org.springframework.boot spring-boot-starter-aop From 2b74a928589bb8a9a0a8ea0a5deefe2697b3cd46 Mon Sep 17 00:00:00 2001 From: Paulo Gomes da Cruz Junior Date: Fri, 12 Jan 2024 11:18:28 -0800 Subject: [PATCH 10/14] fix: fixing log conversion issues --- .../ca/bc/gov/app/service/ches/ChesService.java | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/backend/src/main/java/ca/bc/gov/app/service/ches/ChesService.java b/backend/src/main/java/ca/bc/gov/app/service/ches/ChesService.java index b30d66cfa5..fb22b13bc1 100644 --- a/backend/src/main/java/ca/bc/gov/app/service/ches/ChesService.java +++ b/backend/src/main/java/ca/bc/gov/app/service/ches/ChesService.java @@ -167,25 +167,12 @@ private EmailLogEntity createNewLogEntity(EmailLogDto emailLogDto) { logEntity.setEmailSentInd(emailLogDto.emailSentInd()); logEntity.setEmailId(emailLogDto.emailId()); logEntity.setExceptionMessage(emailLogDto.exceptionMessage()); - logEntity.setEmailVariables(convertTo(emailLogDto.variables())); + //Always set the variables map instead of the json so the converter can kick in + logEntity.setVariables(emailLogDto.variables()); return logEntity; } - private Json convertTo(Map variables) { - String json = "{}"; - - try { - json = builder - .build() - .writeValueAsString(variables); - } catch (JsonProcessingException e) { - log.error("Error while converting matchers to json", e); - } - - return Json.of(json); - } - /** * Sends an email using the BC Government's Common Email Service (Ches) via HTTP POST request * using WebClient. From a744214b4620702389105d9cd3145e07a939558a Mon Sep 17 00:00:00 2001 From: Paulo Gomes da Cruz Junior Date: Fri, 12 Jan 2024 11:55:07 -0800 Subject: [PATCH 11/14] fix(FSADT1-1101|FSADT1-1103|FSADT1-1113|FSADT1-118FSADT1-1106): fixing email for processing --- .../LegacyAbstractPersistenceService.java | 30 ++++++++ ...nAutoProcessingServiceIntegrationTest.java | 4 +- .../ClientSubmissionLoadingServiceTest.java | 3 +- .../LegacyAbstractPersistenceServiceTest.java | 72 +------------------ .../LegacyClientPersistenceServiceTest.java | 9 +-- .../legacy/LegacyLoadingServiceTest.java | 4 +- 6 files changed, 39 insertions(+), 83 deletions(-) diff --git a/processor/src/main/java/ca/bc/gov/app/service/legacy/LegacyAbstractPersistenceService.java b/processor/src/main/java/ca/bc/gov/app/service/legacy/LegacyAbstractPersistenceService.java index 9895f4e2fb..0ca77aebfa 100644 --- a/processor/src/main/java/ca/bc/gov/app/service/legacy/LegacyAbstractPersistenceService.java +++ b/processor/src/main/java/ca/bc/gov/app/service/legacy/LegacyAbstractPersistenceService.java @@ -83,6 +83,14 @@ public Mono> checkClientData(MessagingWrapper contactRepository .findFirstBySubmissionId(message.payload()) .map(contact -> contact.getFirstName() + " " + contact.getLastName()) + .doOnNext(contact -> + log.info( + "Loaded submission contact for persistence on oracle {} {} {}", + message.payload(), + contact, + submissionDetail.getClientNumber() + ) + ) .map(contact -> new MessagingWrapper<>( message.parameters().get(ApplicationConstant.FOREST_CLIENT_NUMBER) @@ -113,6 +121,13 @@ public Mono> createForestClient( // Create the client legacyService .createClient(message.payload()) + .doOnNext(forestClientNumber -> + log.info( + "Created forest client {} {}", + message.payload().clientNumber(), + forestClientNumber + ) + ) // Create the doing business as IF exists .flatMap(clientNumber -> createClientDoingBusinessAs(message, clientNumber)) // Updates the submission detail with the client number @@ -122,6 +137,14 @@ public Mono> createForestClient( (Integer) message.parameters().get(ApplicationConstant.SUBMISSION_ID) ) .map(submissionDetail -> submissionDetail.withClientNumber(clientNumber)) + .doOnNext(submissionDetail -> + log.info( + "Updating submission detail for persistence on oracle {} {} {}", + message.payload().clientNumber(), + submissionDetail.getOrganizationName(), + submissionDetail.getIncorporationNumber() + ) + ) .flatMap(submissionDetailRepository::save) .map(SubmissionDetailEntity::getClientNumber) ) @@ -291,6 +314,13 @@ private Mono createClientDoingBusinessAs(MessagingWrapper isRegisteredSoleProprietorship(message.payload()) ) + .doOnNext(forestClientNumber -> + log.info( + "Creating doing business as for {} {}", + forestClientNumber, + message.parameters().get(ApplicationConstant.FOREST_CLIENT_NAME) + ) + ) .flatMap(forestClientNumber -> legacyService .createDoingBusinessAs( diff --git a/processor/src/test/java/ca/bc/gov/app/service/client/ClientSubmissionAutoProcessingServiceIntegrationTest.java b/processor/src/test/java/ca/bc/gov/app/service/client/ClientSubmissionAutoProcessingServiceIntegrationTest.java index 2df2b04a38..7396232cca 100644 --- a/processor/src/test/java/ca/bc/gov/app/service/client/ClientSubmissionAutoProcessingServiceIntegrationTest.java +++ b/processor/src/test/java/ca/bc/gov/app/service/client/ClientSubmissionAutoProcessingServiceIntegrationTest.java @@ -120,8 +120,8 @@ void shouldReviewSubmission() { .extracting(MessagingWrapper::parameters, as(InstanceOfAssertFactories.MAP)) .isNotNull() .isNotEmpty() - .containsKey("id") - .containsKey("timestamp") + .containsKey("submission-id") + .containsKey("submission-status") .containsEntry(ApplicationConstant.SUBMISSION_ID, 1) ) .verifyComplete(); diff --git a/processor/src/test/java/ca/bc/gov/app/service/client/ClientSubmissionLoadingServiceTest.java b/processor/src/test/java/ca/bc/gov/app/service/client/ClientSubmissionLoadingServiceTest.java index 468b563540..f3d077bcf8 100644 --- a/processor/src/test/java/ca/bc/gov/app/service/client/ClientSubmissionLoadingServiceTest.java +++ b/processor/src/test/java/ca/bc/gov/app/service/client/ClientSubmissionLoadingServiceTest.java @@ -46,8 +46,7 @@ void shouldLoadSubmissionIntoMessage() { .extracting(MessagingWrapper::parameters, as(InstanceOfAssertFactories.MAP)) .isNotNull() .isNotEmpty() - .containsKey("id") - .containsKey("timestamp") + .containsKey("submission-id") .containsEntry(ApplicationConstant.SUBMISSION_ID, 1) ) .verifyComplete(); diff --git a/processor/src/test/java/ca/bc/gov/app/service/legacy/LegacyAbstractPersistenceServiceTest.java b/processor/src/test/java/ca/bc/gov/app/service/legacy/LegacyAbstractPersistenceServiceTest.java index 1a4ffdc99c..96faf69168 100644 --- a/processor/src/test/java/ca/bc/gov/app/service/legacy/LegacyAbstractPersistenceServiceTest.java +++ b/processor/src/test/java/ca/bc/gov/app/service/legacy/LegacyAbstractPersistenceServiceTest.java @@ -282,6 +282,7 @@ void shouldCheckClientData( new MessagingWrapper<>( 2, Map.of( + ApplicationConstant.FOREST_CLIENT_NUMBER, "00000000", ApplicationConstant.SUBMISSION_ID, 2, ApplicationConstant.CREATED_BY, ApplicationConstant.PROCESSOR_USER_NAME, ApplicationConstant.UPDATED_BY, ApplicationConstant.PROCESSOR_USER_NAME @@ -292,7 +293,7 @@ void shouldCheckClientData( .assertNext(message -> { assertThat(message) .isNotNull() - .hasFieldOrPropertyWithValue("payload", 2); + .hasFieldOrPropertyWithValue("payload", "00000000"); assertThat(message.parameters().get(ApplicationConstant.SUBMISSION_ID)) .as("submission id") @@ -377,75 +378,6 @@ void shouldCreateClient() { } - @ParameterizedTest - @MethodSource("data") - @DisplayName("create client that is individual") - void shouldTryToCreateClient(String type) { - - service - .createForestClient( - new MessagingWrapper<>( - CLIENT_ENTITY, - Map.of( - ApplicationConstant.SUBMISSION_ID, 2, - ApplicationConstant.CREATED_BY, - ApplicationConstant.PROCESSOR_USER_NAME, - ApplicationConstant.UPDATED_BY, - ApplicationConstant.PROCESSOR_USER_NAME, - ApplicationConstant.CLIENT_TYPE_CODE, type, - ApplicationConstant.FOREST_CLIENT_NUMBER, "00000000", - ApplicationConstant.FOREST_CLIENT_NAME, "CHAMPAGNE SUPERNOVA" - ) - ) - ) - .as(StepVerifier::create) - .verifyComplete(); - } - - @ParameterizedTest - @MethodSource("data") - @DisplayName("create contact that is individual") - void shouldTryToCreateContact(String type) { - service - .createContact( - new MessagingWrapper<>( - 1, - Map.of( - ApplicationConstant.SUBMISSION_ID, 2, - ApplicationConstant.CREATED_BY, ApplicationConstant.PROCESSOR_USER_NAME, - ApplicationConstant.UPDATED_BY, ApplicationConstant.PROCESSOR_USER_NAME, - ApplicationConstant.CLIENT_TYPE_CODE, type, - ApplicationConstant.FOREST_CLIENT_NUMBER, "00000000", - ApplicationConstant.FOREST_CLIENT_NAME, "CHAMPAGNE SUPERNOVA" - ) - ) - ) - .as(StepVerifier::create) - .verifyComplete(); - } - - @ParameterizedTest - @MethodSource("data") - @DisplayName("create location that is individual") - void shouldTryToCreateLocation(String type) { - service - .createLocations( - new MessagingWrapper<>( - 1, - Map.of( - ApplicationConstant.SUBMISSION_ID, 2, - ApplicationConstant.CREATED_BY, ApplicationConstant.PROCESSOR_USER_NAME, - ApplicationConstant.UPDATED_BY, ApplicationConstant.PROCESSOR_USER_NAME, - ApplicationConstant.CLIENT_TYPE_CODE, type, - ApplicationConstant.FOREST_CLIENT_NUMBER, "00000000", - ApplicationConstant.FOREST_CLIENT_NAME, "CHAMPAGNE SUPERNOVA" - ) - ) - ) - .as(StepVerifier::create) - .verifyComplete(); - } - private static Stream clientData() { return Stream.of( Arguments.of("C", "00000000"), diff --git a/processor/src/test/java/ca/bc/gov/app/service/legacy/LegacyClientPersistenceServiceTest.java b/processor/src/test/java/ca/bc/gov/app/service/legacy/LegacyClientPersistenceServiceTest.java index ad81d9c40b..69cfbb057a 100644 --- a/processor/src/test/java/ca/bc/gov/app/service/legacy/LegacyClientPersistenceServiceTest.java +++ b/processor/src/test/java/ca/bc/gov/app/service/legacy/LegacyClientPersistenceServiceTest.java @@ -92,13 +92,8 @@ void shouldCreateForestClient() { assertThat(message.parameters()) .isNotNull() - .hasFieldOrPropertyWithValue("clientName", "STAR DOT STAR VENTURES") - .hasFieldOrPropertyWithValue("clientTypeCode", "C") - .hasFieldOrPropertyWithValue("registryCompanyTypeCode", "FM") - .hasFieldOrPropertyWithValue("corpRegnNmbr", "0159297") - .hasFieldOrPropertyWithValue("clientNumber", "00000001") - .hasFieldOrPropertyWithValue("clientComment", - "Jhon Snow submitted the client details acquired from BC Registry FM0159297"); + .hasFieldOrPropertyWithValue("forestClientName", "STAR DOT STAR VENTURES") + .hasFieldOrPropertyWithValue("incorporationNumber", "FM0159297"); assertThat(message.parameters().get(ApplicationConstant.SUBMISSION_ID)) .isNotNull() diff --git a/processor/src/test/java/ca/bc/gov/app/service/legacy/LegacyLoadingServiceTest.java b/processor/src/test/java/ca/bc/gov/app/service/legacy/LegacyLoadingServiceTest.java index e9eec8e5d9..cba254c907 100644 --- a/processor/src/test/java/ca/bc/gov/app/service/legacy/LegacyLoadingServiceTest.java +++ b/processor/src/test/java/ca/bc/gov/app/service/legacy/LegacyLoadingServiceTest.java @@ -48,8 +48,8 @@ void shouldCheckAndMatch(SubmissionInformationDto input, String responseChannel) .extracting(MessagingWrapper::parameters, as(InstanceOfAssertFactories.MAP)) .isNotNull() .isNotEmpty() - .containsKey("id") - .containsKey("timestamp") + .containsKey("submission-id") + .containsKey("submission-status") .containsEntry(ApplicationConstant.SUBMISSION_ID, 1) ) .verifyComplete(); From ca8c84e04eca2b2eeb4a04db391810441d9acc57 Mon Sep 17 00:00:00 2001 From: Paulo Gomes da Cruz Junior Date: Fri, 12 Jan 2024 12:08:18 -0800 Subject: [PATCH 12/14] fix(FSADT1-1101|FSADT1-1103|FSADT1-1113|FSADT1-118FSADT1-1106): fixing email for processing --- .../app/service/client/ClientSubmissionLoadingService.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/processor/src/main/java/ca/bc/gov/app/service/client/ClientSubmissionLoadingService.java b/processor/src/main/java/ca/bc/gov/app/service/client/ClientSubmissionLoadingService.java index 9b6ba88671..fe09b6e946 100644 --- a/processor/src/main/java/ca/bc/gov/app/service/client/ClientSubmissionLoadingService.java +++ b/processor/src/main/java/ca/bc/gov/app/service/client/ClientSubmissionLoadingService.java @@ -128,9 +128,9 @@ private String getSubject( ) { return switch ((SubmissionStatusEnum) message.parameters() .get(ApplicationConstant.SUBMISSION_STATUS)) { - case A -> "Client number submission for " + businessName + " was approved"; - case R -> "Client number submission for " + businessName + " was rejected"; - default -> businessName + " submission requires review"; + case A -> "Client number application approved"; + case R -> "Client number application can’t go ahead"; + default -> businessName + " requires review"; }; } From 3caa8faa1ef0125d8d98f87e55f4f0c6c1d08121 Mon Sep 17 00:00:00 2001 From: Paulo Gomes da Cruz Junior Date: Fri, 12 Jan 2024 12:23:00 -0800 Subject: [PATCH 13/14] fix(FSADT1-1113): fixing staff email --- .../bc/gov/app/service/ches/ChesService.java | 23 ++++++++++--------- .../main/resources/templates/revision.html | 2 +- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/backend/src/main/java/ca/bc/gov/app/service/ches/ChesService.java b/backend/src/main/java/ca/bc/gov/app/service/ches/ChesService.java index fb22b13bc1..833e1e9802 100644 --- a/backend/src/main/java/ca/bc/gov/app/service/ches/ChesService.java +++ b/backend/src/main/java/ca/bc/gov/app/service/ches/ChesService.java @@ -18,15 +18,13 @@ import ca.bc.gov.app.exception.UnableToProcessRequestException; import ca.bc.gov.app.exception.UnexpectedErrorException; import ca.bc.gov.app.repository.client.EmailLogRepository; -import com.fasterxml.jackson.core.JsonProcessingException; import freemarker.template.Configuration; import freemarker.template.Template; import freemarker.template.TemplateException; -import io.r2dbc.postgresql.codec.Json; import java.io.IOException; import java.io.StringWriter; import java.time.LocalDateTime; -import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Optional; @@ -37,7 +35,6 @@ import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatusCode; import org.springframework.http.MediaType; -import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; import org.springframework.stereotype.Service; import org.springframework.web.reactive.function.BodyInserters; import org.springframework.web.reactive.function.client.ClientResponse; @@ -57,21 +54,17 @@ public class ChesService { private final EmailLogRepository emailLogRepository; - private final Jackson2ObjectMapperBuilder builder; - public ChesService( ForestClientConfiguration configuration, @Qualifier("chesApi") WebClient chesApi, @Qualifier("authApi") WebClient authApi, - EmailLogRepository emailLogRepository, - Jackson2ObjectMapperBuilder builder + EmailLogRepository emailLogRepository ) { this.configuration = configuration; this.chesApi = chesApi; this.authApi = authApi; this.freeMarkerConfiguration = new Configuration(Configuration.VERSION_2_3_31); this.emailLogRepository = emailLogRepository; - this.builder = builder; freeMarkerConfiguration.setClassForTemplateLoading(this.getClass(), "/templates"); freeMarkerConfiguration.setDefaultEncoding("UTF-8"); } @@ -79,8 +72,16 @@ public ChesService( public Mono sendEmail(String templateName, String emailAddress, String subject, - Map variables, - Integer emailLogId) { + Map emailVariables, + Integer emailLogId + ) { + + if (emailVariables == null) { + emailVariables = new HashMap<>(); + } + emailVariables.put("frontend", configuration.getFrontend().getUrl()); + + final Map variables = new HashMap<>(emailVariables); String processedSubject = configuration.getCognito().getEnvironment().equalsIgnoreCase("prod") diff --git a/backend/src/main/resources/templates/revision.html b/backend/src/main/resources/templates/revision.html index 9cc0f0f760..ae6e60444c 100644 --- a/backend/src/main/resources/templates/revision.html +++ b/backend/src/main/resources/templates/revision.html @@ -21,7 +21,7 @@ An application for a client number for ${userName} needs your review.

- Please review it in the Client Management System and decide if it should be accepted or rejected. + Please review it in the Client Management System and decide if it should be accepted or rejected.

 
From 248c074270d0a15c19f23a48e299acc2cc9598f1 Mon Sep 17 00:00:00 2001 From: Paulo Gomes da Cruz Junior Date: Fri, 12 Jan 2024 12:34:33 -0800 Subject: [PATCH 14/14] test: fixing test --- .../src/main/java/ca/bc/gov/app/service/ches/ChesService.java | 3 +++ backend/src/test/resources/application-default.yml | 2 ++ 2 files changed, 5 insertions(+) diff --git a/backend/src/main/java/ca/bc/gov/app/service/ches/ChesService.java b/backend/src/main/java/ca/bc/gov/app/service/ches/ChesService.java index 833e1e9802..b336cd2bf8 100644 --- a/backend/src/main/java/ca/bc/gov/app/service/ches/ChesService.java +++ b/backend/src/main/java/ca/bc/gov/app/service/ches/ChesService.java @@ -79,6 +79,9 @@ public Mono sendEmail(String templateName, if (emailVariables == null) { emailVariables = new HashMap<>(); } + else { + emailVariables = new HashMap<>(emailVariables); + } emailVariables.put("frontend", configuration.getFrontend().getUrl()); final Map variables = new HashMap<>(emailVariables); diff --git a/backend/src/test/resources/application-default.yml b/backend/src/test/resources/application-default.yml index 77d369596c..9d81e8fe1f 100644 --- a/backend/src/test/resources/application-default.yml +++ b/backend/src/test/resources/application-default.yml @@ -34,6 +34,8 @@ ca: cookie-domain: localhost url: http://localhost:10070 refreshUrl: http://localhost:10070 + frontend: + url: http://localhost:1234 logging: