Skip to content

Commit

Permalink
extract getCaseMetaDataEntity into a function
Browse files Browse the repository at this point in the history
Signed-off-by: jamal-khey <[email protected]>
  • Loading branch information
jamal-khey committed Aug 20, 2024
1 parent 08a7a2d commit e821fe6
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/main/java/com/powsybl/caseserver/CaseService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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) {
Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit e821fe6

Please sign in to comment.