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

chore: upgrade sendinblue to brevo #839

Merged
merged 1 commit into from
Oct 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
39 changes: 5 additions & 34 deletions dossierfacile-api-owner/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -80,40 +80,11 @@
<artifactId>springdoc-openapi-ui</artifactId>
<version>${springdoc.version}</version>
</dependency>
<!-- Caution - transitive dependencies on sendinblue itself are not compatible -->
<dependency>
<groupId>com.sendinblue</groupId>
<artifactId>sib-api-v3-sdk</artifactId>
<version>7.0.0</version>
<exclusions>
<exclusion>
<groupId>com.squareup.okhttp</groupId>
<artifactId>okhttp</artifactId>
</exclusion>
<exclusion>
<groupId>com.squareup.okhttp</groupId>
<artifactId>logging-interceptor</artifactId>
</exclusion>
<exclusion>
<groupId>com.squareup.okio</groupId>
<artifactId>okio</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>logging-interceptor</artifactId>
<version>4.11.0</version>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>4.11.0</version>
</dependency>
<dependency>
<groupId>com.squareup.okio</groupId>
<artifactId>okio</artifactId>
<version>3.5.0</version>
<dependency>
<groupId>com.brevo</groupId>
<artifactId>brevo</artifactId>
<version>1.0.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>net.logstash.logback</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,20 @@
package fr.dossierfacile.api.dossierfacileapiowner.mail;

import fr.dossierfacile.common.entity.ConfirmationToken;
import fr.dossierfacile.common.entity.Owner;
import fr.dossierfacile.common.entity.PasswordRecoveryToken;
import fr.dossierfacile.common.entity.Property;
import fr.dossierfacile.common.entity.Tenant;
import fr.dossierfacile.common.entity.User;
import brevo.ApiClient;
import brevo.ApiException;
import brevo.Configuration;
import brevo.auth.ApiKeyAuth;
import brevoApi.TransactionalEmailsApi;
import brevoModel.SendSmtpEmail;
import brevoModel.SendSmtpEmailTo;
import fr.dossierfacile.common.entity.*;
import fr.dossierfacile.common.enums.TenantType;
import fr.dossierfacile.common.repository.TenantCommonRepository;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import sendinblue.ApiClient;
import sendinblue.ApiException;
import sendinblue.Configuration;
import sendinblue.auth.ApiKeyAuth;
import sibApi.TransactionalEmailsApi;
import sibModel.SendSmtpEmail;
import sibModel.SendSmtpEmailTo;

import java.util.Collections;
import java.util.List;
Expand All @@ -30,24 +25,23 @@
@Slf4j
public class MailServiceImpl implements MailService {
private final TenantCommonRepository tenantCommonRepository;
@Value("${sendinblue.apikey}")
@Value("${brevo.apikey}")
private String sendinblueApiKey;
@Value("${sendinblue.template.id.welcome}")
@Value("${brevo.template.id.welcome}")
private Long templateIDWelcome;
@Value("${sendinblue.template.id.new.password}")
@Value("${brevo.template.id.new.password}")
private Long templateIdNewPassword;
@Value("${owner.url}")
private String ownerUrl;
@Value("${sendinblue.template.id.applicant.validated}")
@Value("${brevo.template.id.applicant.validated}")
private Long templateIdApplicantValidated;
@Value("${sendinblue.template.id.new.applicant.validated}")
@Value("${brevo.template.id.new.applicant.validated}")
private Long templateIdNewApplicantValidated;
@Value("${sendinblue.template.id.new.applicant.not.validated}")
@Value("${brevo.template.id.new.applicant.not.validated}")
private Long templateIdNewApplicantNotValidated;
@Value("${sendinblue.template.id.validated.property}")
@Value("${brevo.template.id.validated.property}")
private Long templateIdValidatedProperty;

@Value("${sendinblue.template.id.follow-up.validated.property}")
@Value("${brevo.template.id.follow-up.validated.property}")
private Long templateIdFollowUpAfterValidatedProperty;

@Value("${property.path}")
Expand Down Expand Up @@ -123,6 +117,7 @@ public void sendEmailNewApplicantValidated(Tenant tenant, Owner owner, Property
.propertyUrl(ownerUrl + propertyPath + property.getId())
.build());
}

