From c9067692f47fc532a6306e3dd8f5df75d8828a7b Mon Sep 17 00:00:00 2001 From: "adheli.tavares" <adheli.tavares@est.tech> Date: Fri, 9 Jul 2021 18:28:28 +0100 Subject: Handle numRecords default setting when built as 0. Check the numRecord to be set as DEFAULT_MAX_RECORDS when not added to the auditFilter (builder set it to 0). Issue-ID: POLICY-3340 Change-Id: I25ad83bbea71ddd82064aec3069ffa4cbce5aac1 Signed-off-by: adheli.tavares <adheli.tavares@est.tech> --- .../persistence/provider/PolicyAuditProvider.java | 49 +++------------------- 1 file changed, 5 insertions(+), 44 deletions(-) (limited to 'models-pap/src/main') diff --git a/models-pap/src/main/java/org/onap/policy/models/pap/persistence/provider/PolicyAuditProvider.java b/models-pap/src/main/java/org/onap/policy/models/pap/persistence/provider/PolicyAuditProvider.java index 432e4c85e..7368d29c7 100644 --- a/models-pap/src/main/java/org/onap/policy/models/pap/persistence/provider/PolicyAuditProvider.java +++ b/models-pap/src/main/java/org/onap/policy/models/pap/persistence/provider/PolicyAuditProvider.java @@ -72,38 +72,6 @@ public class PolicyAuditProvider { dao.createCollection(jpaAudits); } - /** - * Collect all audit records. - * - * @param numRecords number of records to be collected - * @return list of {@link PolicyAudit} records - */ - public List<PolicyAudit> getAuditRecords(@NonNull PfDao dao, @NonNull Integer numRecords) { - numRecords = numRecords > DEFAULT_MAX_RECORDS ? DEFAULT_MAX_RECORDS : numRecords; - - // @formatter:off - return dao.getAll(JpaPolicyAudit.class, "timeStamp DESC", numRecords) - .stream() - .map(JpaPolicyAudit::toAuthorative) - .collect(Collectors.toList()); - // @formatter:on - } - - /** - * Collect audit records based on filters at {@link AuditFilter}. - * - * @param auditFilter {@link AuditFilter} object with filters for search - * @param numRecords number of records to be collected - * @return list of {@link PolicyAudit} records - */ - public List<PolicyAudit> getAuditRecords(@NonNull PfDao dao, @NonNull AuditFilter auditFilter, - @NonNull Integer numRecords) { - - auditFilter.setRecordNum(Math.min(numRecords, DEFAULT_MAX_RECORDS)); - - return getAuditRecords(dao, auditFilter); - } - /** * Collect audit records based on filters at {@link AuditFilter}. * @@ -111,9 +79,12 @@ public class PolicyAuditProvider { * @return list of {@link PolicyAudit} records */ public List<PolicyAudit> getAuditRecords(@NonNull PfDao dao, @NonNull AuditFilter auditFilter) { + if (auditFilter.getRecordNum() < 1 || auditFilter.getRecordNum() > DEFAULT_MAX_RECORDS) { + auditFilter.setRecordNum(DEFAULT_MAX_RECORDS); + } - return dao.getFiltered(JpaPolicyAudit.class, auditFilter) - .stream().map(JpaPolicyAudit::toAuthorative).collect(Collectors.toList()); + return dao.getFiltered(JpaPolicyAudit.class, auditFilter).stream().map(JpaPolicyAudit::toAuthorative) + .collect(Collectors.toList()); } /** @@ -140,16 +111,6 @@ public class PolicyAuditProvider { // initialized lazily, if not set via the builder private Map<String, Object> filterMap; - /** - * Check if even still using build(), none of the params were provided. - * - * @return {@code true} if all empty/null; {@code false} otherwise. - */ - public boolean isEmpty() { - return StringUtils.isAllEmpty(name, version, pdpGroup) && action == null && fromDate == null - && toDate == null; - } - @Override public Instant getStartTime() { return fromDate; -- cgit 1.2.3-korg