Fix issues in existing entity classes 92/126492/6
authora.sreekumar <ajith.sreekumar@bell.ca>
Thu, 6 Jan 2022 14:52:15 +0000 (14:52 +0000)
committera.sreekumar <ajith.sreekumar@bell.ca>
Tue, 11 Jan 2022 17:04:05 +0000 (17:04 +0000)
Issues identified in the entity classes are fixed in this
review. Some fixes doesn't affect the table structure at all.
Tables actually affected by some of these fixes are not really used today, and doesn't
contain any data. A separate review is raised for the db-migrator
changes.

Change-Id: I0efdf2c5f17e12225f1b443b5fe8e27c578229f7
Issue-ID: POLICY-3871
Signed-off-by: a.sreekumar <ajith.sreekumar@bell.ca>
models-base/src/main/java/org/onap/policy/models/base/PfModel.java
models-interactions/model-simulators/src/test/java/org/onap/policy/simulators/DmaapSimulatorTest.java
models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpGroup.java
models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaModel.java
models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaParameter.java
models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicy.java
models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyType.java
models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaProperty.java
models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTrigger.java

index b7f074a..e7b79ca 100644 (file)
@@ -2,6 +2,7 @@
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2019 Nordix Foundation.
  *  Modifications Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved.
+ *  Modifications Copyright (C) 2022 Bell Canada. 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.
@@ -25,10 +26,7 @@ import java.util.List;
 import java.util.Set;
 import java.util.TreeSet;
 import javax.persistence.EmbeddedId;
-import javax.persistence.Entity;
-import javax.persistence.Inheritance;
-import javax.persistence.InheritanceType;
-import javax.persistence.Table;
+import javax.persistence.MappedSuperclass;
 import lombok.Data;
 import lombok.EqualsAndHashCode;
 import lombok.NonNull;
@@ -53,9 +51,7 @@ import org.onap.policy.models.base.validation.annotations.VerifyKey;
  * @param <C> the type of concept on which the interface is applied.
  */
 
