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