diff options
Diffstat (limited to 'models-tosca/src/main/java')
31 files changed, 262 insertions, 873 deletions
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaCapabilityAssignment.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaCapabilityAssignment.java index 63945174a..81c46423a 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaCapabilityAssignment.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaCapabilityAssignment.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2020 Nordix Foundation. + * Modifications Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,7 +25,6 @@ import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; -import java.util.Map.Entry; import javax.persistence.ElementCollection; import javax.persistence.Entity; import javax.persistence.Inheritance; @@ -34,14 +34,13 @@ import javax.persistence.Table; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NonNull; +import org.onap.policy.common.parameters.BeanValidationResult; import org.onap.policy.common.utils.coder.YamlJsonTranslator; import org.onap.policy.models.base.PfAuthorative; import org.onap.policy.models.base.PfConcept; import org.onap.policy.models.base.PfConceptKey; import org.onap.policy.models.base.PfUtils; -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.base.Validated; import org.onap.policy.models.tosca.authorative.concepts.ToscaCapabilityAssignment; /** @@ -160,78 +159,13 @@ public class JpaToscaCapabilityAssignment extends JpaToscaEntityType<ToscaCapabi } @Override - public PfValidationResult validate(final PfValidationResult resultIn) { - PfValidationResult result = super.validate(resultIn); + public BeanValidationResult validate(String fieldName) { + BeanValidationResult result = super.validate(fieldName); - if (properties != null) { - result.append(validateProperties(new PfValidationResult())); - } - - if (attributes != null) { - result.append(validateAttributes(new PfValidationResult())); - } - - if (occurrences != null) { - result.append(validateOccurrences(new PfValidationResult())); - } - - return result; - } + validateMap(result, "properties", properties, Validated::validateEntryValueNotNull); + validateMap(result, "attributes", attributes, Validated::validateEntryValueNotNull); - /** - * Validate the properties. - * - * @param resultIn The result of validations up to now - * @return the validation result - */ - private PfValidationResult validateProperties(final PfValidationResult resultIn) { - PfValidationResult result = resultIn; - - for (Entry<String, String> propertyEntry : properties.entrySet()) { - if (propertyEntry.getValue() == null) { - result.addValidationMessage(new PfValidationMessage(getKey(), this.getClass(), ValidationResult.INVALID, - "capability assignment property " + propertyEntry.getKey() + " value may not be null")); - } - } - return result; - } - - /** - * Validate the attributes. - * - * @param resultIn The result of validations up to now - * @return the validation result - */ - private PfValidationResult validateAttributes(final PfValidationResult resultIn) { - PfValidationResult result = resultIn; - - for (Entry<String, String> attributeEntry : attributes.entrySet()) { - if (attributeEntry.getValue() == null) { - result.addValidationMessage(new PfValidationMessage(getKey(), this.getClass(), ValidationResult.INVALID, - "capability assignment attribute " + attributeEntry.getKey() + " value may not be null")); - } - } - return result; - } - - /** - * Validate the occurrences. - * - * @param resultIn The result of validations up to now - * @return the validation result - */ - private PfValidationResult validateOccurrences(final PfValidationResult resultIn) { - PfValidationResult result = resultIn; - - for (Integer occurrence : occurrences) { - if (occurrence == null) { - result.addValidationMessage(new PfValidationMessage(getKey(), this.getClass(), ValidationResult.INVALID, - "capability assignment occurrence value may not be null ")); - } else if (occurrence < 0 && !occurrence.equals(JPA_UNBOUNDED_VALUE)) { - result.addValidationMessage(new PfValidationMessage(getKey(), this.getClass(), ValidationResult.INVALID, - "capability assignment occurrence value may not be negative")); - } - } + validateList(result, "occurrences", occurrences, validateMin(0, JPA_UNBOUNDED_VALUE, true)); return result; } diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaCapabilityAssignments.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaCapabilityAssignments.java index 5afc89275..18e77bbf1 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaCapabilityAssignments.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaCapabilityAssignments.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2020 Nordix Foundation. + * Modifications Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,10 +32,10 @@ import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NonNull; import lombok.ToString; +import org.onap.policy.common.parameters.BeanValidationResult; 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.ToscaCapabilityAssignment; import org.onap.policy.models.tosca.utils.ToscaUtils; @@ -105,8 +106,8 @@ public class JpaToscaCapabilityAssignments } @Override - public PfValidationResult validate(@NonNull final PfValidationResult resultIn) { - PfValidationResult result = super.validate(resultIn); + public BeanValidationResult validate(@NonNull String fieldName) { + BeanValidationResult result = super.validate(fieldName); for (JpaToscaCapabilityAssignment assignment : this.getConceptMap().values()) { ToscaUtils.getEntityTypeAncestors(this, assignment, result); diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaCapabilityType.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaCapabilityType.java index 4db779557..3a4956c4f 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaCapabilityType.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaCapabilityType.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2020 Nordix Foundation. + * Modifications Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -37,15 +38,14 @@ import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NonNull; import org.apache.commons.collections4.CollectionUtils; +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.PfConceptKey; 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.PfValidationMessage; -import org.onap.policy.models.base.PfValidationResult; -import org.onap.policy.models.base.PfValidationResult.ValidationResult; +import org.onap.policy.models.base.Validated; import org.onap.policy.models.tosca.authorative.concepts.ToscaCapabilityType; import org.onap.policy.models.tosca.authorative.concepts.ToscaProperty; import org.onap.policy.models.tosca.utils.ToscaUtils; @@ -156,41 +156,16 @@ public class JpaToscaCapabilityType extends JpaToscaEntityType<ToscaCapabilityTy } @Override - public PfValidationResult validate(@NonNull final PfValidationResult resultIn) { - PfValidationResult result = super.validate(resultIn); + public BeanValidationResult validate(@NonNull String fieldName) { + BeanValidationResult result = super.validate(fieldName); - if (getKey().isNullVersion()) { - result.addValidationMessage(new PfValidationMessage(getKey(), this.getClass(), ValidationResult.INVALID, - "key version is a null version")); - } + result.addResult(validateKeyVersionNotNull("key", getKey())); - if (properties != null) { - result = validateProperties(result); - } + validateMap(result, "properties", properties, Validated::validateEntryValueNotNull); return result; } - /** - * Validate the capabiltiy type properties. - * - * @param resultIn The result of validations up to now - * @return the validation result - */ - private PfValidationResult validateProperties(final PfValidationResult resultIn) { - PfValidationResult result = resultIn; - - for (JpaToscaProperty property : properties.values()) { - if (property == null) { - result.addValidationMessage(new PfValidationMessage(getKey(), this.getClass(), ValidationResult.INVALID, - "capability type property may not be null ")); - } else { - result = property.validate(result); - } - } - return result; - } - @Override public int compareTo(final PfConcept otherConcept) { if (otherConcept == null) { diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaCapabilityTypes.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaCapabilityTypes.java index 6ec6de56e..e1feaed95 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaCapabilityTypes.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaCapabilityTypes.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2020 Nordix Foundation. + * Modifications Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,9 +32,9 @@ import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NonNull; import lombok.ToString; +import org.onap.policy.common.parameters.BeanValidationResult; 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.ToscaCapabilityType; import org.onap.policy.models.tosca.utils.ToscaUtils; @@ -99,8 +100,8 @@ public class JpaToscaCapabilityTypes extends PfConceptContainer<JpaToscaCapabili } @Override - public PfValidationResult validate(@NonNull final PfValidationResult resultIn) { - PfValidationResult result = super.validate(resultIn); + public BeanValidationResult validate(@NonNull String fieldName) { + BeanValidationResult result = super.validate(fieldName); // Check that all ancestors of this policy type exist for (JpaToscaCapabilityType capabilityType : this.getConceptMap().values()) { diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaDataType.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaDataType.java index 58ac9e326..d80c14a97 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaDataType.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaDataType.java @@ -41,15 +41,14 @@ import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NonNull; import org.apache.commons.collections4.CollectionUtils; +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.PfConceptKey; 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.PfValidationMessage; -import org.onap.policy.models.base.PfValidationResult; -import org.onap.policy.models.base.PfValidationResult.ValidationResult; +import org.onap.policy.models.base.Validated; import org.onap.policy.models.tosca.authorative.concepts.ToscaDataType; import org.onap.policy.models.tosca.authorative.concepts.ToscaProperty; import org.onap.policy.models.tosca.utils.ToscaUtils; @@ -165,54 +164,15 @@ public class JpaToscaDataType extends JpaToscaEntityType<ToscaDataType> implemen } @Override - public PfValidationResult validate(final PfValidationResult resultIn) { - PfValidationResult result = super.validate(resultIn); + public BeanValidationResult validate(String fieldName) { + BeanValidationResult result = super.validate(fieldName); - if (constraints != null) { - validateConstraints(result); - } - - if (properties != null) { - result = validateProperties(result); - } + validateList(result, "constraints", constraints, Validated::validateNotNull); + validateMap(result, "properties", properties, Validated::validateEntryValueNotNull); return result; } - /** - * Validate the constraints. - * - * @param result where to put the validation results - */ - private void validateConstraints(@NonNull final PfValidationResult result) { - for (JpaToscaConstraint constraint : constraints) { - if (constraint == null) { - result.addValidationMessage(new PfValidationMessage(getKey(), this.getClass(), ValidationResult.INVALID, - "data type constraint may not be null ")); - } - } - } - - /** - * Validate the properties. - * - * @param resultIn The result of validations up to now - * @return the validation result - */ - private PfValidationResult validateProperties(final PfValidationResult resultIn) { - PfValidationResult result = resultIn; - - for (JpaToscaProperty property : properties.values()) { - if (property == null) { - result.addValidationMessage(new PfValidationMessage(getKey(), this.getClass(), ValidationResult.INVALID, - "data type property may not be null ")); - } else { - result = property.validate(result); - } - } - return result; - } - @Override public int compareTo(final PfConcept otherConcept) { if (otherConcept == null) { 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 e570c05bb..faa1ce186 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 @@ -30,11 +30,10 @@ import javax.persistence.InheritanceType; import javax.persistence.Table; import lombok.Data; import lombok.EqualsAndHashCode; -import lombok.NonNull; import lombok.ToString; +import org.onap.policy.common.parameters.BeanValidationResult; 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; @@ -103,8 +102,8 @@ public class JpaToscaDataTypes extends PfConceptContainer<JpaToscaDataType, Tosc } @Override - public PfValidationResult validate(@NonNull final PfValidationResult resultIn) { - PfValidationResult result = super.validate(resultIn); + public BeanValidationResult validate(String fieldName) { + BeanValidationResult result = super.validate(fieldName); for (JpaToscaDataType dataType : this.getConceptMap().values()) { ToscaUtils.getEntityTypeAncestors(this, dataType, result); diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaEntityType.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaEntityType.java index 549d93e8a..169d7f244 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaEntityType.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaEntityType.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2019-2020 Nordix Foundation. - * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -35,15 +35,13 @@ import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NonNull; import org.apache.commons.lang3.ObjectUtils; -import org.onap.policy.common.utils.validation.ParameterValidationUtils; +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.PfConceptKey; import org.onap.policy.models.base.PfKey; import org.onap.policy.models.base.PfUtils; -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.base.Validated; import org.onap.policy.models.tosca.authorative.concepts.ToscaEntity; /** @@ -188,38 +186,17 @@ public class JpaToscaEntityType<T extends ToscaEntity> extends PfConcept impleme } @Override - public PfValidationResult validate(PfValidationResult resultIn) { - PfValidationResult result = resultIn; + public BeanValidationResult validate(@NonNull String fieldName) { + BeanValidationResult result = new BeanValidationResult(fieldName, this); - if (key.isNullKey()) { - result.addValidationMessage( - new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID, "key is a null key")); - } - - result = key.validate(result); + result.addResult(validateKeyNotNull("key", key)); - if (derivedFrom != null && derivedFrom.isNullKey()) { - result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "derived from key is a null key")); - } - - if (metadata != null) { - for (Entry<String, String> metadataEntry : metadata.entrySet()) { - if (!ParameterValidationUtils.validateStringParameter(metadataEntry.getKey())) { - result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "property metadata key may not be null")); - } - if (!ParameterValidationUtils.validateStringParameter(metadataEntry.getValue())) { - result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "property metadata value may not be null")); - } - } + if (derivedFrom != null) { + result.addResult(validateKeyNotNull("derivedFrom", derivedFrom)); } - if (description != null && description.trim().length() == 0) { - result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "property description may not be blank")); - } + validateMap(result, "metadata", metadata, Validated::validateEntryNotBlankNotBlank); + result.addResult(validateNotBlank("description", description, false)); return result; } diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaEventFilter.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaEventFilter.java index 90bb0a89e..f0d7b9caa 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaEventFilter.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaEventFilter.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP Policy Model * ================================================================================ - * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved. * Modifications Copyright (C) 2019-2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -34,13 +34,11 @@ import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NonNull; import org.apache.commons.lang3.ObjectUtils; +import org.onap.policy.common.parameters.BeanValidationResult; import org.onap.policy.models.base.PfConcept; import org.onap.policy.models.base.PfConceptKey; import org.onap.policy.models.base.PfKey; import org.onap.policy.models.base.PfReferenceKey; -import org.onap.policy.models.base.PfValidationMessage; -import org.onap.policy.models.base.PfValidationResult; -import org.onap.policy.models.base.PfValidationResult.ValidationResult; /** * Class to represent the EventFilter in TOSCA definition. @@ -124,30 +122,13 @@ public class JpaToscaEventFilter extends PfConcept { } @Override - public PfValidationResult validate(@NonNull final PfValidationResult resultIn) { - PfValidationResult result = resultIn; + public BeanValidationResult validate(@NonNull String fieldName) { + BeanValidationResult result = new BeanValidationResult(fieldName, this); - if (key.isNullKey()) { - result.addValidationMessage( - new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID, "key is a null key")); - } - - result = key.validate(result); - - if (node == null || node.isNullKey()) { - result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "node on an event filter may not be null")); - } - - if (requirement != null && requirement.trim().length() == 0) { - result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "event filter requirement may not be blank")); - } - - if (capability != null && capability.trim().length() == 0) { - result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "event filter capability may not be blank")); - } + result.addResult(validateKeyNotNull("key", key)); + result.addResult(validateKeyNotNull("node", node)); + result.addResult(validateNotBlank("requirement", requirement, false)); + result.addResult(validateNotBlank("capability", capability, false)); return result; } diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaModel.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaModel.java index d65689d8e..c86c34b92 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaModel.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaModel.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2019-2020 Nordix Foundation. - * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,12 +32,12 @@ import javax.persistence.Table; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NonNull; +import org.onap.policy.common.parameters.BeanValidationResult; import org.onap.policy.models.base.PfConcept; import org.onap.policy.models.base.PfConceptKey; import org.onap.policy.models.base.PfKey; import org.onap.policy.models.base.PfModel; import org.onap.policy.models.base.PfModelService; -import org.onap.policy.models.base.PfValidationResult; /** * A container class for a TOSCA model with multiple service templates. This class is a container class that allows a @@ -117,10 +117,12 @@ public class JpaToscaModel extends PfModel { } @Override - public PfValidationResult validate(@NonNull final PfValidationResult resultIn) { - PfValidationResult result = super.validate(resultIn); + public BeanValidationResult validate(String fieldName) { + BeanValidationResult result = super.validate(fieldName); - return serviceTemplates.validate(result); + result.addResult(serviceTemplates.validate("serviceTemplates")); + + return result; } @Override diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaNodeTemplate.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaNodeTemplate.java index 5fccbe27a..05aefa797 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaNodeTemplate.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaNodeTemplate.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2020 Nordix Foundation. + * Modifications Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -41,7 +42,7 @@ import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NonNull; import org.apache.commons.lang3.ObjectUtils; -import org.apache.commons.lang3.StringUtils; +import org.onap.policy.common.parameters.BeanValidationResult; import org.onap.policy.common.utils.coder.CoderException; import org.onap.policy.common.utils.coder.StandardCoder; import org.onap.policy.models.base.PfAuthorative; @@ -50,9 +51,7 @@ import org.onap.policy.models.base.PfConceptKey; import org.onap.policy.models.base.PfKey; import org.onap.policy.models.base.PfModelRuntimeException; import org.onap.policy.models.base.PfUtils; -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.base.Validated; import org.onap.policy.models.tosca.authorative.concepts.ToscaCapabilityAssignment; import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate; @@ -231,44 +230,15 @@ public class JpaToscaNodeTemplate extends JpaToscaEntityType<ToscaNodeTemplate> } @Override - public PfValidationResult validate(final PfValidationResult resultIn) { - PfValidationResult result = super.validate(resultIn); + public BeanValidationResult validate(String fieldName) { + BeanValidationResult result = super.validate(fieldName); - if (StringUtils.isBlank(type)) { - result.addValidationMessage(new PfValidationMessage(getKey(), this.getClass(), ValidationResult.INVALID, - "node template type may not be null")); - } - - if (properties != null) { - result.append(validateProperties(new PfValidationResult())); - } + result.addResult(validateNotBlank("type", type, true)); - if (requirements != null) { - result.append(requirements.validate(result)); - } + validateMap(result, "properties", properties, Validated::validateEntryValueNotNull); + validateOptional(result, "requirements", requirements); + validateOptional(result, "capabilities", capabilities); - if (capabilities != null) { - result.append(validateProperties(capabilities.validate(result))); - } - - return result; - } - - /** - * Validate the properties. - * - * @param resultIn The result of validations up to now - * @return the validation result - */ - private PfValidationResult validateProperties(final PfValidationResult resultIn) { - PfValidationResult result = resultIn; - - for (String property : properties.values()) { - if (property == null) { - result.addValidationMessage(new PfValidationMessage(getKey(), this.getClass(), ValidationResult.INVALID, - "topology template property may not be null ")); - } - } return result; } diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaNodeTemplates.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaNodeTemplates.java index 6c83f67c5..6cc7a1f4e 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaNodeTemplates.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaNodeTemplates.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2020 Nordix Foundation. + * Modifications Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,11 +30,10 @@ import javax.persistence.InheritanceType; import javax.persistence.Table; import lombok.Data; import lombok.EqualsAndHashCode; -import lombok.NonNull; import lombok.ToString; +import org.onap.policy.common.parameters.BeanValidationResult; 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.ToscaNodeTemplate; import org.onap.policy.models.tosca.utils.ToscaUtils; @@ -99,8 +99,8 @@ public class JpaToscaNodeTemplates extends PfConceptContainer<JpaToscaNodeTempla } @Override - public PfValidationResult validate(@NonNull final PfValidationResult resultIn) { - PfValidationResult result = super.validate(resultIn); + public BeanValidationResult validate(String fieldName) { + BeanValidationResult result = super.validate(fieldName); // Check that all ancestors of this node template exist for (JpaToscaNodeTemplate nodeTemplate : this.getConceptMap().values()) { diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaNodeType.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaNodeType.java index 26684b583..f39f9b914 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaNodeType.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaNodeType.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2020 Nordix Foundation. + * Modifications Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -43,15 +44,14 @@ import lombok.EqualsAndHashCode; import lombok.NonNull; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.ObjectUtils; +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.PfConceptKey; 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.PfValidationMessage; -import org.onap.policy.models.base.PfValidationResult; -import org.onap.policy.models.base.PfValidationResult.ValidationResult; +import org.onap.policy.models.base.Validated; import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeType; import org.onap.policy.models.tosca.authorative.concepts.ToscaProperty; import org.onap.policy.models.tosca.utils.ToscaUtils; @@ -185,42 +185,14 @@ public class JpaToscaNodeType extends JpaToscaEntityType<ToscaNodeType> implemen } @Override - public PfValidationResult validate(@NonNull final PfValidationResult resultIn) { - PfValidationResult result = super.validate(resultIn); + public BeanValidationResult validate(String fieldName) { + BeanValidationResult result = super.validate(fieldName); - if (PfKey.NULL_KEY_VERSION.equals(getKey().getVersion())) { - result.addValidationMessage(new PfValidationMessage(getKey(), this.getClass(), ValidationResult.INVALID, - "key version is a null version")); - } - - if (properties != null) { - result = validateProperties(result); - } - - if (requirements != null) { - result = requirements.validate(result); - } - - return result; - } + result.addResult(validateKeyVersionNotNull("key", getKey())); - /** - * Validate the capabiltiy type properties. - * - * @param resultIn The result of validations up to now - * @return the validation result - */ - private PfValidationResult validateProperties(final PfValidationResult resultIn) { - PfValidationResult result = resultIn; + validateMap(result, "properties", properties, Validated::validateEntryValueNotNull); + validateOptional(result, "requirements", requirements); - for (JpaToscaProperty property : properties.values()) { - if (property == null) { - result.addValidationMessage(new PfValidationMessage(getKey(), this.getClass(), ValidationResult.INVALID, - "node type property may not be null ")); - } else { - result = property.validate(result); - } - } return result; } diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaNodeTypes.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaNodeTypes.java index 5eb5a2c49..b1fe40b78 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaNodeTypes.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaNodeTypes.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2020 Nordix Foundation. + * Modifications Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,11 +30,10 @@ import javax.persistence.InheritanceType; import javax.persistence.Table; import lombok.Data; import lombok.EqualsAndHashCode; -import lombok.NonNull; import lombok.ToString; +import org.onap.policy.common.parameters.BeanValidationResult; 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.ToscaNodeType; import org.onap.policy.models.tosca.utils.ToscaUtils; @@ -99,8 +99,8 @@ public class JpaToscaNodeTypes extends PfConceptContainer<JpaToscaNodeType, Tosc } @Override - public PfValidationResult validate(@NonNull final PfValidationResult resultIn) { - PfValidationResult result = super.validate(resultIn); + public BeanValidationResult validate(String fieldName) { + BeanValidationResult result = super.validate(fieldName); // Check that all ancestors of this policy type exist for (JpaToscaNodeType nodeType : this.getConceptMap().values()) { diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaParameter.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaParameter.java index 216e877cc..19e0e5fd5 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaParameter.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaParameter.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2020 Nordix Foundation. + * Modifications Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,15 +32,13 @@ import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NonNull; import org.apache.commons.lang3.StringUtils; +import org.onap.policy.common.parameters.BeanValidationResult; import org.onap.policy.common.utils.coder.YamlJsonTranslator; import org.onap.policy.models.base.PfAuthorative; import org.onap.policy.models.base.PfConcept; import org.onap.policy.models.base.PfConceptKey; import org.onap.policy.models.base.PfKey; import org.onap.policy.models.base.PfReferenceKey; -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.authorative.concepts.ToscaParameter; /** @@ -161,20 +160,11 @@ public class JpaToscaParameter extends PfConcept implements PfAuthorative<ToscaP } @Override - public PfValidationResult validate(final PfValidationResult resultIn) { - PfValidationResult result = resultIn; + public BeanValidationResult validate(String fieldName) { + BeanValidationResult result = new BeanValidationResult(fieldName, this); - if (key.isNullKey()) { - result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "paremeter key is a null key")); - } - - result = key.validate(result); - - if (type == null || type.isNullKey()) { - result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "parameter type may not be null")); - } + result.addResult(validateKeyNotNull("key", key)); + result.addResult(validateKeyNotNull("type", type)); 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 ba32ac314..7c1022c84 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 @@ -30,12 +30,11 @@ import javax.persistence.InheritanceType; import javax.persistence.Table; import lombok.Data; import lombok.EqualsAndHashCode; -import lombok.NonNull; import lombok.ToString; +import org.onap.policy.common.parameters.BeanValidationResult; 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; @@ -105,8 +104,8 @@ public class JpaToscaPolicies extends PfConceptContainer<JpaToscaPolicy, ToscaPo } @Override - public PfValidationResult validate(@NonNull final PfValidationResult resultIn) { - PfValidationResult result = super.validate(resultIn); + public BeanValidationResult validate(String fieldName) { + BeanValidationResult result = super.validate(fieldName); for (JpaToscaPolicy policy : this.getConceptMap().values()) { ToscaUtils.getEntityTypeAncestors(this, policy, result); diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicy.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicy.java index 518a0884b..ae7b34297 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicy.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicy.java @@ -26,7 +26,6 @@ package org.onap.policy.models.tosca.simple.concepts; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; -import java.util.Map.Entry; import javax.persistence.AttributeOverride; import javax.persistence.AttributeOverrides; import javax.persistence.Column; @@ -40,18 +39,16 @@ import javax.ws.rs.core.Response; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NonNull; +import org.onap.policy.common.parameters.BeanValidationResult; import org.onap.policy.common.utils.coder.CoderException; import org.onap.policy.common.utils.coder.StandardCoder; -import org.onap.policy.common.utils.validation.ParameterValidationUtils; import org.onap.policy.models.base.PfAuthorative; import org.onap.policy.models.base.PfConcept; import org.onap.policy.models.base.PfConceptKey; import org.onap.policy.models.base.PfKey; import org.onap.policy.models.base.PfModelRuntimeException; import org.onap.policy.models.base.PfUtils; -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.base.Validated; import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy; /** @@ -234,67 +231,15 @@ public class JpaToscaPolicy extends JpaToscaEntityType<ToscaPolicy> implements P } @Override - public PfValidationResult validate(@NonNull final PfValidationResult resultIn) { - PfValidationResult result = super.validate(resultIn); + public BeanValidationResult validate(String fieldName) { + BeanValidationResult result = super.validate(fieldName); - if (PfKey.NULL_KEY_VERSION.equals(getKey().getVersion())) { - result.addValidationMessage(new PfValidationMessage(getKey(), this.getClass(), ValidationResult.INVALID, - "key version is a null version")); - } - - if (type == null || type.isNullKey()) { - result.addValidationMessage(new PfValidationMessage(getKey(), this.getClass(), ValidationResult.INVALID, - "type is null or a null key")); - } else { - result = type.validate(result); - } - - if (properties != null) { - validateProperties(result); - } + result.addResult(validateKeyVersionNotNull("key", getKey())); + result.addResult(validateKeyNotNull("type", type)); - if (targets != null) { - result = validateTargets(result); - } - - return result; - } + validateMap(result, "properties", properties, Validated::validateEntryNotBlankNotNull); + validateList(result, "targets", targets, Validated::validateNotNull); - /** - * Validate the policy properties. - * - * @param result where to put the validation results - */ - private void validateProperties(final PfValidationResult result) { - - for (Entry<String, String> propertyEntry : properties.entrySet()) { - if (!ParameterValidationUtils.validateStringParameter(propertyEntry.getKey())) { - result.addValidationMessage(new PfValidationMessage(getKey(), this.getClass(), ValidationResult.INVALID, - "policy property key may not be null ")); - } else if (propertyEntry.getValue() == null) { - result.addValidationMessage(new PfValidationMessage(getKey(), this.getClass(), ValidationResult.INVALID, - "policy property value may not be null ")); - } - } - } - - /** - * Validate the policy targets. - * - * @param resultIn The result of validations up to now - * @return the validation result - */ - private PfValidationResult validateTargets(final PfValidationResult resultIn) { - PfValidationResult result = resultIn; - - for (PfConceptKey target : targets) { - if (target == null) { - result.addValidationMessage(new PfValidationMessage(getKey(), this.getClass(), ValidationResult.INVALID, - "policy target may not be null ")); - } else { - result = target.validate(result); - } - } return result; } diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyType.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyType.java index 7a5493ce1..665c79d1f 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyType.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyType.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP Policy Model * ================================================================================ - * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved. * Modifications Copyright (C) 2019-2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -40,15 +40,14 @@ import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NonNull; import org.apache.commons.collections4.CollectionUtils; +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.PfConceptKey; 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.PfValidationMessage; -import org.onap.policy.models.base.PfValidationResult; -import org.onap.policy.models.base.PfValidationResult.ValidationResult; +import org.onap.policy.models.base.Validated; import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType; import org.onap.policy.models.tosca.authorative.concepts.ToscaProperty; import org.onap.policy.models.tosca.utils.ToscaUtils; @@ -188,86 +187,15 @@ public class JpaToscaPolicyType extends JpaToscaEntityType<ToscaPolicyType> impl } @Override - public PfValidationResult validate(@NonNull final PfValidationResult resultIn) { - PfValidationResult result = super.validate(resultIn); + public BeanValidationResult validate(String fieldName) { + BeanValidationResult result = super.validate(fieldName); - if (PfKey.NULL_KEY_VERSION.equals(getKey().getVersion())) { - result.addValidationMessage(new PfValidationMessage(getKey(), this.getClass(), ValidationResult.INVALID, - "key version is a null version")); - } - - if (properties != null) { - result = validateProperties(result); - } - - if (targets != null) { - result = validateTargets(result); - } - - if (triggers != null) { - result = validateTriggers(result); - } + result.addResult(validateKeyVersionNotNull("key", getKey())); - return result; - } + validateMap(result, "properties", properties, Validated::validateEntryValueNotNull); + validateList(result, "targets", targets, Validated::validateNotNull); + validateList(result, "triggers", triggers, Validated::validateNotNull); - /** - * Validate the policy properties. - * - * @param result The result of validations up to now - * @return the validation result - */ - private PfValidationResult validateProperties(final PfValidationResult resultIn) { - PfValidationResult result = resultIn; - - for (JpaToscaProperty property : properties.values()) { - if (property == null) { - result.addValidationMessage(new PfValidationMessage(getKey(), this.getClass(), ValidationResult.INVALID, - "policy property may not be null ")); - } else { - result = property.validate(result); - } - } - return result; - } - - /** - * Validate the policy targets. - * - * @param result The result of validations up to now - * @return the validation result - */ - private PfValidationResult validateTargets(final PfValidationResult resultIn) { - PfValidationResult result = resultIn; - - for (PfConceptKey target : targets) { - if (target == null) { - result.addValidationMessage(new PfValidationMessage(getKey(), this.getClass(), ValidationResult.INVALID, - "policy target may not be null ")); - } else { - result = target.validate(result); - } - } - return result; - } - - /** - * Validate the policy triggers. - * - * @param result The result of validations up to now - * @return the validation result - */ - private PfValidationResult validateTriggers(final PfValidationResult resultIn) { - PfValidationResult result = resultIn; - - for (JpaToscaTrigger trigger : triggers) { - if (trigger == null) { - result.addValidationMessage(new PfValidationMessage(getKey(), this.getClass(), ValidationResult.INVALID, - "policy trigger may not be null ")); - } else { - result = trigger.validate(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 0a3d070ca..c20cada8f 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 @@ -30,11 +30,10 @@ import javax.persistence.InheritanceType; import javax.persistence.Table; import lombok.Data; import lombok.EqualsAndHashCode; -import lombok.NonNull; import lombok.ToString; +import org.onap.policy.common.parameters.BeanValidationResult; 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; @@ -103,8 +102,8 @@ public class JpaToscaPolicyTypes extends PfConceptContainer<JpaToscaPolicyType, } @Override - public PfValidationResult validate(@NonNull final PfValidationResult resultIn) { - PfValidationResult result = super.validate(resultIn); + public BeanValidationResult validate(String fieldName) { + BeanValidationResult result = super.validate(fieldName); // Check that all ancestors of this policy type exist for (JpaToscaPolicyType policyType : this.getConceptMap().values()) { diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaProperty.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaProperty.java index c56dc6a42..a7156bbab 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaProperty.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaProperty.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP Policy Model * ================================================================================ - * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved. * Modifications Copyright (C) 2019-2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -38,6 +38,7 @@ import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NonNull; import org.apache.commons.lang3.ObjectUtils; +import org.onap.policy.common.parameters.BeanValidationResult; import org.onap.policy.common.utils.coder.YamlJsonTranslator; import org.onap.policy.models.base.PfAuthorative; import org.onap.policy.models.base.PfConcept; @@ -45,9 +46,7 @@ import org.onap.policy.models.base.PfConceptKey; 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.PfValidationMessage; -import org.onap.policy.models.base.PfValidationResult; -import org.onap.policy.models.base.PfValidationResult.ValidationResult; +import org.onap.policy.models.base.Validated; import org.onap.policy.models.tosca.authorative.concepts.ToscaProperty; import org.onap.policy.models.tosca.authorative.concepts.ToscaProperty.Status; @@ -241,52 +240,18 @@ public class JpaToscaProperty extends PfConcept implements PfAuthorative<ToscaPr } @Override - public PfValidationResult validate(final PfValidationResult resultIn) { - PfValidationResult result = resultIn; + public BeanValidationResult validate(@NonNull String fieldName) { + BeanValidationResult result = new BeanValidationResult(fieldName, this); - if (key.isNullKey()) { - result.addValidationMessage( - new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID, "key is a null key")); - } - - result = key.validate(result); - - if (type == null || type.isNullKey()) { - result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "property type may not be null")); - } - - return validateFields(result); - } - - /** - * Validate the property fields. - * - * @param resultIn the incoming validation results so far - * @return the validation results including this validation - */ - private PfValidationResult validateFields(final PfValidationResult resultIn) { - PfValidationResult result = resultIn; + result.addResult(validateKeyNotNull("key", key)); + result.addResult(validateKeyNotNull("type", type)); + result.addResult(validateNotBlank("description", description, false)); + result.addResult(validateNotBlank("defaultValue", defaultValue, false)); - if (description != null && description.trim().length() == 0) { - result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "property description may not be blank")); - } + validateList(result, "constraints", constraints, Validated::validateNotNull); + validateOptional(result, "entrySchema", entrySchema); - if (defaultValue != null && defaultValue.trim().length() == 0) { - result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "property default value may not be null")); - } - - if (constraints != null) { - for (JpaToscaConstraint constraint : constraints) { - if (constraint == null) { - result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "property constraint may not be null ")); - } - } - } - return (entrySchema != null ? entrySchema.validate(result) : result); + return result; } @Override diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaRelationshipType.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaRelationshipType.java index d3d06d4a0..4bbcea4ed 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaRelationshipType.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaRelationshipType.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2020 Nordix Foundation. + * Modifications Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -37,15 +38,14 @@ import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NonNull; import org.apache.commons.collections4.CollectionUtils; +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.PfConceptKey; 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.PfValidationMessage; -import org.onap.policy.models.base.PfValidationResult; -import org.onap.policy.models.base.PfValidationResult.ValidationResult; +import org.onap.policy.models.base.Validated; import org.onap.policy.models.tosca.authorative.concepts.ToscaProperty; import org.onap.policy.models.tosca.authorative.concepts.ToscaRelationshipType; import org.onap.policy.models.tosca.utils.ToscaUtils; @@ -153,41 +153,16 @@ public class JpaToscaRelationshipType extends JpaToscaEntityType<ToscaRelationsh } @Override - public PfValidationResult validate(@NonNull final PfValidationResult resultIn) { - PfValidationResult result = super.validate(resultIn); + public BeanValidationResult validate(String fieldName) { + BeanValidationResult result = super.validate(fieldName); - if (PfKey.NULL_KEY_VERSION.equals(getKey().getVersion())) { - result.addValidationMessage(new PfValidationMessage(getKey(), this.getClass(), ValidationResult.INVALID, - "key version is a null version")); - } + result.addResult(validateKeyVersionNotNull("key", getKey())); - if (properties != null) { - result = validateProperties(result); - } + validateMap(result, "properties", properties, Validated::validateEntryValueNotNull); return result; } - /** - * Validate the capabiltiy type properties. - * - * @param resultIn The result of validations up to now - * @return the validation result - */ - private PfValidationResult validateProperties(final PfValidationResult resultIn) { - PfValidationResult result = resultIn; - - for (JpaToscaProperty property : properties.values()) { - if (property == null) { - result.addValidationMessage(new PfValidationMessage(getKey(), this.getClass(), ValidationResult.INVALID, - "relationship type property may not be null ")); - } else { - result = property.validate(result); - } - } - return result; - } - @Override public int compareTo(final PfConcept otherConcept) { if (otherConcept == null) { diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaRelationshipTypes.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaRelationshipTypes.java index 28e1d602c..eed351df5 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaRelationshipTypes.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaRelationshipTypes.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2020 Nordix Foundation. + * Modifications Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,11 +30,10 @@ import javax.persistence.InheritanceType; import javax.persistence.Table; import lombok.Data; import lombok.EqualsAndHashCode; -import lombok.NonNull; import lombok.ToString; +import org.onap.policy.common.parameters.BeanValidationResult; 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.ToscaRelationshipType; import org.onap.policy.models.tosca.utils.ToscaUtils; @@ -100,8 +100,8 @@ public class JpaToscaRelationshipTypes extends PfConceptContainer<JpaToscaRelati } @Override - public PfValidationResult validate(@NonNull final PfValidationResult resultIn) { - PfValidationResult result = super.validate(resultIn); + public BeanValidationResult validate(String fieldName) { + BeanValidationResult result = super.validate(fieldName); // Check that all ancestors of this policy type exist for (JpaToscaRelationshipType relationshipType : this.getConceptMap().values()) { diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaRequirement.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaRequirement.java index aebc31caf..bf1249d4b 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaRequirement.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaRequirement.java @@ -37,14 +37,13 @@ import javax.persistence.Table; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NonNull; +import org.onap.policy.common.parameters.BeanValidationResult; import org.onap.policy.common.utils.coder.YamlJsonTranslator; import org.onap.policy.models.base.PfAuthorative; import org.onap.policy.models.base.PfConcept; import org.onap.policy.models.base.PfConceptKey; -import org.onap.policy.models.base.PfKey; import org.onap.policy.models.base.PfUtils; -import org.onap.policy.models.base.PfValidationMessage; -import org.onap.policy.models.base.PfValidationResult; +import org.onap.policy.models.base.Validated; import org.onap.policy.models.tosca.authorative.concepts.ToscaRequirement; /** @@ -63,7 +62,7 @@ public class JpaToscaRequirement extends JpaToscaEntityType<ToscaRequirement> private static final long serialVersionUID = 2785481541573683089L; private static final String AUTHORATIVE_UNBOUNDED_LITERAL = "UNBOUNDED"; - private static final Double JPA_UNBOUNDED_VALUE = -1.0; + private static final Integer JPA_UNBOUNDED_VALUE = -1; @Column private String capability; @@ -75,7 +74,7 @@ public class JpaToscaRequirement extends JpaToscaEntityType<ToscaRequirement> private String relationship; @ElementCollection - private List<Double> occurrences; + private List<Integer> occurrences; @ElementCollection @Lob @@ -133,11 +132,11 @@ public class JpaToscaRequirement extends JpaToscaEntityType<ToscaRequirement> if (occurrences != null) { List<Object> occurrencesList = new ArrayList<>(occurrences); - for (Double occurrence : occurrences) { - if (occurrence == JPA_UNBOUNDED_VALUE) { + for (Integer occurrence : occurrences) { + if (JPA_UNBOUNDED_VALUE.equals(occurrence)) { occurrencesList.add(AUTHORATIVE_UNBOUNDED_LITERAL); } else { - occurrencesList.add(occurrence.doubleValue()); + occurrencesList.add(occurrence); } } toscaRequirement.setOccurrences(occurrencesList); @@ -170,7 +169,7 @@ public class JpaToscaRequirement extends JpaToscaEntityType<ToscaRequirement> if (occurrence.equals(AUTHORATIVE_UNBOUNDED_LITERAL)) { occurrences.add(JPA_UNBOUNDED_VALUE); } else { - occurrences.add((Double) occurrence); + occurrences.add(((Number) occurrence).intValue()); } } } @@ -186,11 +185,6 @@ public class JpaToscaRequirement extends JpaToscaEntityType<ToscaRequirement> } @Override - public List<PfKey> getKeys() { - return super.getKeys(); - } - - @Override public void clean() { super.clean(); @@ -202,58 +196,11 @@ public class JpaToscaRequirement extends JpaToscaEntityType<ToscaRequirement> } @Override - public PfValidationResult validate(@NonNull final PfValidationResult resultIn) { - PfValidationResult result = super.validate(resultIn); - - if (properties != null) { - result = validateProperties(result); - } - - if (occurrences != null) { - result = validateOccurrences(result); - } - - return result; - } - - /** - * Validate the properties. - * - * @param resultIn The result of validations up to now - * @return the validation result - */ - private PfValidationResult validateProperties(final PfValidationResult resultIn) { - PfValidationResult result = resultIn; - - for (String property : properties.values()) { - if (property == null) { - result.addValidationMessage(new PfValidationMessage(getKey(), this.getClass(), - PfValidationResult.ValidationResult.INVALID, "topology template property may not be null ")); - } - } - return result; - } + public BeanValidationResult validate(String fieldName) { + BeanValidationResult result = super.validate(fieldName); - /** - * Validate the occurrences. - * - * @param resultIn The result of validations up to now - * @return the validation result - */ - private PfValidationResult validateOccurrences(final PfValidationResult resultIn) { - PfValidationResult result = resultIn; - - for (Double occurrence : occurrences) { - if (occurrence == null) { - result.addValidationMessage(new PfValidationMessage(getKey(), this.getClass(), - PfValidationResult.ValidationResult.INVALID, "requirement occurrence value may not be null ")); - } - if (occurrence < -1.0) { - result.addValidationMessage( - new PfValidationMessage(getKey(), this.getClass(), PfValidationResult.ValidationResult.INVALID, - "requirement occurrence value may not be negative")); - } - } + validateMap(result, "properties", properties, Validated::validateEntryValueNotNull); + validateList(result, "occurrences", occurrences, validateMin(0, JPA_UNBOUNDED_VALUE, true)); return result; } diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaRequirements.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaRequirements.java index 08dbb43de..283c161d0 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaRequirements.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaRequirements.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2020 Nordix Foundation. + * Modifications Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,12 +30,11 @@ import javax.persistence.InheritanceType; import javax.persistence.Table; import lombok.Data; import lombok.EqualsAndHashCode; -import lombok.NonNull; import lombok.ToString; +import org.onap.policy.common.parameters.BeanValidationResult; 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.ToscaRequirement; import org.onap.policy.models.tosca.utils.ToscaUtils; @@ -104,8 +104,8 @@ public class JpaToscaRequirements extends PfConceptContainer<JpaToscaRequirement } @Override - public PfValidationResult validate(@NonNull final PfValidationResult resultIn) { - PfValidationResult result = super.validate(resultIn); + public BeanValidationResult validate(String fieldName) { + BeanValidationResult result = super.validate(fieldName); for (JpaToscaRequirement requirement : this.getConceptMap().values()) { ToscaUtils.getEntityTypeAncestors(this, requirement, result); diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaSchemaDefinition.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaSchemaDefinition.java index 6bd1b44cd..bae36299a 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaSchemaDefinition.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaSchemaDefinition.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP Policy Model * ================================================================================ - * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved. * Modifications Copyright (C) 2019-2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -33,14 +33,13 @@ import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; import lombok.NonNull; import org.apache.commons.lang3.ObjectUtils; +import org.onap.policy.common.parameters.BeanValidationResult; import org.onap.policy.common.utils.validation.Assertions; import org.onap.policy.models.base.PfAuthorative; import org.onap.policy.models.base.PfConceptKey; import org.onap.policy.models.base.PfKey; import org.onap.policy.models.base.PfUtils; -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.base.Validated; import org.onap.policy.models.tosca.authorative.concepts.ToscaConstraint; import org.onap.policy.models.tosca.authorative.concepts.ToscaSchemaDefinition; @@ -53,14 +52,11 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaSchemaDefinition; @Data @EqualsAndHashCode(callSuper = false) @NoArgsConstructor -public class JpaToscaSchemaDefinition +public class JpaToscaSchemaDefinition extends Validated implements PfAuthorative<ToscaSchemaDefinition>, Serializable, Comparable<JpaToscaSchemaDefinition> { private static final long serialVersionUID = 3645882081163287058L; - // Recurring string constants - private static final String ENTRY_SCHEMA = "EntrySchema"; - @Column private PfConceptKey type; @@ -147,34 +143,14 @@ public class JpaToscaSchemaDefinition description = (description != null ? description.trim() : null); } - /** - * Validate the entry schema. - * - * @param resultIn the incoming result - * @return the ooutput result witht he result of this validation - */ - public PfValidationResult validate(@NonNull final PfValidationResult resultIn) { - PfValidationResult result = resultIn; - - if (type == null || type.isNullKey()) { - result.addValidationMessage(new PfValidationMessage(new PfConceptKey(ENTRY_SCHEMA, PfKey.NULL_KEY_VERSION), - this.getClass(), ValidationResult.INVALID, "entry schema type may not be null")); - } + @Override + public BeanValidationResult validate(@NonNull String fieldName) { + BeanValidationResult result = new BeanValidationResult(fieldName, this); - if (description != null && description.trim().length() == 0) { - result.addValidationMessage(new PfValidationMessage(new PfConceptKey(ENTRY_SCHEMA, PfKey.NULL_KEY_VERSION), - this.getClass(), ValidationResult.INVALID, "entry schema description may not be blank")); - } + result.addResult(validateKeyNotNull("type", type)); + result.addResult(validateNotBlank("description", description, false)); - if (constraints != null) { - for (JpaToscaConstraint constraint : constraints) { - if (constraint == null) { - result.addValidationMessage( - new PfValidationMessage(new PfConceptKey(ENTRY_SCHEMA, PfKey.NULL_KEY_VERSION), - this.getClass(), ValidationResult.INVALID, "property constraint may not be null ")); - } - } - } + validateList(result, "constraints", constraints, Validated::validateNotNull); return result; } diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaServiceTemplate.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaServiceTemplate.java index 791801616..d4e51840b 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaServiceTemplate.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaServiceTemplate.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2019-2020 Nordix Foundation. - * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -41,14 +41,11 @@ import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NonNull; import org.apache.commons.lang3.ObjectUtils; -import org.onap.policy.common.utils.validation.ParameterValidationUtils; +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.PfConceptKey; import org.onap.policy.models.base.PfKey; -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.authorative.concepts.ToscaCapabilityType; import org.onap.policy.models.tosca.authorative.concepts.ToscaDataType; import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeType; @@ -363,46 +360,28 @@ public class JpaToscaServiceTemplate extends JpaToscaEntityType<ToscaServiceTemp } @Override - public PfValidationResult validate(final PfValidationResult resultIn) { - PfValidationResult result = super.validate(resultIn); + public BeanValidationResult validate(String fieldName) { + BeanValidationResult result = super.validate(fieldName); - if (!ParameterValidationUtils.validateStringParameter(toscaDefinitionsVersion)) { - result.addValidationMessage(new PfValidationMessage(getKey(), this.getClass(), ValidationResult.INVALID, - "service template tosca definitions version may not be null")); - } - - if (dataTypes != null) { - result = dataTypes.validate(result); - } - - if (capabilityTypes != null) { - result = capabilityTypes.validate(result); - } - - if (relationshipTypes != null) { - result = relationshipTypes.validate(result); - } - - if (nodeTypes != null) { - result = nodeTypes.validate(result); - } - - if (policyTypes != null) { - result = policyTypes.validate(result); - } + result.addResult(validateNotBlank("toscaDefinitionsVersion", toscaDefinitionsVersion, true)); - if (topologyTemplate != null) { - result = topologyTemplate.validate(result); - } + validateOptional(result, "dataTypes", dataTypes); + validateOptional(result, "capabilityTypes", capabilityTypes); + validateOptional(result, "relationshipTypes", relationshipTypes); + validateOptional(result, "nodeTypes", nodeTypes); + validateOptional(result, "policyTypes", policyTypes); + validateOptional(result, "topologyTemplate", topologyTemplate); // No point in validating cross references if the structure of the individual parts are not valid - if (!result.isOk()) { + if (!result.isValid()) { return result; } validateReferencedDataTypes(result); - return validatePolicyTypesInPolicies(result); + validatePolicyTypesInPolicies(result); + + return result; } @Override @@ -471,39 +450,35 @@ public class JpaToscaServiceTemplate extends JpaToscaEntityType<ToscaServiceTemp * Validate that all data types referenced in policy types exist. * * @param result the validation result object to use for the validation result - * @return the validation result object + * @param result where the results are added */ - private PfValidationResult validateReferencedDataTypes(final PfValidationResult result) { + private void validateReferencedDataTypes(final BeanValidationResult result) { if (policyTypes == null) { - return result; + return; } if (dataTypes != null) { for (JpaToscaDataType dataType : dataTypes.getAll(null)) { - validateReferencedDataTypesExists(dataType.getKey(), dataType.getReferencedDataTypes(), result); + validateReferencedDataTypesExists(dataType.getReferencedDataTypes(), result); } } for (JpaToscaPolicyType policyType : policyTypes.getAll(null)) { - validateReferencedDataTypesExists(policyType.getKey(), policyType.getReferencedDataTypes(), result); + validateReferencedDataTypesExists(policyType.getReferencedDataTypes(), result); } - - return result; } /** * Validate that the referenced data types exist for a collection of data type keys. * - * @param referencingEntityKey the key of the referencing entity * @param dataTypeKeyCollection the data type key collection - * @param result the result of the validation + * @param result where the results are added */ - private void validateReferencedDataTypesExists(final PfConceptKey referencingEntityKey, - final Collection<PfConceptKey> dataTypeKeyCollection, final PfValidationResult result) { + private void validateReferencedDataTypesExists( + final Collection<PfConceptKey> dataTypeKeyCollection, final BeanValidationResult result) { for (PfConceptKey dataTypeKey : dataTypeKeyCollection) { if (dataTypes == null || dataTypes.get(dataTypeKey) == null) { - result.addValidationMessage(new PfValidationMessage(referencingEntityKey, this.getClass(), - ValidationResult.INVALID, "referenced data type " + dataTypeKey.getId() + " not found")); + addResult(result, "data type", dataTypeKey.getId(), NOT_FOUND); } } } @@ -511,30 +486,24 @@ public class JpaToscaServiceTemplate extends JpaToscaEntityType<ToscaServiceTemp /** * Validate that all policy types referenced in policies exist. * - * @param result the validation result object to use for the validation result - * @return the validation result object + * @param result where the results are added */ - private PfValidationResult validatePolicyTypesInPolicies(PfValidationResult result) { + private void validatePolicyTypesInPolicies(BeanValidationResult result) { if (topologyTemplate == null || topologyTemplate.getPolicies() == null || topologyTemplate.getPolicies().getConceptMap().isEmpty()) { - return result; + return; } if (policyTypes == null || policyTypes.getConceptMap().isEmpty()) { - result.addValidationMessage(new PfValidationMessage(this.getKey(), this.getClass(), - ValidationResult.INVALID, - "no policy types are defined on the service template for the policies in the topology template")); - return result; + addResult(result, "policyTypes", policyTypes, + "no policy types are defined on the service template for the policies in the topology template"); + return; } for (JpaToscaPolicy policy : topologyTemplate.getPolicies().getAll(null)) { if (policyTypes.get(policy.getType()) == null) { - result.addValidationMessage( - new PfValidationMessage(policy.getKey(), this.getClass(), ValidationResult.INVALID, - "policy type " + policy.getType().getId() + " referenced in policy not found")); + addResult(result, "policy type", policy.getType().getId(), NOT_FOUND); } } - - return result; } } diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTimeInterval.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTimeInterval.java index 783e2b576..a8a21c3f0 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTimeInterval.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTimeInterval.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP Policy Model * ================================================================================ - * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved. * Modifications Copyright (C) 2019-2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -34,13 +34,11 @@ import javax.persistence.Table; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NonNull; +import org.onap.policy.common.parameters.BeanValidationResult; import org.onap.policy.models.base.PfConcept; 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.PfValidationMessage; -import org.onap.policy.models.base.PfValidationResult; -import org.onap.policy.models.base.PfValidationResult.ValidationResult; /** * Class to represent the TimeInterval in TOSCA definition. @@ -117,30 +115,21 @@ public class JpaToscaTimeInterval extends PfConcept { } @Override - public PfValidationResult validate(@NonNull final PfValidationResult resultIn) { - PfValidationResult result = resultIn; + public BeanValidationResult validate(@NonNull String fieldName) { + BeanValidationResult result = new BeanValidationResult(fieldName, this); - if (key.isNullKey()) { - result.addValidationMessage( - new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID, "key is a null key")); - } - - result = key.validate(result); + result.addResult(validateKeyNotNull("key", key)); if (startTime == null || startTime.getTime() == 0) { - result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "start time on time interval may not be null or zero")); + addResult(result, "startTime", startTime, "is null or zero"); } if (endTime == null || endTime.getTime() == 0) { - result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "end time on time interval may not be null or zero")); + addResult(result, "endTime", endTime, "is null or zero"); } if (startTime != null && endTime != null && endTime.before(startTime)) { - result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "end time \"" + endTime.toString() + "\" on time interval may not be before start time \"" - + startTime.toString() + "\"")); + addResult(result, "endTime", endTime, "is before startTime"); } return result; diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTopologyTemplate.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTopologyTemplate.java index 32c459cc9..538680f5f 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTopologyTemplate.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTopologyTemplate.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2019-2020 Nordix Foundation. - * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -43,14 +43,13 @@ import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NonNull; import org.apache.commons.lang3.ObjectUtils; +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.PfKey; import org.onap.policy.models.base.PfReferenceKey; import org.onap.policy.models.base.PfUtils; -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.base.Validated; import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate; import org.onap.policy.models.tosca.authorative.concepts.ToscaParameter; import org.onap.policy.models.tosca.authorative.concepts.ToscaTopologyTemplate; @@ -241,54 +240,17 @@ public class JpaToscaTopologyTemplate extends PfConcept implements PfAuthorative } @Override - public PfValidationResult validate(PfValidationResult resultIn) { - PfValidationResult result = resultIn; + public BeanValidationResult validate(@NonNull String fieldName) { + BeanValidationResult result = new BeanValidationResult(fieldName, this); - if (key.isNullKey()) { - result.addValidationMessage( - new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID, "key is a null key")); - } - - result = key.validate(result); - - if (description != null && description.trim().length() == 0) { - result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "property description may not be blank")); - } - - if (inputs != null) { - result = validateInputs(result); - } - - - if (nodeTemplates != null) { - result = nodeTemplates.validate(result); - } + result.addResult(validateKeyNotNull("key", key)); + result.addResult(validateNotBlank("description", description, false)); - if (policies != null) { - result = policies.validate(result); - } + validateMap(result, "inputs", inputs, Validated::validateEntryValueNotNull); - return result; - } + validateOptional(result, "nodeTemplates", nodeTemplates); + validateOptional(result, "policies", policies); - /** - * Validate the inputs. - * - * @param resultIn The result of validations up to now - * @return the validation result - */ - private PfValidationResult validateInputs(final PfValidationResult resultIn) { - PfValidationResult result = resultIn; - - for (JpaToscaParameter input : inputs.values()) { - if (input == null) { - result.addValidationMessage(new PfValidationMessage(getKey(), this.getClass(), ValidationResult.INVALID, - "topology template input may not be null ")); - } else { - result = input.validate(result); - } - } return result; } diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTrigger.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTrigger.java index 10a9d2f66..e30754007 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTrigger.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTrigger.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP Policy Model * ================================================================================ - * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved. * Modifications Copyright (C) 2019-2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -36,13 +36,10 @@ import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NonNull; import org.apache.commons.lang3.ObjectUtils; -import org.onap.policy.common.utils.validation.ParameterValidationUtils; +import org.onap.policy.common.parameters.BeanValidationResult; import org.onap.policy.models.base.PfConcept; import org.onap.policy.models.base.PfKey; import org.onap.policy.models.base.PfReferenceKey; -import org.onap.policy.models.base.PfValidationMessage; -import org.onap.policy.models.base.PfValidationResult; -import org.onap.policy.models.base.PfValidationResult.ValidationResult; /** * Class to represent the trigger of policy type in TOSCA definition. @@ -177,57 +174,23 @@ public class JpaToscaTrigger extends PfConcept { } @Override - public PfValidationResult validate(@NonNull final PfValidationResult resultIn) { - PfValidationResult result = resultIn; + public BeanValidationResult validate(@NonNull String fieldName) { + BeanValidationResult result = new BeanValidationResult(fieldName, this); - if (key.isNullKey()) { - result.addValidationMessage( - new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID, "key is a null key")); - } - - result = key.validate(result); - - if (description != null && description.trim().length() == 0) { - result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "trigger description may not be blank")); - } + result.addResult(validateKeyNotNull("key", key)); - if (!ParameterValidationUtils.validateStringParameter(eventType)) { - result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "event type on trigger must be defined")); - } + result.addResult(validateNotBlank("description", description, false)); + result.addResult(validateNotBlank("eventType", eventType, true)); - result = validateOptionalFields(result); + validateOptional(result, "schedule", schedule); + validateOptional(result, "targetFilter", targetFilter); if (evaluations < 0) { - result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "evaluations on trigger must be zero or a positive integer")); - } - - if (method != null && method.trim().length() == 0) { - result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "method on trigger may not be blank")); - } - - if (!ParameterValidationUtils.validateStringParameter(action)) { - result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "action on trigger must be defined")); + addResult(result, "evaluations", evaluations, "is negative"); } - return result; - } - - /** - * Validate optional fields. - * - * @param resultIn the validation result so far - * @return the validation resutls including these fields - */ - private PfValidationResult validateOptionalFields(final PfValidationResult resultIn) { - PfValidationResult result = resultIn; - - result = (schedule != null ? schedule.validate(result) : result); - result = (targetFilter != null ? targetFilter.validate(result) : result); + result.addResult(validateNotBlank("method", method, false)); + result.addResult(validateNotBlank("action", action, true)); return result; } diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProvider.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProvider.java index 459a32934..8fb4a7711 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProvider.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProvider.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2019-2020 Nordix Foundation. + * Modifications Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,13 +27,13 @@ import java.util.List; import javax.ws.rs.core.Response; import lombok.NonNull; import org.apache.commons.collections4.CollectionUtils; +import org.onap.policy.common.parameters.BeanValidationResult; import org.onap.policy.models.base.PfConcept; import org.onap.policy.models.base.PfConceptFilter; import org.onap.policy.models.base.PfConceptKey; import org.onap.policy.models.base.PfKey; import org.onap.policy.models.base.PfModelException; import org.onap.policy.models.base.PfModelRuntimeException; -import org.onap.policy.models.base.PfValidationResult; import org.onap.policy.models.dao.PfDao; import org.onap.policy.models.tosca.authorative.concepts.ToscaEntity; import org.onap.policy.models.tosca.simple.concepts.JpaToscaDataType; @@ -107,9 +108,9 @@ public class SimpleToscaProvider { ToscaServiceTemplateUtils.addFragment(dbServiceTemplate, incomingServiceTemplateFragment); } - PfValidationResult result = serviceTemplateToWrite.validate(new PfValidationResult()); + BeanValidationResult result = serviceTemplateToWrite.validate("service template"); if (!result.isValid()) { - throw new PfModelRuntimeException(Response.Status.NOT_ACCEPTABLE, result.toString()); + throw new PfModelRuntimeException(Response.Status.NOT_ACCEPTABLE, result.getResult()); } new SimpleToscaServiceTemplateProvider().write(dao, serviceTemplateToWrite); @@ -454,9 +455,11 @@ public class SimpleToscaProvider { POLICY_TYPE + policyTypeKey.getId() + NOT_FOUND); } + BeanValidationResult result = new BeanValidationResult("policy types", serviceTemplate); + for (JpaToscaPolicyType policyType : serviceTemplate.getPolicyTypes().getAll(null)) { Collection<JpaToscaEntityType<ToscaEntity>> ancestorList = ToscaUtils - .getEntityTypeAncestors(serviceTemplate.getPolicyTypes(), policyType, new PfValidationResult()); + .getEntityTypeAncestors(serviceTemplate.getPolicyTypes(), policyType, result); if (ancestorList.contains(policyType4Deletion)) { throw new PfModelRuntimeException(Response.Status.NOT_ACCEPTABLE, POLICY_TYPE + policyTypeKey.getId() 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 7bf4d29e8..fe5299337 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 @@ -25,12 +25,11 @@ import java.util.Map; import java.util.Map.Entry; import javax.ws.rs.core.Response; import lombok.NonNull; +import org.onap.policy.common.parameters.BeanValidationResult; 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.PfValidationMessage; -import org.onap.policy.models.base.PfValidationResult; -import org.onap.policy.models.base.PfValidationResult.ValidationResult; +import org.onap.policy.models.base.Validated; 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; @@ -57,12 +56,13 @@ public class ToscaServiceTemplateUtils { */ public static JpaToscaServiceTemplate addFragment(@NonNull final JpaToscaServiceTemplate originalTemplate, @NonNull final JpaToscaServiceTemplate fragmentTemplate) { - PfValidationResult result = new PfValidationResult(); + + BeanValidationResult result = new BeanValidationResult("incoming fragment", fragmentTemplate); if (originalTemplate.compareToWithoutEntities(fragmentTemplate) != 0) { - result.addValidationMessage(new PfValidationMessage(originalTemplate.getKey(), - ToscaServiceTemplateUtils.class, ValidationResult.INVALID, - "service template in incoming fragment does not equal existing service template")); + Validated.addResult(result, "service template", + originalTemplate.getKey(), + "does not equal existing service template"); } JpaToscaServiceTemplate compositeTemplate = new JpaToscaServiceTemplate(originalTemplate); @@ -79,20 +79,20 @@ public class ToscaServiceTemplateUtils { .setPolicies(addFragmentEntitites(compositeTemplate.getTopologyTemplate().getPolicies(), fragmentTemplate.getTopologyTemplate().getPolicies(), result)); } else { - result.addValidationMessage(new PfValidationMessage(originalTemplate.getTopologyTemplate().getKey(), - ToscaServiceTemplateUtils.class, ValidationResult.INVALID, - "topology template in incoming fragment does not equal existing topology template")); + Validated.addResult(result, "topology template", + originalTemplate.getTopologyTemplate().getKey(), + "does not equal existing topology template"); } } else if (fragmentTemplate.getTopologyTemplate() != null) { compositeTemplate.setTopologyTemplate(new JpaToscaTopologyTemplate(fragmentTemplate.getTopologyTemplate())); } if (result.isValid()) { - result = compositeTemplate.validate(result); + result.addResult(compositeTemplate.validate("composite template")); } if (!result.isValid()) { - String message = result.toString(); + String message = result.getResult(); throw new PfModelRuntimeException(Response.Status.NOT_ACCEPTABLE, message); } @@ -113,7 +113,7 @@ public class ToscaServiceTemplateUtils { private static <S extends PfConceptContainer<? extends JpaToscaEntityType<? extends ToscaEntity>, ? extends ToscaEntity>> S addFragmentEntitites(final S compositeContainer, final S fragmentContainer, - final PfValidationResult result) { + final BeanValidationResult result) { if (compositeContainer == null) { return fragmentContainer; @@ -123,17 +123,22 @@ public class ToscaServiceTemplateUtils { return compositeContainer; } + BeanValidationResult result2 = new BeanValidationResult("incoming fragment", fragmentContainer); + for (Entry<PfConceptKey, ? extends JpaToscaEntityType<? extends ToscaEntity>> fragmentEntry : fragmentContainer .getConceptMap().entrySet()) { JpaToscaEntityType<? extends ToscaEntity> containerEntity = compositeContainer.getConceptMap().get(fragmentEntry.getKey()); if (containerEntity != null && containerEntity.compareTo(fragmentEntry.getValue()) != 0) { - result.addValidationMessage(new PfValidationMessage(fragmentEntry.getKey(), - ToscaServiceTemplateUtils.class, - ValidationResult.INVALID, "entity in incoming fragment does not equal existing entity")); + Validated.addResult(result, "entity", fragmentEntry.getKey(), + "does not equal existing entity"); } } + if (!result2.isClean()) { + result.addResult(result2); + } + // This use of a generic map is required to get around typing errors in directly adding the fragment map to the // original map @SuppressWarnings("rawtypes") 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 70c5027d7..b806e4152 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 @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2019-2020 Nordix Foundation. + * Modifications Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,15 +28,16 @@ import java.util.function.Function; import javax.ws.rs.core.Response; import lombok.NonNull; import org.apache.commons.collections4.CollectionUtils; +import org.onap.policy.common.parameters.BeanValidationResult; +import org.onap.policy.common.parameters.ObjectValidationResult; +import org.onap.policy.common.parameters.ValidationStatus; 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.PfKey; 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.base.Validated; 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; @@ -219,7 +221,7 @@ public final class ToscaUtils { */ public static Collection<JpaToscaEntityType<ToscaEntity>> getEntityTypeAncestors( @NonNull PfConceptContainer<? extends PfConcept, ? extends PfNameVersion> entityTypes, - @NonNull JpaToscaEntityType<?> entityType, @NonNull final PfValidationResult result) { + @NonNull JpaToscaEntityType<?> entityType, @NonNull final BeanValidationResult result) { PfConceptKey parentEntityTypeKey = entityType.getDerivedFrom(); if (parentEntityTypeKey == null || parentEntityTypeKey.getName().endsWith(ROOT_KEY_NAME_SUFFIX)) { @@ -227,9 +229,9 @@ public final class ToscaUtils { } if (entityType.getKey().equals(parentEntityTypeKey)) { - result.addValidationMessage(new PfValidationMessage(entityType.getKey(), ToscaUtils.class, - ValidationResult.INVALID, "entity cannot be an ancestor of itself")); - throw new PfModelRuntimeException(Response.Status.CONFLICT, result.toString()); + result.addResult(new ObjectValidationResult("entity type", entityType.getKey().getId(), + ValidationStatus.INVALID, "ancestor of itself")); + throw new PfModelRuntimeException(Response.Status.CONFLICT, result.getResult()); } @SuppressWarnings("unchecked") @@ -237,8 +239,8 @@ public final class ToscaUtils { .getAll(parentEntityTypeKey.getName(), parentEntityTypeKey.getVersion()); Set<JpaToscaEntityType<ToscaEntity>> ancestorEntitySetToReturn = new HashSet<>(ancestorEntitySet); if (ancestorEntitySet.isEmpty()) { - result.addValidationMessage(new PfValidationMessage(entityType.getKey(), ToscaUtils.class, - ValidationResult.INVALID, "parent " + parentEntityTypeKey.getId() + " of entity not found")); + result.addResult(new ObjectValidationResult("parent", parentEntityTypeKey.getId(), + ValidationStatus.INVALID, Validated.NOT_FOUND)); } else { for (JpaToscaEntityType<?> filteredEntityType : ancestorEntitySet) { ancestorEntitySetToReturn.addAll(getEntityTypeAncestors(entityTypes, filteredEntityType, result)); @@ -258,7 +260,7 @@ public final class ToscaUtils { @NonNull final PfConceptContainer<? extends PfConcept, ? extends PfNameVersion> entityTypes, final String entityName, final String entityVersion) { - PfValidationResult result = new PfValidationResult(); + BeanValidationResult result = new BeanValidationResult("entity", entityName); @SuppressWarnings("unchecked") Set<JpaToscaEntityType<?>> filteredEntitySet = @@ -270,7 +272,7 @@ public final class ToscaUtils { } if (!result.isValid()) { - throw new PfModelRuntimeException(Response.Status.NOT_ACCEPTABLE, result.toString()); + throw new PfModelRuntimeException(Response.Status.NOT_ACCEPTABLE, result.getResult()); } entityTypes.getConceptMap().entrySet() |