aboutsummaryrefslogtreecommitdiffstats
path: root/models/src/main/java/org
diff options
context:
space:
mode:
authorFrancescoFioraEst <francesco.fiora@est.tech>2022-11-10 12:58:30 +0000
committerFrancesco Fiora <francesco.fiora@est.tech>2022-11-11 09:15:13 +0000
commit5ecf73762474de106166c12e7f4c0f54aa12578d (patch)
treebb4c55b1881ef7453dbee98fc7c98f48d3a3a051 /models/src/main/java/org
parent0e1635767afcc47566ec6971386500d75c66e821 (diff)
Add AutomationCompositionDefinition model
Add AutomationCompositionDefinition model for Commissioned Automation Composition endpoints. Issue-ID: POLICY-4452 Change-Id: I73fc5b06cb75ed578a40ea618f1f5a0eec616b08 Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
Diffstat (limited to 'models/src/main/java/org')
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionDefinition.java50
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionDefinition.java85
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/ProviderUtils.java10
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/AutomationCompositionDefinitionRepository.java31
4 files changed, 175 insertions, 1 deletions
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
index 000000000..9c65b1eff
--- /dev/null
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionDefinition.java
@@ -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
index 000000000..46c09d388
--- /dev/null
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionDefinition.java
@@ -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();
+ }
+
+}
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/ProviderUtils.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/ProviderUtils.java
index 9510e5919..7d751fa36 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/ProviderUtils.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/ProviderUtils.java
@@ -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
index 000000000..64a0a0fb4
--- /dev/null
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/AutomationCompositionDefinitionRepository.java
@@ -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> {
+
+}