diff options
author | adheli.tavares <adheli.tavares@est.tech> | 2021-07-09 18:28:28 +0100 |
---|---|---|
committer | adheli.tavares <adheli.tavares@est.tech> | 2021-07-12 16:50:04 +0100 |
commit | c9067692f47fc532a6306e3dd8f5df75d8828a7b (patch) | |
tree | a5ad4ef3cfefc47129a197c4a5c2eb4edbc97616 /models-pap/src/main/java | |
parent | 43ed6b71f24a06834ee9fd6f7ceb28eda2c351ba (diff) |
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>
Diffstat (limited to 'models-pap/src/main/java')
-rw-r--r-- | models-pap/src/main/java/org/onap/policy/models/pap/persistence/provider/PolicyAuditProvider.java | 49 |
1 files changed, 5 insertions, 44 deletions
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 @@ -73,47 +73,18 @@ public class PolicyAuditProvider { } /** - * 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}. * * @param auditFilter {@link AuditFilter} object with filters for search * @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; |