df4e756ace89a71f5213edd1b702aad43560305e
[cps/cps-temporal.git] / src / main / java / org / onap / cps / temporal / controller / event / listener / exception / InvalidEventEnvelopException.java
1 /*
2  * ============LICENSE_START=======================================================
3  * Copyright (c) 2021 Bell Canada.
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  * ============LICENSE_END=========================================================
17  */
18
19 package org.onap.cps.temporal.controller.event.listener.exception;
20
21 import java.io.Serializable;
22 import java.util.ArrayList;
23 import java.util.List;
24 import lombok.AllArgsConstructor;
25 import lombok.EqualsAndHashCode;
26 import lombok.Getter;
27 import lombok.ToString;
28
29 /**
30  * Class representing an invalid event envelop exception.
31  */
32 @Getter
33 public class InvalidEventEnvelopException extends EventListenerException {
34
35     private final List<InvalidField> invalidFields = new ArrayList<>();
36
37     public InvalidEventEnvelopException(final String message) {
38         super(message);
39     }
40
41     public void addInvalidField(final InvalidField invalidField) {
42         this.invalidFields.add(invalidField);
43     }
44
45     public boolean hasInvalidFields() {
46         return ! this.invalidFields.isEmpty();
47     }
48
49     @Override
50     public String getMessage() {
51         return String.format("%s. invalidFields: %s", super.getMessage(), this.invalidFields.toString());
52     }
53
54     @AllArgsConstructor
55     @Getter
56     @EqualsAndHashCode
57     @ToString
58     public static class InvalidField implements Serializable {
59
60         private static final long serialVersionUID = -7118283787669377391L;
61
62         private final ErrorType errorType;
63         private final String fieldName;
64         private final String actualValue;
65         private final String expectedValue;
66
67         public enum ErrorType {
68             UNEXPECTED, MISSING
69         }
70
71     }
72
73 }