summaryrefslogtreecommitdiffstats
path: root/models-tosca/src/main
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2020-12-18 19:01:52 -0500
committerJim Hahn <jrh3@att.com>2020-12-21 10:38:00 -0500
commit12fce55a66848bcc7f71430324b3a9051b8ce0d4 (patch)
treef8fdcb848f5b3bcfc07cc44f728bc51da620c6b3 /models-tosca/src/main
parent6345dce40405740dc09176c45dae03baeb939b8e (diff)
Use annotations to do validation
Modified models to use annotations instead of function calls for most field validations. Created a few new validation annotations for use within models. Per review comments: - renamed Key to VerifyKey - enhanced VerifyKey to imply "@Valid", unless disabled Issue-ID: POLICY-2648 Change-Id: I2b53f218b0a2ab1ed1f5e278816a3509f1408972 Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'models-tosca/src/main')
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaCapabilityAssignment.java22
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaCapabilityType.java8
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaDataType.java18
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaEntityType.java29
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaEventFilter.java22
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaModel.java12
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaNodeTemplate.java25
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaNodeType.java10
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaParameter.java17
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicy.java15
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyType.java12
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaProperty.java30
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaRelationshipType.java8
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaRequirement.java19
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaSchemaDefinition.java22
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaServiceTemplate.java20
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTimeInterval.java8
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTopologyTemplate.java29
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTrigger.java41
19 files changed, 160 insertions, 207 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 81c46423a..28e4cdc2a 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
@@ -34,13 +34,16 @@ 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.parameters.annotations.Entries;
+import org.onap.policy.common.parameters.annotations.Items;
+import org.onap.policy.common.parameters.annotations.NotNull;
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.Validated;
+import org.onap.policy.models.base.validation.annotations.PfItems;
+import org.onap.policy.models.base.validation.annotations.PfMin;
import org.onap.policy.models.tosca.authorative.concepts.ToscaCapabilityAssignment;
/**
@@ -63,13 +66,16 @@ public class JpaToscaCapabilityAssignment extends JpaToscaEntityType<ToscaCapabi
@ElementCollection
@Lob
+ @Entries(key = @Items(notNull = {@NotNull}), value = @Items(notNull = {@NotNull}))
private Map<String, String> properties;
@ElementCollection
@Lob
+ @Entries(key = @Items(notNull = {@NotNull}), value = @Items(notNull = {@NotNull}))
private Map<String, String> attributes;
@ElementCollection
+ @PfItems(notNull = {@NotNull}, pfMin = {@PfMin(value = 0, allowed = -1)})
private List<Integer> occurrences;
/**
@@ -159,18 +165,6 @@ public class JpaToscaCapabilityAssignment extends JpaToscaEntityType<ToscaCapabi
}
@Override
- public BeanValidationResult validate(String fieldName) {
- BeanValidationResult result = super.validate(fieldName);
-
- validateMap(result, "properties", properties, Validated::validateEntryValueNotNull);
- validateMap(result, "attributes", attributes, Validated::validateEntryValueNotNull);
-
- validateList(result, "occurrences", occurrences, validateMin(0, JPA_UNBOUNDED_VALUE, true));
-
- return result;
- }
-
- @Override
public int compareTo(final PfConcept otherConcept) {
if (otherConcept == null) {
return -1;
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 3a4956c4f..40c50c04a 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
@@ -39,13 +39,16 @@ import lombok.EqualsAndHashCode;
import lombok.NonNull;
import org.apache.commons.collections4.CollectionUtils;
import org.onap.policy.common.parameters.BeanValidationResult;
+import org.onap.policy.common.parameters.annotations.Entries;
+import org.onap.policy.common.parameters.annotations.Items;
+import org.onap.policy.common.parameters.annotations.NotNull;
+import org.onap.policy.common.parameters.annotations.Valid;
import org.onap.policy.models.base.PfAuthorative;
import org.onap.policy.models.base.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.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;
@@ -65,6 +68,7 @@ public class JpaToscaCapabilityType extends JpaToscaEntityType<ToscaCapabilityTy
@ElementCollection
@Lob
+ @Entries(key = @Items(notNull = {@NotNull}), value = @Items(notNull = {@NotNull}, valid = {@Valid}))
private Map<String, JpaToscaProperty> properties;
/**
@@ -161,8 +165,6 @@ public class JpaToscaCapabilityType extends JpaToscaEntityType<ToscaCapabilityTy
result.addResult(validateKeyVersionNotNull("key", getKey()));
- validateMap(result, "properties", properties, Validated::validateEntryValueNotNull);
-
return result;
}
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 d80c14a97..29daa3a47 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,14 +41,16 @@ 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.common.parameters.annotations.Entries;
+import org.onap.policy.common.parameters.annotations.Items;
+import org.onap.policy.common.parameters.annotations.NotNull;
+import org.onap.policy.common.parameters.annotations.Valid;
import org.onap.policy.models.base.PfAuthorative;
import org.onap.policy.models.base.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.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;
@@ -68,10 +70,12 @@ public class JpaToscaDataType extends JpaToscaEntityType<ToscaDataType> implemen
private static final long serialVersionUID = -3922690413436539164L;
@ElementCollection
+ @Items(notNull = {@NotNull}, valid = {@Valid})
private List<JpaToscaConstraint> constraints;
@ElementCollection
@Lob
+ @Entries(key = @Items(notNull = {@NotNull}), value = @Items(notNull = {@NotNull}, valid = {@Valid}))
private Map<String, JpaToscaProperty> properties;
/**
@@ -164,16 +168,6 @@ public class JpaToscaDataType extends JpaToscaEntityType<ToscaDataType> implemen
}
@Override
- public BeanValidationResult validate(String fieldName) {
- BeanValidationResult result = super.validate(fieldName);
-
- validateList(result, "constraints", constraints, Validated::validateNotNull);
- validateMap(result, "properties", properties, Validated::validateEntryValueNotNull);
-
- return result;
- }
-
- @Override
public int compareTo(final PfConcept otherConcept) {
if (otherConcept == null) {
return -1;
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 169d7f244..de3279ec4 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
@@ -35,13 +35,16 @@ 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.parameters.annotations.Entries;
+import org.onap.policy.common.parameters.annotations.Items;
+import org.onap.policy.common.parameters.annotations.NotBlank;
+import org.onap.policy.common.parameters.annotations.NotNull;
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.Validated;
+import org.onap.policy.models.base.validation.annotations.VerifyKey;
import org.onap.policy.models.tosca.authorative.concepts.ToscaEntity;
/**
@@ -54,6 +57,8 @@ public class JpaToscaEntityType<T extends ToscaEntity> extends PfConcept impleme
private static final long serialVersionUID = -1330661834220739393L;
@EmbeddedId
+ @VerifyKey
+ @NotNull
private PfConceptKey key;
// @formatter:off
@@ -64,12 +69,16 @@ public class JpaToscaEntityType<T extends ToscaEntity> extends PfConcept impleme
@AttributeOverride(name = "version",
column = @Column(name = "derived_from_version"))
})
+ @VerifyKey
private PfConceptKey derivedFrom;
@ElementCollection
+ @Entries(key = @Items(notNull = {@NotNull}, notBlank = {@NotBlank}),
+ value = @Items(notNull = {@NotNull}, notBlank = {@NotBlank}))
private Map<String, String> metadata;
@Column
+ @NotBlank
private String description;
private transient T toscaEntity;
@@ -186,22 +195,6 @@ public class JpaToscaEntityType<T extends ToscaEntity> extends PfConcept impleme
}
@Override
- public BeanValidationResult validate(@NonNull String fieldName) {
- BeanValidationResult result = new BeanValidationResult(fieldName, this);
-
- result.addResult(validateKeyNotNull("key", key));
-
- if (derivedFrom != null) {
- result.addResult(validateKeyNotNull("derivedFrom", derivedFrom));
- }
-
- validateMap(result, "metadata", metadata, Validated::validateEntryNotBlankNotBlank);
- result.addResult(validateNotBlank("description", description, false));
-
- return result;
- }
-
- @Override
public int compareTo(final PfConcept otherConcept) {
if (otherConcept == null) {
return -1;
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 f0d7b9caa..e879a1305 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
@@ -34,11 +34,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.common.parameters.annotations.NotBlank;
+import org.onap.policy.common.parameters.annotations.NotNull;
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.validation.annotations.VerifyKey;
/**
* Class to represent the EventFilter in TOSCA definition.
@@ -55,15 +57,21 @@ public class JpaToscaEventFilter extends PfConcept {
private static final long serialVersionUID = 8769020537228210247L;
@EmbeddedId
+ @VerifyKey
+ @NotNull
private PfReferenceKey key;
@Column
+ @VerifyKey
+ @NotNull
private PfConceptKey node;
@Column
+ @NotBlank
private String requirement;
@Column
+ @NotBlank
private String capability;
/**
@@ -122,18 +130,6 @@ public class JpaToscaEventFilter extends PfConcept {
}
@Override
- public BeanValidationResult validate(@NonNull String fieldName) {
- BeanValidationResult result = new BeanValidationResult(fieldName, this);
-
- result.addResult(validateKeyNotNull("key", key));
- result.addResult(validateKeyNotNull("node", node));
- result.addResult(validateNotBlank("requirement", requirement, false));
- result.addResult(validateNotBlank("capability", capability, false));
-
- return result;
- }
-
- @Override
public int compareTo(final PfConcept otherConcept) {
if (otherConcept == null) {
return -1;
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 c86c34b92..cd6656b4c 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
@@ -32,7 +32,7 @@ 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.parameters.annotations.Valid;
import org.onap.policy.models.base.PfConcept;
import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.base.PfKey;
@@ -55,6 +55,7 @@ public class JpaToscaModel extends PfModel {
private static final long serialVersionUID = 8800599637708309945L;
@OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true)
+ @Valid
private JpaToscaServiceTemplates serviceTemplates;
/**
@@ -117,15 +118,6 @@ public class JpaToscaModel extends PfModel {
}
@Override
- public BeanValidationResult validate(String fieldName) {
- BeanValidationResult result = super.validate(fieldName);
-
- result.addResult(serviceTemplates.validate("serviceTemplates"));
-
- return result;
- }
-
- @Override
public int compareTo(final PfConcept otherConcept) {
if (otherConcept == null) {
return -1;
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 05aefa797..c2dcab1ec 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
@@ -42,7 +42,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.common.parameters.annotations.Entries;
+import org.onap.policy.common.parameters.annotations.Items;
+import org.onap.policy.common.parameters.annotations.NotBlank;
+import org.onap.policy.common.parameters.annotations.NotNull;
+import org.onap.policy.common.parameters.annotations.Valid;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.models.base.PfAuthorative;
@@ -51,7 +55,6 @@ 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.Validated;
import org.onap.policy.models.tosca.authorative.concepts.ToscaCapabilityAssignment;
import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
@@ -70,21 +73,26 @@ public class JpaToscaNodeTemplate extends JpaToscaEntityType<ToscaNodeTemplate>
private static final StandardCoder STANDARD_CODER = new StandardCoder();
@Column
+ @NotNull
+ @NotBlank
private String type;
@ElementCollection
@Lob
+ @Entries(key = @Items(notNull = {@NotNull}), value = @Items(notNull = {@NotNull}))
private Map<String, String> properties;
// formatter:off
@OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true)
@JoinColumns({@JoinColumn(name = "requirementsName", referencedColumnName = "name"),
@JoinColumn(name = "requirementsVersion", referencedColumnName = "version")})
+ @Valid
private JpaToscaRequirements requirements;
@OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true)
@JoinColumns({@JoinColumn(name = "capabilitiesName", referencedColumnName = "name"),
@JoinColumn(name = "capabilitiesVersion", referencedColumnName = "version")})
+ @Valid
private JpaToscaCapabilityAssignments capabilities;
// @formatter:on
@@ -230,19 +238,6 @@ public class JpaToscaNodeTemplate extends JpaToscaEntityType<ToscaNodeTemplate>
}
@Override
- public BeanValidationResult validate(String fieldName) {
- BeanValidationResult result = super.validate(fieldName);
-
- result.addResult(validateNotBlank("type", type, true));
-
- validateMap(result, "properties", properties, Validated::validateEntryValueNotNull);
- validateOptional(result, "requirements", requirements);
- validateOptional(result, "capabilities", capabilities);
-
- return result;
- }
-
- @Override
public int compareTo(final PfConcept otherConcept) {
if (otherConcept == null) {
return -1;
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 f39f9b914..0965d8b44 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
@@ -45,13 +45,16 @@ 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.common.parameters.annotations.Entries;
+import org.onap.policy.common.parameters.annotations.Items;
+import org.onap.policy.common.parameters.annotations.NotNull;
+import org.onap.policy.common.parameters.annotations.Valid;
import org.onap.policy.models.base.PfAuthorative;
import org.onap.policy.models.base.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.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;
@@ -70,6 +73,7 @@ public class JpaToscaNodeType extends JpaToscaEntityType<ToscaNodeType> implemen
@ElementCollection
@Lob
+ @Entries(key = @Items(notNull = {@NotNull}), value = @Items(notNull = {@NotNull}, valid = {@Valid}))
private Map<String, JpaToscaProperty> properties;
@@ -78,6 +82,7 @@ public class JpaToscaNodeType extends JpaToscaEntityType<ToscaNodeType> implemen
@JoinColumns({@JoinColumn(name = "requirementsName", referencedColumnName = "name"),
@JoinColumn(name = "requirementsVersion", referencedColumnName = "version")})
// @formatter:on
+ @Valid
private JpaToscaRequirements requirements;
/**
@@ -190,9 +195,6 @@ public class JpaToscaNodeType extends JpaToscaEntityType<ToscaNodeType> implemen
result.addResult(validateKeyVersionNotNull("key", getKey()));
- validateMap(result, "properties", properties, Validated::validateEntryValueNotNull);
- validateOptional(result, "requirements", requirements);
-
return result;
}
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 19e0e5fd5..0348bb1d4 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
@@ -32,13 +32,14 @@ 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.parameters.annotations.NotNull;
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.validation.annotations.VerifyKey;
import org.onap.policy.models.tosca.authorative.concepts.ToscaParameter;
/**
@@ -53,9 +54,13 @@ public class JpaToscaParameter extends PfConcept implements PfAuthorative<ToscaP
private static final long serialVersionUID = 1675770231921107988L;
@EmbeddedId
+ @VerifyKey
+ @NotNull
private PfReferenceKey key;
@Column
+ @VerifyKey
+ @NotNull
private PfConceptKey type;
@Column
@@ -160,16 +165,6 @@ public class JpaToscaParameter extends PfConcept implements PfAuthorative<ToscaP
}
@Override
- public BeanValidationResult validate(String fieldName) {
- BeanValidationResult result = new BeanValidationResult(fieldName, this);
-
- result.addResult(validateKeyNotNull("key", key));
- result.addResult(validateKeyNotNull("type", type));
-
- return result;
- }
-
- @Override
public int compareTo(final PfConcept otherConcept) {
if (otherConcept == null) {
return -1;
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 ae7b34297..83ec403da 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
@@ -40,6 +40,11 @@ import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NonNull;
import org.onap.policy.common.parameters.BeanValidationResult;
+import org.onap.policy.common.parameters.annotations.Entries;
+import org.onap.policy.common.parameters.annotations.Items;
+import org.onap.policy.common.parameters.annotations.NotBlank;
+import org.onap.policy.common.parameters.annotations.NotNull;
+import org.onap.policy.common.parameters.annotations.Valid;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.models.base.PfAuthorative;
@@ -48,7 +53,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.Validated;
+import org.onap.policy.models.base.validation.annotations.VerifyKey;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
/**
@@ -79,13 +84,17 @@ public class JpaToscaPolicy extends JpaToscaEntityType<ToscaPolicy> implements P
@AttributeOverride(name = "version",
column = @Column(name = "type_version"))
})
+ @VerifyKey
+ @NotNull
private PfConceptKey type;
@ElementCollection
@Lob
+ @Entries(key = @Items(notNull = {@NotNull}, notBlank = {@NotBlank}), value = @Items(notNull = {@NotNull}))
private Map<String, String> properties;
@ElementCollection
+ @Items(notNull = {@NotNull}, valid = {@Valid})
private List<PfConceptKey> targets;
// @formatter:on
@@ -235,10 +244,6 @@ public class JpaToscaPolicy extends JpaToscaEntityType<ToscaPolicy> implements P
BeanValidationResult result = super.validate(fieldName);
result.addResult(validateKeyVersionNotNull("key", getKey()));
- result.addResult(validateKeyNotNull("type", type));
-
- validateMap(result, "properties", properties, Validated::validateEntryNotBlankNotNull);
- validateList(result, "targets", targets, Validated::validateNotNull);
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 665c79d1f..07850f9de 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
@@ -41,13 +41,16 @@ import lombok.EqualsAndHashCode;
import lombok.NonNull;
import org.apache.commons.collections4.CollectionUtils;
import org.onap.policy.common.parameters.BeanValidationResult;
+import org.onap.policy.common.parameters.annotations.Entries;
+import org.onap.policy.common.parameters.annotations.Items;
+import org.onap.policy.common.parameters.annotations.NotNull;
+import org.onap.policy.common.parameters.annotations.Valid;
import org.onap.policy.models.base.PfAuthorative;
import org.onap.policy.models.base.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.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;
@@ -69,12 +72,15 @@ public class JpaToscaPolicyType extends JpaToscaEntityType<ToscaPolicyType> impl
@ElementCollection
@Lob
+ @Entries(key = @Items(notNull = {@NotNull}), value = @Items(notNull = {@NotNull}, valid = {@Valid}))
private Map<String, JpaToscaProperty> properties;
@ElementCollection
+ @Items(notNull = {@NotNull}, valid = {@Valid})
private List<PfConceptKey> targets;
@ElementCollection
+ @Items(notNull = {@NotNull}, valid = {@Valid})
private List<JpaToscaTrigger> triggers;
/**
@@ -192,10 +198,6 @@ public class JpaToscaPolicyType extends JpaToscaEntityType<ToscaPolicyType> impl
result.addResult(validateKeyVersionNotNull("key", getKey()));
- validateMap(result, "properties", properties, Validated::validateEntryValueNotNull);
- validateList(result, "targets", targets, Validated::validateNotNull);
- validateList(result, "triggers", triggers, Validated::validateNotNull);
-
return result;
}
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 a7156bbab..711fcd2cb 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
@@ -38,7 +38,10 @@ 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.parameters.annotations.Items;
+import org.onap.policy.common.parameters.annotations.NotBlank;
+import org.onap.policy.common.parameters.annotations.NotNull;
+import org.onap.policy.common.parameters.annotations.Valid;
import org.onap.policy.common.utils.coder.YamlJsonTranslator;
import org.onap.policy.models.base.PfAuthorative;
import org.onap.policy.models.base.PfConcept;
@@ -46,7 +49,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.Validated;
+import org.onap.policy.models.base.validation.annotations.VerifyKey;
import org.onap.policy.models.tosca.authorative.concepts.ToscaProperty;
import org.onap.policy.models.tosca.authorative.concepts.ToscaProperty.Status;
@@ -65,27 +68,35 @@ public class JpaToscaProperty extends PfConcept implements PfAuthorative<ToscaPr
private static final long serialVersionUID = 1675770231921107988L;
@EmbeddedId
+ @VerifyKey
+ @NotNull
private PfReferenceKey key;
@Column
+ @VerifyKey
+ @NotNull
private PfConceptKey type;
@Column
+ @NotBlank
private String description;
@Column
private boolean required = false;
@Column(name = "default")
+ @NotBlank
private String defaultValue;
@Column
private Status status = Status.SUPPORTED;
@ElementCollection
+ @Items(notNull = {@NotNull}, valid = {@Valid})
private List<JpaToscaConstraint> constraints;
@Column
+ @Valid
private JpaToscaSchemaDefinition entrySchema;
@ElementCollection
@@ -240,21 +251,6 @@ public class JpaToscaProperty extends PfConcept implements PfAuthorative<ToscaPr
}
@Override
- public BeanValidationResult validate(@NonNull String fieldName) {
- BeanValidationResult result = new BeanValidationResult(fieldName, this);
-
- result.addResult(validateKeyNotNull("key", key));
- result.addResult(validateKeyNotNull("type", type));
- result.addResult(validateNotBlank("description", description, false));
- result.addResult(validateNotBlank("defaultValue", defaultValue, false));
-
- validateList(result, "constraints", constraints, Validated::validateNotNull);
- validateOptional(result, "entrySchema", entrySchema);
-
- return result;
- }
-
- @Override
public int compareTo(final PfConcept otherConcept) {
if (otherConcept == null) {
return -1;
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 4bbcea4ed..1bd23b13f 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
@@ -39,13 +39,16 @@ import lombok.EqualsAndHashCode;
import lombok.NonNull;
import org.apache.commons.collections4.CollectionUtils;
import org.onap.policy.common.parameters.BeanValidationResult;
+import org.onap.policy.common.parameters.annotations.Entries;
+import org.onap.policy.common.parameters.annotations.Items;
+import org.onap.policy.common.parameters.annotations.NotNull;
+import org.onap.policy.common.parameters.annotations.Valid;
import org.onap.policy.models.base.PfAuthorative;
import org.onap.policy.models.base.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.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;
@@ -65,6 +68,7 @@ public class JpaToscaRelationshipType extends JpaToscaEntityType<ToscaRelationsh
@ElementCollection
@Lob
+ @Entries(key = @Items(notNull = {@NotNull}), value = @Items(notNull = {@NotNull}, valid = {@Valid}))
private Map<String, JpaToscaProperty> properties;
/**
@@ -158,8 +162,6 @@ public class JpaToscaRelationshipType extends JpaToscaEntityType<ToscaRelationsh
result.addResult(validateKeyVersionNotNull("key", getKey()));
- validateMap(result, "properties", properties, Validated::validateEntryValueNotNull);
-
return result;
}
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 bf1249d4b..b223c2422 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,13 +37,16 @@ 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.parameters.annotations.Entries;
+import org.onap.policy.common.parameters.annotations.Items;
+import org.onap.policy.common.parameters.annotations.NotNull;
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.Validated;
+import org.onap.policy.models.base.validation.annotations.PfItems;
+import org.onap.policy.models.base.validation.annotations.PfMin;
import org.onap.policy.models.tosca.authorative.concepts.ToscaRequirement;
/**
@@ -74,10 +77,12 @@ public class JpaToscaRequirement extends JpaToscaEntityType<ToscaRequirement>
private String relationship;
@ElementCollection
+ @PfItems(notNull = {@NotNull}, pfMin = {@PfMin(value = 0, allowed = -1)})
private List<Integer> occurrences;
@ElementCollection
@Lob
+ @Entries(key = @Items(notNull = {@NotNull}), value = @Items(notNull = {@NotNull}))
private Map<String, String> properties;
/**
@@ -196,16 +201,6 @@ public class JpaToscaRequirement extends JpaToscaEntityType<ToscaRequirement>
}
@Override
- public BeanValidationResult validate(String fieldName) {
- BeanValidationResult result = super.validate(fieldName);
-
- validateMap(result, "properties", properties, Validated::validateEntryValueNotNull);
- validateList(result, "occurrences", occurrences, validateMin(0, JPA_UNBOUNDED_VALUE, true));
-
- return result;
- }
-
- @Override
public int compareTo(final PfConcept otherConcept) {
if (otherConcept == null) {
return -1;
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 bae36299a..1651d1a93 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
@@ -33,13 +33,17 @@ 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.parameters.annotations.Items;
+import org.onap.policy.common.parameters.annotations.NotBlank;
+import org.onap.policy.common.parameters.annotations.NotNull;
+import org.onap.policy.common.parameters.annotations.Valid;
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.Validated;
+import org.onap.policy.models.base.validation.annotations.VerifyKey;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConstraint;
import org.onap.policy.models.tosca.authorative.concepts.ToscaSchemaDefinition;
@@ -58,12 +62,16 @@ public class JpaToscaSchemaDefinition extends Validated
private static final long serialVersionUID = 3645882081163287058L;
@Column
+ @VerifyKey
+ @NotNull
private PfConceptKey type;
@Column
+ @NotBlank
private String description;
@ElementCollection
+ @Items(notNull = {@NotNull}, valid = {@Valid})
private List<JpaToscaConstraint> constraints;
/**
@@ -144,18 +152,6 @@ public class JpaToscaSchemaDefinition extends Validated
}
@Override
- public BeanValidationResult validate(@NonNull String fieldName) {
- BeanValidationResult result = new BeanValidationResult(fieldName, this);
-
- result.addResult(validateKeyNotNull("type", type));
- result.addResult(validateNotBlank("description", description, false));
-
- validateList(result, "constraints", constraints, Validated::validateNotNull);
-
- return result;
- }
-
- @Override
public int compareTo(final JpaToscaSchemaDefinition other) {
if (other == null) {
return -1;
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 d4e51840b..c0a5cdf75 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
@@ -42,6 +42,9 @@ import lombok.EqualsAndHashCode;
import lombok.NonNull;
import org.apache.commons.lang3.ObjectUtils;
import org.onap.policy.common.parameters.BeanValidationResult;
+import org.onap.policy.common.parameters.annotations.NotBlank;
+import org.onap.policy.common.parameters.annotations.NotNull;
+import org.onap.policy.common.parameters.annotations.Valid;
import org.onap.policy.models.base.PfAuthorative;
import org.onap.policy.models.base.PfConcept;
import org.onap.policy.models.base.PfConceptKey;
@@ -76,6 +79,8 @@ public class JpaToscaServiceTemplate extends JpaToscaEntityType<ToscaServiceTemp
// @formatter:off
@Column
@SerializedName("tosca_definitions_version")
+ @NotNull
+ @NotBlank
private String toscaDefinitionsVersion;
@OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true)
@@ -86,6 +91,7 @@ public class JpaToscaServiceTemplate extends JpaToscaEntityType<ToscaServiceTemp
}
)
@SerializedName("data_types")
+ @Valid
private JpaToscaDataTypes dataTypes;
@OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true)
@@ -96,6 +102,7 @@ public class JpaToscaServiceTemplate extends JpaToscaEntityType<ToscaServiceTemp
}
)
@SerializedName("capability_types")
+ @Valid
private JpaToscaCapabilityTypes capabilityTypes;
@OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true)
@@ -106,6 +113,7 @@ public class JpaToscaServiceTemplate extends JpaToscaEntityType<ToscaServiceTemp
}
)
@SerializedName("relationship_types")
+ @Valid
private JpaToscaRelationshipTypes relationshipTypes;
@OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true)
@@ -116,6 +124,7 @@ public class JpaToscaServiceTemplate extends JpaToscaEntityType<ToscaServiceTemp
}
)
@SerializedName("node_types")
+ @Valid
private JpaToscaNodeTypes nodeTypes;
@OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true)
@@ -126,6 +135,7 @@ public class JpaToscaServiceTemplate extends JpaToscaEntityType<ToscaServiceTemp
}
)
@SerializedName("policy_types")
+ @Valid
private JpaToscaPolicyTypes policyTypes;
@OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true)
@@ -138,6 +148,7 @@ public class JpaToscaServiceTemplate extends JpaToscaEntityType<ToscaServiceTemp
}
)
@SerializedName("topology_template")
+ @Valid
private JpaToscaTopologyTemplate topologyTemplate;
// @formatter:on
@@ -363,15 +374,6 @@ public class JpaToscaServiceTemplate extends JpaToscaEntityType<ToscaServiceTemp
public BeanValidationResult validate(String fieldName) {
BeanValidationResult result = super.validate(fieldName);
- result.addResult(validateNotBlank("toscaDefinitionsVersion", toscaDefinitionsVersion, true));
-
- 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.isValid()) {
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 a8a21c3f0..63921610a 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
@@ -35,10 +35,12 @@ import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NonNull;
import org.onap.policy.common.parameters.BeanValidationResult;
+import org.onap.policy.common.parameters.annotations.NotNull;
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.validation.annotations.VerifyKey;
/**
* Class to represent the TimeInterval in TOSCA definition.
@@ -56,6 +58,8 @@ public class JpaToscaTimeInterval extends PfConcept {
private static final long serialVersionUID = 9151467029611969980L;
@EmbeddedId
+ @VerifyKey
+ @NotNull
private PfReferenceKey key;
@SerializedName("start_time")
@@ -116,9 +120,7 @@ public class JpaToscaTimeInterval extends PfConcept {
@Override
public BeanValidationResult validate(@NonNull String fieldName) {
- BeanValidationResult result = new BeanValidationResult(fieldName, this);
-
- result.addResult(validateKeyNotNull("key", key));
+ BeanValidationResult result = super.validate(fieldName);
if (startTime == null || startTime.getTime() == 0) {
addResult(result, "startTime", startTime, "is null or zero");
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 538680f5f..7f2920c91 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
@@ -43,13 +43,17 @@ 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.parameters.annotations.Entries;
+import org.onap.policy.common.parameters.annotations.Items;
+import org.onap.policy.common.parameters.annotations.NotBlank;
+import org.onap.policy.common.parameters.annotations.NotNull;
+import org.onap.policy.common.parameters.annotations.Valid;
import org.onap.policy.models.base.PfAuthorative;
import org.onap.policy.models.base.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.Validated;
+import org.onap.policy.models.base.validation.annotations.VerifyKey;
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;
@@ -71,14 +75,18 @@ public class JpaToscaTopologyTemplate extends PfConcept implements PfAuthorative
public static final String DEFAULT_LOCAL_NAME = "ToscaTopologyTemplateSimple";
@EmbeddedId
+ @VerifyKey
+ @NotNull
private PfReferenceKey key;
@Column(name = "description")
+ @NotBlank
private String description;
// @formatter:off
@ElementCollection
@Lob
+ @Entries(key = @Items(notNull = {@NotNull}), value = @Items(notNull = {@NotNull}, valid = {@Valid}))
private Map<String, JpaToscaParameter> inputs;
@OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true)
@@ -89,6 +97,7 @@ public class JpaToscaTopologyTemplate extends PfConcept implements PfAuthorative
}
)
@SerializedName("data_types")
+ @Valid
private JpaToscaNodeTemplates nodeTemplates;
@OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true)
@@ -99,6 +108,7 @@ public class JpaToscaTopologyTemplate extends PfConcept implements PfAuthorative
}
)
// @formatter:on
+ @Valid
private JpaToscaPolicies policies;
/**
@@ -240,21 +250,6 @@ public class JpaToscaTopologyTemplate extends PfConcept implements PfAuthorative
}
@Override
- public BeanValidationResult validate(@NonNull String fieldName) {
- BeanValidationResult result = new BeanValidationResult(fieldName, this);
-
- result.addResult(validateKeyNotNull("key", key));
- result.addResult(validateNotBlank("description", description, false));
-
- validateMap(result, "inputs", inputs, Validated::validateEntryValueNotNull);
-
- validateOptional(result, "nodeTemplates", nodeTemplates);
- validateOptional(result, "policies", policies);
-
- return result;
- }
-
- @Override
public int compareTo(final PfConcept otherConcept) {
int result = compareToWithoutEntities(otherConcept);
if (result != 0) {
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 e30754007..677354d8a 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
@@ -36,10 +36,14 @@ 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.parameters.annotations.Min;
+import org.onap.policy.common.parameters.annotations.NotBlank;
+import org.onap.policy.common.parameters.annotations.NotNull;
+import org.onap.policy.common.parameters.annotations.Valid;
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.validation.annotations.VerifyKey;
/**
* Class to represent the trigger of policy type in TOSCA definition.
@@ -56,27 +60,36 @@ public class JpaToscaTrigger extends PfConcept {
private static final long serialVersionUID = -6515211640208986971L;
@EmbeddedId
+ @VerifyKey
+ @NotNull
private PfReferenceKey key;
@Column
+ @NotBlank
private String description;
@Column
@SerializedName("event_type")
+ @NotNull
+ @NotBlank
private String eventType;
@Column
@SerializedName("schedule")
+ @Valid
private JpaToscaTimeInterval schedule;
@Column
@SerializedName("target_filter")
+ @Valid
private JpaToscaEventFilter targetFilter;
@Column
+ @Valid
private JpaToscaConstraint condition;
@Column
+ @Valid
private JpaToscaConstraint constraint;
@Column
@@ -84,12 +97,16 @@ public class JpaToscaTrigger extends PfConcept {
private Duration period;
@Column
+ @Min(0)
private int evaluations = 0;
@Column
+ @NotBlank
private String method;
@Column
+ @NotNull
+ @NotBlank
private String action;
/**
@@ -174,28 +191,6 @@ public class JpaToscaTrigger extends PfConcept {
}
@Override
- public BeanValidationResult validate(@NonNull String fieldName) {
- BeanValidationResult result = new BeanValidationResult(fieldName, this);
-
- result.addResult(validateKeyNotNull("key", key));
-
- result.addResult(validateNotBlank("description", description, false));
- result.addResult(validateNotBlank("eventType", eventType, true));
-
- validateOptional(result, "schedule", schedule);
- validateOptional(result, "targetFilter", targetFilter);
-
- if (evaluations < 0) {
- addResult(result, "evaluations", evaluations, "is negative");
- }
-
- result.addResult(validateNotBlank("method", method, false));
- result.addResult(validateNotBlank("action", action, true));
-
- return result;
- }
-
- @Override
public int compareTo(final PfConcept otherConcept) {
if (otherConcept == null) {
return -1;