Use OperationsHistory from models 28/108628/2
authorJim Hahn <jrh3@att.com>
Fri, 29 May 2020 15:43:49 +0000 (11:43 -0400)
committerJim Hahn <jrh3@att.com>
Mon, 1 Jun 2020 14:06:25 +0000 (10:06 -0400)
Deleted Dbao and replaced it with the shared class in policy-models.
Also had to update the queries and the persistence.xml accordingly.

Issue-ID: POLICY-2581
Change-Id: I59dfa2f37c272796ccebc0f578c9f4e8e1b9c8ab
Signed-off-by: Jim Hahn <jrh3@att.com>
13 files changed:
applications/common/pom.xml
applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/operationshistory/CountRecentOperationsPip.java
applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/operationshistory/Dbao.java [deleted file]
applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/operationshistory/GetOperationOutcomePip.java
applications/common/src/main/resources/persistence.xml
applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/operationshistory/CountRecentOperationsPipTest.java
applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/operationshistory/GetOperationOutcomePipTest.java
applications/common/src/test/resources/META-INF/persistence.xml
applications/guard/src/test/java/org/onap/policy/xacml/pdp/application/guard/GuardPdpApplicationTest.java
applications/guard/src/test/java/org/onap/policy/xacml/pdp/application/guard/SonCoordinationTest.java
applications/guard/src/test/resources/META-INF/persistence.xml
main/src/main/resources/META-INF/persistence.xml
main/src/test/resources/META-INF/persistence.xml

index 2d29ded..0142c4e 100644 (file)
             <artifactId>h2</artifactId>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.onap.policy.models.policy-models-interactions.model-impl</groupId>
+            <artifactId>guard</artifactId>
+            <version>${policy.models.version}</version>
+        </dependency>
         <dependency>
             <groupId>org.onap.policy.common</groupId>
             <artifactId>policy-endpoints</artifactId>
