RED-2422: Port DeletedFilesCleanupService from filemanagement service
This commit is contained in:
parent
753eff7ea7
commit
e0aa7838aa
@ -0,0 +1,55 @@
|
|||||||
|
package com.iqser.red.service.peristence.v1.server.service.scheduler;
|
||||||
|
|
||||||
|
import java.time.OffsetDateTime;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import com.iqser.red.service.peristence.v1.server.service.DossierService;
|
||||||
|
import com.iqser.red.service.peristence.v1.server.service.FileService;
|
||||||
|
import com.iqser.red.service.peristence.v1.server.service.FileStatusService;
|
||||||
|
import com.iqser.red.service.peristence.v1.server.settings.FileManagementServiceSettings;
|
||||||
|
import com.iqser.red.service.persistence.management.v1.processor.entity.dossier.DossierEntity;
|
||||||
|
import com.iqser.red.service.persistence.management.v1.processor.entity.dossier.FileEntity;
|
||||||
|
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@Service
|
||||||
|
public class DeletedFilesCleanupService {
|
||||||
|
|
||||||
|
private final DossierService dossierService;
|
||||||
|
private final FileStatusService fileStatusService;
|
||||||
|
private final FileService fileService;
|
||||||
|
private final FileManagementServiceSettings settings;
|
||||||
|
|
||||||
|
|
||||||
|
@Scheduled(fixedDelay = 300000, initialDelay = 300000)
|
||||||
|
public void timedDeletion() {
|
||||||
|
|
||||||
|
var now = OffsetDateTime.now();
|
||||||
|
List<DossierEntity> dossiers = dossierService.getAllDossiers();
|
||||||
|
|
||||||
|
for (DossierEntity dossierEntity : dossiers) {
|
||||||
|
if (dossierEntity.getSoftDeletedTime() != null && dossierEntity.getHardDeletedTime() == null) {
|
||||||
|
if (dossierEntity.getSoftDeletedTime().isBefore(now.minusHours(settings.getSoftDeleteCleanupTime()))) {
|
||||||
|
dossierService.hardDeleteDossier(dossierEntity.getId());
|
||||||
|
log.info("Hard deleted dossier with dossier id {} ", dossierEntity.getId());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
var fileEntities = fileStatusService.getDossierStatus(dossierEntity.getId());
|
||||||
|
for (FileEntity fileEntity : fileEntities) {
|
||||||
|
if (fileEntity.getHardDeletedTime() == null && fileEntity.getDeleted() != null && fileEntity.getDeleted()
|
||||||
|
.isBefore(now.minusHours(settings.getSoftDeleteCleanupTime()))) {
|
||||||
|
fileService.hardDeleteFile(dossierEntity.getId(), fileEntity.getId());
|
||||||
|
log.info("Hard deleted file with dossier id {} and file id {}", dossierEntity.getId(), fileEntity.getId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -17,5 +17,6 @@ public class FileManagementServiceSettings {
|
|||||||
private int downloadCleanupDownloadFilesHours = 8;
|
private int downloadCleanupDownloadFilesHours = 8;
|
||||||
private int downloadCleanupNotDownloadFilesHours = 72;
|
private int downloadCleanupNotDownloadFilesHours = 72;
|
||||||
|
|
||||||
|
private int softDeleteCleanupTime = 96;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user