Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(FSADT1-936): fixing CHES on non-dev env #683

Merged
merged 8 commits into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/merge-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ jobs:
-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'
-p CHES_API_URL='https://ches-test.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
Expand Down Expand Up @@ -403,7 +403,7 @@ jobs:
-p ZONE=${{ env.ZONE }} -p NAME=${{ github.event.repository.name }}
-p PROMOTE=${{ github.repository }}/backend:${{ env.PREV }}
-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'
-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
Expand Down
5 changes: 0 additions & 5 deletions backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,6 @@
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webflux-ui</artifactId>
<version>2.2.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public class ForestClientConfiguration {
@NestedConfigurationProperty
private CognitoConfiguration cognito;

private Duration submissionLimit;

/**
* The Common hosted email service configuration.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,13 @@ public WebClient authApi(ForestClientConfiguration configuration) {
return WebClient
.builder()
.baseUrl(configuration.getChes().getTokenUrl())
.filter(ExchangeFilterFunctions.basicAuthentication(configuration.getChes().getClientId(),
configuration.getChes().getClientSecret()))
.filter(
ExchangeFilterFunctions
.basicAuthentication(
configuration.getChes().getClientId(),
configuration.getChes().getClientSecret()
)
)
.build();
}

Expand Down Expand Up @@ -183,23 +188,24 @@ public WebClient addressCompleteApi(ForestClientConfiguration configuration) {

/**
* Returns a configured instance of WebClient for accessing the Cognito API.
*
* @param objectMapper the object mapper
* @return A configured instance of WebClient for accessing the Cognito API.
*/
@Bean
public WebClient cognitoApi(ObjectMapper objectMapper) {
return WebClient
.builder()
.codecs(clientCodecConfigurer -> {
clientCodecConfigurer
.customCodecs()
.register(new AwsJsonMessageEncoder(objectMapper));
clientCodecConfigurer
.customCodecs()
.register(new AwsJsonMessageDecoder(objectMapper));
})
.build();
}
public WebClient cognitoApi(ObjectMapper objectMapper) {
return WebClient
.builder()
.codecs(clientCodecConfigurer -> {
clientCodecConfigurer
.customCodecs()
.register(new AwsJsonMessageEncoder(objectMapper));
clientCodecConfigurer
.customCodecs()
.register(new AwsJsonMessageDecoder(objectMapper));
})
.build();
}

@Bean
public ObjectMapper objectMapper(Jackson2ObjectMapperBuilder builder) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import ca.bc.gov.app.dto.client.EmailRequestDto;
import ca.bc.gov.app.service.client.ClientService;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
Expand All @@ -14,20 +14,17 @@
import reactor.core.publisher.Mono;

/**
* Controller for handling email sending via CHES (Common Hosted Email Service).
* This controller provides endpoints for sending emails using the CHES service.
* Controller for handling email sending via CHES (Common Hosted Email Service). This controller
* provides endpoints for sending emails using the CHES service.
*/
@RestController
@Tag(
name = "CHES",
description = "The CHES endpoint is responsible for handling the sending of emails"
)
@Slf4j
@RequestMapping(value = "/api/ches", produces = MediaType.APPLICATION_JSON_VALUE)
@RequiredArgsConstructor
public class ChesController {

private final ClientService clientService;

/**
* Endpoint for sending an email using CHES.
*
Expand All @@ -37,7 +34,8 @@ public class ChesController {
@PostMapping("/email")
@ResponseStatus(HttpStatus.ACCEPTED)
public Mono<Void> sendEmail(@RequestBody EmailRequestDto emailRequestDto) {
log.info("Sending email using CHES {}", emailRequestDto);
return clientService.sendEmail(emailRequestDto);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,6 @@
import ca.bc.gov.app.dto.client.ClientAddressDto;
import ca.bc.gov.app.dto.client.CodeNameDto;
import ca.bc.gov.app.service.client.ClientAddressService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.ArraySchema;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
Expand All @@ -23,81 +16,26 @@

@RestController
@Slf4j
@Tag(
name = "FSA Clients",
description = "The FSA Client endpoint, responsible for handling client data"
)
@RequestMapping(value = "/api/clients", produces = MediaType.APPLICATION_JSON_VALUE)
@RequiredArgsConstructor
public class ClientAddressController {

private final ClientAddressService clientAddressService;

@GetMapping("/addresses")
@Operation(
summary = "Autocomplete addresses",
responses = {
@ApiResponse(
responseCode = "200",
description = "Returns a list of possible addresses",
content = @Content(
mediaType = MediaType.APPLICATION_JSON_VALUE,
array = @ArraySchema(
schema = @Schema(
name = "NameCode",
implementation = CodeNameDto.class
)
)
)
)
}
)
public Flux<CodeNameDto> findPossibleAddresses(
@Parameter(description =
"The name or ISO 2 or 3 character code for the country to search in, defaults to CA",
example = "UK")
@RequestParam(value = "country", required = false, defaultValue = "CA")
String country,

@Parameter(description =
"The maximum number of autocomplete suggestions to return, defaults to 7",
example = "7")
@RequestParam(value = "maxSuggestions", required = false, defaultValue = "7")
Integer maxSuggestions,

@Parameter(description = "The search term to find", example = "2701 ri")
@RequestParam(value = "searchTerm", required = true)
String searchTerm) {
return clientAddressService
.findPossibleAddresses(country, maxSuggestions, searchTerm);
}

@GetMapping("/addresses/{addressId}")
@Operation(
summary = "Retrieve address",
responses = {
@ApiResponse(
responseCode = "200",
description = "Returns an addresses",
content = @Content(
mediaType = MediaType.APPLICATION_JSON_VALUE,
array = @ArraySchema(
schema = @Schema(
name = "Address",
implementation = ClientAddressDto.class
)
)
)
)
}
)
public Mono<ClientAddressDto> getAddress(
@Parameter(
description = """
The id of the address to retrieve the details for.
The id can be obtained through <b>/api/client/addresses<b> endpoint""",
example = "CA|CP|B|0000001"
)
@PathVariable String addressId) {
return clientAddressService
.getAddress(addressId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,94 +2,20 @@

import ca.bc.gov.app.dto.client.ClientAddressDto;
import ca.bc.gov.app.dto.client.ClientContactDto;
import io.swagger.v3.oas.annotations.media.Schema;
import java.util.List;
import lombok.With;

/**
* A data transfer object representing the details of a client.
*/
@Schema(
example = """
{
"name": "Acme Inc.",
"id": "AC0000000",
"goodStanding": true,
"addresses": [
{
"streetAddress": "123 Main St",
"country": {"value": "CA", "text": "Canada"},
"province": {"value": "ON", text": "Ontario"},
"city": "Toronto",
"postalCode": "M5V1E3",
"locationName":"Billing Address",
"index": 0
},
{
"streetAddress": "456 Queen St",
"country": {"value": "CA", text": "Canada"},
"province": {"value": "QC", text": "Quebec"},
"city": "Montreal",
"postalCode": "H3B1A7",
"locationName":"Mailing address",
"index": 1,
},
],
"contacts":[{
"type": "person",
"firstName": "JAMES",
"lastName": "BAXTER",
"phoneNumber": "123456789"
"email": "[email protected]",
"locations":[
{"value": "0", text": "Billing Address"}
}]
}"""
)
@With
public record ClientDetailsDto(
@Schema(description = "The client name as registered on the BC Registry", example = "Acme Inc.")
String name,
@Schema(description = "ID of the client", example = "AC0000000")
String id,
@Schema(
description = "Defines if the client is in good standing with the Ministry of Finance",
example = "true"
)
boolean goodStanding,
@Schema(description = "All available addresses", example = """
[
{
"streetAddress": "123 Main St",
"country": {"value": "CA", "text": "Canada"},
"province": {"value": "ON", text": "Ontario"},
"city": "Toronto",
"postalCode": "M5V1E3",
"locationName":"Billing Address",
"index": 0
},
{
"streetAddress": "456 Queen St",
"country": {"value": "CA", text": "Canada"},
"province": {"value": "QC", text": "Quebec"},
"city": "Montreal",
"postalCode": "H3B1A7",
"locationName":"Mailing Address",
"index": 1
}
]""")
List<ClientAddressDto> addresses,

@Schema(description = "All available contacts", example = """
[
{
"type": "person",
"firstName": "JAMES",
"lastName": "BAXTER",
"phoneNumber": "123456789"
"email": "[email protected]",
}
]""")
List<ClientContactDto> contacts
) {

}
Original file line number Diff line number Diff line change
@@ -1,59 +1,21 @@
package ca.bc.gov.app.dto.client;

import io.swagger.v3.oas.annotations.media.Schema;
import java.util.Map;
import lombok.With;

@Schema(
description = "An address information",
title = "ClientAddressData",
example = """
{
"locationName": "Billing Address",
"streetAddress": "123 Main St",
"country": {
"value": "CA",
"text": "Canada"
},
"province": {
"value": "ON",
"text": "Ontario"
},
"city": "Toronto",
"postalCode": "M5V2L7",
"index": 1
}"""
)

@With
public record ClientAddressDto(
@Schema(description = "The street address", example = "123 Main St")
String streetAddress,
@Schema(description = "The country for this address", example = """
{
"value": "CA",
"text": "Canada"
}""")
ClientValueTextDto country,
@Schema(description = "The province or state for this address", example = """
{
"value": "ON",
"text": "Ontario"
}""")
ClientValueTextDto province,
@Schema(description = "The city for this address", example = "Toronto")
String city,
@Schema(description = "The postal code or zip code for this address", example = "M5V2L7")
String postalCode,
@Schema(description = "The index for this address. It is used to order the addresses",
example = "3")
int index,

@Schema(description = """
The location name of an address. Examples of location names include,
but are not limited to, Mailing Address, Billing Address among others.""",
example = "Billing Address")
String locationName
) {

public Map<String, Object> description() {

final String indexFormatted = String.format("address.[%d]", index);
Expand Down
Loading
Loading