Commit 7f3b6851 authored by Kristel Meikas's avatar Kristel Meikas
Browse files

Merge branch 'develop' into 'master'

Release: merge 'develop' into 'master' created by Siiri Tann

See merge request teis/files-service!105
parents 2da11a82 697346cd
# Changelog
## [2.6.0] - 2022-11-08
* TEIS-2711, TEIS-3331: updated file status for creating zip files and rules for deleting nonexistent files from system
* TEIS-3331: implemented validation before processing file to validate it exists or mark invalid file as deleted;
added file validation to scheduled jobs
* TEIS-3430: refactored functionality to get unique suffix for duplicate filenames
* TEIS-2711: updated delete zip file timer; added getCurrentActiveCleanByObjectId method
* TEIS-3413: added methods to create a zip file
## [2.5.0] - 2022-10-07
* TEIS-3446: added zip file size check to create file logic
......
theGroup=ee.sm.ti.teis
theVersion=2.5.0
commonsVersion=2.11.0
commonApiGatewayVersion=2.8.0
theVersion=2.6.0
commonsVersion=2.12.0
commonApiGatewayVersion=2.10.0
pluginVersion=2.3.0
schedulerVersion=2.0.0
schedulerVersion=2.1.0
......@@ -16,6 +16,7 @@ dependencies {
implementation 'org.hibernate:hibernate-core:5.4.22.Final'
implementation 'org.springframework.data:spring-data-jpa:2.3.4.RELEASE'
implementation "ee.sm.ti.teis:files-client-lib:${commonsVersion}"
implementation "ee.sm.ti.teis:domain-cache-lib:${commonsVersion}"
implementation "ee.sm.ti.teis:common-api-gateway-lib:${commonApiGatewayVersion}"
implementation "ee.sm.ti.teis:service-common-lib:${commonsVersion}"
......
......@@ -21,4 +21,12 @@ public class FileService extends TeisRabbitClient<FileMetadata> {
public static class FileResponse extends DomainResponseDTO<FileMetadata, ErrorDTO> {
}
public FileMetadata createFileMetadata(FileMetadata domain, RequestMetaDTO requestMetaDTO) {
return createItem(domain, CreateFileMsResponse.class, requestMetaDTO);
}
public static class CreateFileMsResponse extends DomainResponseDTO<FileMetadata, ErrorDTO> {
}
}
package ee.sm.ti.teis.file.filereference;
import ee.sm.ti.teis.commongateway.file.FileMetadataDto;
import ee.sm.ti.teis.domain.file.FileMetadata;
import ee.sm.ti.teis.exceptions.TeisBusinessException;
import ee.sm.ti.teis.file.FileService;
import ee.sm.ti.teis.file.domain.FilePointer;
import ee.sm.ti.teis.file.pointer.FilePointerNotifyService;
import ee.sm.ti.teis.fileclient.FileStorageServiceClient;
import ee.sm.ti.teis.serviceclient.files.FilesServiceClient;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import ee.sm.ti.teis.types.enums.classifier.ObjectType;
import ee.sm.ti.teis.utils.UserUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import javax.transaction.Transactional;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import static ee.sm.ti.teis.errors.CommonErrorCode.BAD_REQUEST;
import static ee.sm.ti.teis.types.enums.FileScanStatusType.CLEAN;
import static ee.sm.ti.teis.types.enums.FileStatusType.PENDING;
import static ee.sm.ti.teis.types.enums.ObjectStatus.CURRENT;
import static ee.sm.ti.teis.types.enums.classifier.CreatorType.*;
import static ee.sm.ti.teis.utils.FileUtil.replaceForbiddenSymbols;
import static org.apache.commons.lang3.StringUtils.trim;
@Service
@Transactional
@RequiredArgsConstructor
@Validated
public class CreateZipFileBusinessService {
private final FileReferenceDataService dataService;
private final FileReferenceComposeService composeService;
private final FilePointerNotifyService filePointerNotifyService;
private final FileService fileService;
private final FileStorageServiceClient fileStorageServiceClient;
private final FilesServiceClient filesServiceClient;
public FileMetadataDto createZip(@NotBlank String zipFileName, @NotEmpty List<UUID> fileIdList,
@NotNull ObjectType objectType, RequestMetaDTO requestMetaDTO) {
fileIdList.forEach(id -> validateFile(id, requestMetaDTO));
String fileName = trim(replaceForbiddenSymbols(zipFileName)) + ".zip";
String bucket = fileStorageServiceClient.getBucket(objectType.getCode(), requestMetaDTO);
FileMetadata zipFile = new FileMetadata();
zipFile.setBucket(bucket);
zipFile.setFileId(UUID.randomUUID());
zipFile.setFileName(fileName);
zipFile.setContentType("application/zip");
zipFile.setFileStatusType(PENDING);
zipFile.setScanStatus(CLEAN);
FileMetadata fileMetadata = fileService.createFileMetadata(zipFile, requestMetaDTO);
FileReferenceEntity fileReferenceEntity = composeFileReference(fileMetadata.getFileId(), objectType, fileIdList, fileName, requestMetaDTO);
FileReferenceEntity savedEntity = dataService.saveNew(fileReferenceEntity);
FilePointer filePointer = composeService.toDomain(savedEntity);
filePointerNotifyService.createFilePointer(filePointer, requestMetaDTO);
filesServiceClient.createZipFile(fileIdList, zipFile, objectType, requestMetaDTO);
return composeService.toDto(fileMetadata);
}
private void validateFile(UUID fileId, RequestMetaDTO requestMetaDTO) {
FileMetadata fileMetadata = fileService.getFileMetadata(FileMetadata.builder().fileId(fileId).build(), requestMetaDTO);
if (!CLEAN.equals(fileMetadata.getScanStatus())) {
throw new TeisBusinessException(BAD_REQUEST, "Requested file is not clean");
}
fileStorageServiceClient.getFileStream(fileMetadata.getBucket(), fileMetadata.getFileId());
}
private FileReferenceEntity composeFileReference(UUID zipFileId, ObjectType objectType, List<UUID> fileIdList,
String fileName,
RequestMetaDTO requestMetaDTO) {
FileReferenceEntity fileReferenceEntity = new FileReferenceEntity();
fileReferenceEntity.setFileId(zipFileId);
fileReferenceEntity.setFileName(fileName);
fileReferenceEntity.setObjectId(zipFileId);
fileReferenceEntity.setObjectType(objectType.getId());
fileReferenceEntity.setContextType("ZIP_FILE");
if (UserUtil.isOfficial(requestMetaDTO)) {
fileReferenceEntity.setCreatorType(OFFICIAL.getId());
} else if (UserUtil.isPerson(requestMetaDTO)) {
fileReferenceEntity.setCreatorType(PERSON.getId());
} else {
fileReferenceEntity.setCreatorType(SYSTEM.getId());
}
fileReferenceEntity.setContext(Map.of("fileIds", fileIdList));
fileReferenceEntity.setObjectStatus(CURRENT);
fileReferenceEntity.setFileStatus(PENDING);
fileReferenceEntity.setScanStatus(CLEAN);
return fileReferenceEntity;
}
}
......@@ -15,6 +15,7 @@ import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import ee.sm.ti.teis.types.enums.classifier.FileContextType;
import ee.sm.ti.teis.types.enums.classifier.ObjectType;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
......@@ -28,10 +29,12 @@ import java.util.UUID;
import static ee.sm.ti.teis.types.enums.FileStatusType.ACTIVE;
import static ee.sm.ti.teis.types.enums.FileStatusType.FAILED;
import static ee.sm.ti.teis.types.enums.ObjectStatus.DELETED;
import static java.text.MessageFormat.format;
@Service
@Validated
@Transactional
@Slf4j
@RequiredArgsConstructor
public class FileReferenceBusinessService {
......@@ -142,17 +145,25 @@ public class FileReferenceBusinessService {
return dataService.getCurrentByObjectId(objectId);
}
public List<FileReferenceEntity> getCurrentActiveCleanByObjectId(UUID objectId) {
return dataService.getCurrentActiveCleanByObjectId(objectId);
}
public void updateFilePointer(FilePointerUpdate filePointer, RequestMetaDTO requestMetaDTO) {
filePointerNotifyService.updateFilePointer(filePointer, requestMetaDTO);
}
public void update(FileMetadata domain) {
List<FileReferenceEntity> entities = dataService.getCurrentByFileId(domain.getFileId());
log.debug("FILE REFERENCES FOUND: " + entities.size());
entities.forEach(entity -> {
entity.setFileName(domain.getFileName());
entity.setFileStatus(ACTIVE);
entity.setScanStatus(domain.getScanStatus());
dataService.save(entity);
String message = format("FILE REFERENCE {0} SAVED WITH STATUS: {1}",
entity.getFileId(), entity.getFileStatus());
log.debug(message);
});
}
......
......@@ -23,7 +23,6 @@ import static ee.sm.ti.teis.types.enums.FileScanStatusType.UNCHECKED;
import static ee.sm.ti.teis.types.enums.FileStatusType.PENDING;
import static ee.sm.ti.teis.types.enums.ObjectStatus.CURRENT;
import static ee.sm.ti.teis.types.enums.classifier.ClassifierDefinitionCode.*;
import static java.util.stream.Collectors.toList;
import static org.springframework.util.StringUtils.hasText;
@Service
......@@ -118,7 +117,7 @@ public class FileReferenceComposeService {
@Transactional
List<FileReferenceDto> toDtoList(List<FileReferenceEntity> entities, RequestMetaDTO requestMetaDTO) {
return entities.stream().map(entity -> toDto(entity, requestMetaDTO)).collect(toList());
return entities.stream().map(entity -> toDto(entity, requestMetaDTO)).toList();
}
FileMetadata toDomain(FileMetadataDto dto) {
......@@ -134,7 +133,7 @@ public class FileReferenceComposeService {
}
public List<FileReference> toReferenceDomainListFromDtoList(List<FileReferenceDto> dtoList) {
return dtoList.stream().map(this::toReferenceDomainFromDto).collect(toList());
return dtoList.stream().map(this::toReferenceDomainFromDto).toList();
}
public FileReference toReferenceDomainFromEntity(FileReferenceEntity entity, RequestMetaDTO requestMetaDTO) {
......@@ -158,7 +157,7 @@ public class FileReferenceComposeService {
public List<FileReference> toReferenceDomainListFromEntityList(List<FileReferenceEntity> entities,
RequestMetaDTO requestMetaDTO) {
return entities.stream().map(entity -> toReferenceDomainFromEntity(entity, requestMetaDTO)).collect(toList());
return entities.stream().map(entity -> toReferenceDomainFromEntity(entity, requestMetaDTO)).toList();
}
}
......@@ -77,6 +77,10 @@ public class FileReferenceDataService {
return repository.findCurrentByObjectId(objectId);
}
public List<FileReferenceEntity> getCurrentActiveCleanByObjectId(UUID objectId) {
return repository.findCurrentActiveCleanByObjectId(objectId);
}
public List<FileReferenceEntity> getByObjectId(UUID objectId) {
return repository.findByObjectId(objectId);
}
......
package ee.sm.ti.teis.file.filereference;
import ee.sm.ti.teis.types.enums.FileScanStatusType;
import ee.sm.ti.teis.types.enums.FileStatusType;
import ee.sm.ti.teis.types.enums.ObjectStatus;
import org.springframework.data.jpa.repository.JpaRepository;
......@@ -8,6 +9,7 @@ import java.util.List;
import java.util.Optional;
import java.util.UUID;
import static ee.sm.ti.teis.types.enums.FileScanStatusType.CLEAN;
import static ee.sm.ti.teis.types.enums.FileStatusType.ACTIVE;
import static ee.sm.ti.teis.types.enums.ObjectStatus.CURRENT;
......@@ -51,6 +53,13 @@ public interface FileReferenceRepository extends JpaRepository<FileReferenceEnti
return findByObjectIdAndFileIdAndObjectStatusAndFileStatus(objectId, fileId, CURRENT, ACTIVE);
}
List<FileReferenceEntity> findByObjectIdAndObjectStatusAndFileStatusAndScanStatus(UUID objectId,
ObjectStatus objectStatus, FileStatusType fileStatusType, FileScanStatusType scanStatusType);
default List<FileReferenceEntity> findCurrentActiveCleanByObjectId(UUID objectId) {
return findByObjectIdAndObjectStatusAndFileStatusAndScanStatus(objectId, CURRENT, ACTIVE, CLEAN);
}
List<FileReferenceEntity> findByFileIdAndObjectStatus(UUID fileId, ObjectStatus objectStatus);
default List<FileReferenceEntity> findCurrentByFileId(UUID fileId) {
......
package ee.sm.ti.teis.file.filereference;
import ee.sm.ti.teis.domain.file.FileMetadata;
import ee.sm.ti.teis.file.FileService;
import ee.sm.ti.teis.file.pointer.FilePointerNotifyService;
import ee.sm.ti.teis.fileclient.FileStorageServiceClient;
import ee.sm.ti.teis.serviceclient.files.FilesServiceClient;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import ee.sm.ti.teis.types.enums.classifier.ObjectType;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.mockito.junit.jupiter.MockitoSettings;
import org.mockito.quality.Strictness;
import java.util.List;
import java.util.UUID;
import static ee.sm.ti.teis.types.enums.FileScanStatusType.CLEAN;
import static ee.sm.ti.teis.types.enums.FileStatusType.PENDING;
import static ee.sm.ti.teis.types.enums.RolePrivilegeCode.TI_VIEW_DOCUMENTS;
import static ee.sm.ti.teis.utils.TestUtils.createRandomOfficialUser;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@ExtendWith(MockitoExtension.class)
@MockitoSettings(strictness = Strictness.LENIENT)
class CreateZipFileBusinessServiceTest {
@Mock
FileReferenceDataService dataService;
@Mock
FileReferenceComposeService composeService;
@Mock
FilePointerNotifyService filePointerNotifyService;
@Mock
FileService fileService;
@Mock
FileStorageServiceClient fileStorageServiceClient;
@Mock
FilesServiceClient filesServiceClient;
@InjectMocks
CreateZipFileBusinessService service;
@Captor
ArgumentCaptor<FileMetadata> fileMetadataArgumentCaptor;
@Test
void create_zipFile_success() {
RequestMetaDTO requestMetaDTO = createRandomOfficialUser(List.of(TI_VIEW_DOCUMENTS.name()));
UUID id = UUID.randomUUID();
UUID fileId = UUID.randomUUID();
FileMetadata fileMetadata = FileMetadata.builder().fileId(fileId).scanStatus(CLEAN).fileStatusType(PENDING).build();
FileReferenceEntity fileReferenceEntity = new FileReferenceEntity();
fileReferenceEntity.setFileId(fileId);
when(fileStorageServiceClient.getBucket(any(), any()))
.thenReturn("teis-temp");
when(fileService.createFileMetadata(any(), any()))
.thenReturn(fileMetadata);
when(fileService.getFileMetadata(any(), any()))
.thenReturn(fileMetadata);
when(dataService.saveNew(any()))
.thenReturn(fileReferenceEntity);
service.createZip("zipName", List.of(id), ObjectType.CASE_DOCUMENT, requestMetaDTO);
verify(fileService).createFileMetadata(fileMetadataArgumentCaptor.capture(), eq(requestMetaDTO));
FileMetadata value = fileMetadataArgumentCaptor.getValue();
assertThat(value.getScanStatus()).isEqualTo(CLEAN);
assertThat(value.getFileStatusType()).isEqualTo(PENDING);
verify(composeService).toDto(fileMetadataArgumentCaptor.capture());
value = fileMetadataArgumentCaptor.getValue();
assertThat(value.getFileId()).isEqualTo(fileId);
assertThat(value.getScanStatus()).isEqualTo(CLEAN);
assertThat(value.getFileStatusType()).isEqualTo(PENDING);
}
}
......@@ -12,6 +12,7 @@ import java.util.UUID;
import static ee.sm.ti.teis.types.enums.FileStatusType.ACTIVE;
import static java.util.Collections.emptyList;
import static java.util.Optional.empty;
import static java.util.UUID.randomUUID;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
......@@ -20,6 +21,9 @@ import static org.mockito.Mockito.when;
@ExtendWith(MockitoExtension.class)
class FileReferenceDataServiceTest {
private static final UUID FILE_ID = randomUUID();
private static final UUID OBJECT_ID = randomUUID();
@Mock
FileReferenceRepository repository;
@InjectMocks
......@@ -28,18 +32,18 @@ class FileReferenceDataServiceTest {
@Test
void get_currentByFileAndObject_throws_exception_when_not_found() {
when(repository.findCurrentByFileIdAndObjectId(any(), any())).thenReturn(empty());
assertThrows(TeisResourceNotFoundException.class, () -> service.getCurrentByFileIdAndObjectId(UUID.randomUUID(), UUID.randomUUID()));
assertThrows(TeisResourceNotFoundException.class, () -> service.getCurrentByFileIdAndObjectId(FILE_ID, OBJECT_ID));
}
@Test
void get_activeByFileAndObject_throws_exception_when_not_found() {
when(repository.findByFileIdAndObjectIdAndFileStatus(any(), any(), eq(ACTIVE))).thenReturn(emptyList());
assertThrows(TeisResourceNotFoundException.class, () -> service.getActiveByFileIdAndObjectId(UUID.randomUUID(), UUID.randomUUID()));
assertThrows(TeisResourceNotFoundException.class, () -> service.getActiveByFileIdAndObjectId(FILE_ID, OBJECT_ID));
}
@Test
void get_currentActiveByFileAndObject_throws_exception_when_not_found() {
when(repository.findCurrentActiveByObjectIdAndFileId(any(), any())).thenReturn(empty());
assertThrows(TeisResourceNotFoundException.class, () -> service.getCurrentActiveByObjectIdAndFileId(UUID.randomUUID(), UUID.randomUUID()));
assertThrows(TeisResourceNotFoundException.class, () -> service.getCurrentActiveByObjectIdAndFileId(FILE_ID, OBJECT_ID));
}
}
......@@ -18,6 +18,7 @@ dependencies {
implementation "ee.sm.ti.teis:common-api-gateway-lib:${commonApiGatewayVersion}"
implementation "ee.sm.ti.teis:service-common-lib:${commonsVersion}"
implementation "ee.sm.ti.teis:domain-request-lib:${commonsVersion}"
implementation "ee.sm.ti.teis:domain-cache-lib:${commonsVersion}"
implementation "ee.sm.ti.teis:service-request-lib:${commonsVersion}"
implementation "ee.sm.ti.teis:bpm-lib:${commonsVersion}"
......
......@@ -11,6 +11,7 @@ import ee.sm.ti.teis.file.domain.DeleteFile;
import ee.sm.ti.teis.file.hash.FileHashService;
import ee.sm.ti.teis.file.pointer.FilePointerEntity;
import ee.sm.ti.teis.file.pointer.FilePointerRepository;
import ee.sm.ti.teis.file.service.FileBusinessService;
import ee.sm.ti.teis.file.service.FileMetadataNotifyService.FileMetadataSavedEvent;
import ee.sm.ti.teis.file.thumbnail.FileThumbnailBusinessService;
import ee.sm.ti.teis.fileclient.FileStorageServiceClient;
......@@ -49,6 +50,8 @@ class FileMsListenerTest extends FilesServiceAppTestBase {
@MockBean
FileStorageServiceClient fileStorageServiceClient;
@MockBean
FileBusinessService fileBusinessService;
@MockBean
FileThumbnailBusinessService thumbnailService;
@MockBean
FileHashService hashService;
......@@ -185,6 +188,9 @@ class FileMsListenerTest extends FilesServiceAppTestBase {
file.setFileId(fileId);
event.setPayload(file, new RequestMetaDTO());
doReturn(true)
.when(fileBusinessService).validateFileExistsOrDeleteNonexistentFile(eq(fileId), eq(null), eq(false), any(RequestMetaDTO.class));
listener.updateFileMetadata(event);
verify(hashService)
......
......@@ -22,7 +22,7 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.*;
public class FileMetadataExceptionServiceTest extends FilesServiceAppTestBase {
class FileMetadataExceptionServiceTest extends FilesServiceAppTestBase {
private static final UUID FILE_ID = UUID.fromString("43c79641-f8f7-4ed7-b6aa-f1d3f084f668");
......
package ee.sm.ti.teis.file;
import ee.sm.ti.teis.file.pointer.FilePointerDataService;
import ee.sm.ti.teis.file.pointer.FilePointerEntity;
import ee.sm.ti.teis.file.service.FileBusinessService;
import ee.sm.ti.teis.file.service.FileDataService;
import ee.sm.ti.teis.file.virusscan.bpm.VirusScanProcessService;
import ee.sm.ti.teis.scheduler.domain.SystemJob;
......@@ -20,14 +19,14 @@ public class StartVirusScanJob extends SystemJobExecutor {
private final VirusScanProcessService virusScanProcessService;
private final FileDataService fileDataService;
private final FilePointerDataService filePointerDataService;
private final FileBusinessService fileBusinessService;
public StartVirusScanJob(RabbitTemplate msRabbitTemplate, VirusScanProcessService virusScanProcessService,
FileDataService fileDataService, FilePointerDataService filePointerDataService) {
FileDataService fileDataService, FileBusinessService fileBusinessService) {
super(msRabbitTemplate);
this.virusScanProcessService = virusScanProcessService;
this.fileDataService = fileDataService;
this.filePointerDataService = filePointerDataService;
this.fileBusinessService = fileBusinessService;
}
@Override
......@@ -41,8 +40,7 @@ public class StartVirusScanJob extends SystemJobExecutor {
try {
List<FileEntity> files = fileDataService.getByMissingVirusScan();
files.forEach(file -> {
List<FilePointerEntity> filePointers = filePointerDataService.getByFileId(file.getId());
if(!filePointers.isEmpty()) {
if (fileBusinessService.validateFileExistsOrDeleteNonexistentFile(file.getId(), file.getBucket(), false, requestMetaDto)) {
virusScanProcessService.startProcess(file.getId(), file.getName(), requestMetaDto);
counter.getAndIncrement();
}
......@@ -53,4 +51,5 @@ public class StartVirusScanJob extends SystemJobExecutor {
return "Amount of files virus scan started: " + counter;
}
}
......@@ -2,6 +2,7 @@ package ee.sm.ti.teis.file;
import ee.sm.ti.teis.domain.hash.CalculateFileHash;
import ee.sm.ti.teis.file.hash.FilesHashServiceClient;
import ee.sm.ti.teis.file.service.FileBusinessService;
import ee.sm.ti.teis.file.service.FileDataService;
import ee.sm.ti.teis.scheduler.domain.SystemJob;
import ee.sm.ti.teis.scheduler.job.executor.SystemJobExecutor;
......@@ -22,15 +23,17 @@ import static org.apache.commons.lang3.StringUtils.join;
public class UpdateFilesHashJob extends SystemJobExecutor {
private final FileDataService dataService;
private final FileBusinessService fileBusinessService;
private final FilesHashServiceClient filesHashServiceClient;
@Value("${teis.file.hash.algorithm}")
private String algorithm;
public UpdateFilesHashJob(RabbitTemplate msRabbitTemplate, FileDataService dataService,
FilesHashServiceClient filesHashServiceClient) {
FileBusinessService fileBusinessService, FilesHashServiceClient filesHashServiceClient) {
super(msRabbitTemplate);
this.dataService = dataService;
this.fileBusinessService = fileBusinessService;
this.filesHashServiceClient = filesHashServiceClient;
}
......@@ -46,16 +49,21 @@ public class UpdateFilesHashJob extends SystemJobExecutor {
List<String> failedFileIds = new ArrayList<>();
int counter = 0;
for (FileEntity file : files) {
try {
CalculateFileHash domain = new CalculateFileHash();
domain.setFileId(file.getId());
domain.setAlgorithm(algorithm);
domain.setBucket(file.getBucket());
filesHashServiceClient.calculateFileHash(domain, requestMetaDto);
counter++;
} catch (Exception e) {
if (fileBusinessService.validateFileExistsOrDeleteNonexistentFile(file.getId(), file.getBucket(), false, requestMetaDto)) {
try {
CalculateFileHash domain = new CalculateFileHash();
domain.setFileId(file.getId());
domain.setAlgorithm(algorithm);
domain.setBucket(file.getBucket());
filesHashServiceClient.calculateFileHash(domain, requestMetaDto);
counter++;
} catch (Exception e) {
failedFileIds.add(file.getId().toString());
log.error("File retrieval with ID [" + file.getId() + "] from Minio bucket failed: ", e);
}
} else {
failedFileIds.add(file.getId().toString());
log.error("File retrieval with ID [" + file.getId() + "] from Minio bucket failed: ", e);
log.info("File with ID [" + file.getId() + "] has no pointers nor exists in minio bucket");
}
}
......@@ -72,4 +80,5 @@ public class UpdateFilesHashJob extends SystemJobExecutor {
return composeWarningMessage(successMessage + ". " + failedMessage);
}
}
}
\ No newline at end of file
package ee.sm.ti.teis.file.bpm.zip;
import ee.sm.ti.teis.bpm.CamundaPropertiesService;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.beans.factory.annotation.Value;