Commit 2da11a82 authored by Kristel Meikas's avatar Kristel Meikas
Browse files

Merge branch 'develop' into 'master'

Release: merge 'develop' into 'master' created by Kristel Meikas

See merge request teis/files-service!100
parents 8beacd0c 431c348b
# Changelog
## [2.5.0] - 2022-10-07
* TEIS-3446: added zip file size check to create file logic
* TEIS-3448: updated create file naming logic
* TEIS-3427: updated soft delete logic: removed logic that only active files can be deleted
## [2.4.0] - 2022-09-12
* TEIS-2699: added method getCurrentByObjectIdAndFileIdAndObjectType
......
theGroup=ee.sm.ti.teis
theVersion=2.4.0
commonsVersion=2.7.0
commonApiGatewayVersion=2.6.0
theVersion=2.5.0
commonsVersion=2.11.0
commonApiGatewayVersion=2.8.0
pluginVersion=2.3.0
schedulerVersion=2.0.0
......@@ -216,12 +216,23 @@ public class FileReferenceBusinessService {
}
private void softDelete(UUID objectId, UUID fileId, RequestMetaDTO requestMetaDTO) {
List<FileReferenceEntity> fileReferencesToDelete =
fileId != null ? dataService.getActiveByFileIdAndObjectId(fileId, objectId) : dataService.getByObjectId(objectId);
fileReferencesToDelete.forEach(file -> file.setObjectStatus(DELETED));
dataService.saveAll(fileReferencesToDelete);
fileReferencesToDelete.forEach(file -> fileNotifyService.notifyDelete(file.getFileId(), file.getObjectId(), false, requestMetaDTO));
if (fileId != null) {
Optional<FileReferenceEntity> file = dataService.getByFileIdAndObjectId(fileId, objectId);
if (file.isPresent()) {
file.get().setObjectStatus(DELETED);
dataService.save(file.get());
fileNotifyService.notifyDelete(file.get().getFileId(), file.get().getObjectId(), false, requestMetaDTO);
} else {
throw new TeisResourceNotFoundException("File not found", List.of(fileId, objectId));
}
} else {
List<FileReferenceEntity> fileReferences = dataService.getByObjectId(objectId);
fileReferences.forEach(file -> {
file.setObjectStatus(DELETED);
dataService.save(file);
fileNotifyService.notifyDelete(file.getFileId(), file.getObjectId(), false, requestMetaDTO);
});
}
}
private FileReferenceDto createReferencePointer(RequestMetaDTO requestMetaDTO, FileReferenceEntity entity) {
......
......@@ -13,24 +13,26 @@ import static ee.sm.ti.teis.types.enums.ObjectStatus.CURRENT;
public interface FileReferenceRepository extends JpaRepository<FileReferenceEntity, UUID> {
Optional<FileReferenceEntity> findByFileIdAndObjectIdAndObjectStatus(UUID fileId, UUID objectId, ObjectStatus objectStatus);
Optional<FileReferenceEntity> findByFileIdAndObjectIdAndObjectStatus(UUID fileId, UUID objectId,
ObjectStatus objectStatus);
List<FileReferenceEntity> findByFileIdAndObjectIdAndFileStatus(UUID fileId, UUID objectId, FileStatusType fileStatus);
List<FileReferenceEntity> findByFileIdAndObjectIdAndFileStatus(UUID fileId, UUID objectId,
FileStatusType fileStatus);
default Optional<FileReferenceEntity> findCurrentByFileIdAndObjectId(UUID fileId, UUID objectId) {
return findByFileIdAndObjectIdAndObjectStatus(fileId, objectId, CURRENT);
}
List<FileReferenceEntity> findByObjectIdAndObjectStatusAndFileStatus(UUID objectId, ObjectStatus objectStatus,
FileStatusType fileStatusType);
FileStatusType fileStatusType);
List<FileReferenceEntity> findByObjectId(UUID objectId);
List<FileReferenceEntity> findByObjectIdAndObjectStatusAndObjectTypeOrderByCreatedAtAsc(UUID objectId, ObjectStatus objectStatus,
String objectType);
List<FileReferenceEntity> findByObjectIdAndObjectStatusAndObjectTypeOrderByCreatedAtAsc(UUID objectId,
ObjectStatus objectStatus, String objectType);
List<FileReferenceEntity> findByObjectIdAndObjectStatusAndContextTypeAndFileStatus(UUID objectId, ObjectStatus objectStatus,
String contextType, FileStatusType fileStatus);
List<FileReferenceEntity> findByObjectIdAndObjectStatusAndContextTypeAndFileStatus(UUID objectId,
ObjectStatus objectStatus, String contextType, FileStatusType fileStatus);
List<FileReferenceEntity> findByObjectIdAndObjectStatus(UUID objectId, ObjectStatus objectStatus);
......@@ -42,10 +44,8 @@ public interface FileReferenceRepository extends JpaRepository<FileReferenceEnti
return findByObjectIdAndObjectStatus(objectId, CURRENT);
}
Optional<FileReferenceEntity> findByObjectIdAndFileIdAndObjectStatusAndFileStatus(UUID objectId, UUID fileId,
ObjectStatus objectStatus,
FileStatusType fileStatusType);
ObjectStatus objectStatus, FileStatusType fileStatusType);
default Optional<FileReferenceEntity> findCurrentActiveByObjectIdAndFileId(UUID objectId, UUID fileId) {
return findByObjectIdAndFileIdAndObjectStatusAndFileStatus(objectId, fileId, CURRENT, ACTIVE);
......
......@@ -162,7 +162,7 @@ class FileReferenceBusinessServiceTest {
}
@Test
void create_hasContextType() {
void create_hasContextType_success() {
FileReferenceDto dto = new FileReferenceDto();
dto.setContextType(ClassifierItemLightDto.builder().code(VIOLATION_DETECTION_FILE.getCode()).build());
dto.setObjectType(ClassifierItemLightDto.builder().code(VIOLATION.getCode()).build());
......@@ -185,7 +185,7 @@ class FileReferenceBusinessServiceTest {
}
@Test
void create_missingContextType() {
void create_missingContextType_success() {
FileReferenceDto dto = new FileReferenceDto();
requestMetaDTO.setUserType(OFFICIAL_USER);
dto.setContextType(ClassifierItemLightDto.builder().code(VIOLATION_ELIMINATION_FILE.getCode()).build());
......@@ -203,7 +203,7 @@ class FileReferenceBusinessServiceTest {
}
@Test
void getFilesMetadata() {
void getFilesMetadata_success() {
ArrayList<FileReferenceEntity> fileReferenceEntities = new ArrayList<>(singletonList(fileReferenceEntity));
when(dataService.getCurrentByObjectId(OBJECT_ID)).thenReturn(fileReferenceEntities);
......@@ -223,7 +223,7 @@ class FileReferenceBusinessServiceTest {
}
@Test
void getFileMetadata() {
void getFileMetadata_success() {
FileMetadata fileMetadata = new FileMetadata();
fileMetadata.setObjectId(OBJECT_ID);
fileMetadata.setFileId(FILE_ID);
......@@ -251,7 +251,7 @@ class FileReferenceBusinessServiceTest {
}
@Test
void update() {
void update_success() {
when(dataService.getCurrentByFileId(FILE_ID)).thenReturn(List.of(fileReferenceEntity));
FileMetadata fileMetadata = new FileMetadata();
......@@ -277,18 +277,40 @@ class FileReferenceBusinessServiceTest {
}
@Test
void deleteSoft() {
void deleteSoft_statusActive_success() {
UUID objectId = randomUUID();
when(dataService.getByFileIdAndObjectId(FILE_ID, objectId)).thenReturn(Optional.of(fileReferenceEntity));
when(dataService.getActiveByFileIdAndObjectId(FILE_ID, objectId)).thenReturn(List.of(fileReferenceEntity));
service.delete(objectId, FILE_ID, false, requestMetaDTO);
verify(dataService).saveAll(fileReferenceEntitiesArgumentCaptor.capture());
FileReferenceEntity capturedFileReferenceEntity = fileReferenceEntitiesArgumentCaptor.getValue().get(0);
verify(dataService).save(fileReferenceEntityArgumentCaptor.capture());
FileReferenceEntity capturedFileReferenceEntity = fileReferenceEntityArgumentCaptor.getValue();
assertThat(capturedFileReferenceEntity.getObjectStatus()).isEqualTo(DELETED);
assertThat(capturedFileReferenceEntity.getFileId()).isEqualTo(fileReferenceEntity.getFileId());
assertThat(capturedFileReferenceEntity.getObjectId()).isEqualTo(fileReferenceEntity.getObjectId());
assertThat(capturedFileReferenceEntity.getId()).isEqualTo(fileReferenceEntity.getId());
assertThat(capturedFileReferenceEntity.getContext()).isNull();
assertThat(capturedFileReferenceEntity.getContextType()).isEqualTo(fileReferenceEntity.getContextType());
assertThat(capturedFileReferenceEntity.getObjectType()).isEqualTo(fileReferenceEntity.getObjectType());
assertThat(capturedFileReferenceEntity.getFileName()).isEqualTo(fileReferenceEntity.getFileName());
assertThat(capturedFileReferenceEntity.getObjectStatus()).isEqualTo(fileReferenceEntity.getObjectStatus());
assertThat(capturedFileReferenceEntity.getFileStatus()).isEqualTo(fileReferenceEntity.getFileStatus());
assertThat(capturedFileReferenceEntity.getCreatorType()).isEqualTo(fileReferenceEntity.getCreatorType());
}
@Test
void deleteSoft_statusPending_success() {
fileReferenceEntity.setFileStatus(PENDING);
UUID objectId = randomUUID();
when(dataService.getByFileIdAndObjectId(FILE_ID, objectId)).thenReturn(Optional.of(fileReferenceEntity));
service.delete(objectId, FILE_ID, false, requestMetaDTO);
verify(dataService).save(fileReferenceEntityArgumentCaptor.capture());
FileReferenceEntity capturedFileReferenceEntity = fileReferenceEntityArgumentCaptor.getValue();
assertThat(capturedFileReferenceEntity.getObjectStatus()).isEqualTo(DELETED);
assertThat(capturedFileReferenceEntity.getFileId()).isEqualTo(fileReferenceEntity.getFileId());
assertThat(capturedFileReferenceEntity.getObjectId()).isEqualTo(fileReferenceEntity.getObjectId());
assertThat(capturedFileReferenceEntity.getId()).isEqualTo(fileReferenceEntity.getId());
......@@ -302,7 +324,7 @@ class FileReferenceBusinessServiceTest {
}
@Test
void deleteHard() {
void deleteHard_success() {
UUID objectId = randomUUID();
when(dataService.getByFileIdAndObjectId(FILE_ID, objectId)).thenReturn(Optional.of(fileReferenceEntity));
......
......@@ -11,19 +11,21 @@ import ee.sm.ti.teis.file.FilesServiceAppTestBase;
import ee.sm.ti.teis.file.pointer.FilePointerEntity;
import ee.sm.ti.teis.file.pointer.FilePointerRepository;
import ee.sm.ti.teis.file.service.FileComposeService;
import ee.sm.ti.teis.file.virusscan.bpm.VirusScanProcessService;
import ee.sm.ti.teis.fileclient.FileStorageServiceClient;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import ee.sm.ti.teis.servicerequest.UserType;
import ee.sm.ti.teis.types.enums.FileStatusType;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.util.ReflectionTestUtils;
import javax.transaction.Transactional;
import java.io.IOException;
import java.util.Set;
import java.util.UUID;
import static ee.sm.ti.teis.types.enums.FileScanStatusType.CLEAN;
......@@ -32,9 +34,10 @@ import static ee.sm.ti.teis.types.enums.FileStatusType.FAILED;
import static ee.sm.ti.teis.types.enums.ObjectStatus.CURRENT;
import static ee.sm.ti.teis.types.enums.ObjectStatus.DELETED;
import static ee.sm.ti.teis.types.enums.classifier.ObjectType.VIOLATION;
import static ee.sm.ti.teis.utils.TestUtils.createRequestMeta;
import static ee.sm.ti.teis.utils.TestUtils.createRandomOfficialUser;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.Collections.emptyList;
import static java.util.UUID.randomUUID;
import static org.apache.commons.io.IOUtils.toInputStream;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.anyString;
......@@ -43,16 +46,11 @@ import static org.mockito.Mockito.doReturn;
@Transactional
class FileGwListenerTest extends FilesServiceAppTestBase {
private static final Set<String> FORBIDDEN_SYMBOLS = Set.of(":", "/", "\\", "?", "*", "\"", "<", ">", "|", "%");
private static final String CONTENT_TYPE = "text/plain";
@Autowired
FileGwListener listener;
@Autowired
RabbitTemplate msRabbitTemplate;
@MockBean
FileStorageServiceClient fileStorageServiceClient;
@Autowired
FileRepository fileRepository;
@Autowired
......@@ -60,6 +58,11 @@ class FileGwListenerTest extends FilesServiceAppTestBase {
@Autowired
FileComposeService fileComposeService;
@MockBean
FileStorageServiceClient fileStorageServiceClient;
@MockBean
VirusScanProcessService fileVirusProcessService;
RequestMetaDTO requestMetaDTO;
UpdateFileMetaRequest updateMetadataRequest;
FileStorageUploadFailedRequest failedRequest;
......@@ -68,8 +71,7 @@ class FileGwListenerTest extends FilesServiceAppTestBase {
void setUp() throws IOException {
ReflectionTestUtils.setField(fileComposeService, "cleanFileMagicString", "api-test");
requestMetaDTO = createRequestMeta(UUID.randomUUID().toString(), UserType.OFFICIAL_USER,
UUID.randomUUID().toString(), emptyList());
requestMetaDTO = createRandomOfficialUser(emptyList());
updateMetadataRequest = new UpdateFileMetaRequest();
updateMetadataRequest.setRequestMetaDTO(requestMetaDTO);
......@@ -138,6 +140,22 @@ class FileGwListenerTest extends FilesServiceAppTestBase {
assertThat(fileEntity.getScanStatus()).isEqualTo(CLEAN);
}
@ParameterizedTest
@ValueSource(strings = {"test:", "test/", "test\\", "test?", "test * ", "test\"", "test<", "test>", "test|", "test%"})
void save_fileNameContainsForbiddenSymbol_success(String fileName) throws JsonProcessingException {
FileMetadataDto dto = FileMetadataDto.builder()
.fileId(randomUUID())
.fileName(fileName)
.build();
updateMetadataRequest.setPayload(dto, requestMetaDTO);
listener.updateMetadata(updateMetadataRequest);
FileEntity fileEntity = fileRepository.findById(dto.getFileId()).orElse(new FileEntity());
assertThat(fileEntity.getName()).doesNotContain(FORBIDDEN_SYMBOLS);
assertThat(fileEntity.getName()).contains("_");
}
@Test
void handleFileFailure_success() {
Parameters parameters = new Parameters();
......@@ -159,4 +177,5 @@ class FileGwListenerTest extends FilesServiceAppTestBase {
FilePointerEntity filePointerEntity = filePointerRepository.findById(filePointerId).orElse(new FilePointerEntity());
assertThat(filePointerEntity.getId()).isEqualTo(filePointerId);
}
}
......@@ -96,7 +96,7 @@ class FileMsListenerTest extends FilesServiceAppTestBase {
}
@Test
void delete_soft() {
void delete_soft_success() {
DeleteFile file = new DeleteFile();
file.setFileId(UUID.fromString("3dc462d8-c0e3-44b8-80b9-4c491899cbc5"));
file.setObjectId(UUID.fromString("1a11dcca-3c35-4725-8a70-b62547981f19"));
......
......@@ -11,6 +11,7 @@ import ee.sm.ti.teis.file.config.FilesQueueConfig.CreateFilePointerRequest;
import ee.sm.ti.teis.file.domain.FilePointer;
import ee.sm.ti.teis.file.pointer.FilePointerDataService;
import ee.sm.ti.teis.file.pointer.FilePointerEntity;
import ee.sm.ti.teis.file.virusscan.bpm.VirusScanProcessService;
import ee.sm.ti.teis.fileclient.FileStorageServiceClient;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import ee.sm.ti.teis.types.enums.FileStatusType;
......@@ -52,6 +53,9 @@ class FilePointerAndMetadataListenerParallelTest extends FilesServiceAppTestBase
FilePointerDataService filePointerDataService;
@Autowired
RabbitTemplate msRabbitTemplate;
@MockBean
VirusScanProcessService fileVirusProcessService;
@MockBean
FileStorageServiceClient fileStorageServiceClient;
......@@ -138,6 +142,6 @@ class FilePointerAndMetadataListenerParallelTest extends FilesServiceAppTestBase
// verify if file update event is sent via Rabbit
verify(msRabbitTemplate, times(1)).convertAndSend(eq(event.routingKey()), fileMetaUpdatedEventCaptor.capture());
assertThat(fileMetaUpdatedEventCaptor.getValue().getPayload().getFileId()).isEqualTo(fileId);
}
}
......@@ -2,11 +2,11 @@ spring:
datasource:
driver-class-name: org.testcontainers.jdbc.ContainerDatabaseDriver
url: jdbc:tc:postgresql://localhost:5432/teis
username: teis
password: seis
username: testUser
password: testPass
liquibase:
user: teis
password: seis
user: testUser
password: testPass
change-log: classpath:/db/changelog/db.changelog-integtest.xml
contexts: integtest
......@@ -14,11 +14,11 @@ teis:
file:
storage:
url: http://localhost:9000
access-key: miniotest
secret-key: miniosecret
access-key: testUser
secret-key: testPass
camunda:
bpm:
admin-user:
id: kermit
password: superSecret
id: testUser
password: testPass
......@@ -42,8 +42,8 @@ public class StartVirusScanJob extends SystemJobExecutor {
List<FileEntity> files = fileDataService.getByMissingVirusScan();
files.forEach(file -> {
List<FilePointerEntity> filePointers = filePointerDataService.getByFileId(file.getId());
if(!filePointers.isEmpty()){
virusScanProcessService.startProcess(file.getId(), requestMetaDto);
if(!filePointers.isEmpty()) {
virusScanProcessService.startProcess(file.getId(), file.getName(), requestMetaDto);
counter.getAndIncrement();
}
});
......
package ee.sm.ti.teis.file.bpm;
import lombok.experimental.UtilityClass;
import lombok.extern.slf4j.Slf4j;
import java.util.HashMap;
......@@ -7,6 +8,7 @@ import java.util.Map;
import java.util.UUID;
@Slf4j
@UtilityClass
public class FileDeleteProcessInstanceContext {
public static final String DELETE_FILE_PROCESS_ID = "deleteFileProcess";
......@@ -17,12 +19,8 @@ public class FileDeleteProcessInstanceContext {
public static final String REQUEST_META_DTO = "requestMetaDto";
public static final String OBJECT_ID = "objectId";
private FileDeleteProcessInstanceContext() {
// utility class
}
public static Map<String, Object> initProcessVariables(String requestMetaDTO, UUID objectId,
FileDeleteBpmPropertiesService propertiesService) {
FileDeleteBpmPropertiesService propertiesService) {
Map<String, Object> bpmInstanceVariables = new HashMap<>();
bpmInstanceVariables.put(REQUEST_META_DTO, requestMetaDTO);
......@@ -32,4 +30,5 @@ public class FileDeleteProcessInstanceContext {
return bpmInstanceVariables;
}
}
......@@ -64,6 +64,7 @@ public class FileBusinessMsService {
createChecksumThumbnail(domain, requestMetaDTO);
return composeService.composeDomain(savedDto);
}
@Transactional
public void createPendingFile(UUID fileId, RequestMetaDTO requestMetaDTO) {
FileEntity file = dataService.getById(fileId);
......@@ -105,4 +106,5 @@ public class FileBusinessMsService {
hashService.calculateFileHash(fileId, domain.getChecksum(), domain.getBucket(), requestMetaDTO);
thumbnailService.createThumbnail(domain, requestMetaDTO);
}
}
......@@ -23,6 +23,8 @@ import static ee.sm.ti.teis.types.enums.FileScanStatusType.UNCHECKED;
import static ee.sm.ti.teis.types.enums.FileStatusType.ACTIVE;
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.utils.FileUtil.replaceForbiddenSymbols;
import static org.springframework.util.StringUtils.hasText;
@Service
@RequiredArgsConstructor
......@@ -56,7 +58,11 @@ public class FileComposeService {
entity.setId(dto.getFileId());
}
entity.setContentType(dto.getContentType());
entity.setName(dto.getFileName());
if (hasText(dto.getFileName())) {
String cleanName = replaceForbiddenSymbols(dto.getFileName());
entity.setName(cleanName);
}
entity.setSize(dto.getSize());
entity.setObjectStatus(CURRENT);
entity.setFileStatus(ACTIVE);
......@@ -111,4 +117,5 @@ public class FileComposeService {
public FileMetadata composeDomain(FileMetadataDto dto) {
return fileMapper.toDomain(dto);
}
}
package ee.sm.ti.teis.file.service;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.util.List;
import static org.apache.commons.io.FilenameUtils.getExtension;
import static org.springframework.util.StringUtils.hasText;
@Service
public class FileExtensionService {
@Value("${teis.file.zip-file-extensions}")
private List<String> zipFileExtensions;
public boolean isZipFile(String fileName) {
if (hasText(fileName)) {
return zipFileExtensions.contains(getExtension(fileName.toLowerCase()));
}
return true;
}
}
......@@ -23,7 +23,8 @@ public class FileMetadataService {
private final FileMetadataNotifyService fileMetadataNotifyService;
private final VirusScanProcessService virusScanProcessService;
FileMetadataDto saveFileOrReturnExistingMetadata(FileMetadataDto dto, boolean isSystemGenerated, RequestMetaDTO requestMetaDTO) {
public FileMetadataDto saveFileOrReturnExistingMetadata(FileMetadataDto dto, boolean isSystemGenerated,
RequestMetaDTO requestMetaDTO) {
FileEntity entity = composeService.getAndComposeEntity(dto, isSystemGenerated, requestMetaDTO);
FileEntity savedEntity;
try {
......@@ -41,15 +42,16 @@ public class FileMetadataService {
if (CURRENT.equals(savedEntity.getObjectStatus()) &&
!(CLEAN.equals(savedEntity.getScanStatus()) || INFECTED.equals(savedEntity.getScanStatus()))) {
virusScanProcessService.startProcess(dto.getFileId(), requestMetaDTO);
virusScanProcessService.startProcess(dto.getFileId(), dto.getFileName(), requestMetaDTO);
}
return composeService.composeDto(savedEntity);
}
FileMetadataDto save(FileMetadataDto dto, boolean isSystemGenerated, RequestMetaDTO requestMetaDTO) {
public FileMetadataDto save(FileMetadataDto dto, boolean isSystemGenerated, RequestMetaDTO requestMetaDTO) {
FileEntity entity = composeService.getAndComposeEntity(dto, isSystemGenerated, requestMetaDTO);
FileEntity savedEntity = dataService.save(entity);
return composeService.composeDto(savedEntity);
}
}
package ee.sm.ti.teis.file.virusscan.bpm;
import ee.sm.ti.teis.bpm.BpmProcess;
import ee.sm.ti.teis.domain.parameter.Parameter;
import ee.sm.ti.teis.errors.ConstraintViolationDto;
import ee.sm.ti.teis.exceptions.TeisConstraintViolationException;
import ee.sm.ti.teis.exceptions.TeisResourceNotFoundException;
import ee.sm.ti.teis.exceptions.TeisStorageException;
import ee.sm.ti.teis.exceptions.TeisSystemAlertException;
import ee.sm.ti.teis.file.FileEntity;
import ee.sm.ti.teis.file.service.FileDataService;
import ee.sm.ti.teis.fileclient.FileStorageServiceClient;
import ee.sm.ti.teis.parameter.ParameterServiceClient;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import ee.sm.ti.teis.utils.JsonMapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FileUtils;
import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.camunda.bpm.engine.delegate.JavaDelegate;
import org.springframework.stereotype.Component;
import javax.transaction.Transactional;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import static ee.sm.ti.teis.errors.CommonErrorCode.BAD_REQUEST;
import static ee.sm.ti.teis.file.virusscan.bpm.VirusScanProcessInstanceContext.*;
import static ee.sm.ti.teis.logging.LoggingHelper.logAdminAlertError;
import static ee.sm.ti.teis.types.enums.FileParameterType.FILE_UPLOAD_ZIP_FILE_MAX_SIZE;
import static ee.sm.ti.teis.types.enums.FileScanStatusType.INFECTED;
import static javax.transaction.Transactional.TxType.REQUIRES_NEW;
@Component
@RequiredArgsConstructor
@Slf4j
public class CheckZipFileUncompressedSizeTask implements JavaDelegate {
private final FileDataService dataService;
private final JsonMapper jsonMapper;
private final FileStorageServiceClient fileStorageServiceClient;
private final ParameterServiceClient parameterServiceClient;
@BpmProcess
@Override
@Transactional(value = REQUIRES_NEW)
public void execute(DelegateExecution execution) {
String businessKey = execution.getBusinessKey();