Add basic model object concepts
[policy/models.git] / models-base / src / main / java / org / onap / policy / models / base / PfValidationMessage.java
1 /*-
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
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.models.base;
22
23 import org.onap.policy.common.utils.validation.Assertions;
24 import org.onap.policy.models.base.PfValidationResult.ValidationResult;
25
26 /**
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.
30  */
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;
36
37     /**
38      * Create an validation observation with the given fields.
39      *
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
44      */
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");
51
52         this.observedKey = observedKey;
53         this.observedClass = observedClass.getCanonicalName();
54         this.validationResult = validationResult;
55         this.message = message;
56     }
57
58     /**
59      * Gets the key of the observation.
60      *
61      * @return the key of the observation
62      */
63     public PfKey getObservedKey() {
64         return observedKey;
65     }
66
67     /**
68      * Gets the observed class.
69      *
70      * @return the observed class
71      */
72     public String getObservedClass() {
73         return observedClass;
74     }
75
76     /**
77      * Gets the type of observation made.
78      *
79      * @return the type of observation made
80      */
81     public ValidationResult getValidationResult() {
82         return validationResult;
83     }
84
85     /**
86      * Get a description of the observation.
87      *
88      * @return the observation description
89      */
90     public String getMessage() {
91         return message;
92     }
93
94     /*
95      * (non-Javadoc)
96      *
97      * @see java.lang.Object#toString()
98      */
99     @Override
100     public String toString() {
101         return observedKey.toString() + ':' + observedClass + ':' + validationResult.name() + ':' + message;
102     }
103 }