-@Entity
-@Table(name = "PfModel")
-@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
+@MappedSuperclass
 @Data
 @EqualsAndHashCode(callSuper = false)
 public abstract class PfModel extends PfConcept {
index fab041f..19c399d 100644 (file)
@@ -1,6 +1,7 @@
 /*-
  * ============LICENSE_START=======================================================
  * Copyright (C) 2019, 2022 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2022 Bell Canada. 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.
@@ -18,6 +19,7 @@
 
 package org.onap.policy.simulators;
 
+import static org.assertj.core.api.Assertions.assertThat;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 
@@ -85,6 +87,7 @@ public class DmaapSimulatorTest {
                         .register((infra, topic, event) -> queue.add(event));
 
         DmaapTopicSink sink = TopicEndpointManager.getManager().getDmaapTopicSink(TOPIC);
+        assertThat(queue.poll(1, TimeUnit.SECONDS)).isNull();
         sink.send("hello");
         assertEquals("hello", queue.poll(MAX_WAIT_SEC, TimeUnit.SECONDS));
 
index 2856bfb..07f9261 100644 (file)
@@ -4,6 +4,7 @@
  * ================================================================================
  * Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved.
  * Modifications Copyright (C) 2019,2021 Nordix Foundation.
+ * Modifications Copyright (C) 2022 Bell Canada. 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.
@@ -90,10 +91,8 @@ public class JpaPdpGroup extends PfConcept implements PfAuthorative<PdpGroup> {
     // @formatter:off
     @OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true)
     @CollectionTable(joinColumns = {
-        @JoinColumn(name = "pdpGroupParentKeyName",    referencedColumnName = "parentKeyName"),
-        @JoinColumn(name = "pdpGroupParentKeyVersion", referencedColumnName = "parentKeyVersion"),
-        @JoinColumn(name = "pdpGroupParentLocalName",  referencedColumnName = "parentLocalName"),
-        @JoinColumn(name = "pdpGroupLocalName",        referencedColumnName = "localName")
+        @JoinColumn(name = "name",    referencedColumnName = "name"),
+        @JoinColumn(name = "version", referencedColumnName = "version")
     })
     // @formatter:on
     @NotNull
index cd6656b..09c406e 100644 (file)
@@ -2,6 +2,7 @@
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2019-2020 Nordix Foundation.
  *  Modifications Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
+ *  Modifications Copyright (C) 2022 Bell Canada. 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.
@@ -27,6 +28,7 @@ import javax.persistence.Entity;
 import javax.persistence.FetchType;
 import javax.persistence.Inheritance;
 import javax.persistence.InheritanceType;
+import javax.persistence.JoinColumn;
 import javax.persistence.OneToOne;
 import javax.persistence.Table;
 import lombok.Data;
@@ -55,6 +57,8 @@ public class JpaToscaModel extends PfModel {
     private static final long serialVersionUID = 8800599637708309945L;
 
     @OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true)
+    @JoinColumn(name = "serviceTemplatesName", referencedColumnName = "name")
+    @JoinColumn(name = "serviceTemplatesVersion", referencedColumnName = "version")
     @Valid
     private JpaToscaServiceTemplates serviceTemplates;
 
index 9b023dc..552d9c1 100644 (file)
@@ -2,6 +2,7 @@
  * ============LICENSE_START=======================================================
  * Copyright (C) 2020 Nordix Foundation.
  * Modifications Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2022 Bell Canada. 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,10 +25,6 @@ package org.onap.policy.models.tosca.simple.concepts;
 import java.util.List;
 import javax.persistence.Column;
 import javax.persistence.EmbeddedId;
-import javax.persistence.Entity;
-import javax.persistence.Inheritance;
-import javax.persistence.InheritanceType;
-import javax.persistence.Table;
 import lombok.Data;
 import lombok.EqualsAndHashCode;
 import lombok.NonNull;
@@ -45,9 +42,6 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaParameter;
 /**
  * Class to represent the parameter in TOSCA definition.
  */
-@Entity
-@Table(name = "ToscaParameter")
-@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
 @Data
 @EqualsAndHashCode(callSuper = false)
 public class JpaToscaParameter extends PfConcept implements PfAuthorative<ToscaParameter> {
index 76861d2..feae48e 100644 (file)
@@ -4,6 +4,7 @@
  * ================================================================================
  * Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved.
  * Modifications Copyright (C) 2019-2021 Nordix Foundation.
+ * Modifications Copyright (C) 2022 Bell Canada. 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.
@@ -25,10 +26,12 @@ package org.onap.policy.models.tosca.simple.concepts;
 
 import java.util.LinkedHashMap;
 import java.util.List;
+import javax.persistence.CollectionTable;
 import javax.persistence.ElementCollection;
 import javax.persistence.Entity;
 import javax.persistence.Inheritance;
 import javax.persistence.InheritanceType;
+import javax.persistence.JoinColumn;
 import javax.persistence.Table;
 import javax.ws.rs.core.Response;
 import lombok.Data;
@@ -67,6 +70,10 @@ public class JpaToscaPolicy extends JpaToscaWithTypeAndStringProperties<ToscaPol
     private static final StandardCoder STANDARD_CODER = new StandardCoder();
 
     @ElementCollection
+    @CollectionTable(joinColumns = {
+        @JoinColumn(name = "toscaPolicyName",    referencedColumnName = "name"),
+        @JoinColumn(name = "toscaPolicyVersion",    referencedColumnName = "version")
+    })
     private List<@NotNull @Valid PfConceptKey> targets;
 
     /**
index f6c1a7c..dfdf7ed 100644 (file)
@@ -4,6 +4,7 @@
  * ================================================================================
  * Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved.
  * Modifications Copyright (C) 2019-2020 Nordix Foundation.
+ * Modifications Copyright (C) 2022 Bell Canada. 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.
 package org.onap.policy.models.tosca.simple.concepts;
 
 import java.util.List;
+import javax.persistence.CollectionTable;
 import javax.persistence.ElementCollection;
 import javax.persistence.Entity;
 import javax.persistence.Inheritance;
 import javax.persistence.InheritanceType;
+import javax.persistence.JoinColumn;
+import javax.persistence.Lob;
 import javax.persistence.Table;
 import lombok.Data;
 import lombok.EqualsAndHashCode;
@@ -59,9 +63,14 @@ public class JpaToscaPolicyType extends JpaToscaWithToscaProperties<ToscaPolicyT
     private static final long serialVersionUID = -563659852901842616L;
 
     @ElementCollection
+    @CollectionTable(joinColumns = {
+        @JoinColumn(name = "toscaPolicyTypeName",    referencedColumnName = "name"),
+        @JoinColumn(name = "toscaPolicyTypeVersion",    referencedColumnName = "version")
+    })
     private List<@NotNull @Valid PfConceptKey> targets;
 
     @ElementCollection
+    @Lob
     private List<@NotNull @Valid JpaToscaTrigger> triggers;
 
     /**
index f49c0ea..73b9fab 100644 (file)
@@ -4,6 +4,7 @@
  * ================================================================================
  * Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved.
  * Modifications Copyright (C) 2019-2021 Nordix Foundation.
+ * Modifications Copyright (C) 2022 Bell Canada. 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.
@@ -30,10 +31,6 @@ import java.util.Map;
 import javax.persistence.Column;
 import javax.persistence.ElementCollection;
 import javax.persistence.EmbeddedId;
-import javax.persistence.Entity;
-import javax.persistence.Inheritance;
-import javax.persistence.InheritanceType;
-import javax.persistence.Table;
 import lombok.Data;
 import lombok.EqualsAndHashCode;
 import lombok.NonNull;
@@ -58,9 +55,6 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaProperty.Status;
  * @author Chenfei Gao (cgao@research.att.com)
  * @author Liam Fallon (liam.fallon@est.tech)
  */
-@Entity
-@Table(name = "ToscaProperty")
-@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
 @Data
 @EqualsAndHashCode(callSuper = false)
 public class JpaToscaProperty extends PfConcept implements PfAuthorative<ToscaProperty> {
index 546ea07..1e13b22 100644 (file)
@@ -4,6 +4,7 @@
  * ================================================================================
  * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
  * Modifications Copyright (C) 2019-2021 Nordix Foundation.
+ * Modifications Copyright (C) 2022 Bell Canada. 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.
@@ -28,10 +29,6 @@ import java.time.Duration;
 import java.util.List;
 import javax.persistence.Column;
 import javax.persistence.EmbeddedId;
-import javax.persistence.Entity;
-import javax.persistence.Inheritance;
-import javax.persistence.InheritanceType;
-import javax.persistence.Table;
 import lombok.Data;
 import lombok.EqualsAndHashCode;
 import lombok.NonNull;
@@ -51,9 +48,6 @@ import org.onap.policy.models.base.validation.annotations.VerifyKey;
  * @author Chenfei Gao (cgao@research.att.com)
  * @author Liam Fallon (liam.fallon@est.tech)
  */
-@Entity
-@Table(name = "ToscaTrigger")
-@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
 @Data
 @EqualsAndHashCode(callSuper = false)
 public class JpaToscaTrigger extends PfConcept {