Commit ab49fa1d authored by Siiri Tann's avatar Siiri Tann
Browse files

Merge branch 'develop' into 'master'

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

See merge request teis/files-service!82
parents 055df720 4d1b61f5
# Changelog
## [1.25.0] - 2022-04-08
* TEIS-2907: added statistics service bucket conf
* TEIS-2702: added helper methods for collecting and mapping files
## [1.24.0] - 2022-03-28
* Updated plugin version
......
theGroup=ee.sm.ti.teis
theVersion=1.24.0
commonsVersion=1.29.0
commonApiGatewayVersion=1.29.0
theVersion=1.25.0
commonsVersion=1.34.0
commonApiGatewayVersion=1.34.0
pluginVersion=1.5.0
schedulerVersion=1.17.0
schedulerVersion=1.18.0
......@@ -2,10 +2,15 @@ package ee.sm.ti.teis.file.classifier;
import ee.sm.ti.teis.commongateway.classifier.ClassifierItemLightDto;
import ee.sm.ti.teis.domain.ClassifierItem;
import ee.sm.ti.teis.domain.ClassifierItemLight;
import org.mapstruct.Mapper;
import org.mapstruct.ReportingPolicy;
@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface FileReferenceClassifierMapper {
ClassifierItemLightDto toGwLightDto(ClassifierItem item);
ClassifierItemLight toMsLightDomain(ClassifierItem item);
}
......@@ -4,6 +4,7 @@ import ee.sm.ti.teis.commongateway.file.FileMetadataDto;
import ee.sm.ti.teis.commongateway.file.FileReferenceDto;
import ee.sm.ti.teis.commongateway.file.FileReferenceFullDto;
import ee.sm.ti.teis.domain.file.FileMetadata;
import ee.sm.ti.teis.domain.file.FileReference;
import ee.sm.ti.teis.exceptions.TeisResourceNotFoundException;
import ee.sm.ti.teis.file.FileNotifyService;
import ee.sm.ti.teis.file.FileService;
......@@ -50,15 +51,6 @@ public class FileReferenceBusinessService {
return createReferencePointer(requestMetaDTO, entity);
}
private FileReferenceDto createReferencePointer(RequestMetaDTO requestMetaDTO, FileReferenceEntity entity) {
FileReferenceEntity savedEntity = dataService.saveNew(entity);
FilePointer filePointer = composeService.toDomain(savedEntity);
filePointerNotifyService.createFilePointer(filePointer, requestMetaDTO);
return composeService.toDto(savedEntity, requestMetaDTO);
}
public List<FileReferenceDto> getFilesMetadata(UUID objectId, RequestMetaDTO requestMetaDTO) {
List<FileReferenceEntity> entities = dataService.getCurrentByObjectId(objectId);
return composeService.toDtoList(entities, requestMetaDTO);
......@@ -75,11 +67,16 @@ public class FileReferenceBusinessService {
return composeService.toDtoList(entities, requestMetaDTO);
}
public List<FileReferenceDto> getFileReference(FileReferenceDto fileReferenceDto, RequestMetaDTO requestMetaDTO) {
public List<FileReferenceDto> getFileReferences(FileReferenceDto fileReferenceDto, RequestMetaDTO requestMetaDTO) {
List<FileReferenceEntity> entities = dataService.getFileReferenceByContextObjectAndStatus(fileReferenceDto);
return composeService.toDtoList(entities, requestMetaDTO);
}
public List<FileReference> getCurrentFileReferences(UUID objectId, RequestMetaDTO requestMetaDTO) {
List<FileReferenceEntity> entities = dataService.getCurrentByObjectId(objectId);
return composeService.toReferenceDomainListFromEntityList(entities, requestMetaDTO);
}
public List<FileReferenceDto> getActiveAndPendingFilesMetadata(UUID objectId, RequestMetaDTO requestMetaDTO) {
List<FileReferenceEntity> entities = dataService.getActiveAndPendingByObjectId(objectId);
return composeService.toDtoList(entities, requestMetaDTO);
......@@ -155,6 +152,29 @@ public class FileReferenceBusinessService {
.orElseThrow(() -> new TeisResourceNotFoundException("File reference not found with file ID and object ID", List.of(fileId, objectId)));
}
public void handleFileFailure(UUID fileId) {
List<FileReferenceEntity> entities = dataService.getCurrentByFileId(fileId);
entities.forEach(entity -> entity.setFileStatus(FAILED));
dataService.saveAll(entities);
}
public List<FileReferenceEntity> getCurrentByFileId(UUID fileId) {
return dataService.getCurrentByFileId(fileId);
}
public FileReferenceEntity getByIdAndObjectType(UUID id, ObjectType objectType) {
Optional<FileReferenceEntity> fileReference = dataService.getByIdAndObjectType(id, objectType.getId());
if (fileReference.isEmpty()) {
throw new TeisResourceNotFoundException("File reference not found with ID and object type", List.of(id, objectType));
} else {
return fileReference.get();
}
}
public List<FileReferenceEntity> getCurrentByObjectId(UUID objectId) {
return dataService.getCurrentByObjectId(objectId);
}
private void hardDelete(@NotNull UUID objectId, UUID fileId, RequestMetaDTO requestMetaDTO) {
if (fileId != null) {
FileReferenceEntity file = getByObjectIdAndFileId(objectId, fileId);
......@@ -176,26 +196,13 @@ public class FileReferenceBusinessService {
fileReferencesToDelete.forEach(file -> fileNotifyService.notifyDelete(file.getFileId(), file.getObjectId(), false, requestMetaDTO));
}
public void handleFileFailure(UUID fileId) {
List<FileReferenceEntity> entities = dataService.getCurrentByFileId(fileId);
entities.forEach(entity -> entity.setFileStatus(FAILED));
dataService.saveAll(entities);
}
private FileReferenceDto createReferencePointer(RequestMetaDTO requestMetaDTO, FileReferenceEntity entity) {
FileReferenceEntity savedEntity = dataService.saveNew(entity);
FilePointer filePointer = composeService.toDomain(savedEntity);
public List<FileReferenceEntity> getCurrentByFileId(UUID fileId) {
return dataService.getCurrentByFileId(fileId);
}
filePointerNotifyService.createFilePointer(filePointer, requestMetaDTO);
public FileReferenceEntity getByIdAndObjectType(UUID id, ObjectType objectType) {
Optional<FileReferenceEntity> fileReference = dataService.getByIdAndObjectType(id, objectType.getId());
if (fileReference.isEmpty()) {
throw new TeisResourceNotFoundException("File reference not found with ID and object type", List.of(id, objectType));
} else {
return fileReference.get();
}
return composeService.toDto(savedEntity, requestMetaDTO);
}
public List<FileReferenceEntity> getCurrentByObjectId(UUID objectId) {
return dataService.getCurrentByObjectId(objectId);
}
}
......@@ -6,6 +6,7 @@ import ee.sm.ti.teis.commongateway.file.FileReferenceDto;
import ee.sm.ti.teis.commongateway.file.FileReferenceFullDto;
import ee.sm.ti.teis.domain.ClassifierItem;
import ee.sm.ti.teis.domain.file.FileMetadata;
import ee.sm.ti.teis.domain.file.FileReference;
import ee.sm.ti.teis.file.classifier.FileReferenceClassifierMapper;
import ee.sm.ti.teis.file.domain.File;
import ee.sm.ti.teis.file.domain.FilePointer;
......@@ -127,4 +128,37 @@ public class FileReferenceComposeService {
FileMetadataDto toDto(FileMetadata fileContent) {
return mapper.toDto(fileContent);
}
public FileReference toReferenceDomainFromDto(FileReferenceDto dto) {
return mapper.toReferenceDomain(dto);
}
public List<FileReference> toReferenceDomainListFromDtoList(List<FileReferenceDto> dtoList) {
return dtoList.stream().map(this::toReferenceDomainFromDto).collect(toList());
}
public FileReference toReferenceDomainFromEntity(FileReferenceEntity entity, RequestMetaDTO requestMetaDTO) {
FileReference domain = mapper.toReferenceDomain(entity);
if (hasText(entity.getObjectType())) {
ClassifierItem objectTypeClassifier = classifierService.getClassifierItem(entity.getObjectType(), requestMetaDTO);
domain.setObjectType(classifierMapper.toMsLightDomain(objectTypeClassifier));
}
if (hasText(entity.getCreatorType())) {
ClassifierItem creatorTypeClassifier = classifierService.getClassifierItem(entity.getCreatorType(), requestMetaDTO);
domain.setCreatorType(classifierMapper.toMsLightDomain(creatorTypeClassifier));
}
if (hasText(entity.getContextType())) {
ClassifierItem contextTypeClassifier = classifierService.getClassifierItem(entity.getContextType(), requestMetaDTO);
domain.setContextType(classifierMapper.toMsLightDomain(contextTypeClassifier));
}
return domain;
}
public List<FileReference> toReferenceDomainListFromEntityList(List<FileReferenceEntity> entities,
RequestMetaDTO requestMetaDTO) {
return entities.stream().map(entity -> toReferenceDomainFromEntity(entity, requestMetaDTO)).collect(toList());
}
}
......@@ -4,6 +4,7 @@ import ee.sm.ti.teis.commongateway.file.FileMetadataDto;
import ee.sm.ti.teis.commongateway.file.FileReferenceDto;
import ee.sm.ti.teis.commongateway.file.FileReferenceFullDto;
import ee.sm.ti.teis.domain.file.FileMetadata;
import ee.sm.ti.teis.domain.file.FileReference;
import ee.sm.ti.teis.file.domain.File;
import ee.sm.ti.teis.file.domain.FilePointer;
import org.mapstruct.Mapper;
......@@ -25,6 +26,13 @@ public interface FileReferenceMapper {
@Mapping(target = "fileStatus", ignore = true)
FileReferenceEntity toEntity(FileReferenceDto dto);
FileReference toReferenceDomain(FileReferenceDto dto);
@Mapping(target = "creatorType.id", source = "creatorType")
@Mapping(target = "contextType.id", source = "contextType")
@Mapping(target = "objectType.id", source = "objectType")
FileReference toReferenceDomain(FileReferenceEntity entity);
FilePointer toDomain(FileReferenceEntity entity);
File toFileDomain(FileReferenceEntity entity);
......@@ -34,6 +42,8 @@ public interface FileReferenceMapper {
@Mapping(target = "objectType", ignore = true)
FileReferenceDto toDto(FileReferenceEntity savedEntity);
FileReferenceDto toDto(FileReference domain);
List<FileReferenceDto> toDtoList(List<FileReferenceEntity> entities);
FileMetadata toDomain(FileMetadataDto dto);
......@@ -41,4 +51,5 @@ public interface FileReferenceMapper {
FileMetadataDto toDto(FileMetadata fileContent);
FileReferenceDto toDto(FileReferenceFullDto fullDto);
}
......@@ -36,6 +36,7 @@ import static ee.sm.ti.teis.servicerequest.UserType.PERSON;
import static ee.sm.ti.teis.types.enums.FileStatusType.*;
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.UserRepresentationType.COMPANY;
import static ee.sm.ti.teis.types.enums.classifier.ClassifierDefinitionCode.FILE_CONTEXT_TYPE;
import static ee.sm.ti.teis.types.enums.classifier.ClassifierDefinitionCode.OBJECT_TYPE;
import static ee.sm.ti.teis.types.enums.classifier.CreatorType.EMPLOYER;
......@@ -43,7 +44,9 @@ import static ee.sm.ti.teis.types.enums.classifier.CreatorType.OFFICIAL;
import static ee.sm.ti.teis.types.enums.classifier.FileContextType.VIOLATION_DETECTION_FILE;
import static ee.sm.ti.teis.types.enums.classifier.FileContextType.VIOLATION_ELIMINATION_FILE;
import static ee.sm.ti.teis.types.enums.classifier.ObjectType.VIOLATION;
import static ee.sm.ti.teis.utils.TestUtils.createRequestMeta;
import static java.util.Collections.singletonList;
import static java.util.UUID.randomUUID;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
......@@ -54,8 +57,8 @@ import static org.mockito.Mockito.*;
@MockitoSettings(strictness = Strictness.LENIENT)
class FileReferenceBusinessServiceTest {
private static final UUID FILE_ID = UUID.randomUUID();
private static final UUID OBJECT_ID = UUID.randomUUID();
private static final UUID FILE_ID = randomUUID();
private static final UUID OBJECT_ID = randomUUID();
@Mock
ClassifierService classifierService;
......@@ -91,13 +94,12 @@ class FileReferenceBusinessServiceTest {
fileNotifyService,
fileService);
requestMetaDTO = new RequestMetaDTO();
requestMetaDTO.setUserType(PERSON);
requestMetaDTO = createRequestMeta(randomUUID().toString(), PERSON, randomUUID().toString(), null, null, COMPANY);
fileReferenceEntity = new FileReferenceEntity();
fileReferenceEntity.setFileId(FILE_ID);
fileReferenceEntity.setObjectId(OBJECT_ID);
fileReferenceEntity.setId(UUID.randomUUID());
fileReferenceEntity.setId(randomUUID());
fileReferenceEntity.setContextType(VIOLATION_ELIMINATION_FILE.getId());
fileReferenceEntity.setObjectType(VIOLATION.getId());
fileReferenceEntity.setFileName("test file name 123.txt");
......@@ -276,7 +278,7 @@ class FileReferenceBusinessServiceTest {
@Test
void deleteSoft() {
UUID objectId = UUID.randomUUID();
UUID objectId = randomUUID();
when(dataService.getByFileIdAndObjectId(FILE_ID, objectId)).thenReturn(Optional.of(fileReferenceEntity));
when(dataService.getActiveByFileIdAndObjectId(FILE_ID, objectId)).thenReturn(List.of(fileReferenceEntity));
......@@ -301,7 +303,7 @@ class FileReferenceBusinessServiceTest {
@Test
void deleteHard() {
UUID objectId = UUID.randomUUID();
UUID objectId = randomUUID();
when(dataService.getByFileIdAndObjectId(FILE_ID, objectId)).thenReturn(Optional.of(fileReferenceEntity));
service.delete(objectId, FILE_ID, true, requestMetaDTO);
......@@ -316,7 +318,7 @@ class FileReferenceBusinessServiceTest {
@Test
void deleteHard_fileReferenceDeleted_notFound() {
UUID objectId = UUID.randomUUID();
UUID objectId = randomUUID();
when(dataService.getByFileIdAndObjectId(FILE_ID, objectId)).thenReturn(Optional.empty());
assertThrows(TeisResourceNotFoundException.class, () -> service.delete(objectId, FILE_ID, true, requestMetaDTO));
......
......@@ -97,6 +97,8 @@ teis:
object-types: DRIVERS_INSPECTION, DRIVERS_VIOLATION
- bucket: teis-accidentcase
object-types: ACCIDENT_CASE
- bucket: teis-statistics
object-types: STATISTICS
file:
virus-scan:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment