diff options
Diffstat (limited to 'models-tosca/src/main/java/org/onap')
5 files changed, 98 insertions, 7 deletions
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaDataTypes.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaDataTypes.java index 8908ba7bf..94659e720 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaDataTypes.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaDataTypes.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. + * Copyright (C) 2019-2020 Nordix Foundation. * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -32,10 +32,14 @@ import javax.persistence.Table; import lombok.Data; import lombok.EqualsAndHashCode; +import lombok.NonNull; import lombok.ToString; + import org.onap.policy.models.base.PfConceptContainer; import org.onap.policy.models.base.PfConceptKey; +import org.onap.policy.models.base.PfValidationResult; import org.onap.policy.models.tosca.authorative.concepts.ToscaDataType; +import org.onap.policy.models.tosca.utils.ToscaUtils; /** * This class is a container for TOSCA data types. @@ -97,6 +101,18 @@ public class JpaToscaDataTypes extends PfConceptContainer<JpaToscaDataType, Tosc * @param authorativeConceptMapList the authorative concept to copy from */ public JpaToscaDataTypes(final List<Map<String, ToscaDataType>> authorativeConceptMapList) { + super(new PfConceptKey(DEFAULT_NAME, DEFAULT_VERSION)); this.fromAuthorative(authorativeConceptMapList); } + + @Override + public PfValidationResult validate(@NonNull final PfValidationResult resultIn) { + PfValidationResult result = super.validate(resultIn); + + for (JpaToscaDataType dataType : this.getConceptMap().values()) { + ToscaUtils.getEntityTypeAncestors(this, dataType, result); + } + + return result; + } } diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicies.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicies.java index 25e7dc071..74b925b80 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicies.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicies.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. + * Copyright (C) 2019-2020 Nordix Foundation. * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -32,11 +32,15 @@ import javax.persistence.Table; import lombok.Data; import lombok.EqualsAndHashCode; +import lombok.NonNull; import lombok.ToString; + import org.onap.policy.models.base.PfAuthorative; import org.onap.policy.models.base.PfConceptContainer; import org.onap.policy.models.base.PfConceptKey; +import org.onap.policy.models.base.PfValidationResult; import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy; +import org.onap.policy.models.tosca.utils.ToscaUtils; /** * This class is a container for TOSCA data types. @@ -99,6 +103,18 @@ public class JpaToscaPolicies extends PfConceptContainer<JpaToscaPolicy, ToscaPo * @param authorativeConceptMapList the authorative concept to copy from */ public JpaToscaPolicies(final List<Map<String, ToscaPolicy>> authorativeConceptMapList) { + super(new PfConceptKey(DEFAULT_NAME, DEFAULT_VERSION)); this.fromAuthorative(authorativeConceptMapList); } + + @Override + public PfValidationResult validate(@NonNull final PfValidationResult resultIn) { + PfValidationResult result = super.validate(resultIn); + + for (JpaToscaPolicy policy : this.getConceptMap().values()) { + ToscaUtils.getEntityTypeAncestors(this, policy, result); + } + + return result; + } } diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTypes.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTypes.java index 5a54a33a7..9c059b483 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTypes.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTypes.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. + * Copyright (C) 2019-2020 Nordix Foundation. * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -32,10 +32,14 @@ import javax.persistence.Table; import lombok.Data; import lombok.EqualsAndHashCode; +import lombok.NonNull; import lombok.ToString; + import org.onap.policy.models.base.PfConceptContainer; import org.onap.policy.models.base.PfConceptKey; +import org.onap.policy.models.base.PfValidationResult; import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType; +import org.onap.policy.models.tosca.utils.ToscaUtils; /** * This class is a container for TOSCA policy types. @@ -97,6 +101,18 @@ public class JpaToscaPolicyTypes extends PfConceptContainer<JpaToscaPolicyType, * @param authorativeConceptMapList the authorative concept to copy from */ public JpaToscaPolicyTypes(final List<Map<String, ToscaPolicyType>> authorativeConceptMapList) { + super(new PfConceptKey(DEFAULT_NAME, DEFAULT_VERSION)); this.fromAuthorative(authorativeConceptMapList); } + + @Override + public PfValidationResult validate(@NonNull final PfValidationResult resultIn) { + PfValidationResult result = super.validate(resultIn); + + for (JpaToscaPolicyType policyType : this.getConceptMap().values()) { + ToscaUtils.getEntityTypeAncestors(this, policyType, result); + } + + return result; + } } diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/utils/ToscaServiceTemplateUtils.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/utils/ToscaServiceTemplateUtils.java index 343e02300..87b499b4c 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/utils/ToscaServiceTemplateUtils.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/utils/ToscaServiceTemplateUtils.java @@ -37,15 +37,11 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaEntity; import org.onap.policy.models.tosca.simple.concepts.JpaToscaEntityType; import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate; import org.onap.policy.models.tosca.simple.concepts.JpaToscaTopologyTemplate; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** * This utility class provides methods to manage service templates. */ public class ToscaServiceTemplateUtils { - private static final Logger LOGGER = LoggerFactory.getLogger(ToscaServiceTemplateUtils.class); - /** * Private constructor to prevent subclassing. */ diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/utils/ToscaUtils.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/utils/ToscaUtils.java index f29854d96..7e106fa53 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/utils/ToscaUtils.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/utils/ToscaUtils.java @@ -20,11 +20,24 @@ package org.onap.policy.models.tosca.utils; +import java.util.Collection; +import java.util.Set; import java.util.function.Function; import javax.ws.rs.core.Response; +import lombok.NonNull; + +import org.apache.commons.collections4.CollectionUtils; +import org.onap.policy.models.base.PfConcept; +import org.onap.policy.models.base.PfConceptContainer; +import org.onap.policy.models.base.PfConceptKey; import org.onap.policy.models.base.PfModelRuntimeException; +import org.onap.policy.models.base.PfNameVersion; +import org.onap.policy.models.base.PfValidationMessage; +import org.onap.policy.models.base.PfValidationResult; +import org.onap.policy.models.base.PfValidationResult.ValidationResult; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaEntityType; import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -37,6 +50,8 @@ import org.slf4j.LoggerFactory; public final class ToscaUtils { private static final Logger LOGGER = LoggerFactory.getLogger(ToscaUtils.class); + private static final String ROOT_KEY_NAME_SUFFIX = ".Root"; + /** * Private constructor to prevent subclassing. */ @@ -171,4 +186,36 @@ public final class ToscaUtils { return null; } + + /** + * Find all the ancestors of an entity type. + * + * @param entityTypes the set of entity types that exist + * @param entityType the entity type for which to get the parents + * @param result the result of the ancestor search with any warnings or errors + * @return + */ + public static Collection<? extends JpaToscaEntityType<?>> getEntityTypeAncestors( + @NonNull PfConceptContainer<? extends PfConcept, ? extends PfNameVersion> entityTypes, + @NonNull JpaToscaEntityType<?> entityType, @NonNull final PfValidationResult result) { + + PfConceptKey parentEntityTypeKey = entityType.getDerivedFrom(); + if (parentEntityTypeKey == null || parentEntityTypeKey.getName().endsWith(ROOT_KEY_NAME_SUFFIX)) { + return CollectionUtils.emptyCollection(); + } + + @SuppressWarnings("unchecked") + Set<JpaToscaEntityType<?>> ancestorEntitySet = (Set<JpaToscaEntityType<?>>) entityTypes + .getAll(parentEntityTypeKey.getName(), parentEntityTypeKey.getVersion()); + + if (ancestorEntitySet.isEmpty()) { + result.addValidationMessage(new PfValidationMessage(entityType.getKey(), ToscaUtils.class, + ValidationResult.INVALID, "parent " + parentEntityTypeKey.getId() + " of entity not found")); + } else { + for (JpaToscaEntityType<?> filteredEntityType : ancestorEntitySet) { + ancestorEntitySet.addAll(getEntityTypeAncestors(entityTypes, filteredEntityType, result)); + } + } + return ancestorEntitySet; + } } |