c98ce5178314de0593b3fb51edd8bf638b6939ab
[policy/apex-pdp.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2016-2018 Ericsson. All rights reserved.
4  *  Modifications Copyright (C) 2019 Nordix Foundation.
5  * ================================================================================
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * SPDX-License-Identifier: Apache-2.0
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.policy.apex.model.basicmodel.concepts;
23
24 import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult.ValidationResult;
25 import org.onap.policy.common.utils.validation.Assertions;
26
27 /**
28  * A validation message is created for each validation observation observed during validation of a concept. The message
29  * holds the key and the class of the concept on which the observation was made as well as the type of observation and a
30  * message describing the observation.
31  *
32  * @author Liam Fallon (liam.fallon@ericsson.com)
33  */
34 public class AxValidationMessage {
35     private final AxKey observedKey;
36     private ValidationResult validationResult = ValidationResult.VALID;
37     private final String observedClass;
38     private final String message;
39
40     /**
41      * Create an validation observation with the given fields.
42      *
43      * @param observedKey the key of the class on which the validation observation was made
44      * @param observedClass the class on which the validation observation was made
45      * @param validationResult the type of observation made
46      * @param message a message describing the observation
47      */
48     public AxValidationMessage(final AxKey observedKey, final Class<?> observedClass,
49             final ValidationResult validationResult, final String message) {
50         Assertions.argumentNotNull(observedKey, "observedKey may not be null");
51         Assertions.argumentNotNull(observedClass, "observedClass may not be null");
52         Assertions.argumentNotNull(validationResult, "validationResult may not be null");
53         Assertions.argumentNotNull(message, "message may not be null");
54
55         this.observedKey = observedKey;
56         this.observedClass = observedClass.getName();
57         this.validationResult = validationResult;
58         this.message = message;
59     }
60
61     /**
62      * Gets the key of the observation.
63      *
64      * @return the key of the observation
65      */
66     public AxKey getObservedKey() {
67         return observedKey;
68     }
69
70     /**
71      * Gets the observed class.
72      *
73      * @return the observed class
74      */
75     public String getObservedClass() {
76         return observedClass;
77     }
78
79     /**
80      * Gets the type of observation made.
81      *
82      * @return the type of observation made
83      */
84     public ValidationResult getValidationResult() {
85         return validationResult;
86     }
87
88     /**
89      * Get a description of the observation.
90      *
91      * @return the observation description
92      */
93     public String getMessage() {
94         return message;
95     }
96
97     /*
98      * (non-Javadoc)
99      *
100      * @see java.lang.Object#toString()
101      */
102     @Override
103     public String toString() {
104         return observedKey.toString() + ':' + observedClass + ':' + validationResult.name() + ':' + message;
105     }
106 }