Skip to content

Commit

Permalink
fix(FSADT1-1101): updating mail configuration on test (#726)
Browse files Browse the repository at this point in the history
* fix(FSADT1-1101): updating mail configuration on test

* fix(FSADT1-1059): adding corporation to list

* fix(FSADT1-1106): moving copy emails to bcc

* fix(FSADT1-1106): fixing ches copy mail list

* chore: adding logs to track down mail message

* feat(FSADT1-1101): changing birthdate to be localdatetime

* feat(FSADT1-1101): fixing birthdate

* fix(FSADT1-1101|FSADT1-1103|FSADT1-1113|FSADT1-118FSADT1-1106): fixing email for processing

* fix(FSADT1-1101|FSADT1-1103|FSADT1-1113|FSADT1-118FSADT1-1106): fixing email for processing

* fix: fixing log conversion issues

* fix(FSADT1-1101|FSADT1-1103|FSADT1-1113|FSADT1-118FSADT1-1106): fixing email for processing

* fix(FSADT1-1101|FSADT1-1103|FSADT1-1113|FSADT1-118FSADT1-1106): fixing email for processing

* fix(FSADT1-1113): fixing staff email

* test: fixing test
  • Loading branch information
paulushcgcj authored Jan 12, 2024
1 parent 5cf7da7 commit e8e5ab8
Show file tree
Hide file tree
Showing 45 changed files with 1,432 additions and 1,904 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/merge-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions backend/openshift.deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> AVAILABLE_CLIENT_TYPES = List.of("A", "I", "S", "SP", "RSP",
"USP", "BC", "GP");
"USP", "BC", "GP","C");
}

49 changes: 18 additions & 31 deletions backend/src/main/java/ca/bc/gov/app/service/ches/ChesService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -57,34 +54,37 @@ 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");
}

public Mono<String> sendEmail(String templateName,
String emailAddress,
String subject,
Map<String, Object> variables,
Integer emailLogId) {
Map<String, Object> emailVariables,
Integer emailLogId
) {

if (emailVariables == null) {
emailVariables = new HashMap<>();
}
else {
emailVariables = new HashMap<>(emailVariables);
}
emailVariables.put("frontend", configuration.getFrontend().getUrl());

List<String> emails = new ArrayList<>();
emails.add(emailAddress);
emails.addAll(configuration.getChes().getCopyEmail());
final Map<String,Object> variables = new HashMap<>(emailVariables);

String processedSubject =
configuration.getCognito().getEnvironment().equalsIgnoreCase("prod")
Expand All @@ -93,7 +93,7 @@ public Mono<String> 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)
Expand Down Expand Up @@ -171,25 +171,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<String, Object> 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.
Expand All @@ -212,7 +199,7 @@ public Mono<String> sendEmail(ChesRequestDto requestContent, String subject) {
.map(request ->
new ChesMailRequest(
null,
null,
configuration.getChes().getCopyEmail(),
ChesMailBodyType.HTML,
request.emailBody(),
null,
Expand Down
2 changes: 1 addition & 1 deletion backend/src/main/resources/templates/rejection.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<div>&nbsp;</div>

<p>
Your application for a client number can't go ahead because <b>${name}</b>
Your application for a client number can't go ahead because <b>${business.name}</b>
${reason}
</p>
<div>&nbsp;</div>
Expand Down
2 changes: 1 addition & 1 deletion backend/src/main/resources/templates/revision.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
An application for a client number for <b>${userName}</b> needs your review.
</p>
<p>
Please review it in the Client Management System and decide if it should be accepted or rejected.
Please review it in the <a href="${frontend}/submissions/${submission}">Client Management System</a> and decide if it should be accepted or rejected.
</p>
<div>&nbsp;</div>

Expand Down
2 changes: 2 additions & 0 deletions backend/src/test/resources/application-default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ ca:
cookie-domain: localhost
url: http://localhost:10070
refreshUrl: http://localhost:10070
frontend:
url: http://localhost:1234


logging:
Expand Down
1 change: 1 addition & 0 deletions common/openshift.init.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 ")
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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();
}

}
10 changes: 10 additions & 0 deletions legacy/src/main/java/ca/bc/gov/app/mappers/ForestClientMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ public interface ForestClientMapper extends
source = "clientNumber",
qualifiedByName = "InitialRevisionQualifier"
)
@Mapping(
target = "birthdate",
source = "birthdate",
qualifiedByName = "LocalDateDateTimeQualifier"
)
ForestClientEntity toEntity(ForestClientDto dto);

@Override
Expand All @@ -52,5 +57,10 @@ public interface ForestClientMapper extends
target= "orgUnit",
qualifiedByName = "InitialRevisionQualifier"
)
@Mapping(
target = "birthdate",
source = "birthdate",
qualifiedByName = "LocalDateTimeDateQualifier"
)
ForestClientDto toDto(ForestClientEntity entity);
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ private Mono<Boolean> locateClient(
.findByIndividual(
entity.getLegalFirstName(),
entity.getClientName(),
entity.getBirthdate().atStartOfDay()
entity.getBirthdate()
)
.map(client -> false) // means you can't create it
.defaultIfEmpty(true)
Expand Down
Loading

0 comments on commit e8e5ab8

Please sign in to comment.