aboutsummaryrefslogtreecommitdiffstats
path: root/models/src/main
diff options
context:
space:
mode:
authorLiam Fallon <liam.fallon@est.tech>2022-11-28 14:59:43 +0000
committerGerrit Code Review <gerrit@onap.org>2022-11-28 14:59:43 +0000
commitbff1cfc07634e2a28460deca196b5b877948684e (patch)
treead7c573b593c37e6ec789d91fa633999f877de53 /models/src/main
parentfb321a1af5a5ad0b7ccbc13aab54b9a1e77af5f8 (diff)
parent933f1325044e6233ca0da1eecf223bc5bbb06b36 (diff)
Merge "Link the AutomationComposition with AutomationCompositionDefinition"
Diffstat (limited to 'models/src/main')
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationComposition.java16
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationComposition.java43
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionDefinition.java24
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AcDefinitionProvider.java27
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AutomationCompositionProvider.java80
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/ProviderUtils.java6
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/AutomationCompositionRepository.java5
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/ToscaNodeTemplateRepository.java30
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/utils/AcmUtils.java46
9 files changed, 124 insertions, 153 deletions
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationComposition.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationComposition.java
index 4736d3190..c3245d27c 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationComposition.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationComposition.java
@@ -27,9 +27,7 @@ import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import org.apache.commons.collections4.MapUtils;
-import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.base.PfUtils;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
import org.onap.policy.models.tosca.authorative.concepts.ToscaEntity;
/**
@@ -40,7 +38,7 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaEntity;
@EqualsAndHashCode(callSuper = true)
public class AutomationComposition extends ToscaEntity implements Comparable<AutomationComposition> {
@NonNull
- private ToscaConceptIdentifier definition = new ToscaConceptIdentifier(PfConceptKey.getNullKey());
+ private UUID compositionId;
@NonNull
private AutomationCompositionState state = AutomationCompositionState.UNINITIALISED;
@@ -53,16 +51,6 @@ public class AutomationComposition extends ToscaEntity implements Comparable<Aut
@NonNull
private Boolean primed = false;
- @Override
- public String getType() {
- return definition.getName();
- }
-
- @Override
- public String getTypeVersion() {
- return definition.getVersion();
- }
-
/**
* Copy contructor, does a deep copy.
*
@@ -70,7 +58,7 @@ public class AutomationComposition extends ToscaEntity implements Comparable<Aut
*/
public AutomationComposition(final AutomationComposition otherAutomationComposition) {
super(otherAutomationComposition);
- this.definition = new ToscaConceptIdentifier(otherAutomationComposition.definition);
+ this.compositionId = otherAutomationComposition.compositionId;
this.state = otherAutomationComposition.state;
this.orderedState = otherAutomationComposition.orderedState;
this.elements = PfUtils.mapMap(otherAutomationComposition.elements, AutomationCompositionElement::new);
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationComposition.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationComposition.java
index e5c44d0a2..8268e9066 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationComposition.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationComposition.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021 Nordix Foundation.
+ * Copyright (C) 2021-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.
@@ -25,12 +25,12 @@ import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.UUID;
-import javax.persistence.AttributeOverride;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.FetchType;
+import javax.persistence.Index;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.ManyToMany;
@@ -52,7 +52,6 @@ import org.onap.policy.models.base.PfKey;
import org.onap.policy.models.base.PfReferenceKey;
import org.onap.policy.models.base.PfUtils;
import org.onap.policy.models.base.validation.annotations.VerifyKey;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
/**
* Class to represent a automation composition in the database.
@@ -60,7 +59,7 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
* @author Liam Fallon (liam.fallon@est.tech)
*/
@Entity
-@Table(name = "AutomationComposition")
+@Table(name = "AutomationComposition", indexes = {@Index(name = "ac_compositionId", columnList = "compositionId")})
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@Data
@EqualsAndHashCode(callSuper = false)
@@ -72,13 +71,8 @@ public class JpaAutomationComposition extends PfConcept implements PfAuthorative
@NotNull
private PfConceptKey key;
- // @formatter:off
- @VerifyKey
@NotNull
- @AttributeOverride(name = "name", column = @Column(name = "definition_name"))
- @AttributeOverride(name = "version", column = @Column(name = "definition_version"))
- private PfConceptKey definition;
- // @formatter:on
+ private String compositionId;
@Column
@NotNull
@@ -112,22 +106,22 @@ public class JpaAutomationComposition extends PfConcept implements PfAuthorative
* @param key the key
*/
public JpaAutomationComposition(@NonNull final PfConceptKey key) {
- this(key, new PfConceptKey(), AutomationCompositionState.UNINITIALISED, new LinkedHashMap<>());
+ this(key, UUID.randomUUID().toString(), AutomationCompositionState.UNINITIALISED, new LinkedHashMap<>());
}
/**
* The Key Constructor creates a {@link JpaAutomationComposition} object with all mandatory fields.
*
* @param key the key
- * @param definition the TOSCA definition of the automation composition
+ * @param compositionId the TOSCA compositionId of the automation composition definition
* @param state the state of the automation composition
* @param elements the elements of the automation composition in participants
*/
- public JpaAutomationComposition(@NonNull final PfConceptKey key, @NonNull final PfConceptKey definition,
- @NonNull final AutomationCompositionState state,
- @NonNull final Map<UUID, JpaAutomationCompositionElement> elements) {
+ public JpaAutomationComposition(@NonNull final PfConceptKey key, @NonNull final String compositionId,
+ @NonNull final AutomationCompositionState state,
+ @NonNull final Map<UUID, JpaAutomationCompositionElement> elements) {
this.key = key;
- this.definition = definition;
+ this.compositionId = compositionId;
this.state = state;
this.elements = elements;
}
@@ -140,12 +134,12 @@ public class JpaAutomationComposition extends PfConcept implements PfAuthorative
public JpaAutomationComposition(@NonNull final JpaAutomationComposition copyConcept) {
super(copyConcept);
this.key = new PfConceptKey(copyConcept.key);
- this.definition = new PfConceptKey(copyConcept.definition);
+ this.compositionId = copyConcept.compositionId;
this.state = copyConcept.state;
this.orderedState = copyConcept.orderedState;
this.description = copyConcept.description;
this.elements =
- PfUtils.mapMap(copyConcept.elements, JpaAutomationCompositionElement::new, new LinkedHashMap<>(0));
+ PfUtils.mapMap(copyConcept.elements, JpaAutomationCompositionElement::new, new LinkedHashMap<>(0));
this.primed = copyConcept.primed;
}
@@ -164,12 +158,12 @@ public class JpaAutomationComposition extends PfConcept implements PfAuthorative
automationComposition.setName(getKey().getName());
automationComposition.setVersion(getKey().getVersion());
- automationComposition.setDefinition(new ToscaConceptIdentifier(definition));
+ automationComposition.setCompositionId(UUID.fromString(compositionId));
automationComposition.setState(state);
automationComposition.setOrderedState(orderedState != null ? orderedState : state.asOrderedState());
automationComposition.setDescription(description);
automationComposition.setElements(
- PfUtils.mapMap(elements, JpaAutomationCompositionElement::toAuthorative, new LinkedHashMap<>(0)));
+ PfUtils.mapMap(elements, JpaAutomationCompositionElement::toAuthorative, new LinkedHashMap<>(0)));
automationComposition.setPrimed(primed);
return automationComposition;
@@ -181,7 +175,7 @@ public class JpaAutomationComposition extends PfConcept implements PfAuthorative
this.setKey(new PfConceptKey(automationComposition.getName(), automationComposition.getVersion()));
}
- this.definition = automationComposition.getDefinition().asConceptKey();
+ this.compositionId = automationComposition.getCompositionId().toString();
this.state = automationComposition.getState();
this.orderedState = automationComposition.getOrderedState();
this.description = automationComposition.getDescription();
@@ -191,7 +185,7 @@ public class JpaAutomationComposition extends PfConcept implements PfAuthorative
for (Entry<UUID, AutomationCompositionElement> elementEntry : automationComposition.getElements().entrySet()) {
var jpaAutomationCompositionElement = new JpaAutomationCompositionElement();
jpaAutomationCompositionElement
- .setKey(new PfReferenceKey(getKey(), elementEntry.getValue().getId().toString()));
+ .setKey(new PfReferenceKey(getKey(), elementEntry.getValue().getId().toString()));
jpaAutomationCompositionElement.fromAuthorative(elementEntry.getValue());
this.elements.put(elementEntry.getKey(), jpaAutomationCompositionElement);
}
@@ -201,8 +195,6 @@ public class JpaAutomationComposition extends PfConcept implements PfAuthorative
public List<PfKey> getKeys() {
List<PfKey> keyList = getKey().getKeys();
- keyList.add(definition);
-
for (JpaAutomationCompositionElement element : elements.values()) {
keyList.addAll(element.getKeys());
}
@@ -213,7 +205,6 @@ public class JpaAutomationComposition extends PfConcept implements PfAuthorative
@Override
public void clean() {
key.clean();
- definition.clean();
description = (description == null ? null : description.trim());
for (JpaAutomationCompositionElement element : elements.values()) {
@@ -239,7 +230,7 @@ public class JpaAutomationComposition extends PfConcept implements PfAuthorative
return result;
}
- result = definition.compareTo(other.definition);
+ result = ObjectUtils.compare(compositionId, other.compositionId);
if (result != 0) {
return result;
}
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 46c09d388..247d8f28c 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
@@ -32,11 +32,14 @@ import javax.persistence.OneToOne;
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.persistence.provider.ProviderUtils;
+import org.onap.policy.clamp.models.acm.utils.AcmUtils;
+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;
/**
@@ -47,7 +50,8 @@ import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate;
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@Data
@EqualsAndHashCode(callSuper = false)
-public class JpaAutomationCompositionDefinition implements PfAuthorative<AutomationCompositionDefinition> {
+public class JpaAutomationCompositionDefinition extends Validated
+ implements PfAuthorative<AutomationCompositionDefinition> {
@Id
@NotNull
@@ -69,9 +73,7 @@ public class JpaAutomationCompositionDefinition implements PfAuthorative<Automat
@Override
public void fromAuthorative(final AutomationCompositionDefinition copyConcept) {
compositionId = copyConcept.getCompositionId().toString();
- serviceTemplate = ProviderUtils.getJpaAndValidate(copyConcept.getServiceTemplate(),
- JpaToscaServiceTemplate::new, "toscaServiceTemplate");
-
+ serviceTemplate = new JpaToscaServiceTemplate(copyConcept.getServiceTemplate());
}
public JpaAutomationCompositionDefinition(final AutomationCompositionDefinition acmDefinition) {
@@ -82,4 +84,16 @@ public class JpaAutomationCompositionDefinition implements PfAuthorative<Automat
super();
}
+ @Override
+ public BeanValidationResult validate(@NonNull String fieldName) {
+ var result = super.validate(fieldName);
+
+ AcmUtils.validateToscaTopologyTemplate(result, serviceTemplate);
+
+ if (!result.isValid()) {
+ return result;
+ }
+
+ 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 5740207c7..dc1785e52 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
@@ -21,6 +21,7 @@
package org.onap.policy.clamp.models.acm.persistence.provider;
import java.util.List;
+import java.util.Optional;
import java.util.UUID;
import javax.ws.rs.core.Response;
import lombok.RequiredArgsConstructor;
@@ -53,7 +54,10 @@ public class AcDefinitionProvider {
var acmDefinition = new AutomationCompositionDefinition();
acmDefinition.setCompositionId(UUID.randomUUID());
acmDefinition.setServiceTemplate(serviceTemplate);
- var result = acmDefinitionRepository.save(new JpaAutomationCompositionDefinition(acmDefinition));
+ var jpaAcmDefinition = ProviderUtils.getJpaAndValidate(acmDefinition, JpaAutomationCompositionDefinition::new,
+ "AutomationCompositionDefinition");
+ var result = acmDefinitionRepository.save(jpaAcmDefinition);
+
return result.toAuthorative();
}
@@ -107,13 +111,26 @@ public class AcDefinitionProvider {
}
/**
- * Get service templates.
+ * Get the requested automation composition definition.
*
- * @return the topology templates found
+ * @param compositionId The UUID of the automation composition definition to delete
+ * @return the automation composition definition
+ */
+ @Transactional(readOnly = true)
+ public Optional<ToscaServiceTemplate> findAcDefinition(UUID compositionId) {
+ var jpaGet = acmDefinitionRepository.findById(compositionId.toString());
+ return jpaGet.stream().map(JpaAutomationCompositionDefinition::getServiceTemplate)
+ .map(JpaToscaServiceTemplate::toAuthorative).findFirst();
+ }
+
+ /**
+ * Get Automation Composition Definitions.
+ *
+ * @return the Automation Composition Definitions found
*/
@Transactional(readOnly = true)
- public List<ToscaServiceTemplate> getAllServiceTemplates() {
- var jpaList = serviceTemplateRepository.findAll();
+ public List<AutomationCompositionDefinition> getAllAcDefinitions() {
+ var jpaList = acmDefinitionRepository.findAll();
return ProviderUtils.asEntityList(jpaList);
}
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AutomationCompositionProvider.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AutomationCompositionProvider.java
index c4f8b91e7..272ea422b 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AutomationCompositionProvider.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AutomationCompositionProvider.java
@@ -24,6 +24,7 @@ package org.onap.policy.clamp.models.acm.persistence.provider;
import java.util.List;
import java.util.Optional;
+import java.util.UUID;
import javax.persistence.EntityNotFoundException;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
@@ -32,13 +33,9 @@ import lombok.NonNull;
import org.onap.policy.clamp.models.acm.concepts.AutomationComposition;
import org.onap.policy.clamp.models.acm.persistence.concepts.JpaAutomationComposition;
import org.onap.policy.clamp.models.acm.persistence.repository.AutomationCompositionRepository;
-import org.onap.policy.clamp.models.acm.persistence.repository.ToscaNodeTemplateRepository;
import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaTypedEntityFilter;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaNodeTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -51,7 +48,6 @@ import org.springframework.transaction.annotation.Transactional;
public class AutomationCompositionProvider {
private final AutomationCompositionRepository automationCompositionRepository;
- private final ToscaNodeTemplateRepository toscaNodeTemplateRepository;
/**
* Get automation composition.
@@ -62,7 +58,7 @@ public class AutomationCompositionProvider {
*/
@Transactional(readOnly = true)
public AutomationComposition getAutomationComposition(final ToscaConceptIdentifier automationCompositionId)
- throws PfModelException {
+ throws PfModelException {
try {
return automationCompositionRepository.getById(automationCompositionId.asConceptKey()).toAuthorative();
} catch (EntityNotFoundException e) {
@@ -80,7 +76,7 @@ public class AutomationCompositionProvider {
*/
@Transactional(readOnly = true)
public Optional<AutomationComposition> findAutomationComposition(@NonNull final String name,
- @NonNull final String version) throws PfModelException {
+ @NonNull final String version) throws PfModelException {
return findAutomationComposition(new PfConceptKey(name, version));
}
@@ -93,12 +89,12 @@ public class AutomationCompositionProvider {
*/
@Transactional(readOnly = true)
public Optional<AutomationComposition> findAutomationComposition(
- final ToscaConceptIdentifier automationCompositionId) throws PfModelException {
+ final ToscaConceptIdentifier automationCompositionId) throws PfModelException {
return findAutomationComposition(automationCompositionId.asConceptKey());
}
private Optional<AutomationComposition> findAutomationComposition(@NonNull final PfConceptKey key)
- throws PfModelException {
+ throws PfModelException {
try {
return automationCompositionRepository.findById(key).map(JpaAutomationComposition::toAuthorative);
} catch (IllegalArgumentException e) {
@@ -114,10 +110,10 @@ public class AutomationCompositionProvider {
* @throws PfModelException on errors updating the automation composition
*/
public AutomationComposition saveAutomationComposition(final AutomationComposition automationComposition)
- throws PfModelException {
+ throws PfModelException {
try {
var result = automationCompositionRepository.save(ProviderUtils.getJpaAndValidate(automationComposition,
- JpaAutomationComposition::new, "automation composition"));
+ JpaAutomationComposition::new, "automation composition"));
// Return the saved participant
return result.toAuthorative();
@@ -127,14 +123,15 @@ public class AutomationCompositionProvider {
}
/**
- * Get all automation compositions.
+ * Get all automation compositions by compositionId.
*
+ * @param compositionId the compositionId of the automation composition definition
* @return all automation compositions found
*/
@Transactional(readOnly = true)
- public List<AutomationComposition> getAutomationCompositions() {
-
- return ProviderUtils.asEntityList(automationCompositionRepository.findAll());
+ public List<AutomationComposition> getAcInstancesByCompositionId(UUID compositionId) {
+ return ProviderUtils
+ .asEntityList(automationCompositionRepository.findByCompositionId(compositionId.toString()));
}
/**
@@ -147,8 +144,8 @@ public class AutomationCompositionProvider {
@Transactional(readOnly = true)
public List<AutomationComposition> getAutomationCompositions(final String name, final String version) {
- return ProviderUtils
- .asEntityList(automationCompositionRepository.getFiltered(JpaAutomationComposition.class, name, version));
+ return ProviderUtils.asEntityList(
+ automationCompositionRepository.getFiltered(JpaAutomationComposition.class, name, version));
}
/**
@@ -159,11 +156,11 @@ public class AutomationCompositionProvider {
* @throws PfModelException on errors creating automation compositions
*/
public List<AutomationComposition> saveAutomationCompositions(
- @NonNull final List<AutomationComposition> automationCompositions) throws PfModelException {
+ @NonNull final List<AutomationComposition> automationCompositions) throws PfModelException {
try {
var result =
- automationCompositionRepository.saveAll(ProviderUtils.getJpaAndValidateList(automationCompositions,
- JpaAutomationComposition::new, "automation compositions"));
+ automationCompositionRepository.saveAll(ProviderUtils.getJpaAndValidateList(automationCompositions,
+ JpaAutomationComposition::new, "automation compositions"));
// Return the saved participant
return ProviderUtils.asEntityList(result);
@@ -181,14 +178,14 @@ public class AutomationCompositionProvider {
* @throws PfModelException on errors deleting the automation composition
*/
public AutomationComposition deleteAutomationComposition(@NonNull final String name, @NonNull final String version)
- throws PfModelException {
+ throws PfModelException {
var automationCompositionKey = new PfConceptKey(name, version);
var jpaDeleteAutomationComposition = automationCompositionRepository.findById(automationCompositionKey);
if (jpaDeleteAutomationComposition.isEmpty()) {
String errorMessage = "delete of automation composition \"" + automationCompositionKey.getId()
- + "\" failed, automation composition does not exist";
+ + "\" failed, automation composition does not exist";
throw new PfModelException(Response.Status.NOT_FOUND, errorMessage);
}
@@ -196,43 +193,4 @@ public class AutomationCompositionProvider {
return jpaDeleteAutomationComposition.get().toAuthorative();
}
-
- /**
- * Get All Node Templates.
- *
- * @return the list of node templates found
- */
- @Transactional(readOnly = true)
- public List<ToscaNodeTemplate> getAllNodeTemplates() {
- return ProviderUtils.asEntityList(toscaNodeTemplateRepository.findAll());
- }
-
- /**
- * Get Node Templates.
- *
- * @param name the name of the node template to get, null to get all node templates
- * @param version the version of the node template to get, null to get all node templates
- * @return the node templates found
- * @throws PfModelException on errors getting node templates
- */
- @Transactional(readOnly = true)
- public List<ToscaNodeTemplate> getNodeTemplates(final String name, final String version) {
- return ProviderUtils
- .asEntityList(toscaNodeTemplateRepository.getFiltered(JpaToscaNodeTemplate.class, name, version));
- }
-
- /**
- * Get filtered node templates.
- *
- * @param filter the filter for the node templates to get
- * @return the node templates found
- * @throws PfModelException on errors getting node templates
- */
- @Transactional(readOnly = true)
- public List<ToscaNodeTemplate> getFilteredNodeTemplates(
- @NonNull final ToscaTypedEntityFilter<ToscaNodeTemplate> filter) {
-
- return filter.filter(ProviderUtils.asEntityList(toscaNodeTemplateRepository
- .getFiltered(JpaToscaNodeTemplate.class, filter.getName(), filter.getVersion())));
- }
}
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 7d751fa36..9dc07ae72 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
@@ -31,7 +31,7 @@ import org.onap.policy.common.parameters.BeanValidationResult;
import org.onap.policy.models.base.PfAuthorative;
import org.onap.policy.models.base.PfConcept;
import org.onap.policy.models.base.PfModelRuntimeException;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaEntity;
+import org.onap.policy.models.base.Validated;
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class ProviderUtils {
@@ -72,7 +72,7 @@ public final class ProviderUtils {
* @param conceptDescription the description used for validation result
* @return the Jpa object
*/
- public static <A, J extends PfConcept & PfAuthorative<A>> J getJpaAndValidate(A authorativeConcept,
+ public static <A, J extends Validated & PfAuthorative<A>> J getJpaAndValidate(A authorativeConcept,
Supplier<J> jpaSupplier, String conceptDescription) {
var validationResult = new BeanValidationResult(conceptDescription, authorativeConcept);
@@ -95,7 +95,7 @@ public final class ProviderUtils {
* @param jpaEntityList the list to convert
* @return the authorative list
*/
- public static <T extends ToscaEntity, J extends PfAuthorative<T>> List<T> asEntityList(List<J> jpaEntityList) {
+ public static <T, J extends PfAuthorative<T>> List<T> asEntityList(List<J> jpaEntityList) {
return jpaEntityList.stream().map(J::toAuthorative).collect(Collectors.toList());
}
}
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/AutomationCompositionRepository.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/AutomationCompositionRepository.java
index 8eeb77e0d..273b99a63 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/AutomationCompositionRepository.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/AutomationCompositionRepository.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021 Nordix Foundation.
+ * Copyright (C) 2021-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.
@@ -20,6 +20,7 @@
package org.onap.policy.clamp.models.acm.persistence.repository;
+import java.util.List;
import org.onap.policy.clamp.models.acm.persistence.concepts.JpaAutomationComposition;
import org.onap.policy.models.base.PfConceptKey;
import org.springframework.data.jpa.repository.JpaRepository;
@@ -28,4 +29,6 @@ import org.springframework.stereotype.Repository;
@Repository
public interface AutomationCompositionRepository
extends JpaRepository<JpaAutomationComposition, PfConceptKey>, FilterRepository {
+
+ List<JpaAutomationComposition> findByCompositionId(String compositionId);
}
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/ToscaNodeTemplateRepository.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/ToscaNodeTemplateRepository.java
deleted file mode 100644
index 20d0f0f7e..000000000
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/ToscaNodeTemplateRepository.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.JpaToscaNodeTemplate;
-import org.springframework.data.jpa.repository.JpaRepository;
-
-public interface ToscaNodeTemplateRepository
- extends JpaRepository<JpaToscaNodeTemplate, 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 283edd49e..a8203484a 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,6 +48,7 @@ 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,6 +58,8 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaTopologyTemplate;
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 ENTRY = "entry ";
/**
@@ -175,20 +178,19 @@ public final class AcmUtils {
*/
public static BeanValidationResult validateAutomationComposition(AutomationComposition automationComposition,
ToscaServiceTemplate serviceTemplate) {
- var result = new BeanValidationResult(ENTRY + automationComposition.getDefinition().getName(),
- automationComposition);
+ var result = new BeanValidationResult(ENTRY + automationComposition.getName(), automationComposition);
var map = getMapToscaNodeTemplates(serviceTemplate);
- var toscaNodeTemplate = map.get(new ToscaConceptIdentifier(automationComposition.getDefinition().getName(),
- automationComposition.getDefinition().getVersion()));
+ var nodeTemplateGet = map.values().stream()
+ .filter(nodeTemplate -> AUTOMATION_COMPOSITION_NODE_TYPE.equals(nodeTemplate.getType())).findFirst();
- if (toscaNodeTemplate == null || !AUTOMATION_COMPOSITION_NODE_TYPE.equals(toscaNodeTemplate.getType())) {
- result.addResult(
- new ObjectValidationResult("AutomationComposition", automationComposition.getDefinition().getName(),
- ValidationStatus.INVALID, "Commissioned automation composition definition not found"));
+ if (nodeTemplateGet.isEmpty()) {
+ result.addResult(new ObjectValidationResult("ToscaServiceTemplate", serviceTemplate.getName(),
+ ValidationStatus.INVALID, "Commissioned automation composition definition not consistent"));
} else {
+ var toscaNodeTemplate = nodeTemplateGet.get();
var acElementDefinitions = getAutomationCompositionElementDefinitions(map, toscaNodeTemplate);
// @formatter:off
@@ -354,4 +356,32 @@ 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);
+ }
+ }
+
}