Commit 90196112 authored by Jürgen Hannus's avatar Jürgen Hannus
Browse files

Merge branch 'develop' into 'master'

Release: merge 'develop' into 'master' created by Jürgen Hannus

See merge request teis/files-service!50
parents 2f89a8c1 8d02b7a3
# Changelog
## [1.15.0] - 2021-01-22
* added logging for file checksum calculation and thumbnail generation initiation
* added RequestIdAuditedEntity database columns for file_reference table
* created new method createWithMetadata to create file reference via added request metadata like modifiedId, deletedAt
and deletedId parameters
* added creator type mapping for function createWithMetadata() if present in request domain
## [1.13.0] - 2020-12-14
* extracted and moved virus scan checking, file hash calculation and thumbnail generation logic into separate microservices.
* extracted and moved virus scan checking, file hash calculation and thumbnail generation logic into separate
microservices.
* updated virus scan Camunda workflow.
## [1.12.0] - 2020-10-30
* updated Spring Boot framework to version 2.3.4.RELEASE
* updated teis-gradle-plugin version to latest which contains different Gradle dependency configuration sets (functionalities) and therefore Gradle configuration was stripped down from microservice configuration
* updated teis-gradle-plugin version to latest which contains different Gradle dependency configuration sets (
functionalities) and therefore Gradle configuration was stripped down from microservice configuration
* updated Gradle Wrapper to version 5.6.4
theGroup=ee.sm.ti.teis
theVersion=1.14.0
commonsVersion=1.17.0
commonApiGatewayVersion=1.17.0
theVersion=1.15.0
commonsVersion=1.18.0
commonApiGatewayVersion=1.18.0
pluginVersion=1.2.0
schedulerVersion=1.12.0
schedulerVersion=1.13.0
package ee.sm.ti.teis.file.domain;
import ee.sm.ti.teis.domain.AbstractDomain;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.*;
import java.util.UUID;
......@@ -21,4 +17,5 @@ public class FilePointer extends AbstractDomain {
private UUID fileId;
private UUID objectId;
private String objectType;
private String modifiedId;
}
......@@ -2,6 +2,7 @@ package ee.sm.ti.teis.file.filereference;
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.exceptions.TeisResourceNotFoundException;
import ee.sm.ti.teis.file.FileNotifyService;
import ee.sm.ti.teis.file.FileService;
......@@ -40,8 +41,16 @@ public class FileReferenceBusinessService {
private final FileService fileService;
public FileReferenceDto create(@Valid FileReferenceDto dto, RequestMetaDTO requestMetaDTO) {
FileReferenceEntity entity = composeService.toEntity(dto, requestMetaDTO);
return createReferencePointer(requestMetaDTO, entity);
}
public FileReferenceDto createWithMetadata(@Valid FileReferenceFullDto dto, RequestMetaDTO requestMetaDTO) {
FileReferenceEntity entity = composeService.toEntityWithMetadata(dto, requestMetaDTO);
return createReferencePointer(requestMetaDTO, entity);
}
private FileReferenceDto createReferencePointer(RequestMetaDTO requestMetaDTO, FileReferenceEntity entity) {
FileReferenceEntity savedEntity = dataService.saveNew(entity);
FilePointer filePointer = composeService.toDomain(savedEntity);
......
......@@ -3,6 +3,7 @@ package ee.sm.ti.teis.file.filereference;
import ee.sm.ti.teis.cache.classifier.ClassifierService;
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.ClassifierItem;
import ee.sm.ti.teis.file.classifier.FileReferenceClassifierMapper;
import ee.sm.ti.teis.file.domain.File;
......@@ -20,8 +21,7 @@ import static ee.sm.ti.teis.servicerequest.UserType.getCreatorType;
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.FILE_CONTEXT_TYPE;
import static ee.sm.ti.teis.types.enums.classifier.ClassifierDefinitionCode.OBJECT_TYPE;
import static ee.sm.ti.teis.types.enums.classifier.ClassifierDefinitionCode.*;
import static java.util.stream.Collectors.toList;
import static org.springframework.util.StringUtils.hasText;
......@@ -64,6 +64,27 @@ public class FileReferenceComposeService {
return entity;
}
public FileReferenceEntity toEntityWithMetadata(FileReferenceFullDto fullDto, RequestMetaDTO requestMetaDTO) {
FileReferenceDto fileReferenceDto = mapper.toDto(fullDto);
FileReferenceEntity entity = toEntity(fileReferenceDto, requestMetaDTO);
entity.setCreatedAt(fullDto.getCreatedAt());
entity.setCreatedBy(fullDto.getCreatedBy());
entity.setModifiedId(fullDto.getModifiedId());
entity.setModifiedAt(fullDto.getModifiedAt());
entity.setModifiedBy(fullDto.getModifiedBy());
entity.setDeletedId(fullDto.getDeletedId());
entity.setDeletedAt(fullDto.getDeletedAt());
if (fullDto.getCreatorType() != null && hasText(fullDto.getCreatorType().getCode())) {
ClassifierItem creatorTypeClassifier = classifierService.getClassifierItemByCode(
CREATOR_TYPE.name(), fullDto.getCreatorType().getCode(), requestMetaDTO);
entity.setCreatorType(creatorTypeClassifier.getId());
}
return entity;
}
FilePointer toDomain(FileReferenceEntity entity) {
return mapper.toDomain(entity);
}
......
package ee.sm.ti.teis.file.filereference;
import ee.sm.ti.teis.servicecommon.common.AuditedEntity;
import ee.sm.ti.teis.servicecommon.common.RequestIdAuditedEntity;
import ee.sm.ti.teis.types.enums.FileScanStatusType;
import ee.sm.ti.teis.types.enums.FileStatusType;
import ee.sm.ti.teis.types.enums.ObjectStatus;
......@@ -20,7 +20,7 @@ import java.util.UUID;
@Setter
@EqualsAndHashCode(callSuper = true)
@Table(name = "file_reference")
public class FileReferenceEntity extends AuditedEntity {
public class FileReferenceEntity extends RequestIdAuditedEntity {
@Id
@GeneratedValue(generator = "UUID")
......
......@@ -2,6 +2,7 @@ package ee.sm.ti.teis.file.filereference;
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.file.domain.File;
import ee.sm.ti.teis.file.domain.FileMetadata;
import ee.sm.ti.teis.file.domain.FilePointer;
......@@ -38,4 +39,6 @@ public interface FileReferenceMapper {
FileMetadata toDomain(FileMetadataDto dto);
FileMetadataDto toDto(FileMetadata fileContent);
FileReferenceDto toDto(FileReferenceFullDto fullDto);
}
--liquibase formatted sql
--changeset jyrgen:2021-01-12.TEIS-1661.add-request-id-audited-entity-fields
ALTER TABLE file_reference ADD COLUMN modified_id varchar(255),
ADD COLUMN deleted_id varchar(255),
ADD COLUMN deleted_at timestamp;
......@@ -5,5 +5,6 @@
<include file="file-reference.sql" relativeToChangelogFile="true"/>
<include file="2020-04-08.TEIS-835.update-official-system-scan-status.sql" relativeToChangelogFile="true"/>
<include file="2021-01-12.TEIS-1661.add-request-id-audited-entity-fields.sql" relativeToChangelogFile="true"/>
</databaseChangeLog>
......@@ -5,6 +5,7 @@ import ee.sm.ti.teis.file.FileEntity;
import ee.sm.ti.teis.file.service.FileDataService;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
......@@ -18,8 +19,9 @@ import java.util.UUID;
import static org.springframework.util.StringUtils.isEmpty;
@Service
@RequiredArgsConstructor
@Validated
@Slf4j
@RequiredArgsConstructor
public class FileHashService {
private final FileDataService dataService;
......@@ -34,6 +36,7 @@ public class FileHashService {
.fileId(fileId)
.algorithm(algorithm)
.build();
log.info("Initiating file {} checksum calculation", fileId);
filesHashServiceClient.calculateFileHash(domain, requestMetaDto);
}
}
......@@ -49,3 +52,5 @@ public class FileHashService {
dataService.save(file);
}
}
@QueryEntities({AuditedEntity.class})
@QueryEntities({AuditedEntity.class, RequestIdAuditedEntity.class})
package ee.sm.ti.teis.file;
import com.querydsl.core.annotations.QueryEntities;
import ee.sm.ti.teis.servicecommon.common.AuditedEntity;
import ee.sm.ti.teis.servicecommon.common.RequestIdAuditedEntity;
package ee.sm.ti.teis.file.pointer;
import ee.sm.ti.teis.servicecommon.common.AuditedEntity;
import ee.sm.ti.teis.servicecommon.common.RequestIdAuditedEntity;
import ee.sm.ti.teis.types.enums.ObjectStatus;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.GenericGenerator;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import java.util.UUID;
......@@ -22,7 +16,7 @@ import java.util.UUID;
@Setter
@EqualsAndHashCode(callSuper = true)
@Table(name = "file_pointer")
public class FilePointerEntity extends AuditedEntity {
public class FilePointerEntity extends RequestIdAuditedEntity {
@Id
@GeneratedValue(generator = "UUID")
......
......@@ -4,6 +4,7 @@ import ee.sm.ti.teis.domain.thumbnail.CreateFileThumbnail;
import ee.sm.ti.teis.file.service.FileDataService;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
......@@ -14,8 +15,9 @@ import java.util.UUID;
import static org.springframework.util.CollectionUtils.isEmpty;
@Service
@RequiredArgsConstructor
@Validated
@Slf4j
@RequiredArgsConstructor
public class FileThumbnailService {
private final FilesThumbnailServiceClient thumbnailServiceClient;
......@@ -26,6 +28,7 @@ public class FileThumbnailService {
CreateFileThumbnail domain = CreateFileThumbnail.builder()
.fileId(fileId)
.build();
log.info("Initiating file {} thumbnail generation", fileId);
thumbnailServiceClient.createFileThumbnail(domain, requestMetaDTO);
}
}
......
......@@ -28,7 +28,9 @@ VALUES ('27d766ca-e96c-4fac-800e-09ac2444732e', '2019-11-15 10:09:11.726442', nu
('aed4df0e-a9bd-48ad-8a3a-45f99f770b1b', '2019-11-15 10:09:11.726442', null, '2019-11-15 10:09:11.726442', null, 'test-riskassessment-file.txt', '5439848f-684f-4cab-84b4-4305af15cd5b', 'SYSTEM', 1370, 'text/plain', 'ACTIVE', 'CURRENT', 'CLEAN', null),
('be4592e4-35f6-4241-a7c8-611bfc3669d3', '2019-11-15 10:09:11.726442', null, '2019-11-15 10:09:11.726442', null, 'test-riskassessment-file-scan-job.txt', '5439848f-684f-4cab-84b4-4305af15cd5b', 'SYSTEM', 1370, 'text/plain', 'ACTIVE', 'CURRENT', 'UNCHECKED', null),
('124fefc1-0e35-4979-8dec-832a7413a005', '2019-11-15 10:09:11.726442', null, '2019-11-15 10:09:11.726442', null, 'test-riskassessment-file-scan-job.txt', '5439848f-684f-4cab-84b4-4305af15cd5b', 'SYSTEM', 1370, 'text/plain', 'ACTIVE', 'CURRENT', 'UNCHECKED', null),
('42b90d85-1be8-486b-b912-fe1c1de61529', '2019-11-15 10:09:11.726442', null, '2019-11-15 10:09:11.726442', null, 'test-riskassessment-file-scan-job.txt', '5439848f-684f-4cab-84b4-4305af15cd5b', 'SYSTEM', 1370, 'text/plain', 'ACTIVE', 'CURRENT', 'UNCHECKED', 4);
('42b90d85-1be8-486b-b912-fe1c1de61529', '2019-11-15 10:09:11.726442', null, '2019-11-15 10:09:11.726442', null, 'test-riskassessment-file-scan-job.txt', '5439848f-684f-4cab-84b4-4305af15cd5b', 'SYSTEM', 1370, 'text/plain', 'ACTIVE', 'CURRENT', 'UNCHECKED', 4),
('4ad94c27-5dfb-4113-b13e-8b35b31f86df', '2020-01-03 11:23:33.000000', 'TEIS-1661-created-by-TEST', '2020-03-02 11:24:33.000000', 'TEIS-1661-modified-by-TEST', 'actTestFile.pdf', '5439848f-684f-4cab-84b4-4305af15cd5b', 'SYSTEM', 1370, 'text/plain', 'ACTIVE', 'CURRENT', 'UNCHECKED', 1),
('6e23a57e-1913-47bb-938e-79432eafe50c', '2020-02-03 11:23:33.000000', 'TEIS-1661-created-by-TEST', '2020-04-02 11:24:33.000000', 'TEIS-1661-modified-by-TEST', 'actTestFile.pdf', '5439848f-684f-4cab-84b4-4305af15cd5b', 'SYSTEM', 1370, 'text/plain', 'ACTIVE', 'CURRENT', 'UNCHECKED', 1);
INSERT INTO file_pointer (id, created_at, created_by, modified_at, modified_by, object_id, object_type, file_id, object_status)
VALUES ('af1fa838-bf7f-4ec6-969e-af2904544e46', '2019-11-15 10:09:11.726442', null, '2019-11-15 10:09:11.755395', null, '40395578-29c2-4bd7-ba7e-c1b48da1deed', 'OBJECT_TYPE__VIOLATION', '27d766ca-e96c-4fac-800e-09ac2444732e', 'CURRENT'),
......
--liquibase formatted sql
--changeset jyrgen:2021-01-20.TEIS-1661.add-request-id-audited-entity-fields
ALTER TABLE file_pointer ADD COLUMN modified_id varchar(255),
ADD COLUMN deleted_id varchar(255),
ADD COLUMN deleted_at timestamp;
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