index f2d7980..3d7270e 100644 (file)
@@ -145,7 +145,7 @@ public class CountRecentOperationsPip extends StdOnapPip {
             //
             // We are expecting a single result
             //
-            return em.createQuery("select count(e) from Dbao e"
+            return em.createQuery("select count(e) from OperationsHistory e"
                                   + " where e.outcome<>'Failure_Guard'"
                                   + " and e.actor= ?1"
                                   + " and e.operation= ?2"
diff --git a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/operationshistory/Dbao.java b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/operationshistory/Dbao.java
deleted file mode 100644 (file)
index b4ee559..0000000
+++ /dev/null
@@ -1,79 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP
- * ================================================================================
- * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.pdp.xacml.application.common.operationshistory;
-
-import java.io.Serializable;
-import java.util.Date;
-import javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.GeneratedValue;
-import javax.persistence.Id;
-import javax.persistence.Index;
-import javax.persistence.Table;
-import lombok.Data;
-
-@Entity
-@Table(name = "operationshistory",
-                indexes = {@Index(name = "operationshistory_clreqid_index", columnList = "closedLoopName,requestId"),
-                                @Index(name = "operationshistory_target_index", columnList = "target,operation,actor")})
-@Data
-public class Dbao implements Serializable {
-
-    private static final long serialVersionUID = -551420180714993577L;
-
-    @Id
-    @GeneratedValue
-    @Column(name = "id")
-    private Long id;
-
-    @Column(name = "closedLoopName", length = 255)
-    private String closedLoopName;
-
-    @Column(name = "requestId", length = 50)
-    private String requestId;
-
-    @Column(name = "subrequestId", length = 50)
-    private String subrequestId;
-
-    @Column(name = "actor", length = 50)
-    private String actor;
-
-    @Column(name = "operation", length = 50)
-    private String operation;
-
-    @Column(name = "target", length = 50)
-    private String target;
-
-    @Column(name = "starttime")
-    private Date starttime;
-
-    @Column(name = "outcome", length = 50)
-    private String outcome;
-
-    @Column(name = "message", length = 255)
-    private String message;
-
-    @Column(name = "endtime")
-    private Date endtime;
-
-}
index 60e26a2..9559598 100644 (file)
@@ -28,7 +28,6 @@ import com.att.research.xacml.std.pip.StdPIPResponse;
 import com.google.common.base.Strings;
 import java.util.Arrays;
 import java.util.Collection;
-
 import javax.persistence.NoResultException;
 import org.onap.policy.pdp.xacml.application.common.ToscaDictionary;
 import org.onap.policy.pdp.xacml.application.common.std.StdOnapPip;
@@ -117,7 +116,7 @@ public class GetOperationOutcomePip extends StdOnapPip {
             // We are expecting a single result
             //
             String result = em
-                .createQuery("select e.outcome from Dbao e" + " where e.closedLoopName= ?1"
+                .createQuery("select e.outcome from OperationsHistory e" + " where e.closedLoopName= ?1"
                     + " order by e.starttime desc", String.class)
                 .setParameter(1, clname).setMaxResults(1).getSingleResult();
 
index e3f4a2f..a9dedcc 100644 (file)
@@ -3,14 +3,14 @@
   ============LICENSE_START=======================================================
   ONAP
   ================================================================================
-  Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+  Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
   ================================================================================
   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at
-  
+
        http://www.apache.org/licenses/LICENSE-2.0
-  
+
   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -24,7 +24,7 @@
     <persistence-unit name="OperationsHistoryPU" transaction-type="RESOURCE_LOCAL">
         <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
 
-        <class>org.onap.policy.pdp.xacml.application.common.operationshistory.Dbao</class>
+        <class>org.onap.policy.guard.OperationsHistory</class>
 
         <properties>
             <property name="javax.persistence.schema-generation.database.action" value="create" />
@@ -33,6 +33,6 @@
             <property name="eclipselink.logging.level" value="INFO" />
         </properties>
     </persistence-unit>
-    
+
 </persistence>
-  
\ No newline at end of file
+
index 29eb2a0..badc5f9 100644 (file)
@@ -51,6 +51,7 @@ import org.junit.BeforeClass;
 import org.junit.Test;
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
+import org.onap.policy.guard.OperationsHistory;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -216,7 +217,7 @@ public class CountRecentOperationsPipTest {
         //
         // create entry
         //
-        Dbao newEntry = createEntry("cl-foobar-1", "vnf-1", "SUCCESS");
+        OperationsHistory newEntry = createEntry("cl-foobar-1", "vnf-1", "SUCCESS");
         //
         // No entries yet
         //
@@ -241,7 +242,7 @@ public class CountRecentOperationsPipTest {
     @Test
     public void testStringToChronoUnit() throws PIPException {
         // not configured yet
-        Dbao newEntry = createEntry("cl-foobar-1", "vnf-1", "SUCCESS");
+        OperationsHistory newEntry = createEntry("cl-foobar-1", "vnf-1", "SUCCESS");
         assertEquals(-1, getCount(newEntry));
 
         // now configure it
@@ -266,7 +267,7 @@ public class CountRecentOperationsPipTest {
         assertEquals(-1, getCount(newEntry));
     }
 
-    private long getCount(Dbao newEntry) throws PIPException {
+    private long getCount(OperationsHistory newEntry) throws PIPException {
         responses = new LinkedList<>(Arrays.asList(resp1, resp2, resp3));
         attributes = new LinkedList<>(
                         Arrays.asList(newEntry.getActor(), newEntry.getOperation(), newEntry.getTarget()));
@@ -279,11 +280,11 @@ public class CountRecentOperationsPipTest {
         return ((Number) value.getValue()).longValue();
     }
 
-    private Dbao createEntry(String cl, String target, String outcome) {
+    private OperationsHistory createEntry(String cl, String target, String outcome) {
         //
         // Create entry
         //
-        Dbao newEntry = new Dbao();
+        OperationsHistory newEntry = new OperationsHistory();
         newEntry.setClosedLoopName(cl);
         newEntry.setTarget(target);
         newEntry.setOutcome(outcome);
index b5273e6..dd961d8 100644 (file)
@@ -47,6 +47,7 @@ import org.junit.BeforeClass;
 import org.junit.Test;
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
+import org.onap.policy.guard.OperationsHistory;
 import org.onap.policy.pdp.xacml.application.common.ToscaDictionary;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -234,7 +235,7 @@ public class GetOperationOutcomePipTest {
         //
         // Create entry
         //
-        Dbao newEntry = new Dbao();
+        OperationsHistory newEntry = new OperationsHistory();
         newEntry.setClosedLoopName(cl);
         newEntry.setTarget(target);
         newEntry.setOutcome(outcome);
index d917c06..a0f0d45 100644 (file)
@@ -3,7 +3,7 @@
   ============LICENSE_START=======================================================
   ONAP
   ================================================================================
-  Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+  Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
   ================================================================================
   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
@@ -23,8 +23,7 @@
 
     <persistence-unit name="PipEngineTest" transaction-type="RESOURCE_LOCAL">
         <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
-
-        <class>org.onap.policy.pdp.xacml.application.common.operationshistory.Dbao</class>
+        <class>org.onap.policy.guard.OperationsHistory</class>
 
         <properties>
             <property name="eclipselink.ddl-generation" value="create-tables" />
index f5392cf..e83f4d2 100644 (file)
@@ -52,6 +52,7 @@ import org.onap.policy.common.endpoints.parameters.RestServerParameters;
 import org.onap.policy.common.utils.coder.CoderException;
 import org.onap.policy.common.utils.coder.StandardCoder;
 import org.onap.policy.common.utils.resources.TextFileUtils;
+import org.onap.policy.guard.OperationsHistory;
 import org.onap.policy.models.decisions.concepts.DecisionRequest;
 import org.onap.policy.models.decisions.concepts.DecisionResponse;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
@@ -60,7 +61,6 @@ import org.onap.policy.pdp.xacml.application.common.XacmlApplicationException;
 import org.onap.policy.pdp.xacml.application.common.XacmlApplicationServiceProvider;
 import org.onap.policy.pdp.xacml.application.common.XacmlPolicyUtils;
 import org.onap.policy.pdp.xacml.application.common.operationshistory.CountRecentOperationsPip;
-import org.onap.policy.pdp.xacml.application.common.operationshistory.Dbao;
 import org.onap.policy.pdp.xacml.xacmltest.TestUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -160,7 +160,7 @@ public class GuardPdpApplicationTest {
     @Before
     public void startClean() throws Exception {
         em.getTransaction().begin();
-        em.createQuery("DELETE FROM Dbao").executeUpdate();
+        em.createQuery("DELETE FROM OperationsHistory").executeUpdate();
         em.getTransaction().commit();
     }
 
@@ -362,7 +362,7 @@ public class GuardPdpApplicationTest {
         //
         // Add an entry
         //
-        Dbao newEntry = new Dbao();
+        OperationsHistory newEntry = new OperationsHistory();
         newEntry.setActor(properties.get("actor").toString());
         newEntry.setOperation(properties.get("operation").toString());
         newEntry.setClosedLoopName(properties.get("clname").toString());
index 4c5bced..ba51f55 100644 (file)
@@ -34,10 +34,8 @@ import java.util.Map;
 import java.util.Properties;
 import java.util.ServiceLoader;
 import java.util.UUID;
-
 import javax.persistence.EntityManager;
 import javax.persistence.Persistence;
-
 import org.apache.commons.lang3.tuple.Pair;
 import org.junit.AfterClass;
 import org.junit.Before;
@@ -51,13 +49,13 @@ import org.onap.policy.common.endpoints.parameters.RestServerParameters;
 import org.onap.policy.common.utils.coder.CoderException;
 import org.onap.policy.common.utils.coder.StandardCoder;
 import org.onap.policy.common.utils.resources.TextFileUtils;
+import org.onap.policy.guard.OperationsHistory;
 import org.onap.policy.models.decisions.concepts.DecisionRequest;
 import org.onap.policy.models.decisions.concepts.DecisionResponse;
 import org.onap.policy.pdp.xacml.application.common.XacmlApplicationException;
 import org.onap.policy.pdp.xacml.application.common.XacmlApplicationServiceProvider;
 import org.onap.policy.pdp.xacml.application.common.XacmlPolicyUtils;
 import org.onap.policy.pdp.xacml.application.common.operationshistory.CountRecentOperationsPip;
-import org.onap.policy.pdp.xacml.application.common.operationshistory.Dbao;
 import org.onap.policy.pdp.xacml.xacmltest.TestUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -154,7 +152,7 @@ public class SonCoordinationTest {
     @Before
     public void startClean() throws Exception {
         em.getTransaction().begin();
-        em.createQuery("DELETE FROM Dbao").executeUpdate();
+        em.createQuery("DELETE FROM OperationsHistory").executeUpdate();
         em.getTransaction().commit();
     }
 
@@ -271,7 +269,7 @@ public class SonCoordinationTest {
         //
         // Add an entry
         //
-        Dbao newEntry = new Dbao();
+        OperationsHistory newEntry = new OperationsHistory();
         newEntry.setActor(properties.get("actor").toString());
         newEntry.setOperation(properties.get("operation").toString());
         newEntry.setClosedLoopName(properties.get("clname").toString());
@@ -288,7 +286,7 @@ public class SonCoordinationTest {
 
     private void updateOperationEvent(long id, String outcome) {
 
-        Dbao updateEntry = em.find(Dbao.class, id);
+        OperationsHistory updateEntry = em.find(OperationsHistory.class, id);
         updateEntry.setOutcome(outcome);
         updateEntry.setEndtime(Date.from(Instant.now()));
         em.getTransaction().begin();
index 41b25b4..ceb255f 100644 (file)
@@ -3,7 +3,7 @@
   ============LICENSE_START=======================================================
   ONAP
   ================================================================================
-  Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+  Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
   ================================================================================
   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
@@ -23,7 +23,7 @@
 
     <persistence-unit name="OperationsHistoryPUTest" transaction-type="RESOURCE_LOCAL">
         <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
-        <class>org.onap.policy.pdp.xacml.application.common.operationshistory.Dbao</class>
+        <class>org.onap.policy.guard.OperationsHistory</class>
         <properties>
             <property name="eclipselink.ddl-generation" value="create-tables" />
             <property name="eclipselink.logging.level" value="FINE" />
index e3f4a2f..a9dedcc 100644 (file)
@@ -3,14 +3,14 @@
   ============LICENSE_START=======================================================
   ONAP
   ================================================================================
-  Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+  Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
   ================================================================================
   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at
-  
+
        http://www.apache.org/licenses/LICENSE-2.0
-  
+
   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -24,7 +24,7 @@
     <persistence-unit name="OperationsHistoryPU" transaction-type="RESOURCE_LOCAL">
         <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
 
-        <class>org.onap.policy.pdp.xacml.application.common.operationshistory.Dbao</class>
+        <class>org.onap.policy.guard.OperationsHistory</class>
 
         <properties>
             <property name="javax.persistence.schema-generation.database.action" value="create" />
@@ -33,6 +33,6 @@
             <property name="eclipselink.logging.level" value="INFO" />
         </properties>
     </persistence-unit>
-    
+
 </persistence>
-  
\ No newline at end of file
+
index d917c06..8ca12a9 100644 (file)
@@ -3,7 +3,7 @@
   ============LICENSE_START=======================================================
   ONAP
   ================================================================================
-  Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+  Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
   ================================================================================
   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
@@ -24,7 +24,7 @@
     <persistence-unit name="PipEngineTest" transaction-type="RESOURCE_LOCAL">
         <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
 
-        <class>org.onap.policy.pdp.xacml.application.common.operationshistory.Dbao</class>
+        <class>org.onap.policy.guard.OperationsHistory</class>
 
         <properties>
             <property name="eclipselink.ddl-generation" value="create-tables" />