Add AutomationCompositionDefinition model 43/132143/1
authorFrancescoFioraEst <francesco.fiora@est.tech>
Thu, 10 Nov 2022 12:58:30 +0000 (12:58 +0000)
committerFrancesco Fiora <francesco.fiora@est.tech>
Fri, 11 Nov 2022 09:15:13 +0000 (09:15 +0000)
Add AutomationCompositionDefinition model
for Commissioned Automation Composition endpoints.

Issue-ID: POLICY-4452
Change-Id: I73fc5b06cb75ed578a40ea618f1f5a0eec616b08
Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionDefinition.java [new file with mode: 0644]
models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionDefinition.java [new file with mode: 0644]
models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/ProviderUtils.java
models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/AutomationCompositionDefinitionRepository.java [new file with mode: 0644]
models/src/test/resources/META-INF/persistence.xml

diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionDefinition.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionDefinition.java
new file mode 100644 (file)
index 0000000..9c65b1e
--- /dev/null
@@ -0,0 +1,50 @@
+/*-
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2022 Nordix Foundation.
+ * ================================================================================
+ * 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.clamp.models.acm.concepts;
+
+import java.util.UUID;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.NoArgsConstructor;
+import lombok.NonNull;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
+
+@NoArgsConstructor
+@Data
+@EqualsAndHashCode
+public class AutomationCompositionDefinition {
+
+    @NonNull
+    private UUID compositionId;
+
+    @NonNull
+    private ToscaServiceTemplate serviceTemplate;
+
+    /**
+     * Copy contructor, does a deep copy.
+     *
+     * @param otherAcmDefinition the other element to copy from
+     */
+    public AutomationCompositionDefinition(final AutomationCompositionDefinition otherAcmDefinition) {
+        this.compositionId = otherAcmDefinition.compositionId;
+        this.serviceTemplate = otherAcmDefinition.serviceTemplate;
+    }
+}
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionDefinition.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionDefinition.java
new file mode 100644 (file)
index 0000000..46c09d3
--- /dev/null
@@ -0,0 +1,85 @@
+/*-
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2022 Nordix Foundation.
+ * ================================================================================
+ * 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.clamp.models.acm.persistence.concepts;
+
+import com.google.gson.annotations.SerializedName;
+import java.util.UUID;
+import javax.persistence.CascadeType;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.Id;
+import javax.persistence.Inheritance;
+import javax.persistence.InheritanceType;
+import javax.persistence.OneToOne;
+import javax.persistence.Table;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionDefinition;
+import org.onap.policy.clamp.models.acm.persistence.provider.ProviderUtils;
+import org.onap.policy.common.parameters.annotations.NotNull;
+import org.onap.policy.common.parameters.annotations.Valid;
+import org.onap.policy.models.base.PfAuthorative;
+import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate;
+
+/**
+ * Class to represent a automation composition definition in the database.
+ */
+@Entity
+@Table(name = "AutomationCompositionDefinition")
+@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
+@Data
+@EqualsAndHashCode(callSuper = false)
+public class JpaAutomationCompositionDefinition implements PfAuthorative<AutomationCompositionDefinition> {
+
+    @Id
+    @NotNull
+    private String compositionId;
+
+    @OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true)
+    @SerializedName("serviceTemplate")
+    @Valid
+    private JpaToscaServiceTemplate serviceTemplate;
+
+    @Override
+    public AutomationCompositionDefinition toAuthorative() {
+        var acmDefinition = new AutomationCompositionDefinition();
+        acmDefinition.setCompositionId(UUID.fromString(compositionId));
+        acmDefinition.setServiceTemplate(serviceTemplate.toAuthorative());
+        return acmDefinition;
+    }
+
+    @Override
+    public void fromAuthorative(final AutomationCompositionDefinition copyConcept) {
+        compositionId = copyConcept.getCompositionId().toString();
+        serviceTemplate = ProviderUtils.getJpaAndValidate(copyConcept.getServiceTemplate(),
+                JpaToscaServiceTemplate::new, "toscaServiceTemplate");
+
+    }
+
+    public JpaAutomationCompositionDefinition(final AutomationCompositionDefinition acmDefinition) {
+        fromAuthorative(acmDefinition);
+    }
+
+    public JpaAutomationCompositionDefinition() {
+        super();
+    }
+
+}
index 9510e59..7d751fa 100644 (file)
@@ -64,7 +64,15 @@ public final class ProviderUtils {
         return jpaConceptList;
     }
 
-    protected static <A, J extends PfConcept & PfAuthorative<A>> J getJpaAndValidate(A authorativeConcept,
+    /**
+     * Convert a concept to a Jpa object.
+     *
+     * @param authorativeConcept the concept
+     * @param jpaSupplier  the Jpa Supplier
+     * @param conceptDescription the description used for validation result
+     * @return the Jpa object
+     */
+    public static <A, J extends PfConcept & PfAuthorative<A>> J getJpaAndValidate(A authorativeConcept,
             Supplier<J> jpaSupplier, String conceptDescription) {
         var validationResult = new BeanValidationResult(conceptDescription, authorativeConcept);
 
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/AutomationCompositionDefinitionRepository.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/AutomationCompositionDefinitionRepository.java
new file mode 100644 (file)
index 0000000..64a0a0f
--- /dev/null
@@ -0,0 +1,31 @@
+/*-
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2022 Nordix Foundation.
+ * ================================================================================
+ * 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.clamp.models.acm.persistence.repository;
+
+import org.onap.policy.clamp.models.acm.persistence.concepts.JpaAutomationCompositionDefinition;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.stereotype.Repository;
+
+@Repository
+public interface AutomationCompositionDefinitionRepository
+        extends JpaRepository<JpaAutomationCompositionDefinition, String> {
+
+}
index f36a582..6020f24 100644 (file)
@@ -52,6 +52,7 @@
         <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaTopologyTemplate</class>
         <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaTrigger</class>
         <class>org.onap.policy.clamp.models.acm.persistence.concepts.JpaAutomationComposition</class>
+        <class>org.onap.policy.clamp.models.acm.persistence.concepts.JpaAutomationCompositionDefinition</class>
         <class>org.onap.policy.clamp.models.acm.persistence.concepts.JpaAutomationCompositionElement</class>
         <class>org.onap.policy.clamp.models.acm.persistence.concepts.JpaParticipant</class>