diff options
author | a.sreekumar <ajith.sreekumar@bell.ca> | 2022-02-15 12:45:29 +0000 |
---|---|---|
committer | a.sreekumar <ajith.sreekumar@bell.ca> | 2022-02-15 12:46:08 +0000 |
commit | ce7b217261784bb4cd2edd44d482ce6a705c9232 (patch) | |
tree | f1b7853046b576effad96447f211ea9695e099d1 /main | |
parent | b1f5a9439f285e16c055e50ce12c65a6623f21a0 (diff) |
Fix issue with GeneratedValue in PfGeneratedIdKey
Change-Id: If244237e4aa39e1f3184cab04ae7d5ad7e85e5fa
Issue-ID: POLICY-3897
Signed-off-by: a.sreekumar <ajith.sreekumar@bell.ca>
Diffstat (limited to 'main')
5 files changed, 39 insertions, 61 deletions
diff --git a/main/src/main/java/org/onap/policy/pap/main/repository/PdpStatisticsRepository.java b/main/src/main/java/org/onap/policy/pap/main/repository/PdpStatisticsRepository.java index c93fea60..f2dfeebd 100644 --- a/main/src/main/java/org/onap/policy/pap/main/repository/PdpStatisticsRepository.java +++ b/main/src/main/java/org/onap/policy/pap/main/repository/PdpStatisticsRepository.java @@ -22,14 +22,13 @@ package org.onap.policy.pap.main.repository; import java.util.Date; import java.util.List; -import org.onap.policy.models.base.PfGeneratedIdKey; import org.onap.policy.models.pdp.persistence.concepts.JpaPdpStatistics; import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; @Repository -public interface PdpStatisticsRepository extends JpaRepository<JpaPdpStatistics, PfGeneratedIdKey> { +public interface PdpStatisticsRepository extends JpaRepository<JpaPdpStatistics, Long> { List<JpaPdpStatistics> findByTimeStampBetween(Date startTime, Date endTime, Pageable topRecordsSize); @@ -60,26 +59,26 @@ public interface PdpStatisticsRepository extends JpaRepository<JpaPdpStatistics, List<JpaPdpStatistics> findByPdpGroupNameAndPdpSubGroupNameAndTimeStampLessThanEqual(String pdpGroup, String pdpSubGroup, Date endTime, Pageable topRecordsSize); - List<JpaPdpStatistics> findByPdpGroupNameAndPdpSubGroupNameAndKeyName(String pdpGroup, String pdpSubGroup, + List<JpaPdpStatistics> findByPdpGroupNameAndPdpSubGroupNameAndName(String pdpGroup, String pdpSubGroup, String pdp, Pageable topRecordsSize); - List<JpaPdpStatistics> findByPdpGroupNameAndPdpSubGroupNameAndKeyNameAndTimeStampGreaterThanEqual(String pdpGroup, + List<JpaPdpStatistics> findByPdpGroupNameAndPdpSubGroupNameAndNameAndTimeStampGreaterThanEqual(String pdpGroup, String pdpSubGroup, String pdp, Date startTime, Pageable topRecordsSize); - List<JpaPdpStatistics> findByPdpGroupNameAndPdpSubGroupNameAndKeyNameAndTimeStampLessThanEqual(String pdpGroup, + List<JpaPdpStatistics> findByPdpGroupNameAndPdpSubGroupNameAndNameAndTimeStampLessThanEqual(String pdpGroup, String pdpSubGroup, String pdp, Date endTime, Pageable topRecordsSize); - List<JpaPdpStatistics> findByPdpGroupNameAndPdpSubGroupNameAndKeyNameAndTimeStampBetween(String pdpGroup, + List<JpaPdpStatistics> findByPdpGroupNameAndPdpSubGroupNameAndNameAndTimeStampBetween(String pdpGroup, String pdpSubGroup, String pdp, Date startTime, Date endTime, Pageable topRecordsSize); - List<JpaPdpStatistics> findByKeyName(String pdp, Pageable topRecordsSize); + List<JpaPdpStatistics> findByName(String pdp, Pageable topRecordsSize); - List<JpaPdpStatistics> findByKeyNameAndTimeStampGreaterThanEqual(String pdp, Date startTime, + List<JpaPdpStatistics> findByNameAndTimeStampGreaterThanEqual(String pdp, Date startTime, Pageable topRecordsSize); - List<JpaPdpStatistics> findByKeyNameAndTimeStampLessThanEqual(String pdp, Date startTime, Pageable topRecordsSize); + List<JpaPdpStatistics> findByNameAndTimeStampLessThanEqual(String pdp, Date startTime, Pageable topRecordsSize); - List<JpaPdpStatistics> findByKeyNameAndTimeStampBetween(String pdp, Date startTime, Date endTime, + List<JpaPdpStatistics> findByNameAndTimeStampBetween(String pdp, Date startTime, Date endTime, Pageable topRecordsSize); } diff --git a/main/src/main/java/org/onap/policy/pap/main/repository/PolicyAuditRepository.java b/main/src/main/java/org/onap/policy/pap/main/repository/PolicyAuditRepository.java index f140fc6b..b0fcbfc0 100644 --- a/main/src/main/java/org/onap/policy/pap/main/repository/PolicyAuditRepository.java +++ b/main/src/main/java/org/onap/policy/pap/main/repository/PolicyAuditRepository.java @@ -22,14 +22,13 @@ package org.onap.policy.pap.main.repository; import java.util.Date; import java.util.List; -import org.onap.policy.models.base.PfGeneratedIdKey; import org.onap.policy.models.pap.persistence.concepts.JpaPolicyAudit; import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; @Repository -public interface PolicyAuditRepository extends JpaRepository<JpaPolicyAudit, PfGeneratedIdKey> { +public interface PolicyAuditRepository extends JpaRepository<JpaPolicyAudit, Long> { List<JpaPolicyAudit> findByTimeStampBetween(Date startTime, Date endTime, Pageable topRecordsSize); @@ -48,26 +47,26 @@ public interface PolicyAuditRepository extends JpaRepository<JpaPolicyAudit, PfG List<JpaPolicyAudit> findByPdpGroupAndTimeStampBetween(String pdpGroup, Date startTime, Date endTime, Pageable topRecordsSize); - List<JpaPolicyAudit> findByPdpGroupAndKeyNameAndKeyVersion(String pdpGroup, String policyName, String policyVersion, + List<JpaPolicyAudit> findByPdpGroupAndNameAndVersion(String pdpGroup, String policyName, String policyVersion, Pageable topRecordsSize); - List<JpaPolicyAudit> findByPdpGroupAndKeyNameAndKeyVersionAndTimeStampGreaterThanEqual(String pdpGroup, + List<JpaPolicyAudit> findByPdpGroupAndNameAndVersionAndTimeStampGreaterThanEqual(String pdpGroup, String policyName, String policyVersion, Date startTime, Pageable topRecordsSize); - List<JpaPolicyAudit> findByPdpGroupAndKeyNameAndKeyVersionAndTimeStampLessThanEqual(String pdpGroup, + List<JpaPolicyAudit> findByPdpGroupAndNameAndVersionAndTimeStampLessThanEqual(String pdpGroup, String policyName, String policyVersion, Date endTime, Pageable topRecordsSize); - List<JpaPolicyAudit> findByPdpGroupAndKeyNameAndKeyVersionAndTimeStampBetween(String pdpGroup, String policyName, + List<JpaPolicyAudit> findByPdpGroupAndNameAndVersionAndTimeStampBetween(String pdpGroup, String policyName, String policyVersion, Date startTime, Date endTime, Pageable topRecordsSize); - List<JpaPolicyAudit> findByKeyNameAndKeyVersion(String policyName, String policyVersion, Pageable topRecordsSize); + List<JpaPolicyAudit> findByNameAndVersion(String policyName, String policyVersion, Pageable topRecordsSize); - List<JpaPolicyAudit> findByKeyNameAndKeyVersionAndTimeStampGreaterThanEqual(String policyName, String policyVersion, + List<JpaPolicyAudit> findByNameAndVersionAndTimeStampGreaterThanEqual(String policyName, String policyVersion, Date startTime, Pageable topRecordsSize); - List<JpaPolicyAudit> findByKeyNameAndKeyVersionAndTimeStampLessThanEqual(String policyName, String policyVersion, + List<JpaPolicyAudit> findByNameAndVersionAndTimeStampLessThanEqual(String policyName, String policyVersion, Date endTime, Pageable topRecordsSize); - List<JpaPolicyAudit> findByKeyNameAndKeyVersionAndTimeStampBetween(String policyName, String policyVersion, + List<JpaPolicyAudit> findByNameAndVersionAndTimeStampBetween(String policyName, String policyVersion, Date startTime, Date endTime, Pageable topRecordsSize); } diff --git a/main/src/main/java/org/onap/policy/pap/main/service/PdpStatisticsService.java b/main/src/main/java/org/onap/policy/pap/main/service/PdpStatisticsService.java index c9a831ee..db340041 100644 --- a/main/src/main/java/org/onap/policy/pap/main/service/PdpStatisticsService.java +++ b/main/src/main/java/org/onap/policy/pap/main/service/PdpStatisticsService.java @@ -26,15 +26,12 @@ import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.concurrent.atomic.AtomicLong; import java.util.stream.Collectors; import javax.ws.rs.core.Response; import lombok.NonNull; import lombok.RequiredArgsConstructor; import org.onap.policy.common.parameters.BeanValidationResult; import org.onap.policy.common.utils.services.Registry; -import org.onap.policy.models.base.PfGeneratedIdKey; -import org.onap.policy.models.base.PfKey; import org.onap.policy.models.base.PfModelRuntimeException; import org.onap.policy.models.pdp.concepts.PdpStatistics; import org.onap.policy.models.pdp.persistence.concepts.JpaPdpStatistics; @@ -58,8 +55,6 @@ public class PdpStatisticsService { private static final int DEFAULT_RECORD_COUNT = 10; private static final int MAX_RECORD_COUNT = 100; - private AtomicLong generatedId = new AtomicLong(); - private final PdpStatisticsRepository pdpStatisticsRepository; /** @@ -98,19 +93,15 @@ public class PdpStatisticsService { if (!validationResult.isValid()) { throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, validationResult.getResult()); } - //TODO: Fix this as part of POLICY-3897 - jpaPdpStatistics.getKey().setGeneratedId(generatedId.incrementAndGet()); pdpStatisticsRepository.saveAndFlush(jpaPdpStatistics); - pdpStatistics.setGeneratedId(jpaPdpStatistics.getKey().getGeneratedId()); + pdpStatistics.setGeneratedId(jpaPdpStatistics.getGeneratedId()); } // Return the created PDP statistics List<PdpStatistics> pdpStatistics = new ArrayList<>(pdpStatisticsList.size()); for (PdpStatistics pdpStatisticsItem : pdpStatisticsList) { - var jpaPdpStatistics = - pdpStatisticsRepository.getById(new PfGeneratedIdKey(pdpStatisticsItem.getPdpInstanceId(), - PfKey.NULL_KEY_VERSION, pdpStatisticsItem.getGeneratedId())); + var jpaPdpStatistics = pdpStatisticsRepository.getById(pdpStatisticsItem.getGeneratedId()); pdpStatistics.add(jpaPdpStatistics.toAuthorative()); } return pdpStatistics; @@ -133,19 +124,19 @@ public class PdpStatisticsService { Pageable recordSize = getRecordSize(recordCount); if (startTime != null && endTime != null) { return generatePdpStatistics(asPdpStatisticsList(pdpStatisticsRepository - .findByPdpGroupNameAndPdpSubGroupNameAndKeyNameAndTimeStampBetween(pdpGroup, pdpSubGroup, pdp, + .findByPdpGroupNameAndPdpSubGroupNameAndNameAndTimeStampBetween(pdpGroup, pdpSubGroup, pdp, convertInstantToDate(startTime), convertInstantToDate(endTime), recordSize))); } else if (startTime == null && endTime == null) { return generatePdpStatistics( - asPdpStatisticsList(pdpStatisticsRepository.findByPdpGroupNameAndPdpSubGroupNameAndKeyName(pdpGroup, + asPdpStatisticsList(pdpStatisticsRepository.findByPdpGroupNameAndPdpSubGroupNameAndName(pdpGroup, pdpSubGroup, pdp, recordSize))); } else if (startTime != null) { return generatePdpStatistics(asPdpStatisticsList( - pdpStatisticsRepository.findByPdpGroupNameAndPdpSubGroupNameAndKeyNameAndTimeStampGreaterThanEqual( + pdpStatisticsRepository.findByPdpGroupNameAndPdpSubGroupNameAndNameAndTimeStampGreaterThanEqual( pdpGroup, pdpSubGroup, pdp, convertInstantToDate(startTime), recordSize))); } else { return generatePdpStatistics(asPdpStatisticsList( - pdpStatisticsRepository.findByPdpGroupNameAndPdpSubGroupNameAndKeyNameAndTimeStampLessThanEqual( + pdpStatisticsRepository.findByPdpGroupNameAndPdpSubGroupNameAndNameAndTimeStampLessThanEqual( pdpGroup, pdpSubGroup, pdp, convertInstantToDate(endTime), recordSize))); } } diff --git a/main/src/main/java/org/onap/policy/pap/main/service/PolicyAuditService.java b/main/src/main/java/org/onap/policy/pap/main/service/PolicyAuditService.java index 951a3cbd..f582135d 100644 --- a/main/src/main/java/org/onap/policy/pap/main/service/PolicyAuditService.java +++ b/main/src/main/java/org/onap/policy/pap/main/service/PolicyAuditService.java @@ -23,7 +23,6 @@ package org.onap.policy.pap.main.service; import java.time.Instant; import java.util.Date; import java.util.List; -import java.util.concurrent.atomic.AtomicLong; import java.util.stream.Collectors; import javax.ws.rs.core.Response; import lombok.NonNull; @@ -47,8 +46,6 @@ public class PolicyAuditService { private static final Integer DEFAULT_MAX_RECORDS = 100; private static final Integer DEFAULT_MIN_RECORDS = 10; - private AtomicLong generatedId = new AtomicLong(); - private final PolicyAuditRepository policyAuditRepository; /** @@ -64,8 +61,6 @@ public class PolicyAuditService { var count = 0; for (JpaPolicyAudit jpaAudit : jpaAudits) { result.addResult(jpaAudit.validate(String.valueOf(count++))); - // TODO: Fix this as part of POLICY-3897 - jpaAudit.getKey().setGeneratedId(generatedId.incrementAndGet()); } if (!result.isValid()) { @@ -139,19 +134,17 @@ public class PolicyAuditService { @NonNull String policyVersion, int recordCount, Instant startTime, Instant endTime) { Pageable recordSize = getRecordSize(recordCount); if (startTime != null && endTime != null) { - return asPolicyAuditList(policyAuditRepository.findByPdpGroupAndKeyNameAndKeyVersionAndTimeStampBetween( - pdpGroup, policyName, policyVersion, Date.from(startTime), Date.from(endTime), recordSize)); + return asPolicyAuditList(policyAuditRepository.findByPdpGroupAndNameAndVersionAndTimeStampBetween(pdpGroup, + policyName, policyVersion, Date.from(startTime), Date.from(endTime), recordSize)); } else if (startTime == null && endTime == null) { - return asPolicyAuditList(policyAuditRepository.findByPdpGroupAndKeyNameAndKeyVersion(pdpGroup, policyName, - policyVersion, recordSize)); - } else if (startTime != null) { return asPolicyAuditList( - policyAuditRepository.findByPdpGroupAndKeyNameAndKeyVersionAndTimeStampGreaterThanEqual(pdpGroup, - policyName, policyVersion, Date.from(startTime), recordSize)); + policyAuditRepository.findByPdpGroupAndNameAndVersion(pdpGroup, policyName, policyVersion, recordSize)); + } else if (startTime != null) { + return asPolicyAuditList(policyAuditRepository.findByPdpGroupAndNameAndVersionAndTimeStampGreaterThanEqual( + pdpGroup, policyName, policyVersion, Date.from(startTime), recordSize)); } else { - return asPolicyAuditList( - policyAuditRepository.findByPdpGroupAndKeyNameAndKeyVersionAndTimeStampLessThanEqual(pdpGroup, - policyName, policyVersion, Date.from(endTime), recordSize)); + return asPolicyAuditList(policyAuditRepository.findByPdpGroupAndNameAndVersionAndTimeStampLessThanEqual( + pdpGroup, policyName, policyVersion, Date.from(endTime), recordSize)); } } @@ -169,17 +162,16 @@ public class PolicyAuditService { Instant startTime, Instant endTime) { Pageable recordSize = getRecordSize(recordCount); if (startTime != null && endTime != null) { - return asPolicyAuditList(policyAuditRepository.findByKeyNameAndKeyVersionAndTimeStampBetween(policyName, + return asPolicyAuditList(policyAuditRepository.findByNameAndVersionAndTimeStampBetween(policyName, policyVersion, Date.from(startTime), Date.from(endTime), recordSize)); } else if (startTime == null && endTime == null) { - return asPolicyAuditList( - policyAuditRepository.findByKeyNameAndKeyVersion(policyName, policyVersion, recordSize)); + return asPolicyAuditList(policyAuditRepository.findByNameAndVersion(policyName, policyVersion, recordSize)); } else if (startTime != null) { - return asPolicyAuditList(policyAuditRepository.findByKeyNameAndKeyVersionAndTimeStampGreaterThanEqual( - policyName, policyVersion, Date.from(startTime), recordSize)); + return asPolicyAuditList(policyAuditRepository.findByNameAndVersionAndTimeStampGreaterThanEqual(policyName, + policyVersion, Date.from(startTime), recordSize)); } else { - return asPolicyAuditList(policyAuditRepository.findByKeyNameAndKeyVersionAndTimeStampLessThanEqual( - policyName, policyVersion, Date.from(endTime), recordSize)); + return asPolicyAuditList(policyAuditRepository.findByNameAndVersionAndTimeStampLessThanEqual(policyName, + policyVersion, Date.from(endTime), recordSize)); } } diff --git a/main/src/test/java/org/onap/policy/pap/main/service/PdpStatisticsServiceTest.java b/main/src/test/java/org/onap/policy/pap/main/service/PdpStatisticsServiceTest.java index fc604cee..7bfc9973 100644 --- a/main/src/test/java/org/onap/policy/pap/main/service/PdpStatisticsServiceTest.java +++ b/main/src/test/java/org/onap/policy/pap/main/service/PdpStatisticsServiceTest.java @@ -30,7 +30,6 @@ import java.util.Map; import org.junit.After; import org.junit.Before; import org.junit.Test; -import org.onap.policy.models.base.Validated; import org.onap.policy.models.pdp.concepts.PdpStatistics; import org.onap.policy.pap.main.repository.PdpStatisticsRepository; import org.onap.policy.pap.main.rest.CommonPapRestServer; @@ -101,11 +100,9 @@ public class PdpStatisticsServiceTest extends CommonPapRestServer { PdpStatistics pdpStatisticsErr = new PdpStatistics(); pdpStatisticsErr.setPdpInstanceId("NULL"); pdpStatisticsErr.setPdpGroupName(GROUP); - assertThatThrownBy(() -> { pdpStatisticsService.createPdpStatistics(List.of(pdpStatisticsErr)); - }).hasMessageContaining("pdp statistics").hasMessageContaining("key") - .hasMessageContaining(Validated.IS_A_NULL_KEY); + }).hasMessageContaining("item \"name\" value \"NULL\" INVALID, is null"); } @Test |