* ============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");
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;
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;
}
@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