2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2021 Bell Canada. All rights reserved.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 * ============LICENSE_END=========================================================
19 package org.onap.policy.pap.main.rest;
21 import java.util.Collection;
22 import org.onap.policy.common.utils.services.Registry;
23 import org.onap.policy.models.base.PfModelException;
24 import org.onap.policy.models.pap.concepts.PolicyAudit;
25 import org.onap.policy.models.pap.persistence.provider.PolicyAuditProvider.AuditFilter;
26 import org.onap.policy.models.provider.PolicyModelsProvider;
27 import org.onap.policy.pap.main.PapConstants;
28 import org.onap.policy.pap.main.PolicyModelsProviderFactoryWrapper;
29 import org.springframework.boot.context.event.ApplicationReadyEvent;
30 import org.springframework.context.event.EventListener;
31 import org.springframework.stereotype.Service;
34 * Provider for PAP component to query policy audit information.
37 public class PolicyAuditProvider {
40 * Factory for PAP DAO.
42 private PolicyModelsProviderFactoryWrapper daoFactory;
44 @EventListener(ApplicationReadyEvent.class)
45 public void initialize() {
46 this.daoFactory = Registry.get(PapConstants.REG_PAP_DAO_FACTORY, PolicyModelsProviderFactoryWrapper.class);
50 * Gets the audit record of all policies.
52 * @param auditFilter the filter for the query
53 * @return the audit record of all policies
54 * @throws PfModelException if a DB error occurs
56 public Collection<PolicyAudit> getAuditRecords(AuditFilter auditFilter)
57 throws PfModelException {
58 try (PolicyModelsProvider dao = daoFactory.create()) {
59 return dao.getAuditRecords(auditFilter);