2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 Nordix Foundation.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.models.base;
23 import org.onap.policy.common.utils.validation.Assertions;
24 import org.onap.policy.models.base.PfValidationResult.ValidationResult;
27 * A validation message is created for each validation observation observed during validation of a
28 * concept. The message holds the key and the class of the concept on which the observation was made
29 * as well as the type of observation and a message describing the observation.
31 public class PfValidationMessage {
32 private final PfKey observedKey;
33 private ValidationResult validationResult = ValidationResult.VALID;
34 private final String observedClass;
35 private final String message;
38 * Create an validation observation with the given fields.
40 * @param observedKey the key of the class on which the validation observation was made
41 * @param observedClass the class on which the validation observation was made
42 * @param validationResult the type of observation made
43 * @param message a message describing the observation
45 public PfValidationMessage(final PfKey observedKey, final Class<?> observedClass,
46 final ValidationResult validationResult, final String message) {
47 Assertions.argumentNotNull(observedKey, "observedKey may not be null");
48 Assertions.argumentNotNull(observedClass, "observedClass may not be null");
49 Assertions.argumentNotNull(validationResult, "validationResult may not be null");
50 Assertions.argumentNotNull(message, "message may not be null");
52 this.observedKey = observedKey;
53 this.observedClass = observedClass.getCanonicalName();
54 this.validationResult = validationResult;
55 this.message = message;
59 * Gets the key of the observation.
61 * @return the key of the observation
63 public PfKey getObservedKey() {
68 * Gets the observed class.
70 * @return the observed class
72 public String getObservedClass() {
77 * Gets the type of observation made.
79 * @return the type of observation made
81 public ValidationResult getValidationResult() {
82 return validationResult;
86 * Get a description of the observation.
88 * @return the observation description
90 public String getMessage() {
97 * @see java.lang.Object#toString()
100 public String toString() {
101 return observedKey.toString() + ':' + observedClass + ':' + validationResult.name() + ':' + message;