From 4645443381db63532036b2d5c31eeaa15b33879c Mon Sep 17 00:00:00 2001 From: Fabien Date: Thu, 13 Jun 2024 09:16:25 +0200 Subject: [PATCH] fix: temp fix failure on notification at the end of op treatment --- .../api/front/service/UserServiceImpl.java | 12 +++++- .../fr/gouv/bo/service/TenantService.java | 41 ++++++++++++++----- .../common/entity/ApartmentSharing.java | 10 ----- .../service/PartnerCallBackServiceImpl.java | 19 +++++---- 4 files changed, 53 insertions(+), 29 deletions(-) diff --git a/dossierfacile-api-tenant/src/main/java/fr/dossierfacile/api/front/service/UserServiceImpl.java b/dossierfacile-api-tenant/src/main/java/fr/dossierfacile/api/front/service/UserServiceImpl.java index 96760707..ebf52815 100644 --- a/dossierfacile-api-tenant/src/main/java/fr/dossierfacile/api/front/service/UserServiceImpl.java +++ b/dossierfacile-api-tenant/src/main/java/fr/dossierfacile/api/front/service/UserServiceImpl.java @@ -81,13 +81,21 @@ public void forgotPassword(String email) { PasswordRecoveryToken passwordRecoveryToken = passwordRecoveryTokenService.create(tenant); mailService.sendEmailNewPassword(tenant, passwordRecoveryToken); } - + private List groupingAllTenantUserApisInTheApartment(ApartmentSharing as) { + List tenantUserApis = new ArrayList<>(); + if (as.getTenants() != null && !as.getTenants().isEmpty()) { + as.getTenants().stream() + .filter(t -> t.getTenantsUserApi() != null && !t.getTenantsUserApi().isEmpty()) + .forEach(t -> tenantUserApis.addAll(t.getTenantsUserApi())); + } + return tenantUserApis; + } @Override @Transactional public void deleteAccount(Tenant tenant) { List webhookDTOList = new ArrayList<>(); ApartmentSharing apartmentSharing = tenant.getApartmentSharing(); - apartmentSharing.groupingAllTenantUserApisInTheApartment().forEach((tenantUserApi) -> { + groupingAllTenantUserApisInTheApartment(apartmentSharing).forEach((tenantUserApi) -> { UserApi userApi = tenantUserApi.getUserApi(); webhookDTOList.add(partnerCallBackService.getWebhookDTO(tenant, userApi, PartnerCallBackType.DELETED_ACCOUNT)); }); diff --git a/dossierfacile-bo/src/main/java/fr/gouv/bo/service/TenantService.java b/dossierfacile-bo/src/main/java/fr/gouv/bo/service/TenantService.java index 67889b61..bce834cb 100644 --- a/dossierfacile-bo/src/main/java/fr/gouv/bo/service/TenantService.java +++ b/dossierfacile-bo/src/main/java/fr/gouv/bo/service/TenantService.java @@ -519,18 +519,25 @@ private void changeTenantStatusToValidated(Tenant tenant, User operator, Process operatorLogRepository.save(new OperatorLog(tenant, operator, tenant.getStatus(), ActionOperatorType.STOP_PROCESS, processedDocuments.count(), processedDocuments.timeSpent())); TransactionalUtil.afterCommit(() -> { - if (tenant.getApartmentSharing().getApplicationType() == ApplicationType.GROUP) { - mailService.sendEmailToTenantAfterValidateAllDocumentsOfTenant(tenant); - } else { - if (tenant.getApartmentSharing().getTenants().stream() - .allMatch(t -> t.getStatus() == TenantFileStatus.VALIDATED)) { - tenant.getApartmentSharing().getTenants().stream() - .filter(t -> isNotBlank(t.getEmail())) - .forEach(t -> mailService.sendEmailToTenantAfterValidateAllDocuments(t)); + try { + if (tenant.getApartmentSharing().getApplicationType() == ApplicationType.GROUP) { + mailService.sendEmailToTenantAfterValidateAllDocumentsOfTenant(tenant); + } else { + if (tenant.getApartmentSharing().getTenants().stream() + .allMatch(t -> t.getStatus() == TenantFileStatus.VALIDATED)) { + tenant.getApartmentSharing().getTenants().stream() + .filter(t -> isNotBlank(t.getEmail())) + .forEach(t -> mailService.sendEmailToTenantAfterValidateAllDocuments(t)); + } } + } catch (Exception e) { + log.error("CAUTION Unable to send notification to user "); + } + try { + partnerCallBackService.sendCallBack(tenant, PartnerCallBackType.VERIFIED_ACCOUNT); + } catch (Exception e) { + log.error("CAUTION Unable to send notification to partner"); } - - partnerCallBackService.sendCallBack(tenant, PartnerCallBackType.VERIFIED_ACCOUNT); }); } @@ -544,6 +551,20 @@ private void changeTenantStatusToDeclined(Tenant tenant, User operator, Message tenant, operator, tenant.getStatus(), ActionOperatorType.STOP_PROCESS, processedDocuments.count(), processedDocuments.timeSpent() )); + // TODO This part should be here to load tenant futur tenant data Please use DTO in AfterCommit INSTEAD ! + // This part should treat sendMail and sendCallback + if (tenant.getApartmentSharing().getApplicationType() == ApplicationType.COUPLE) { + tenant.getApartmentSharing().getTenants().stream() + .filter(t -> isNotBlank(t.getEmail())) + .forEach(t -> { + if (t.isBelongToPartner()) + t.getTenantsUserApi().get(0).getUserApi(); + }); + } else { + if (tenant.isBelongToPartner()) + tenant.getTenantsUserApi().get(0).getUserApi(); + } + TransactionalUtil.afterCommit(() -> { if (tenant.getApartmentSharing().getApplicationType() == ApplicationType.COUPLE) { tenant.getApartmentSharing().getTenants().stream() diff --git a/dossierfacile-common-library/src/main/java/fr/dossierfacile/common/entity/ApartmentSharing.java b/dossierfacile-common-library/src/main/java/fr/dossierfacile/common/entity/ApartmentSharing.java index d5982833..c24e52c0 100644 --- a/dossierfacile-common-library/src/main/java/fr/dossierfacile/common/entity/ApartmentSharing.java +++ b/dossierfacile-common-library/src/main/java/fr/dossierfacile/common/entity/ApartmentSharing.java @@ -122,16 +122,6 @@ public Integer totalSalary() { return totalSalary; } - public List groupingAllTenantUserApisInTheApartment() { - List tenantUserApis = new ArrayList<>(); - if (tenants != null && !tenants.isEmpty()) { - tenants.stream() - .filter(t -> t.getTenantsUserApi() != null && !t.getTenantsUserApi().isEmpty()) - .forEach(t -> tenantUserApis.addAll(t.getTenantsUserApi())); - } - return tenantUserApis; - } - public Integer totalGuarantorSalary() { int totalSalary = 0; for (Tenant tenant : tenants) { diff --git a/dossierfacile-common-library/src/main/java/fr/dossierfacile/common/service/PartnerCallBackServiceImpl.java b/dossierfacile-common-library/src/main/java/fr/dossierfacile/common/service/PartnerCallBackServiceImpl.java index bb0e3de2..137f351c 100644 --- a/dossierfacile-common-library/src/main/java/fr/dossierfacile/common/service/PartnerCallBackServiceImpl.java +++ b/dossierfacile-common-library/src/main/java/fr/dossierfacile/common/service/PartnerCallBackServiceImpl.java @@ -20,10 +20,7 @@ import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; -import java.util.Collections; -import java.util.List; -import java.util.Objects; -import java.util.Optional; +import java.util.*; @Service @RequiredArgsConstructor @@ -66,19 +63,27 @@ public void registerTenant(String internalPartnerId, Tenant tenant, UserApi user } } } - + private List groupingAllTenantUserApisInTheApartment(ApartmentSharing as) { + List tenantUserApis = new ArrayList<>(); + if (as.getTenants() != null && !as.getTenants().isEmpty()) { + as.getTenants().stream() + .filter(t -> t.getTenantsUserApi() != null && !t.getTenantsUserApi().isEmpty()) + .forEach(t -> tenantUserApis.addAll(t.getTenantsUserApi())); + } + return tenantUserApis; + } + // TODO send callback should be transactionnal or have DTO public void sendCallBack(Tenant tenant, PartnerCallBackType partnerCallBackType) { Optional apartmentSharing = apartmentSharingRepository.findByTenant(tenant.getId()); if (apartmentSharing.isEmpty()) { return; } - apartmentSharing.get().groupingAllTenantUserApisInTheApartment().forEach(tenantUserApi -> { + groupingAllTenantUserApisInTheApartment(apartmentSharing.get()).forEach(tenantUserApi -> { UserApi userApi = tenantUserApi.getUserApi(); WebhookDTO webhookDTO = getWebhookDTO(tenant, userApi, partnerCallBackType); sendCallBack(tenant, webhookDTO); }); } - @Override public void sendCallBack(List tenantList, PartnerCallBackType partnerCallBackType) { if (tenantList != null && !tenantList.isEmpty()) {