summaryrefslogtreecommitdiffstats
path: root/models/src/main
diff options
context:
space:
mode:
authorFrancescoFioraEst <francesco.fiora@est.tech>2022-11-28 17:31:45 +0000
committerFrancesco Fiora <francesco.fiora@est.tech>2022-11-30 10:44:45 +0000
commit92c372362b9c2dabc4bd0ff3eb6e65ad5659ffb4 (patch)
tree548c03b01ecdb78500d581c8da19b2923a02e468 /models/src/main
parentbff1cfc07634e2a28460deca196b5b877948684e (diff)
Save ToscaServiceTemplate as Json in ACM
Save ToscaServiceTemplate as Json using DocToscaServiceTemplate as model. Issue-ID: POLICY-4468 Change-Id: I4c6f49012d091b87f0da4db2edcd5f16af2f4d5c Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
Diffstat (limited to 'models/src/main')
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/document/base/ToscaServiceTemplateValidation.java38
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaProperty.java3
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaSchemaDefinition.java3
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaWithTypeAndStringProperties.java4
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionDefinition.java30
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AcDefinitionProvider.java33
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/AutomationCompositionDefinitionRepository.java5
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/ToscaServiceTemplateRepository.java30
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/utils/AcmUtils.java33
9 files changed, 85 insertions, 94 deletions
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/document/base/ToscaServiceTemplateValidation.java b/models/src/main/java/org/onap/policy/clamp/models/acm/document/base/ToscaServiceTemplateValidation.java
index 76496780d..c265e6458 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/document/base/ToscaServiceTemplateValidation.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/document/base/ToscaServiceTemplateValidation.java
@@ -29,6 +29,8 @@ import lombok.NoArgsConstructor;
import lombok.NonNull;
import org.onap.policy.clamp.models.acm.document.concepts.DocToscaEntity;
import org.onap.policy.clamp.models.acm.document.concepts.DocToscaServiceTemplate;
+import org.onap.policy.clamp.models.acm.document.concepts.DocToscaTopologyTemplate;
+import org.onap.policy.clamp.models.acm.utils.AcmUtils;
import org.onap.policy.common.parameters.BeanValidationResult;
import org.onap.policy.common.parameters.ValidationStatus;
import org.onap.policy.models.base.Validated;
@@ -37,6 +39,8 @@ import org.onap.policy.models.base.Validated;
public final class ToscaServiceTemplateValidation {
private static final String ROOT_KEY_NAME_SUFFIX = ".Root";
+ private static final String AC_NODE_TYPE_NOT_PRESENT =
+ "NodeTemplate with type " + AcmUtils.AUTOMATION_COMPOSITION_NODE_TYPE + " must exist!";
/**
* validate a serviceTemplate.
@@ -62,6 +66,8 @@ public final class ToscaServiceTemplateValidation {
}
}
+ validateToscaTopologyTemplate(result, serviceTemplate.getToscaTopologyTemplate());
+
if (serviceTemplate.getToscaTopologyTemplate() != null) {
validEntityTypeAncestors(serviceTemplate.getToscaTopologyTemplate().getNodeTemplates(),
references.get(DocUtil.REF_NODE_TEMPLATES), result);
@@ -85,6 +91,32 @@ public final class ToscaServiceTemplateValidation {
}
/**
+ * Validate ToscaTopologyTemplate.
+ *
+ * @param result
+ *
+ * @param topologyTemplate the ToscaServiceTemplate
+ */
+ public static void validateToscaTopologyTemplate(BeanValidationResult result,
+ DocToscaTopologyTemplate topologyTemplate) {
+ if (topologyTemplate != null && topologyTemplate.getNodeTemplates() != null) {
+ var nodeTemplates = topologyTemplate.getNodeTemplates();
+ var acNumber = nodeTemplates.values().stream().filter(
+ nodeTemplate -> AcmUtils.AUTOMATION_COMPOSITION_NODE_TYPE.equals(nodeTemplate.getType()))
+ .count();
+ if (acNumber == 0) {
+ result.addResult("TopologyTemplate", nodeTemplates, ValidationStatus.INVALID, AC_NODE_TYPE_NOT_PRESENT);
+ }
+ if (acNumber > 1) {
+ result.addResult("TopologyTemplate", nodeTemplates, ValidationStatus.INVALID, "NodeTemplate with type "
+ + AcmUtils.AUTOMATION_COMPOSITION_NODE_TYPE + " not allowed to be more than one!");
+ }
+ } else {
+ result.addResult("TopologyTemplate", topologyTemplate, ValidationStatus.INVALID, AC_NODE_TYPE_NOT_PRESENT);
+ }
+ }
+
+ /**
* Validate that all data types referenced in policy types exist.
*
* @param result where the results are added
@@ -199,8 +231,7 @@ public final class ToscaServiceTemplateValidation {
continue;
}
if (!isTypePresent(parentEntityTypeKey, reference)) {
- result.addResult("parent", parentEntityTypeKey, ValidationStatus.INVALID,
- Validated.NOT_FOUND);
+ result.addResult("parent", parentEntityTypeKey, ValidationStatus.INVALID, Validated.NOT_FOUND);
}
}
}
@@ -222,8 +253,7 @@ public final class ToscaServiceTemplateValidation {
continue;
}
if (!isTypePresent(parentEntityTypeKey, reference)) {
- result.addResult("parent", parentEntityTypeKey, ValidationStatus.INVALID,
- Validated.NOT_FOUND);
+ result.addResult("parent", parentEntityTypeKey, ValidationStatus.INVALID, Validated.NOT_FOUND);
}
}
}
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaProperty.java b/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaProperty.java
index 1bcbd6b0a..cdd1ab947 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaProperty.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaProperty.java
@@ -106,7 +106,8 @@ public class DocToscaProperty implements PfAuthorative<ToscaProperty>, Serializa
var toscaProperty = new ToscaProperty();
toscaProperty.setName(name);
- toscaProperty.setType(getTypeDocConceptKey().getId());
+ toscaProperty.setType(type);
+ toscaProperty.setTypeVersion(typeVersion);
toscaProperty.setDescription(description);
toscaProperty.setRequired(required);
toscaProperty.setStatus(status);
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaSchemaDefinition.java b/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaSchemaDefinition.java
index 89b3c42cd..f13ad6c41 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaSchemaDefinition.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaSchemaDefinition.java
@@ -70,7 +70,8 @@ public class DocToscaSchemaDefinition
var toscaEntrySchema = new ToscaSchemaDefinition();
toscaEntrySchema.setName(name);
- toscaEntrySchema.setType(getTypeDocConceptKey().getId());
+ toscaEntrySchema.setType(type);
+ toscaEntrySchema.setTypeVersion(typeVersion);
toscaEntrySchema.setDescription(description);
if (constraints != null) {
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaWithTypeAndStringProperties.java b/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaWithTypeAndStringProperties.java
index 377cecb28..025aafb07 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaWithTypeAndStringProperties.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaWithTypeAndStringProperties.java
@@ -66,8 +66,8 @@ public class DocToscaWithTypeAndStringProperties<T extends ToscaWithTypeAndObjec
public T toAuthorative() {
var tosca = super.toAuthorative();
- tosca.setType(getTypeDocConceptKey().getId());
- tosca.setTypeVersion("");
+ tosca.setType(type);
+ tosca.setTypeVersion(typeVersion);
tosca.setProperties(PfUtils.mapMap(properties, x -> x));
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
index 247d8f28c..c46bdb96c 100644
--- 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
@@ -20,27 +20,25 @@
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.Convert;
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.Lob;
import javax.persistence.Table;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NonNull;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionDefinition;
-import org.onap.policy.clamp.models.acm.utils.AcmUtils;
+import org.onap.policy.clamp.models.acm.document.base.ToscaServiceTemplateValidation;
+import org.onap.policy.clamp.models.acm.document.concepts.DocToscaServiceTemplate;
import org.onap.policy.common.parameters.BeanValidationResult;
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.base.Validated;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate;
/**
* Class to represent a automation composition definition in the database.
@@ -57,10 +55,17 @@ public class JpaAutomationCompositionDefinition extends Validated
@NotNull
private String compositionId;
- @OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true)
- @SerializedName("serviceTemplate")
+ @NotNull
+ private String name;
+
+ @NotNull
+ private String version;
+
+ @Lob
+ @Convert(converter = StringToServiceTemplateConverter.class)
+ @NotNull
@Valid
- private JpaToscaServiceTemplate serviceTemplate;
+ private DocToscaServiceTemplate serviceTemplate;
@Override
public AutomationCompositionDefinition toAuthorative() {
@@ -73,7 +78,9 @@ public class JpaAutomationCompositionDefinition extends Validated
@Override
public void fromAuthorative(final AutomationCompositionDefinition copyConcept) {
compositionId = copyConcept.getCompositionId().toString();
- serviceTemplate = new JpaToscaServiceTemplate(copyConcept.getServiceTemplate());
+ serviceTemplate = new DocToscaServiceTemplate(copyConcept.getServiceTemplate());
+ setName(serviceTemplate.getName());
+ setVersion(serviceTemplate.getVersion());
}
public JpaAutomationCompositionDefinition(final AutomationCompositionDefinition acmDefinition) {
@@ -87,8 +94,7 @@ public class JpaAutomationCompositionDefinition extends Validated
@Override
public BeanValidationResult validate(@NonNull String fieldName) {
var result = super.validate(fieldName);
-
- AcmUtils.validateToscaTopologyTemplate(result, serviceTemplate);
+ ToscaServiceTemplateValidation.validate(result, serviceTemplate);
if (!result.isValid()) {
return result;
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AcDefinitionProvider.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AcDefinitionProvider.java
index dc1785e52..12a05946e 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AcDefinitionProvider.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AcDefinitionProvider.java
@@ -23,15 +23,16 @@ package org.onap.policy.clamp.models.acm.persistence.provider;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
+import java.util.stream.Collectors;
import javax.ws.rs.core.Response;
import lombok.RequiredArgsConstructor;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionDefinition;
+import org.onap.policy.clamp.models.acm.document.concepts.DocToscaServiceTemplate;
import org.onap.policy.clamp.models.acm.persistence.concepts.JpaAutomationCompositionDefinition;
import org.onap.policy.clamp.models.acm.persistence.repository.AutomationCompositionDefinitionRepository;
-import org.onap.policy.clamp.models.acm.persistence.repository.ToscaServiceTemplateRepository;
import org.onap.policy.models.base.PfModelRuntimeException;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate;
+import org.springframework.data.domain.Example;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -40,7 +41,6 @@ import org.springframework.transaction.annotation.Transactional;
@RequiredArgsConstructor
public class AcDefinitionProvider {
- private final ToscaServiceTemplateRepository serviceTemplateRepository;
private final AutomationCompositionDefinitionRepository acmDefinitionRepository;
/**
@@ -68,9 +68,12 @@ public class AcDefinitionProvider {
* @param serviceTemplate the service template to be created
*/
public void updateServiceTemplate(UUID compositionId, ToscaServiceTemplate serviceTemplate) {
- var jpaServiceTemplate =
- ProviderUtils.getJpaAndValidate(serviceTemplate, JpaToscaServiceTemplate::new, "toscaServiceTemplate");
- serviceTemplateRepository.save(jpaServiceTemplate);
+ var acmDefinition = new AutomationCompositionDefinition();
+ acmDefinition.setCompositionId(compositionId);
+ acmDefinition.setServiceTemplate(serviceTemplate);
+ var jpaAcmDefinition = ProviderUtils.getJpaAndValidate(acmDefinition, JpaAutomationCompositionDefinition::new,
+ "AutomationCompositionDefinition");
+ acmDefinitionRepository.save(jpaAcmDefinition);
}
/**
@@ -88,7 +91,6 @@ public class AcDefinitionProvider {
}
var item = jpaDelete.get().getServiceTemplate();
- serviceTemplateRepository.deleteById(item.getKey());
acmDefinitionRepository.deleteById(compositionId.toString());
return item.toAuthorative();
}
@@ -120,7 +122,7 @@ public class AcDefinitionProvider {
public Optional<ToscaServiceTemplate> findAcDefinition(UUID compositionId) {
var jpaGet = acmDefinitionRepository.findById(compositionId.toString());
return jpaGet.stream().map(JpaAutomationCompositionDefinition::getServiceTemplate)
- .map(JpaToscaServiceTemplate::toAuthorative).findFirst();
+ .map(DocToscaServiceTemplate::toAuthorative).findFirst();
}
/**
@@ -143,7 +145,18 @@ public class AcDefinitionProvider {
*/
@Transactional(readOnly = true)
public List<ToscaServiceTemplate> getServiceTemplateList(final String name, final String version) {
- var jpaList = serviceTemplateRepository.getFiltered(JpaToscaServiceTemplate.class, name, version);
- return ProviderUtils.asEntityList(jpaList);
+ List<JpaAutomationCompositionDefinition> jpaList = null;
+ if (name != null || version != null) {
+ var entity = new JpaAutomationCompositionDefinition();
+ entity.setName(name);
+ entity.setVersion(version);
+ var example = Example.of(entity);
+ jpaList = acmDefinitionRepository.findAll(example);
+ } else {
+ jpaList = acmDefinitionRepository.findAll();
+ }
+
+ return jpaList.stream().map(JpaAutomationCompositionDefinition::getServiceTemplate)
+ .map(DocToscaServiceTemplate::toAuthorative).collect(Collectors.toList());
}
}
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
index 64a0a0fb4..df4d7dffa 100644
--- 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
@@ -22,10 +22,11 @@ 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.data.repository.query.QueryByExampleExecutor;
import org.springframework.stereotype.Repository;
@Repository
public interface AutomationCompositionDefinitionRepository
- extends JpaRepository<JpaAutomationCompositionDefinition, String> {
-
+ extends JpaRepository<JpaAutomationCompositionDefinition, String>,
+ QueryByExampleExecutor<JpaAutomationCompositionDefinition> {
}
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/ToscaServiceTemplateRepository.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/ToscaServiceTemplateRepository.java
deleted file mode 100644
index b9190d0a7..000000000
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/ToscaServiceTemplateRepository.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2021 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.models.base.PfConceptKey;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate;
-import org.springframework.data.jpa.repository.JpaRepository;
-
-public interface ToscaServiceTemplateRepository
- extends JpaRepository<JpaToscaServiceTemplate, PfConceptKey>, FilterRepository {
-
-}
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/utils/AcmUtils.java b/models/src/main/java/org/onap/policy/clamp/models/acm/utils/AcmUtils.java
index a8203484a..cdd3e1e54 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/utils/AcmUtils.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/utils/AcmUtils.java
@@ -48,7 +48,6 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeType;
import org.onap.policy.models.tosca.authorative.concepts.ToscaProperty;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
import org.onap.policy.models.tosca.authorative.concepts.ToscaTopologyTemplate;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate;
/**
* Utility functions used in acm-runtime and participants.
@@ -57,9 +56,7 @@ import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate;
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class AcmUtils {
- private static final String AUTOMATION_COMPOSITION_NODE_TYPE = "org.onap.policy.clamp.acm.AutomationComposition";
- private static final String AC_NODE_TYPE_NOT_PRESENT =
- "NodeTemplate with type " + AUTOMATION_COMPOSITION_NODE_TYPE + " must exist!";
+ public static final String AUTOMATION_COMPOSITION_NODE_TYPE = "org.onap.policy.clamp.acm.AutomationComposition";
public static final String ENTRY = "entry ";
/**
@@ -356,32 +353,4 @@ public final class AcmUtils {
return getFinalNodeTypesMap(serviceTemplate.getNodeTypes(), tempNodeTypesMap);
}
-
- /**
- * Validate ToscaTopologyTemplate.
- *
- * @param result
- *
- * @param serviceTemplate the ToscaServiceTemplate
- */
- public static void validateToscaTopologyTemplate(BeanValidationResult result,
- JpaToscaServiceTemplate serviceTemplate) {
- if (serviceTemplate.getTopologyTemplate() != null
- && serviceTemplate.getTopologyTemplate().getNodeTemplates() != null) {
- var nodeTemplates = serviceTemplate.getTopologyTemplate().getNodeTemplates();
- var acNumber = nodeTemplates.getConceptMap().values().stream()
- .filter(nodeTemplate -> AUTOMATION_COMPOSITION_NODE_TYPE.equals(nodeTemplate.getType().getName()))
- .count();
- if (acNumber == 0) {
- result.addResult("TopologyTemplate", nodeTemplates, ValidationStatus.INVALID, AC_NODE_TYPE_NOT_PRESENT);
- }
- if (acNumber > 1) {
- result.addResult("TopologyTemplate", nodeTemplates, ValidationStatus.INVALID, "NodeTemplate with type "
- + AUTOMATION_COMPOSITION_NODE_TYPE + " not allowed to be more than one!");
- }
- } else {
- result.addResult("ServiceTemplate", serviceTemplate, ValidationStatus.INVALID, AC_NODE_TYPE_NOT_PRESENT);
- }
- }
-
}