summaryrefslogtreecommitdiffstats
path: root/models-dao
diff options
context:
space:
mode:
authoradheli.tavares <adheli.tavares@est.tech>2021-05-11 14:35:20 +0100
committeradheli.tavares <adheli.tavares@est.tech>2021-05-28 15:45:52 +0100
commit09e2bc57b947fb71c4dde9a8c0ded52f695abda1 (patch)
treef2259c0b5a0968792d6f3fa51bc4c9ae31ae2756 /models-dao
parente6bc3b407aadcab3b54074e39afc4c4dfe142b06 (diff)
Handling Policy deploy/undeploy audit models
Added a new Entity to store information when a Pdp Policy is deployed or undeployed and its create/retrieve methods. Change-Id: I35b3608c878bbfbbee0a99a124d100a48fe08131 Issue-ID: POLICY-2899 Signed-off-by: adheli.tavares <adheli.tavares@est.tech>
Diffstat (limited to 'models-dao')
-rw-r--r--models-dao/src/main/java/org/onap/policy/models/dao/PfDao.java11
-rw-r--r--models-dao/src/main/java/org/onap/policy/models/dao/impl/DefaultPfDao.java35
-rw-r--r--models-dao/src/test/java/org/onap/policy/models/dao/EntityTest.java1
3 files changed, 40 insertions, 7 deletions
diff --git a/models-dao/src/main/java/org/onap/policy/models/dao/PfDao.java b/models-dao/src/main/java/org/onap/policy/models/dao/PfDao.java
index 844759367..378ae59b6 100644
--- a/models-dao/src/main/java/org/onap/policy/models/dao/PfDao.java
+++ b/models-dao/src/main/java/org/onap/policy/models/dao/PfDao.java
@@ -256,6 +256,17 @@ public interface PfDao {
*
* @param <T> the type of the objects to get, a subclass of {@link PfConcept}
* @param someClass the class of the objects to get, a subclass of {@link PfConcept}
+ * @param orderBy field from class to order results by
+ * @param numRecords number of records to be retrieved
+ * @return the objects or null if no objects were retrieved
+ */
+ <T extends PfConcept> List<T> getAll(Class<T> someClass, String orderBy, Integer numRecords);
+
+ /**
+ * Get all the objects in the database of a given type.
+ *
+ * @param <T> the type of the objects to get, a subclass of {@link PfConcept}
+ * @param someClass the class of the objects to get, a subclass of {@link PfConcept}
* @param name the name of the concepts for which to get all versions
* @return the objects or null if no objects were retrieved
*/
diff --git a/models-dao/src/main/java/org/onap/policy/models/dao/impl/DefaultPfDao.java b/models-dao/src/main/java/org/onap/policy/models/dao/impl/DefaultPfDao.java
index d1e32935c..009563078 100644
--- a/models-dao/src/main/java/org/onap/policy/models/dao/impl/DefaultPfDao.java
+++ b/models-dao/src/main/java/org/onap/policy/models/dao/impl/DefaultPfDao.java
@@ -32,6 +32,7 @@ import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.persistence.TypedQuery;
import javax.ws.rs.core.Response;
+import org.apache.commons.lang3.StringUtils;
import org.onap.policy.models.base.PfConcept;
import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.base.PfGeneratedIdKey;
@@ -72,6 +73,7 @@ public class DefaultPfDao implements PfDao {
private static final String WHERE = " WHERE ";
private static final String AND = " AND ";
+ private static final String ORDER_BY = " ORDER BY c.";
private static final String NAME_FILTER = "c.key.name = :name";
private static final String VERSION_FILTER = "c.key.version = :version";
@@ -395,9 +397,8 @@ public class DefaultPfDao implements PfDao {
try {
PfFilter timeStampFilter = new PfFilterFactory().createFilter(someClass);
- filterQueryString = timeStampFilter.addFilter(filterQueryString,
- name, startTime, endTime, filterMap, sortOrder, getRecordNum);
-
+ filterQueryString = timeStampFilter.addFilter(filterQueryString, name, startTime, endTime, filterMap,
+ sortOrder, getRecordNum);
TypedQuery<T> query = mg.createQuery(setQueryTable(filterQueryString, someClass), someClass);
@@ -427,7 +428,7 @@ public class DefaultPfDao implements PfDao {
LOGGER.debug("filterQueryString is \"{}\"", filterQueryString);
return query.getResultList();
- } finally {
+ } finally {
mg.close();
}
}
@@ -505,6 +506,27 @@ public class DefaultPfDao implements PfDao {
}
@Override
+ public <T extends PfConcept> List<T> getAll(Class<T> someClass, String orderBy, Integer numRecords) {
+
+ if (someClass == null) {
+ return Collections.emptyList();
+ }
+ final var mg = getEntityManager();
+ try {
+ String query = setQueryTable(SELECT_FROM_TABLE, someClass);
+
+ if (StringUtils.isNotBlank(orderBy)) {
+ query = query.concat(ORDER_BY).concat(orderBy);
+ }
+
+ return mg.createQuery(query, someClass).setMaxResults(numRecords)
+ .getResultList();
+ } finally {
+ mg.close();
+ }
+ }
+
+ @Override
public <T extends PfConcept> List<T> getAllVersionsByParent(final Class<T> someClass, final String parentKeyName) {
if (someClass == null || parentKeyName == null) {
return Collections.emptyList();
@@ -539,9 +561,8 @@ public class DefaultPfDao implements PfDao {
}
@Override
- public <T extends PfConcept> List<T> getByTimestamp(final Class<T> someClass,
- final PfGeneratedIdKey key,
- final Instant timeStamp) {
+ public <T extends PfConcept> List<T> getByTimestamp(final Class<T> someClass, final PfGeneratedIdKey key,
+ final Instant timeStamp) {
if (someClass == null || key == null || timeStamp == null) {
return Collections.emptyList();
}
diff --git a/models-dao/src/test/java/org/onap/policy/models/dao/EntityTest.java b/models-dao/src/test/java/org/onap/policy/models/dao/EntityTest.java
index 66fc1b502..59fc9b482 100644
--- a/models-dao/src/test/java/org/onap/policy/models/dao/EntityTest.java
+++ b/models-dao/src/test/java/org/onap/policy/models/dao/EntityTest.java
@@ -183,6 +183,7 @@ public class EntityTest {
pfDao.get(null, nullTimeKey);
pfDao.getAll(null);
pfDao.getAll(null, nullKey);
+ pfDao.getAll(null, null, null);
pfDao.getConcept(null, nullKey);
pfDao.getConcept(PfConceptKey.class, nullKey);
pfDao.getConcept(null, nullRefKey);