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-1121): fixing persistence #732

Merged
merged 14 commits into from
Jan 15, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class ChesController {
*/
@PostMapping("/email")
@ResponseStatus(HttpStatus.ACCEPTED)
public Mono<Void> sendEmail(@RequestBody EmailRequestDto emailRequestDto) {
public Mono<String> sendEmail(@RequestBody EmailRequestDto emailRequestDto) {
log.info("Sending email using CHES {}", emailRequestDto);
return clientService.sendEmail(emailRequestDto);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public Mono<String> sendEmail(String templateName,
"",
throwable.getMessage(),
variables),
"Error sending email"
"Error sending email " + throwable.getMessage()
)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,10 +253,10 @@ public Flux<ClientLookUpDto> findByClientNameOrIncorporation(String value) {
* <p>Send email to a client.</p>
*
* @param emailRequestDto The request data containing client details.
* @return A {@link Mono} of {@link Void}.
* @return A {@link Mono} of {@link String}.
*/
public Mono<Void> sendEmail(EmailRequestDto emailRequestDto) {
return triggerEmail(emailRequestDto).then();
public Mono<String> sendEmail(EmailRequestDto emailRequestDto) {
return triggerEmail(emailRequestDto);
}

/**
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 @@ -18,7 +18,7 @@
<div>&nbsp;</div>

<p>
An application for a client number for <b>${userName}</b> needs your review.
An application for a client number for <b>${business.name}</b> needs your review.
</p>
<p>
Please review it in the <a href="${frontend}/submissions/${submission}">Client Management System</a> and decide if it should be accepted or rejected.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ void shouldSubmitRegisteredBusinessData() {
.body(Mono.just(EMAIL_REQUEST), EmailRequestDto.class)
.exchange()
.expectStatus().isAccepted()
.expectBody().isEmpty();
.expectBody(String.class)
.isEqualTo("Email sent successfully. Transaction ID: 00000000-0000-0000-0000-000000000000");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ public interface AbstractForestClientMapper<D, E> {
@InheritInverseConfiguration
E toEntity(D dto);

@Named("UserIdSizeQualifier")
default String limitUserId(String origin) {
return origin.length() > 30 ? origin.substring(0, 30) : origin;
}

@Named("EmptySpaceQualifier")
default String defaultEmptySpace(Object origin) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,15 @@ public interface ForestClientContactMapper extends
source = "clientNumber",
qualifiedByName = "InitialRevisionQualifier"
)
@Mapping(
source = "createdBy",
target = "createdBy",
qualifiedByName = "UserIdSizeQualifier"
)
@Mapping(
source = "updatedBy",
target = "updatedBy",
qualifiedByName = "UserIdSizeQualifier"
)
ForestClientContactEntity toEntity(ForestClientContactDto dto);
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,15 @@ public interface ForestClientDoingBusinessAsMapper extends
source = "clientNumber",
qualifiedByName = "InitialRevisionQualifier"
)
@Mapping(
source = "createdBy",
target = "createdBy",
qualifiedByName = "UserIdSizeQualifier"
)
@Mapping(
source = "updatedBy",
target = "updatedBy",
qualifiedByName = "UserIdSizeQualifier"
)
ClientDoingBusinessAsEntity toEntity(ClientDoingBusinessAsDto dto);
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,15 @@ public interface ForestClientLocationMapper extends
source = "clientNumber",
qualifiedByName = "InitialRevisionQualifier"
)
@Mapping(
source = "createdBy",
target = "createdBy",
qualifiedByName = "UserIdSizeQualifier"
)
@Mapping(
source = "updatedBy",
target = "updatedBy",
qualifiedByName = "UserIdSizeQualifier"
)
ForestClientLocationEntity toEntity(ForestClientLocationDto dto);
}
2 changes: 1 addition & 1 deletion processor/openshift.deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ objects:
name: ${NAME}-${ZONE}
key: database-user
- name: CLIENT_URI
value: https://${NAME}-${ZONE}-backend.${DOMAIN}/api
value: https://${NAME}-${URL_ZONE}-backend.${DOMAIN}/api
- name: LEGACY_URI
value: https://${NAME}-${URL_ZONE}-legacy.${DOMAIN}
- name: TIMING
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public final class ApplicationConstant {
public static final String LOCATION_ID = "locationId";
public static final String TOTAL = "total";
public static final String INDEX = "index";
public static final String PROCESSOR_USER_NAME = "IDIR\\OTTOMATED";
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 CLIENT_TYPE_CODE = "CLIENT_TYPE_CODE";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

public record MessagingWrapper<T>(
T payload,
Expand All @@ -19,4 +20,11 @@ public MessagingWrapper<T> withParameter(String key, Object value) {
return this;
}

@SuppressWarnings({"unchecked", "unused"})
public <P> P getParameter(String key,Class<P> clazz) {
if(Objects.isNull(this.parameters.get(key)))
return null;
return (P) this.parameters.get(key);
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package ca.bc.gov.app.dto.legacy;

import lombok.With;

@With
public record ForestClientContactDto(
String clientNumber,
String clientLocnCode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,17 +146,21 @@ private Map<String, Object> getParameter(
.get(ApplicationConstant.SUBMISSION_STATUS)) {
case A -> approvalParameters(username, businessName, clientNumber);
case R -> rejectionParameters(username, businessName, clientNumber, reason);
default -> revisionParameters(username, submissionId);
default -> revisionParameters(username, businessName, submissionId);
};
}

private Map<String, Object> revisionParameters(
String username,
String businessName,
Integer submissionId
) {
return Map.of(
"userName", username,
"submission", submissionId
"submission", submissionId,
"business", Map.of(
"name", businessName
)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ public class ClientSubmissionMailService {

private final WebClient forestClientApi;

/*@ServiceActivator(inputChannel = ApplicationConstant.SUBMISSION_MAIL_CHANNEL)*/
public Mono<Void> sendMail(EmailRequestDto mailMessage) {
public Mono<String> sendMail(EmailRequestDto mailMessage) {

log.info("Sending email to {} {} -> {}",
mailMessage.email(),
Expand All @@ -28,8 +27,10 @@ public Mono<Void> sendMail(EmailRequestDto mailMessage) {
.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()));
.exchangeToMono(clientResponse -> clientResponse.bodyToMono(String.class))
.doOnNext(source -> log.info("Email sent to {} {}", mailMessage.email(),source))
.doOnError(throwable -> log.error("Error sending email to {}", mailMessage.email(),
throwable));

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public Mono<MessagingWrapper<Integer>> loadSubmission(MessagingWrapper<Integer>
submission.getSubmissionId())
)
.map(submission ->
new MessagingWrapper<Integer>(
new MessagingWrapper<>(
message.payload(),
message.parameters()
)
Expand Down Expand Up @@ -85,16 +85,14 @@ public Mono<MessagingWrapper<String>> checkClientData(MessagingWrapper<Integer>
.map(contact -> contact.getFirstName() + " " + contact.getLastName())
.doOnNext(contact ->
log.info(
"Loaded submission contact for persistence on oracle {} {} {}",
"Loaded submission contact for persistence on oracle {} {}",
message.payload(),
contact,
submissionDetail.getClientNumber()
contact
)
)
.map(contact ->
new MessagingWrapper<>(
message.parameters().get(ApplicationConstant.FOREST_CLIENT_NUMBER)
.toString(),
message.getParameter(ApplicationConstant.FOREST_CLIENT_NUMBER,String.class),
message.parameters()
)
.withParameter(ApplicationConstant.CLIENT_TYPE_CODE,
Expand Down Expand Up @@ -260,8 +258,8 @@ public Mono<MessagingWrapper<Integer>> createContact(MessagingWrapper<Integer> m
RegExUtils.replaceAll(submissionContact.getBusinessPhoneNumber(), "\\D",
StringUtils.EMPTY),
submissionContact.getEmailAddress(),
getUser(message, ApplicationConstant.CREATED_BY),
getUser(message, ApplicationConstant.UPDATED_BY),
ApplicationConstant.PROCESSOR_USER_NAME,
ApplicationConstant.PROCESSOR_USER_NAME,
ApplicationConstant.ORG_UNIT
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ public Mono<MessagingWrapper<ForestClientDto>> generateForestClient(
.withCorpRegnNmbr(
ProcessorUtil.extractNumbers(submissionDetail.getIncorporationNumber())
)
.withClientNumber(message.parameters()
.get(ApplicationConstant.FOREST_CLIENT_NUMBER).toString())
)
.map(forestClient ->
new MessagingWrapper<>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,7 @@ public Mono<MessagingWrapper<ForestClientDto>> generateForestClient(
return
getSubmissionDetailRepository()
.findBySubmissionId(
(Integer)
message
.parameters()
.get(ApplicationConstant.SUBMISSION_ID)
message.getParameter(ApplicationConstant.SUBMISSION_ID, Integer.class)
)
.map(detailEntity ->
getBaseForestClient(
Expand All @@ -76,13 +73,16 @@ public Mono<MessagingWrapper<ForestClientDto>> generateForestClient(
" submitted the individual with data acquired from BC Services Card"
)
.withClientTypeCode("I")
.withClientIdTypeCode("BCSC")
//Assuming that individuals can only be created by BCSC users
.withClientIdTypeCode(
ProcessorUtil.getClientIdTypeCode(
ProcessorUtil.splitName(
getUser(message, ApplicationConstant.CREATED_BY))[1]
)
)
.withClientIdentification(
getUser(message, ApplicationConstant.CREATED_BY).replace("bcsc\\",
StringUtils.EMPTY))
.withClientNumber(message.parameters()
.get(ApplicationConstant.FOREST_CLIENT_NUMBER).toString())
ProcessorUtil.splitName(
getUser(message, ApplicationConstant.CREATED_BY))[0]
)
)
.map(forestClient ->
new MessagingWrapper<>(forestClient, message.parameters())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,6 @@ public Mono<MessagingWrapper<ForestClientDto>> generateForestClient(
.withClientName(contact[1])
.withClientTypeCode("I")
.withClientIdTypeCode("BCRE")
.withClientNumber(message.parameters()
.get(ApplicationConstant.FOREST_CLIENT_NUMBER).toString())
)
)
.map(forestClient ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ public LegacyService(
public void setUp() {
countryCodeRepository.findAll().doOnNext(
countryCode -> countryList.put(countryCode.getCountryCode(), countryCode.getDescription()))
.collectList().subscribe();
.collectList()
.subscribe(list -> log.info("Loaded {} country codes", list.size()));
}


Expand Down Expand Up @@ -75,8 +76,8 @@ public Mono<String> createLocation(
null,
"Y",
StringUtils.EMPTY,
user,
user,
ApplicationConstant.PROCESSOR_USER_NAME,
ApplicationConstant.PROCESSOR_USER_NAME,
ApplicationConstant.ORG_UNIT,
ApplicationConstant.ORG_UNIT
);
Expand All @@ -86,12 +87,22 @@ public Mono<String> createLocation(
}

public Mono<String> createContact(ForestClientContactDto dto) {
return postRequestToLegacy("/api/contacts", dto)
return postRequestToLegacy(
"/api/contacts",
dto
.withCreatedBy(ApplicationConstant.PROCESSOR_USER_NAME)
.withUpdatedBy(ApplicationConstant.PROCESSOR_USER_NAME)
)
.thenReturn(dto.clientNumber());
}

public Mono<String> createClient(ForestClientDto dto) {
return postRequestToLegacy("/api/clients", dto);
return postRequestToLegacy(
"/api/clients",
dto
.withCreatedBy(ApplicationConstant.PROCESSOR_USER_NAME)
.withUpdatedBy(ApplicationConstant.PROCESSOR_USER_NAME)
);
}

public Mono<String> createDoingBusinessAs(
Expand All @@ -105,8 +116,8 @@ public Mono<String> createDoingBusinessAs(
new ClientDoingBusinessAsDto(
clientNumber,
doingBusinessAsName,
createdBy,
updatedBy,
ApplicationConstant.PROCESSOR_USER_NAME,
ApplicationConstant.PROCESSOR_USER_NAME,
ApplicationConstant.ORG_UNIT
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,16 @@ public Mono<MessagingWrapper<ForestClientDto>> generateForestClient(
getUser(message, ApplicationConstant.CLIENT_SUBMITTER_NAME) +
" submitted the sole proprietor with data acquired from Business BCeID")
.withClientTypeCode("I")
.withClientNumber(message.parameters()
.get(ApplicationConstant.FOREST_CLIENT_NUMBER).toString())
.withClientIdTypeCode(
ProcessorUtil.getClientIdTypeCode(
ProcessorUtil.splitName(
getUser(message, ApplicationConstant.CREATED_BY))[1]
)
)
.withClientIdentification(
ProcessorUtil.splitName(
getUser(message, ApplicationConstant.CREATED_BY))[0]
)
)
.doOnNext(forestClient ->
log.info("Generated forest client for USP {}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ public void processedMessages() {

)
.doOnNext(submission -> log.info("Submission post processed {}, building message", submission))
.onErrorContinue((throwable, o) -> log.error("Error processing submission {}", o, throwable))
.flatMap(submissionLoadingService::buildMailMessage)
.doOnNext(message -> log.info("Email ready to be sent {}", message))
.flatMap(mailService::sendMail)
Expand Down
Loading
Loading