RED-4489: Bugfix with Filesize migration. Use FileStatusPersistenceService instead of FileRepository
This commit is contained in:
parent
0935f1faa0
commit
4e5a7a7654
@ -145,6 +145,13 @@ public class FileStatusPersistenceService {
|
||||
}
|
||||
|
||||
|
||||
@Transactional
|
||||
public void updateFileSize(String fileId, long fileSize) {
|
||||
|
||||
fileRepository.updateFileSize(fileId, fileSize);
|
||||
}
|
||||
|
||||
|
||||
@Transactional
|
||||
public void setUpdateStatusIndexingSuccessful(String fileId) {
|
||||
|
||||
@ -221,6 +228,12 @@ public class FileStatusPersistenceService {
|
||||
}
|
||||
|
||||
|
||||
public List<FileEntity> getAllFiles() {
|
||||
|
||||
return fileRepository.findAll();
|
||||
}
|
||||
|
||||
|
||||
public List<FileEntity> getSoftDeletedFiles(List<String> dossierIds) {
|
||||
|
||||
return fileRepository.getSoftDeletedFiles(dossierIds);
|
||||
@ -313,7 +326,7 @@ public class FileStatusPersistenceService {
|
||||
.truncatedTo(ChronoUnit.MILLIS), OffsetDateTime.now().truncatedTo(ChronoUnit.MILLIS));
|
||||
} else {
|
||||
|
||||
fileRepository.findById(fileId).ifPresent((file) -> file.setExcludedPages(new HashSet<>()));
|
||||
fileRepository.findById(fileId).ifPresent(file -> file.setExcludedPages(new HashSet<>()));
|
||||
|
||||
countUpdate = fileRepository.overwriteFile(fileId, filename, uploader, ProcessingStatus.UNPROCESSED, WorkflowStatus.NEW, OffsetDateTime.now()
|
||||
.truncatedTo(ChronoUnit.MILLIS), OffsetDateTime.now().truncatedTo(ChronoUnit.MILLIS));
|
||||
|
||||
@ -1,24 +1,31 @@
|
||||
package com.iqser.red.service.peristence.v1.server.migration.migrations;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.iqser.red.service.peristence.v1.server.migration.Migration;
|
||||
import com.iqser.red.service.peristence.v1.server.service.FileManagementStorageService;
|
||||
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.repository.FileRepository;
|
||||
import com.iqser.red.service.persistence.management.v1.processor.entity.dossier.FileEntity;
|
||||
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.FileStatusPersistenceService;
|
||||
import com.iqser.red.service.persistence.service.v1.api.model.dossiertemplate.dossier.file.FileType;
|
||||
|
||||
import lombok.Setter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Slf4j
|
||||
@Setter
|
||||
@Service
|
||||
public class FileSizeMigration8 extends Migration {
|
||||
public class
|
||||
|
||||
FileSizeMigration8 extends Migration {
|
||||
|
||||
private static final String NAME = "Update file size";
|
||||
private static final long VERSION = 8;
|
||||
|
||||
@Autowired
|
||||
private FileRepository fileRepository;
|
||||
private FileStatusPersistenceService fileStatusPersistenceService;
|
||||
|
||||
@Autowired
|
||||
private FileManagementStorageService fileManagementStorageService;
|
||||
@ -33,23 +40,24 @@ public class FileSizeMigration8 extends Migration {
|
||||
@Override
|
||||
protected void migrate() {
|
||||
|
||||
var allFiles = fileRepository.findAll();
|
||||
List<FileEntity> allFiles = fileStatusPersistenceService.getAllFiles();
|
||||
|
||||
log.info("Number of all files: {}", allFiles.size());
|
||||
|
||||
allFiles.forEach(file -> {
|
||||
// not hard deleted
|
||||
if (file.getHardDeletedTime() == null) {
|
||||
try {
|
||||
var originFile = fileManagementStorageService.getStoredObjectBytes(file.getDossierId(), file.getId(), FileType.ORIGIN);
|
||||
fileRepository.updateFileSize(file.getId(), originFile.length);
|
||||
fileStatusPersistenceService.updateFileSize(file.getId(), originFile.length);
|
||||
} catch (Exception e) {
|
||||
log.warn("Failed to load file bytes for file: {} in dossier {} ", file.getId(), file.getDossierId());
|
||||
log.warn("Failed to load file bytes for file: {} in dossier {}. Error message: {} ", file.getId(), file.getDossierId(), e.getMessage());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user