b33c118deb9680773a7fb78979fb4f9be1d6c672
[ccsdk/cds.git] / ms / error-catalog / core / src / main / kotlin / org / onap / ccsdk / error / catalog / core / ErrorLibData.kt
1 /*
2  *  Copyright © 2020 IBM, Bell Canada.
3  *
4  *  Licensed under the Apache License, Version 2.0 (the "License");
5  *  you may not use this file except in compliance with the License.
6  *  You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *  Unless required by applicable law or agreed to in writing, software
11  *  distributed under the License is distributed on an "AS IS" BASIS,
12  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *  See the License for the specific language governing permissions and
14  *  limitations under the License.
15  */
16
17 package org.onap.ccsdk.error.catalog.core
18
19 import com.fasterxml.jackson.annotation.JsonFormat
20 import org.slf4j.event.Level
21 import org.onap.ccsdk.error.catalog.core.ErrorMessageLibConstants.ERROR_CATALOG_DEFAULT_ERROR_CODE
22 import java.time.LocalDateTime
23
24 open class ErrorPayload {
25     var code: Int = ERROR_CATALOG_DEFAULT_ERROR_CODE
26     var status: String = ""
27     @get:JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
28     var timestamp: LocalDateTime = LocalDateTime.now()
29     var message: String = ""
30     var debugMessage: String = ""
31     var logLevel: String = Level.ERROR.name
32     val subErrors: ArrayList<ErrorMessage> = ArrayList()
33
34     constructor()
35
36     constructor(
37         code: Int = ERROR_CATALOG_DEFAULT_ERROR_CODE,
38         status: String,
39         message: String,
40         logLevel: String = Level.ERROR.name,
41         debugMessage: String = ""
42     ) {
43         this.code = code
44         this.status = status
45         this.message = message
46         this.logLevel = logLevel
47         this.debugMessage = debugMessage
48     }
49
50     constructor(
51         code: Int = ERROR_CATALOG_DEFAULT_ERROR_CODE,
52         status: String,
53         message: String,
54         logLevel: String = Level.ERROR.name,
55         debugMessage: String = "",
56         errorMessage: ErrorMessage
57     ) {
58         this.code = code
59         this.status = status
60         this.message = message
61         this.logLevel = logLevel
62         this.debugMessage = debugMessage
63         this.subErrors.add(errorMessage)
64     }
65
66     fun isEqualTo(errorPayload: ErrorPayload): Boolean {
67         return (this.code == errorPayload.code && this.status == errorPayload.status && this.message == errorPayload.message &&
68             this.logLevel == errorPayload.logLevel && this.debugMessage == errorPayload.debugMessage &&
69             this.subErrors == errorPayload.subErrors)
70     }
71 }
72
73 /**
74  *
75  *
76  * @author Steve Siani
77  */
78 data class ErrorMessage(
79     val domainId: String,
80     val message: String,
81     val cause: String
82 )
83
84 data class ErrorCatalog(
85     val errorId: String,
86     val domainId: String,
87     val code: Int,
88     val action: String,
89     val cause: String
90 ) {
91     fun getMessage(): String {
92         return "Cause: $cause ${System.lineSeparator()} Action : $action"
93     }
94 }