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

[PPANTT-215] feat: Send emails to CIs in UAT & PROD #527

Merged
merged 3 commits into from
Dec 3, 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
1 change: 1 addition & 0 deletions helm/values-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ microservice-chart:
GEC_SERVICE_URL: https://api.dev.platform.pagopa.it
FORWARDER_SERVICE_URL: https://api.dev.platform.pagopa.it
TAXONOMY_SERVICE_URL: https://api.platform.pagopa.it
ENABLE_SEND_EMAIL: false
AZURE_RESOURCE_GROUP: pagopa-d-api-rg
AZURE_SERVICE_NAME: pagopa-d-apim
APPCONFIGURATION_ENDPOINT: 'https://pagopa-d-selfcare-appconfiguration.azconfig.io'
Expand Down
1 change: 1 addition & 0 deletions helm/values-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ microservice-chart:
GEC_SERVICE_URL: https://api.platform.pagopa.it
FORWARDER_SERVICE_URL: https://api.platform.pagopa.it
TAXONOMY_SERVICE_URL: https://api.platform.pagopa.it
ENABLE_SEND_EMAIL: true
AZURE_RESOURCE_GROUP: pagopa-p-api-rg
AZURE_SERVICE_NAME: pagopa-p-apim
APPCONFIGURATION_ENDPOINT: 'https://pagopa-p-selfcare-appconfiguration.azconfig.io'
Expand Down
1 change: 1 addition & 0 deletions helm/values-uat.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ microservice-chart:
GEC_SERVICE_URL: https://api.uat.platform.pagopa.it
FORWARDER_SERVICE_URL: https://api.uat.platform.pagopa.it
TAXONOMY_SERVICE_URL: https://api.platform.pagopa.it
ENABLE_SEND_EMAIL: true
AZURE_RESOURCE_GROUP: pagopa-u-api-rg
AZURE_SERVICE_NAME: pagopa-u-apim
APPCONFIGURATION_ENDPOINT: 'https://pagopa-u-selfcare-appconfiguration.azconfig.io'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class AwsSesClient {

private final ExternalApiClient externalApiClient;

private final String environment;
private final Boolean enableSendEmail;

private final String testEmailAddress;

Expand All @@ -44,17 +44,17 @@ public AwsSesClient(
@Value("${aws.ses.user}") String from,
SpringTemplateEngine templateEngine,
ExternalApiClient externalApiClient,
@Value("${info.properties.environment}") String environment,
@Value("${institution.subscription.test-email}") String testEmailAddress,
@Value("${institution.subscription.pagopa-operator-email}") String pagopaOperatorEmailAddress
) {
@Value("${institution.subscription.pagopa-operator-email}") String pagopaOperatorEmailAddress,
@Value("${institution.subscription.enable-send-email}") Boolean enableSendEmail) {
this.sesClient = sesClient;
this.from = from;
this.templateEngine = templateEngine;
this.externalApiClient = externalApiClient;
this.environment = environment;

this.testEmailAddress = testEmailAddress;
this.pagopaOperatorEmailAddress = pagopaOperatorEmailAddress;
this.enableSendEmail = enableSendEmail;
}

/**
Expand All @@ -72,7 +72,7 @@ public AwsSesClient(
*/
public void sendEmail(EmailMessageDetail email, boolean sendEmailToPagopaOperator) {
String taxCode = email.getInstitutionTaxCode();
if (isNotProdWithoutTestEmail() || isProdWithNullDestinationInstitutionTaxCode(taxCode)) {
if (hasNotRequiredData(taxCode)) {
log.warn("Skip send email process");
return;
}
Expand Down Expand Up @@ -132,7 +132,7 @@ private SendEmailRequest buildEmailRequest(EmailMessageDetail email, String[] to
}

private String[] getToAddressList(String taxCode, SelfcareProductUser destinationUserType) {
if (!this.environment.equals("PROD")) {
if (Boolean.FALSE.equals(this.enableSendEmail)) {
return new String[]{testEmailAddress};
}
Optional<Institution> optionalInstitution = this.externalApiClient.getInstitutionsFiltered(taxCode)
Expand All @@ -158,11 +158,7 @@ private String[] getToAddressList(String taxCode, SelfcareProductUser destinatio
.toArray(new String[0]);
}

private boolean isProdWithNullDestinationInstitutionTaxCode(String taxCode) {
return this.environment.equals("PROD") && taxCode == null;
}

private boolean isNotProdWithoutTestEmail() {
return !this.environment.equals("PROD") && StringUtils.isBlank(testEmailAddress);
private boolean hasNotRequiredData(String taxCode) {
return Boolean.FALSE.equals(this.enableSendEmail) ? StringUtils.isBlank(testEmailAddress) : taxCode == null;
}
}
1 change: 1 addition & 0 deletions src/main/resources/application-local.properties
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,5 @@ authorization.taxonomy.subscriptionKey=${PAPGOPA_APIM_TAXONOMY_API_KEY_PAGOPA}
# Other
institution.subscription.test-email=${TEST_EMAIL}
institution.subscription.pagopa-operator-email=${PAGOPA_OPERATOR_EMAIL}
institution.subscription.enable-send-email=${ENABLE_SEND_EMAIL}
cron.job.schedule.enabled=true
2 changes: 1 addition & 1 deletion src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ extraction.bundles.getAllBundles.pageLimit=${EXTRACTION_BUNDLES_GETALLBUNDLES_LI
# Other
institution.subscription.test-email=${TEST_EMAIL:}
institution.subscription.pagopa-operator-email=${PAGOPA_OPERATOR_EMAIL:}

institution.subscription.enable-send-email=${ENABLE_SEND_EMAIL:}
# Client API retry
retry.utils.maxAttempts=${CLIENT_RETRY_MAX_ATTEMPTS:3}
retry.utils.maxDelay=${CLIENT_RETRY_MAX_DELAY:2000}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class AwsSesClientTest {

@Test
void sendEmailPRODSuccess() {
ReflectionTestUtils.setField(sut, "environment", "PROD");
ReflectionTestUtils.setField(sut, "enableSendEmail", true);

Institutions institutions = buildInstitutions();
List<InstitutionProductUsers> institutionProductUsers = buildInstitutionProductUsers();
Expand All @@ -68,7 +68,7 @@ void sendEmailPRODSuccess() {

@Test
void sendEmailNotPRODSuccess() {
ReflectionTestUtils.setField(sut, "environment", "DEV");
ReflectionTestUtils.setField(sut, "enableSendEmail", false);

when(templateEngine.process(anyString(), any())).thenReturn("html template");
when(sesClient.sendEmail(any(SendEmailRequest.class))).thenReturn(SendEmailResponse.builder().build());
Expand All @@ -86,7 +86,7 @@ void sendEmailNotPRODSuccess() {

@Test
void sendEmailPRODFail() {
ReflectionTestUtils.setField(sut, "environment", "PROD");
ReflectionTestUtils.setField(sut, "enableSendEmail", true);

Institutions institutions = buildInstitutions();
List<InstitutionProductUsers> institutionProductUsers = buildInstitutionProductUsers();
Expand All @@ -106,7 +106,7 @@ void sendEmailPRODFail() {

@Test
void sendEmailPRODNoInstitutionTaxCodeSkipped() {
ReflectionTestUtils.setField(sut, "environment", "PROD");
ReflectionTestUtils.setField(sut, "enableSendEmail", true);
ReflectionTestUtils.setField(sut, "testEmailAddress", "[email protected]");

assertDoesNotThrow(() -> sut.sendEmail(buildEmailMessageDetail(null)));
Expand All @@ -124,7 +124,7 @@ void sendEmailPRODNoInstitutionTaxCodeSkipped() {

@Test
void sendEmailNoInstitutionFoundSkipped() {
ReflectionTestUtils.setField(sut, "environment", "PROD");
ReflectionTestUtils.setField(sut, "enableSendEmail", true);

when(externalApiClient.getInstitutionsFiltered(INSTITUTION_TAX_CODE))
.thenReturn(Institutions.builder().institutions(Collections.emptyList()).build());
Expand All @@ -143,7 +143,7 @@ void sendEmailNoInstitutionFoundSkipped() {

@Test
void sendEmailNoDestinationSkipped() {
ReflectionTestUtils.setField(sut, "environment", "PROD");
ReflectionTestUtils.setField(sut, "enableSendEmail", true);

Institutions institutions = buildInstitutions();

Expand All @@ -163,7 +163,7 @@ void sendEmailNoDestinationSkipped() {

@Test
void sendEmailNotPRODAndNoTestEmailSkipped() {
ReflectionTestUtils.setField(sut, "environment", "DEV");
ReflectionTestUtils.setField(sut, "enableSendEmail", false);
ReflectionTestUtils.setField(sut, "testEmailAddress", null);

assertDoesNotThrow(() -> sut.sendEmail(buildEmailMessageDetail(INSTITUTION_TAX_CODE)));
Expand All @@ -181,7 +181,7 @@ void sendEmailNotPRODAndNoTestEmailSkipped() {

@Test
void sendEmailPRODSWithPagopaOperatorSuccess() {
ReflectionTestUtils.setField(sut, "environment", "PROD");
ReflectionTestUtils.setField(sut, "enableSendEmail", true);

Institutions institutions = buildInstitutions();
List<InstitutionProductUsers> institutionProductUsers = buildInstitutionProductUsers();
Expand Down
3 changes: 2 additions & 1 deletion src/test/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -96,5 +96,6 @@ extraction.ibans.clean.olderThanDays=7
extraction.ibans.persistIbanBatchSize=8000
extraction.bundles.getAllBundles.pageLimit=200
# Other
institution.subscription.test-email=tes@mail.it
institution.subscription.test-email=test@mail.it
[email protected]
institution.subscription.enable-send-email=false
Loading