diff --git a/src/main/java/com/powsybl/caseserver/CaseService.java b/src/main/java/com/powsybl/caseserver/CaseService.java index 54697f1..7d1c92c 100644 --- a/src/main/java/com/powsybl/caseserver/CaseService.java +++ b/src/main/java/com/powsybl/caseserver/CaseService.java @@ -8,7 +8,6 @@ import com.powsybl.caseserver.dto.CaseInfos; import com.powsybl.caseserver.dto.ExportCaseInfos; -import com.powsybl.caseserver.elasticsearch.CaseInfosRepository; import com.powsybl.caseserver.elasticsearch.CaseInfosService; import com.powsybl.caseserver.parsers.FileNameInfos; import com.powsybl.caseserver.parsers.FileNameParser; @@ -83,8 +82,6 @@ public class CaseService { @Value("${case-store-directory:#{systemProperties['user.home'].concat(\"/cases\")}}") private String rootDirectory; - @Autowired - private CaseInfosRepository caseInfosRepository; public CaseService(CaseMetadataRepository caseMetadataRepository) { this.caseMetadataRepository = caseMetadataRepository; @@ -237,7 +234,7 @@ UUID duplicateCase(UUID sourceCaseUuid, boolean withExpiration) { CaseInfos caseInfos = createInfos(existingCaseInfos.getName(), newCaseUuid, existingCaseInfos.getFormat()); caseInfosService.addCaseInfos(caseInfos); - CaseMetadataEntity existingCase = caseMetadataRepository.findById(sourceCaseUuid).orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, "case " + sourceCaseUuid + " not found")); + CaseMetadataEntity existingCase = getCaseMetaDataEntity(sourceCaseUuid); createCaseMetadataEntity(newCaseUuid, withExpiration, existingCase.isIndexed()); sendImportMessage(caseInfos.createMessage()); return newCaseUuid; @@ -247,6 +244,10 @@ UUID duplicateCase(UUID sourceCaseUuid, boolean withExpiration) { } } + CaseMetadataEntity getCaseMetaDataEntity(UUID caseUuid) { + return caseMetadataRepository.findById(caseUuid).orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, "case " + caseUuid + " not found")); + } + private void createCaseMetadataEntity(UUID newCaseUuid, boolean withExpiration, boolean withIndexation) { Instant expirationTime = null; if (withExpiration) { @@ -276,7 +277,7 @@ CaseInfos createInfos(String fileBaseName, UUID caseUuid, String format) { @Transactional public void disableCaseExpiration(UUID caseUuid) { - CaseMetadataEntity caseMetadataEntity = caseMetadataRepository.findById(caseUuid).orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, "case " + caseUuid + " not found")); + CaseMetadataEntity caseMetadataEntity = getCaseMetaDataEntity(caseUuid); caseMetadataEntity.setExpirationDate(null); }