@Override
public void sendEmailNewApplicantNotValidated(Tenant tenant, Owner owner, Property property) {
sendTransactionalEmail(templateIdNewApplicantNotValidated, owner,
Expand All @@ -135,6 +130,7 @@ public void sendEmailNewApplicantNotValidated(Tenant tenant, Owner owner, Proper
.propertyUrl(ownerUrl + propertyPath + property.getId())
.build());
}

@Async
@Override
public void sendEmailValidatedProperty(User user, Property property) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ spring.security.oauth2.resourceserver.jwt.jwk-set-uri=

spring.mvc.pathmatch.matching-strategy=ant_path_matcher

sendinblue.apikey=
sendinblue.template.id.welcome=10
sendinblue.template.id.new.password=21
sendinblue.template.id.applicant.validated=139
sendinblue.template.id.new.applicant=98
sendinblue.template.id.new.applicant.validated=137
sendinblue.template.id.new.applicant.not.validated=138
sendinblue.template.id.validated.property=95
sendinblue.template.id.follow-up.validated.property=96
brevo.apikey=
brevo.template.id.welcome=10
brevo.template.id.new.password=21
brevo.template.id.applicant.validated=139
brevo.template.id.new.applicant=98
brevo.template.id.new.applicant.validated=137
brevo.template.id.new.applicant.not.validated=138
brevo.template.id.validated.property=95
brevo.template.id.follow-up.validated.property=96

owner.url=https://proprietaire.dossierfacile.fr
property.path=/consulte-propriete/
Expand Down
22 changes: 4 additions & 18 deletions dossierfacile-api-tenant/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -194,25 +194,11 @@
<artifactId>HikariCP</artifactId>
<version>5.0.1</version>
</dependency>
<!-- Caution - transitive dependencies on sendinblue itself are not compatible -->
<dependency>
<groupId>com.sendinblue</groupId>
<artifactId>sib-api-v3-sdk</artifactId>
<version>7.0.0</version>
<exclusions>
<exclusion>
<groupId>com.squareup.okhttp</groupId>
<artifactId>okhttp</artifactId>
</exclusion>
<exclusion>
<groupId>com.squareup.okhttp</groupId>
<artifactId>logging-interceptor</artifactId>
</exclusion>
<exclusion>
<groupId>com.squareup.okio</groupId>
<artifactId>okio</artifactId>
</exclusion>
</exclusions>
<groupId>com.brevo</groupId>
<artifactId>brevo</artifactId>
<version>1.0.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
package fr.dossierfacile.api.front.config;

import brevo.ApiClient;
import brevo.auth.ApiKeyAuth;
import brevoApi.TransactionalEmailsApi;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import sendinblue.ApiClient;
import sendinblue.auth.ApiKeyAuth;
import sibApi.TransactionalEmailsApi;

@Configuration
public class MailConfiguration {
@Value("${sendinblue.apikey}")
@Value("${brevo.apikey}")
private String sendinblueApiKey;

@Bean
public TransactionalEmailsApi transactionalEmailsApi() {
ApiClient defaultClient = sendinblue.Configuration.getDefaultApiClient();
ApiClient defaultClient = brevo.Configuration.getDefaultApiClient();
ApiKeyAuth apiKey = (ApiKeyAuth) defaultClient.getAuthentication("api-key");
apiKey.setApiKey(sendinblueApiKey);
return new TransactionalEmailsApi();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ public abstract class TenantMapper {
private static final String DOSSIER_PDF_PATH = "/api/application/fullPdf/";
private static final String DOSSIER_PATH = "/file/";

@Value("${application.domain}")
protected String domain;
@Value("${application.base.url}")
protected String applicationBaseUrl;

@Value("${tenant.domain}")
protected String tenantDomain;
@Value("${tenant.base.url}")
protected String tenantBaseUrl;

protected CategoriesMapper categoriesMapper;

Expand All @@ -45,14 +45,14 @@ public void setCategoriesMapper(CategoriesMapper categoriesMapper) {
@Mapping(target = "passwordEnabled", expression = "java(tenant.getPassword() != null)")
public abstract TenantModel toTenantModel(Tenant tenant, @Context UserApi userApi);

@Mapping(target = "name", expression = "java((document.getWatermarkFile() != null )? domain + \"/" + PATH + "/\" + document.getName() : null)")
@Mapping(target = "name", expression = "java((document.getWatermarkFile() != null )? applicationBaseUrl + \"/" + PATH + "/\" + document.getName() : null)")
@MapDocumentCategories
public abstract DocumentModel toDocumentModel(Document document, @Context UserApi userApi);

@Mapping(target = "connectedTenantId", source = "id")
public abstract ConnectedTenantModel toTenantModelDfc(Tenant tenant);

@Mapping(target = "preview", expression = "java((documentFile.getPreview() != null )? domain + \"" + PREVIEW_PATH + "\" + documentFile.getId() : null)")
@Mapping(target = "preview", expression = "java((documentFile.getPreview() != null )? applicationBaseUrl + \"" + PREVIEW_PATH + "\" + documentFile.getId() : null)")
@Mapping(target = "size", source = "documentFile.storageFile.size")
@Mapping(target = "contentType", source = "documentFile.storageFile.contentType")
@Mapping(target = "originalName", source = "documentFile.storageFile.name")
Expand All @@ -63,8 +63,8 @@ void modificationsAfterMapping(@MappingTarget TenantModel.TenantModelBuilder ten
TenantModel tenantModel = tenantModelBuilder.build();
ApartmentSharingModel apartmentSharingModel = tenantModel.getApartmentSharing();
if (apartmentSharingModel.getStatus() == TenantFileStatus.VALIDATED) {
apartmentSharingModel.setDossierPdfUrl(domain + DOSSIER_PDF_PATH + apartmentSharingModel.getToken());
apartmentSharingModel.setDossierUrl(tenantDomain + DOSSIER_PATH + apartmentSharingModel.getToken());
apartmentSharingModel.setDossierPdfUrl(applicationBaseUrl + DOSSIER_PDF_PATH + apartmentSharingModel.getToken());
apartmentSharingModel.setDossierUrl( tenantBaseUrl + DOSSIER_PATH + apartmentSharingModel.getToken());
} else {
apartmentSharingModel.setToken(null);
apartmentSharingModel.setTokenPublic(null);
Expand Down Expand Up @@ -121,7 +121,7 @@ private void setDocumentDeniedReasonsAndDocumentAndFilesRoutes(List<DocumentMode
if (previewOnly) {
fileModel.setPath("");
} else {
fileModel.setPath(domain + filePath + fileModel.getId());
fileModel.setPath(applicationBaseUrl + filePath + fileModel.getId());
}
}));
}));
Expand All @@ -132,8 +132,8 @@ void modificationsAfterMapping(@MappingTarget ConnectedTenantModel.ConnectedTena
ConnectedTenantModel connectedTenantModel = connectedTenantModelBuilder.build();
fr.dossierfacile.api.front.model.dfc.apartment_sharing.ApartmentSharingModel apartmentSharingModel = connectedTenantModel.getApartmentSharing();
if (apartmentSharingModel.getStatus() == TenantFileStatus.VALIDATED) {
apartmentSharingModel.setDossierPdfUrl(domain + DOSSIER_PDF_PATH + apartmentSharingModel.getToken());
apartmentSharingModel.setDossierUrl(tenantDomain + DOSSIER_PATH + apartmentSharingModel.getToken());
apartmentSharingModel.setDossierPdfUrl(applicationBaseUrl + DOSSIER_PDF_PATH + apartmentSharingModel.getToken());
apartmentSharingModel.setDossierUrl(tenantBaseUrl + DOSSIER_PATH + apartmentSharingModel.getToken());
} else {
apartmentSharingModel.setToken(null);
apartmentSharingModel.setTokenPublic(null);
Expand Down
Loading
Loading