diff options
author | 2023-12-07 08:58:32 +0000 | |
---|---|---|
committer | 2023-12-07 11:11:41 +0000 | |
commit | b2393969603cb943bc76f2b65da748b871ee9d17 (patch) | |
tree | 80610ffcca8752119e8cc105d07002c541fad5ec /models/src/main | |
parent | 3b28926870225fce8df70030d931d5027943e775 (diff) |
Add validation for AC instance element id
Issue-ID: POLICY-4900
Change-Id: I78be5924950eec508856be5850a3a749860e0e49
Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
Diffstat (limited to 'models/src/main')
-rwxr-xr-x | models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AutomationCompositionProvider.java | 33 |
1 files changed, 33 insertions, 0 deletions
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 6b90619c9..1ffcc1b6e 100755 --- 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 @@ -40,6 +40,8 @@ import org.onap.policy.clamp.models.acm.persistence.concepts.JpaAutomationCompos import org.onap.policy.clamp.models.acm.persistence.repository.AutomationCompositionElementRepository; import org.onap.policy.clamp.models.acm.persistence.repository.AutomationCompositionRepository; 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.PfModelRuntimeException; import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; import org.springframework.data.domain.Example; @@ -225,4 +227,35 @@ public class AutomationCompositionProvider { ProviderUtils.validate(element, jpaAcElement, "AutomationCompositionElement"); acElementRepository.save(jpaAcElement); } + + /** + * Validate ElementIds. + * + * @param automationComposition the AutomationComposition + * @return the BeanValidationResult + */ + public BeanValidationResult validateElementIds(final AutomationComposition automationComposition) { + var result = new BeanValidationResult( + "UUID elements " + automationComposition.getName(), automationComposition); + + var ids = automationComposition + .getElements().values().stream().map(AutomationCompositionElement::getId).toList(); + var elements = acElementRepository.findAllById(ids.stream().map(UUID::toString).toList()); + if (automationComposition.getInstanceId() == null) { + for (var element : elements) { + result.addResult( + element.getDescription(), element.getElementId(), ValidationStatus.INVALID, "UUID already used"); + } + } else { + var instanceId = automationComposition.getInstanceId().toString(); + for (var element : elements) { + if (!instanceId.equals(element.getInstanceId())) { + result.addResult( + element.getDescription(), element.getElementId(), ValidationStatus.INVALID, + "UUID already used"); + } + } + } + return result; + } } |