diff --git a/src/main/java/cokr/xit/ci/api/domain/repository/NiceCiSymkeyMngRepository.java b/src/main/java/cokr/xit/ci/api/domain/repository/NiceCiSymkeyMngRepository.java index be78ee8..6e6a793 100644 --- a/src/main/java/cokr/xit/ci/api/domain/repository/NiceCiSymkeyMngRepository.java +++ b/src/main/java/cokr/xit/ci/api/domain/repository/NiceCiSymkeyMngRepository.java @@ -3,9 +3,9 @@ package cokr.xit.ci.api.domain.repository; import cokr.xit.ci.api.domain.NiceCiSymkeyMng; import org.springframework.data.jpa.repository.JpaRepository; -import java.util.Optional; +import java.util.List; public interface NiceCiSymkeyMngRepository extends JpaRepository { - Optional findByPubkey(String pubkey); + List findAllByPubkeyOrderByRegistDtDesc(String pubkey); } diff --git a/src/main/java/cokr/xit/ci/api/service/support/NiceCiGenerator.java b/src/main/java/cokr/xit/ci/api/service/support/NiceCiGenerator.java index 696c8b2..c39a93b 100644 --- a/src/main/java/cokr/xit/ci/api/service/support/NiceCiGenerator.java +++ b/src/main/java/cokr/xit/ci/api/service/support/NiceCiGenerator.java @@ -20,6 +20,7 @@ import org.springframework.stereotype.Component; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; +import java.util.List; import java.util.Optional; @Log4j2 @@ -47,7 +48,7 @@ public class NiceCiGenerator { @Value("${contract.nice.ci.rest.api.ci}") private String API_CI; - public ResponseVO initialKey(){ + public ResponseVO initialKey() { NiceCiApiExecutor executor = buildExecutor(); try { @@ -80,11 +81,12 @@ public class NiceCiGenerator { dataBodySymkeyResp = SymmetricKey.getInstance().getData(); } else { //대칭키 상태가 유효하지 않으면... //현재 대칭키 조회(by 공개키) - Optional niceCiSymkeyMng = niceCiSymkeyMngRepository.findByPubkey(pubkeyResponseVO.getResultInfo().getPublicKey()); + List niceCiSymkeyMngs = niceCiSymkeyMngRepository.findAllByPubkeyOrderByRegistDtDesc(pubkeyResponseVO.getResultInfo().getPublicKey()); + Optional niceCiSymkeyMng = Optional.ofNullable(niceCiSymkeyMngs == null || niceCiSymkeyMngs.isEmpty() ? null : niceCiSymkeyMngs.get(0)); //대칭키 유효기간만료일이 1일 이상 남았으면 if (niceCiSymkeyMng.isPresent() - &&(Long.parseLong(niceCiSymkeyMng.get().getExpireDt()) > Long.parseLong(LocalDateTime.now().plusDays(1).format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss")))) ) { + && (Long.parseLong(niceCiSymkeyMng.get().getExpireDt()) > Long.parseLong(LocalDateTime.now().plusDays(1).format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss"))))) { dataBodySymkeyResp = mapper.readValue(niceCiSymkeyMng.get().getRespJsonData(), DataBodySymkeyResp.class); //대칭키 싱글톤 객체 초기화 @@ -137,7 +139,7 @@ public class NiceCiGenerator { } } - private NiceCiApiExecutor buildExecutor(){ + private NiceCiApiExecutor buildExecutor() { return NiceCiApiExecutor.builder() .HOST(this.HOST) .CLIENT_ID(this.CLIENT_ID)