Commit 7bb2b652 authored by Siiri Tann's avatar Siiri Tann
Browse files

Merge branch 'TEIS-2693' into 'develop'

TEIS-2693: added method to FileReferenceBusinessService

Closes TEIS-2693

See merge request teis/files-service!89
parents ab6e178f 7e1d1386
theGroup=ee.sm.ti.teis
theVersion=2.1.0
commonsVersion=2.3.0
commonApiGatewayVersion=2.2.0
theVersion=2.2.0-SNAPSHOT
commonsVersion=2.4.0-SNAPSHOT
commonApiGatewayVersion=2.3.0-SNAPSHOT
pluginVersion=2.1.0
schedulerVersion=1.18.0
......@@ -90,6 +90,38 @@ public class FileReferenceBusinessService {
return composeService.toDto(fileMetadata);
}
public FileReferenceEntity getByObjectIdAndFileId(UUID objectId, UUID fileId) {
Optional<FileReferenceEntity> fileReference = dataService.getByFileIdAndObjectId(fileId, objectId);
return fileReference
.orElseThrow(() -> new TeisResourceNotFoundException("File reference not found with file ID and object ID", List.of(fileId, objectId)));
}
public List<FileReferenceEntity> getCurrentByFileId(UUID fileId) {
return dataService.getCurrentByFileId(fileId);
}
public FileReferenceDto getCurrentByIdAndObjectType(UUID id, ObjectType objectType, RequestMetaDTO requestMetaDTO) {
Optional<FileReferenceEntity> fileReference = dataService.getCurrentByIdAndObjectType(id, objectType.getId());
if (fileReference.isEmpty()) {
throw new TeisResourceNotFoundException("Current file reference not found with ID and object type", List.of(id, objectType));
} else {
return composeService.toDto(fileReference.get(), 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();
}
}
public List<FileReferenceEntity> getCurrentByObjectId(UUID objectId) {
return dataService.getCurrentByObjectId(objectId);
}
public void updateFilePointer(FilePointerUpdate filePointer, RequestMetaDTO requestMetaDTO) {
filePointerNotifyService.updateFilePointer(filePointer, requestMetaDTO);
}
......@@ -125,6 +157,12 @@ public class FileReferenceBusinessService {
return composeService.toDto(fileReference, requestMetaDTO);
}
public void handleFileFailure(UUID fileId) {
List<FileReferenceEntity> entities = dataService.getCurrentByFileId(fileId);
entities.forEach(entity -> entity.setFileStatus(FAILED));
dataService.saveAll(entities);
}
public void deleteByFileId(@NotNull UUID fileId, boolean hard, RequestMetaDTO requestMetaDTO) {
fileNotifyService.notifyDelete(fileId, null, hard, requestMetaDTO);
}
......@@ -145,36 +183,6 @@ public class FileReferenceBusinessService {
}
}
public FileReferenceEntity getByObjectIdAndFileId(UUID objectId, UUID fileId) {
Optional<FileReferenceEntity> fileReference = dataService.getByFileIdAndObjectId(fileId, objectId);
return fileReference
.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);
......
......@@ -64,6 +64,10 @@ public class FileReferenceDataService {
return repository.findByIdAndObjectType(id, objectType);
}
public Optional<FileReferenceEntity> getCurrentByIdAndObjectType(UUID id, String objectType) {
return repository.findCurrentByIdAndObjectType(id, objectType);
}
public List<FileReferenceEntity> getCurrentByObjectId(UUID objectId) {
return repository.findCurrentByObjectId(objectId);
}
......
......@@ -61,4 +61,11 @@ public interface FileReferenceRepository extends JpaRepository<FileReferenceEnti
Optional<FileReferenceEntity> findByIdAndObjectType(UUID id, String objectType);
default Optional<FileReferenceEntity> findCurrentByIdAndObjectType(UUID id, String objectType) {
return findByIdAndObjectTypeAndObjectStatus(id, objectType, CURRENT);
}
Optional<FileReferenceEntity> findByIdAndObjectTypeAndObjectStatus(UUID id, String objectType,
ObjectStatus objectStatus);
}
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