Use annotations to do validation
[policy/models.git] / models-tosca / src / main / java / org / onap / policy / models / tosca / simple / concepts / JpaToscaNodeType.java
index f39f9b9..0965d8b 100644 (file)
@@ -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;
     }