Use spring boot actuator version 2.5.4
[policy/pap.git] / main / src / main / java / org / onap / policy / pap / main / rest / PolicyAuditProvider.java
1 /*-
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
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
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=========================================================
17  */
18
19 package org.onap.policy.pap.main.rest;
20
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;
32
33 /**
34  * Provider for PAP component to query policy audit information.
35  */
36 @Service
37 public class PolicyAuditProvider {
38
39     /**
40      * Factory for PAP DAO.
41      */
42     private PolicyModelsProviderFactoryWrapper daoFactory;
43
44     @EventListener(ApplicationReadyEvent.class)
45     public void initialize() {
46         this.daoFactory = Registry.get(PapConstants.REG_PAP_DAO_FACTORY, PolicyModelsProviderFactoryWrapper.class);
47     }
48
49     /**
50      * Gets the audit record of all policies.
51      *
52      * @param auditFilter the filter for the query
53      * @return the audit record of all policies
54      * @throws PfModelException if a DB error occurs
55      */
56     public Collection<PolicyAudit> getAuditRecords(AuditFilter auditFilter)
57                     throws PfModelException {
58         try (PolicyModelsProvider dao = daoFactory.create()) {
59             return dao.getAuditRecords(auditFilter);
60         }
61     }
62 }