From 5ecf73762474de106166c12e7f4c0f54aa12578d Mon Sep 17 00:00:00 2001 From: FrancescoFioraEst Date: Thu, 10 Nov 2022 12:58:30 +0000 Subject: Add AutomationCompositionDefinition model Add AutomationCompositionDefinition model for Commissioned Automation Composition endpoints. Issue-ID: POLICY-4452 Change-Id: I73fc5b06cb75ed578a40ea618f1f5a0eec616b08 Signed-off-by: FrancescoFioraEst --- .../concepts/AutomationCompositionDefinition.java | 50 +++++++++++++ .../JpaAutomationCompositionDefinition.java | 85 ++++++++++++++++++++++ .../acm/persistence/provider/ProviderUtils.java | 10 ++- .../AutomationCompositionDefinitionRepository.java | 31 ++++++++ models/src/test/resources/META-INF/persistence.xml | 1 + 5 files changed, 176 insertions(+), 1 deletion(-) create mode 100644 models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionDefinition.java create mode 100644 models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionDefinition.java create mode 100644 models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/AutomationCompositionDefinitionRepository.java (limited to 'models/src') 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 { + + @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 > 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 > J getJpaAndValidate(A authorativeConcept, Supplier 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 { + +} diff --git a/models/src/test/resources/META-INF/persistence.xml b/models/src/test/resources/META-INF/persistence.xml index f36a5823a..6020f2413 100644 --- a/models/src/test/resources/META-INF/persistence.xml +++ b/models/src/test/resources/META-INF/persistence.xml @@ -52,6 +52,7 @@ org.onap.policy.models.tosca.simple.concepts.JpaToscaTopologyTemplate org.onap.policy.models.tosca.simple.concepts.JpaToscaTrigger org.onap.policy.clamp.models.acm.persistence.concepts.JpaAutomationComposition + org.onap.policy.clamp.models.acm.persistence.concepts.JpaAutomationCompositionDefinition org.onap.policy.clamp.models.acm.persistence.concepts.JpaAutomationCompositionElement org.onap.policy.clamp.models.acm.persistence.concepts.JpaParticipant -- cgit 1.2.3-korg