7ca0b2f3c537f3da23b74dd1b5deb043670e0d9a
[policy/apex-pdp.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2016-2018 Ericsson. All rights reserved.
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.apex.model.basicmodel.concepts;
22
23 import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult.ValidationResult;
24 import org.onap.policy.apex.model.utilities.Assertions;
25
26 /**
27  * A validation message is created for each validation observation observed during validation of a concept. The message
28  * holds the key and the class of the concept on which the observation was made as well as the type of observation and a
29  * message describing the observation.
30  *
31  * @author Liam Fallon (liam.fallon@ericsson.com)
32  */
33 public class AxValidationMessage {
34     private final AxKey observedKey;
35     private ValidationResult validationResult = ValidationResult.VALID;
36     private final String observedClass;
37     private final String message;
38
39     /**
40      * Create an validation observation with the given fields.
41      *
42      * @param observedKey the key of the class on which the validation observation was made
43      * @param observedClass the class on which the validation observation was made
44      * @param validationResult the type of observation made
45      * @param message a message describing the observation
46      */
47     public AxValidationMessage(final AxKey observedKey, final Class<?> observedClass,
48             final ValidationResult validationResult, final String message) {
49         Assertions.argumentNotNull(observedKey, "observedKey may not be null");
50         Assertions.argumentNotNull(observedClass, "observedClass may not be null");
51         Assertions.argumentNotNull(validationResult, "validationResult may not be null");
52         Assertions.argumentNotNull(message, "message may not be null");
53
54         this.observedKey = observedKey;
55         this.observedClass = observedClass.getCanonicalName();
56         this.validationResult = validationResult;
57         this.message = message;
58     }
59
60     /**
61      * Gets the key of the observation.
62      *
63      * @return the key of the observation
64      */
65     public AxKey getObservedKey() {
66         return observedKey;
67     }
68
69     /**
70      * Gets the observed class.
71      *
72      * @return the observed class
73      */
74     public String getObservedClass() {
75         return observedClass;
76     }
77
78     /**
79      * Gets the type of observation made.
80      *
81      * @return the type of observation made
82      */
83     public ValidationResult getValidationResult() {
84         return validationResult;
85     }
86
87     /**
88      * Get a description of the observation.
89      *
90      * @return the observation description
91      */
92     public String getMessage() {
93         return message;
94     }
95
96     /*
97      * (non-Javadoc)
98      *
99      * @see java.lang.Object#toString()
100      */
101     @Override
102     public String toString() {
103         return observedKey.toString() + ':' + observedClass + ':' + validationResult.name() + ':' + message;
104     }
105 }