Skip to content

Commit

Permalink
chore: workaround bo crash
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabien committed Nov 22, 2024
1 parent a5a4eb9 commit 79dceab
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 34 deletions.
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
package fr.dossierfacile.api.front.service;

import fr.dossierfacile.common.dto.mail.TenantDto;
import fr.dossierfacile.api.front.exception.PasswordRecoveryTokenNotFoundException;
import fr.dossierfacile.api.front.exception.UserNotFoundException;
import fr.dossierfacile.api.front.mapper.TenantMapper;
import fr.dossierfacile.common.mapper.mail.TenantMapperForMail;
import fr.dossierfacile.api.front.model.tenant.TenantModel;
import fr.dossierfacile.api.front.repository.PasswordRecoveryTokenRepository;
import fr.dossierfacile.api.front.repository.UserRepository;
import fr.dossierfacile.api.front.service.interfaces.*;
import fr.dossierfacile.common.model.apartment_sharing.ApplicationModel;
import fr.dossierfacile.common.utils.TransactionalUtil;
import fr.dossierfacile.common.dto.mail.TenantDto;
import fr.dossierfacile.common.entity.*;
import fr.dossierfacile.common.enums.ApplicationType;
import fr.dossierfacile.common.enums.LogType;
import fr.dossierfacile.common.enums.PartnerCallBackType;
import fr.dossierfacile.common.enums.TenantType;
import fr.dossierfacile.common.mapper.mail.TenantMapperForMail;
import fr.dossierfacile.common.model.apartment_sharing.ApplicationModel;
import fr.dossierfacile.common.repository.TenantCommonRepository;
import fr.dossierfacile.common.service.interfaces.LogService;
import fr.dossierfacile.common.service.interfaces.PartnerCallBackService;
import fr.dossierfacile.common.service.interfaces.TenantCommonService;
import fr.dossierfacile.common.utils.TransactionalUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
Expand All @@ -28,6 +28,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -96,12 +97,12 @@ private List<TenantUserApi> groupingAllTenantUserApisInTheApartment(ApartmentSha
@Override
@Transactional
public void deleteAccount(Tenant tenant) {
List<ApplicationModel> webhookDTOList = new ArrayList<>();
ApartmentSharing apartmentSharing = tenant.getApartmentSharing();
groupingAllTenantUserApisInTheApartment(apartmentSharing).forEach((tenantUserApi) -> {
UserApi userApi = tenantUserApi.getUserApi();
webhookDTOList.add(partnerCallBackService.getWebhookDTO(tenant, userApi, PartnerCallBackType.DELETED_ACCOUNT));
});
Map<TenantUserApi, ApplicationModel> webhookDTOMap = groupingAllTenantUserApisInTheApartment(apartmentSharing).stream()
.collect(Collectors.toMap(
tenantUserApi -> tenantUserApi,
tenantUserApi -> partnerCallBackService.getWebhookDTO(tenant, tenantUserApi.getUserApi(), PartnerCallBackType.DELETED_ACCOUNT)
));
logService.saveLogWithTenantData(LogType.ACCOUNT_DELETE, tenant);
TenantDto tenantToDeleteDto = tenantMapperForMail.toDto(tenant);
tenantCommonService.deleteTenantData(tenant);
Expand All @@ -116,9 +117,8 @@ public void deleteAccount(Tenant tenant) {
userRepository.delete(tenant);
apartmentSharingService.removeTenant(tenant.getApartmentSharing(), tenant);
}
for (ApplicationModel webhookDTO : webhookDTOList) {
partnerCallBackService.sendCallBack(tenant, webhookDTO.getUserApi(), webhookDTO);
}
webhookDTOMap.forEach((tenantUserApi, webhookDTO) -> partnerCallBackService.sendCallBack(tenant, tenantUserApi.getUserApi(), webhookDTO));


TransactionalUtil.afterCommit(() -> {
mailService.sendEmailAccountDeleted(tenantToDeleteDto);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
public class Producer {
private final QueueMessageRepository queueMessageRepository;

@Async
public void generatePdf(Long documentId) {
log.debug("Sending document with ID [{}] for pdf generation", documentId);
queueMessageRepository.save(QueueMessage.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ private CsrfTokenRepository csrfTokenRepository() {
@Bean
public Executor taskExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(2);
executor.setMaxPoolSize(2);
executor.setQueueCapacity(500);
executor.setThreadNamePrefix("Mailer-");
executor.setCorePoolSize(4);
executor.setMaxPoolSize(4);
executor.setQueueCapacity(200);
executor.setThreadNamePrefix("BOAsyncExecutor-");
executor.initialize();
return executor;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package fr.dossierfacile.common.model.apartment_sharing;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import fr.dossierfacile.common.entity.UserApi;
import fr.dossierfacile.common.enums.ApplicationType;
import fr.dossierfacile.common.enums.FileStatus;
import fr.dossierfacile.common.enums.PartnerCallBackType;
Expand Down Expand Up @@ -33,6 +31,4 @@ public class ApplicationModel {
private List<TenantModel> tenants;
@JsonFormat(pattern="yyyy-MM-dd'T'HH:mm:ss.SSSSSS")
private LocalDateTime lastUpdateDate;
@JsonIgnore
private UserApi userApi = null;
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,10 @@
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

Expand Down Expand Up @@ -89,12 +85,15 @@ public void sendCallBack(Tenant tenant, PartnerCallBackType partnerCallBackType)
if (apartmentSharing.isEmpty()) {
return;
}
List<ApplicationModel> applicationModelList = findAllUserApi(tenant.getApartmentSharing()).stream()
.map(userApi -> getWebhookDTO(tenant, userApi, partnerCallBackType)).toList();
Map<UserApi, ApplicationModel> applicationModelMap = findAllUserApi(tenant.getApartmentSharing()).stream()
.collect(Collectors.toMap(
userApi -> userApi,
userApi -> getWebhookDTO(tenant, userApi, partnerCallBackType)
));

TransactionalUtil.afterCommit(() -> {
try {
applicationModelList.forEach(model -> sendCallBack(tenant, model.getUserApi(), model));
applicationModelMap.forEach((userApi, applicationModel) -> sendCallBack(tenant, userApi, applicationModel));
} catch (Exception e) {
log.error("CAUTION Unable to send notification to partner", e);
}
Expand Down Expand Up @@ -135,7 +134,6 @@ public void sendRevokedAccessCallback(Tenant tenant, UserApi userApi) {
ApplicationModel applicationModel = new ApplicationModel();
applicationModel.setOnTenantId(tenant.getId());
applicationModel.setPartnerCallBackType(PartnerCallBackType.ACCESS_REVOKED);
applicationModel.setUserApi(userApi);

sendCallBack(tenant, userApi, applicationModel);
}
Expand All @@ -144,7 +142,6 @@ public void sendRevokedAccessCallback(Tenant tenant, UserApi userApi) {
public ApplicationModel getWebhookDTO(Tenant tenant, UserApi userApi, PartnerCallBackType partnerCallBackType) {
ApartmentSharing apartmentSharing = tenant.getApartmentSharing();
ApplicationModel applicationModel = applicationFullMapper.toApplicationModel(apartmentSharing, userApi);
applicationModel.setUserApi(userApi);

List<Tenant> tenantList = tenantRepository.findAllByApartmentSharing(apartmentSharing);
for (Tenant t : tenantList) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public class RequestServiceImpl implements RequestService {
private static final String CALL_BACK_RESPONSE = "CallBack ResponseStatus: {}";
private final RestTemplate restTemplate;

@Transactional(propagation = Propagation.NOT_SUPPORTED)
@Async
public void send(ApplicationModel applicationModel, String urlCallback, String partnerApiKeyCallback) {
HttpHeaders headers = new HttpHeaders();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,5 @@ public interface PartnerCallBackService {
void sendCallBack(List<Tenant> tenantList, PartnerCallBackType partnerCallBackType);
void sendCallBack(Tenant tenant, UserApi userApi, ApplicationModel applicationModel);
void sendRevokedAccessCallback(Tenant tenant, UserApi userApi);

@Nullable
ApplicationModel getWebhookDTO(Tenant tenant, UserApi userApi, PartnerCallBackType partnerCallBackType);
}

0 comments on commit 79dceab

Please sign in to comment.