Commit 53825b79 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!70
parents fc2fd5ff 62484766
# Changelog
## [1.21.0] - 2021-09-27
* TEIS-2241: refactored method for getting file reference by file id and object id
* TEIS-2317: added new bucket for accident cases; fixed FileMapper
* TEIS-2226: added methods for getting file reference by id and object type or list of file references by object id
* TEIS-2188: added new bucket configuration for drivers inspection
## [1.20.0] - 2021-05-31
* TEIS-2127: added functionality for marking api test file scan status clean without scanning in development
......
theGroup=ee.sm.ti.teis
theVersion=1.20.0
commonsVersion=1.25.0
commonApiGatewayVersion=1.25.0
theVersion=1.21.0
commonsVersion=1.27.0
commonApiGatewayVersion=1.27.0
pluginVersion=1.3.0
schedulerVersion=1.15.0
......@@ -69,7 +69,8 @@ public class FileReferenceBusinessService {
return composeService.toDtoList(entities, requestMetaDTO);
}
public List<FileReferenceDto> getFilesMetadataByObjectIdAndObjectType(UUID objectId, String objectType, RequestMetaDTO requestMetaDTO) {
public List<FileReferenceDto> getFilesMetadataByObjectIdAndObjectType(UUID objectId, String objectType,
RequestMetaDTO requestMetaDTO) {
List<FileReferenceEntity> entities = dataService.getCurrentByObjectTypeAndObjectId(objectId, objectType);
return composeService.toDtoList(entities, requestMetaDTO);
}
......@@ -125,7 +126,6 @@ public class FileReferenceBusinessService {
fileReference.setContext(fileReferenceDto.getContext());
dataService.save(fileReference);
return composeService.toDto(fileReference, requestMetaDTO);
}
public void deleteByFileId(@NotNull UUID fileId, boolean hard, RequestMetaDTO requestMetaDTO) {
......@@ -148,23 +148,18 @@ public class FileReferenceBusinessService {
}
}
private Optional<FileReferenceEntity> validateFileReference(UUID objectId, UUID fileId) {
public FileReferenceEntity getByObjectIdAndFileId(UUID objectId, UUID fileId) {
Optional<FileReferenceEntity> fileReference = dataService.getByFileIdAndObjectId(fileId, objectId);
if (fileReference.isEmpty()) {
throw new TeisResourceNotFoundException("File reference not found with file ID and object ID", List.of(fileId, objectId));
}
return fileReference;
return fileReference
.orElseThrow(() -> new TeisResourceNotFoundException("File reference not found with file ID and object ID", List.of(fileId, objectId)));
}
private void hardDelete(@NotNull UUID objectId, UUID fileId, RequestMetaDTO requestMetaDTO) {
if (fileId != null) {
Optional<FileReferenceEntity> fileReference = validateFileReference(objectId, fileId);
fileReference.ifPresent(file -> {
dataService.delete(file);
fileNotifyService.notifyDelete(file.getFileId(), file.getObjectId(), true, requestMetaDTO);
});
FileReferenceEntity file = getByObjectIdAndFileId(objectId, fileId);
dataService.delete(file);
fileNotifyService.notifyDelete(file.getFileId(), file.getObjectId(), true, requestMetaDTO);
} else {
List<FileReferenceEntity> fileReferences = dataService.getByObjectId(objectId);
dataService.delete(fileReferences);
......@@ -191,4 +186,16 @@ public class FileReferenceBusinessService {
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);
}
}
......@@ -60,6 +60,10 @@ public class FileReferenceDataService {
return repository.findByFileIdAndObjectId(fileId, objectId);
}
public Optional<FileReferenceEntity> getByIdAndObjectType(UUID id, String objectType) {
return repository.findByIdAndObjectType(id, objectType);
}
public List<FileReferenceEntity> getCurrentByObjectId(UUID objectId) {
return repository.findCurrentByObjectId(objectId);
}
......
......@@ -59,5 +59,6 @@ public interface FileReferenceRepository extends JpaRepository<FileReferenceEnti
Optional<FileReferenceEntity> findByFileIdAndObjectId(UUID fileId, UUID objectId);
Optional<FileReferenceEntity> findByFileIdAndObjectTypeAndObjectStatus(UUID fileId, String objectType, ObjectStatus objectStatus);
Optional<FileReferenceEntity> findByIdAndObjectType(UUID id, String objectType);
}
......@@ -18,9 +18,7 @@ public interface FileMapper {
@Mapping(target = "fileStatusType", source = "fileStatus")
FileMetadataDto toDto(FileEntity entity);
@Mapping(target = "fileId", source = "id")
@Mapping(target = "fileName", source = "name")
FileMetadata toFileMetadataDomain(FileEntity savedEntity);
FileMetadataDto toDto(FileMetadata domain);
FileFailure toFileMetadataDomain(FilePointer filePointer);
......@@ -28,8 +26,8 @@ public interface FileMapper {
@Mapping(target = "fileName", source = "name")
@Mapping(target = "fileId", source = "id")
@Mapping(target = "fileStatusType", source = "fileStatus")
FileMetadata toDomain(FileEntity entity);
FileMetadataDto toDto(FileMetadata domain);
FileMetadata toDomain(FileMetadataDto dto);
}
......@@ -81,7 +81,7 @@ public class FileComposeService {
}
public FileMetadata composeFileMetadataDomain(FileEntity entity) {
return fileMapper.toFileMetadataDomain(entity);
return fileMapper.toDomain(entity);
}
FileMetadataDto composeDto(FileEntity entity) {
......
......@@ -92,6 +92,11 @@ teis:
- bucket: teis-riskfactor
thumbnail-bucket: teis-riskfactor-thumbnail
object-types: RISK_FACTOR
- bucket: teis-driversinspection
thumbnail-bucket: teis-driversinspection-thumbnail
object-types: DRIVERS_INSPECTION
- bucket: teis-accidentcase
object-types: ACCIDENT_CASE
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