aboutsummaryrefslogtreecommitdiffstats
path: root/models-provider/src
diff options
context:
space:
mode:
authoradheli.tavares <adheli.tavares@est.tech>2021-06-03 10:37:35 +0100
committeradheli.tavares <adheli.tavares@est.tech>2021-06-03 12:50:14 +0100
commitd72a2ab96255ccc7a9c3a3506eab5509cbcf9ac9 (patch)
treeff63a01bc3ca1bf5c8430b98ed0437c3dafec246 /models-provider/src
parent443f9f35fe733fdb88b51ab9c574949f5dd4c03c (diff)
Exposing the Audit provider through Models provider.
Change-Id: I4a3a28b6dbbfbad533a69cf46c545ece7e0b147e Issue-ID: POLICY-2899 Signed-off-by: adheli.tavares <adheli.tavares@est.tech>
Diffstat (limited to 'models-provider/src')
-rw-r--r--models-provider/src/main/java/org/onap/policy/models/provider/PolicyModelsProvider.java17
-rw-r--r--models-provider/src/main/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderImpl.java19
-rw-r--r--models-provider/src/main/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderImpl.java13
-rw-r--r--models-provider/src/test/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderTest.java30
-rw-r--r--models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyBadProviderImpl.java13
-rw-r--r--models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderTest.java2
-rw-r--r--models-provider/src/test/resources/META-INF/persistence.xml1
7 files changed, 95 insertions, 0 deletions
diff --git a/models-provider/src/main/java/org/onap/policy/models/provider/PolicyModelsProvider.java b/models-provider/src/main/java/org/onap/policy/models/provider/PolicyModelsProvider.java
index 3af069e24..5321e8597 100644
--- a/models-provider/src/main/java/org/onap/policy/models/provider/PolicyModelsProvider.java
+++ b/models-provider/src/main/java/org/onap/policy/models/provider/PolicyModelsProvider.java
@@ -27,6 +27,8 @@ import java.util.Collection;
import java.util.List;
import lombok.NonNull;
import org.onap.policy.models.base.PfModelException;
+import org.onap.policy.models.pap.concepts.PolicyAudit;
+import org.onap.policy.models.pap.persistence.provider.PolicyAuditProvider.AuditFilter;
import org.onap.policy.models.pdp.concepts.Pdp;
import org.onap.policy.models.pdp.concepts.PdpGroup;
import org.onap.policy.models.pdp.concepts.PdpGroupFilter;
@@ -408,4 +410,19 @@ public interface PolicyModelsProvider extends AutoCloseable {
*/
public void cudPolicyStatus(Collection<PdpPolicyStatus> createObjs, Collection<PdpPolicyStatus> updateObjs,
Collection<PdpPolicyStatus> deleteObjs);
+
+ /**
+ * Creates records for audit actions on policies.
+ *
+ * @param auditRecords the objects to create
+ */
+ public void createAuditRecords(@NonNull List<PolicyAudit> auditRecords);
+
+ /**
+ * Collect the audit records.
+ * @param auditFilter filter for search
+ * @param numRecords max number of records to be collected
+ * @return list of {@link PolicyAudit} or empty if none or not match with filter
+ */
+ public List<PolicyAudit> getAuditRecords(AuditFilter auditFilter, @NonNull Integer numRecords);
}
diff --git a/models-provider/src/main/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderImpl.java b/models-provider/src/main/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderImpl.java
index a90dc895c..3bba1518a 100644
--- a/models-provider/src/main/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderImpl.java
+++ b/models-provider/src/main/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderImpl.java
@@ -29,6 +29,9 @@ import javax.ws.rs.core.Response;
import lombok.NonNull;
import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.base.PfModelRuntimeException;
+import org.onap.policy.models.pap.concepts.PolicyAudit;
+import org.onap.policy.models.pap.persistence.provider.PolicyAuditProvider;
+import org.onap.policy.models.pap.persistence.provider.PolicyAuditProvider.AuditFilter;
import org.onap.policy.models.pdp.concepts.Pdp;
import org.onap.policy.models.pdp.concepts.PdpGroup;
import org.onap.policy.models.pdp.concepts.PdpGroupFilter;
@@ -309,6 +312,22 @@ public class DatabasePolicyModelsProviderImpl extends AbstractModelsProvider imp
new PdpProvider().cudPolicyStatus(getPfDao(), createObjs, updateObjs, deleteObjs);
}
+ @Override
+ public void createAuditRecords(List<PolicyAudit> auditRecords) {
+ assertInitialized();
+ new PolicyAuditProvider().createAuditRecords(getPfDao(), auditRecords);
+ }
+
+ @Override
+ public List<PolicyAudit> getAuditRecords(AuditFilter auditFilter, @NonNull Integer numRecords) {
+ assertInitialized();
+ if (auditFilter == null || auditFilter.isEmpty()) {
+ return new PolicyAuditProvider().getAuditRecords(getPfDao(), numRecords);
+ } else {
+ return new PolicyAuditProvider().getAuditRecords(getPfDao(), auditFilter, numRecords);
+ }
+ }
+
/**
* Check if the model provider is initialized.
*/
diff --git a/models-provider/src/main/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderImpl.java b/models-provider/src/main/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderImpl.java
index f47f4d464..dbeccfaeb 100644
--- a/models-provider/src/main/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderImpl.java
+++ b/models-provider/src/main/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderImpl.java
@@ -32,6 +32,8 @@ import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.common.utils.resources.ResourceUtils;
import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.base.PfModelRuntimeException;
+import org.onap.policy.models.pap.concepts.PolicyAudit;
+import org.onap.policy.models.pap.persistence.provider.PolicyAuditProvider.AuditFilter;
import org.onap.policy.models.pdp.concepts.Pdp;
import org.onap.policy.models.pdp.concepts.PdpGroup;
import org.onap.policy.models.pdp.concepts.PdpGroupFilter;
@@ -267,6 +269,17 @@ public class DummyPolicyModelsProviderImpl implements PolicyModelsProvider {
// Not implemented
}
+ @Override
+ public void createAuditRecords(List<PolicyAudit> auditRecords) {
+ // Not implemented
+ }
+
+ @Override
+ public List<PolicyAudit> getAuditRecords(AuditFilter auditFilter, @NonNull Integer numRecords) {
+ // Not implemented
+ return new ArrayList<>();
+ }
+
/**
* Return a ToscaServicetemplate dummy response.
*
diff --git a/models-provider/src/test/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderTest.java b/models-provider/src/test/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderTest.java
index 9e8ba0bbc..4356e4b1d 100644
--- a/models-provider/src/test/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderTest.java
+++ b/models-provider/src/test/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderTest.java
@@ -36,6 +36,9 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.onap.policy.models.base.PfModelException;
+import org.onap.policy.models.pap.concepts.PolicyAudit;
+import org.onap.policy.models.pap.concepts.PolicyAudit.AuditAction;
+import org.onap.policy.models.pap.persistence.provider.PolicyAuditProvider.AuditFilter;
import org.onap.policy.models.pdp.concepts.Pdp;
import org.onap.policy.models.pdp.concepts.PdpGroup;
import org.onap.policy.models.pdp.concepts.PdpGroupFilter;
@@ -538,6 +541,33 @@ public class DatabasePolicyModelsProviderTest {
databaseProvider.close();
}
+ @Test
+ public void testCreateAuditRecords() throws PfModelException {
+ PolicyAudit audit = PolicyAudit.builder().action(AuditAction.DEPLOYMENT).pdpGroup(GROUP).pdpType(GROUP)
+ .policy(new ToscaConceptIdentifier(NAME, VERSION_100)).user("user").build();
+
+ databaseProvider = new PolicyModelsProviderFactory().createPolicyModelsProvider(parameters);
+
+ databaseProvider.createAuditRecords(List.of(audit));
+ List<PolicyAudit> createdAudits = databaseProvider.getAuditRecords(null, 10);
+ assertThat(createdAudits).hasSize(1);
+
+ createdAudits = databaseProvider.getAuditRecords(AuditFilter.builder().build(), 10);
+ assertThat(createdAudits).hasSize(1);
+
+ List<PolicyAudit> emptyList =
+ databaseProvider.getAuditRecords(AuditFilter.builder().action(AuditAction.UNDEPLOYMENT).build(), 10);
+ assertThat(emptyList).isEmpty();
+
+ assertThatThrownBy(() -> databaseProvider.createAuditRecords(null))
+ .hasMessageContaining("audits is marked non-null but is null");
+
+ assertThatThrownBy(() -> databaseProvider.getAuditRecords(null, null))
+ .hasMessageContaining("numRecords is marked non-null but is null");
+
+ databaseProvider.close();
+ }
+
private List<PdpStatistics> makePdpStatisticsList() {
PdpStatistics pdpStatistics = new PdpStatistics();
pdpStatistics.setPdpInstanceId(NAME);
diff --git a/models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyBadProviderImpl.java b/models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyBadProviderImpl.java
index 4daeaba4c..34cdbff0f 100644
--- a/models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyBadProviderImpl.java
+++ b/models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyBadProviderImpl.java
@@ -31,6 +31,8 @@ import javax.ws.rs.core.Response;
import lombok.NonNull;
import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.base.PfModelRuntimeException;
+import org.onap.policy.models.pap.concepts.PolicyAudit;
+import org.onap.policy.models.pap.persistence.provider.PolicyAuditProvider.AuditFilter;
import org.onap.policy.models.pdp.concepts.Pdp;
import org.onap.policy.models.pdp.concepts.PdpGroup;
import org.onap.policy.models.pdp.concepts.PdpGroupFilter;
@@ -264,4 +266,15 @@ public class DummyBadProviderImpl implements PolicyModelsProvider {
// Not implemented
return null;
}
+
+ @Override
+ public void createAuditRecords(List<PolicyAudit> auditRecords) {
+ // Not implemented
+ }
+
+ @Override
+ public List<PolicyAudit> getAuditRecords(AuditFilter auditFilter, @NonNull Integer numRecords) {
+ // Not implemented
+ return null;
+ }
}
diff --git a/models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderTest.java b/models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderTest.java
index 67a1449f6..de320724a 100644
--- a/models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderTest.java
+++ b/models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderTest.java
@@ -126,6 +126,8 @@ public class DummyPolicyModelsProviderTest {
assertThat(dummyProvider.getGroupPolicyStatus("name")).isEmpty();
assertThatCode(() -> dummyProvider.cudPolicyStatus(null, null,
null)).doesNotThrowAnyException();
+ assertThatCode(() -> dummyProvider.createAuditRecords(null)).doesNotThrowAnyException();
+ assertThat(dummyProvider.getAuditRecords(null, 10)).isEmpty();
}
@Test
diff --git a/models-provider/src/test/resources/META-INF/persistence.xml b/models-provider/src/test/resources/META-INF/persistence.xml
index 249b29aae..3b4d95656 100644
--- a/models-provider/src/test/resources/META-INF/persistence.xml
+++ b/models-provider/src/test/resources/META-INF/persistence.xml
@@ -27,6 +27,7 @@
<class>org.onap.policy.models.base.PfConceptKey</class>
<class>org.onap.policy.models.dao.converters.CDataConditioner</class>
<class>org.onap.policy.models.dao.converters.Uuid2String</class>
+ <class>org.onap.policy.models.pap.persistence.concepts.JpaPolicyAudit</class>
<class>org.onap.policy.models.pdp.persistence.concepts.JpaPdp</class>
<class>org.onap.policy.models.pdp.persistence.concepts.JpaPdpPolicyStatus</class>
<class>org.onap.policy.models.pdp.persistence.concepts.JpaPdpGroup</class>