Fixing Blueprint Typo's and docs
[ccsdk/cds.git] / ms / blueprintsprocessor / modules / blueprints / blueprint-core / src / main / kotlin / org / onap / ccsdk / cds / controllerblueprints / core / BluePrintProcessorException.kt
1 /*
2  * Copyright © 2017-2018 AT&T Intellectual Property.
3  * Modifications Copyright © 2018 - 2020 IBM, 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  */
17
18 package org.onap.ccsdk.cds.controllerblueprints.core
19
20 import org.apache.commons.lang.exception.ExceptionUtils
21 import org.onap.ccsdk.cds.error.catalog.core.ErrorCatalogException
22 import org.onap.ccsdk.cds.error.catalog.core.ErrorCatalogExceptionFluent
23 import org.onap.ccsdk.cds.error.catalog.core.ErrorMessage
24
25 /**
26  *
27  *
28  * @author Brinda Santh
29  */
30 open class BluePrintProcessorException : ErrorCatalogException, ErrorCatalogExceptionFluent<BluePrintProcessorException> {
31
32     constructor(message: String, cause: Throwable) : super(message, cause)
33     constructor(message: String) : super(message)
34     constructor(cause: Throwable) : super(cause)
35     constructor(cause: Throwable, message: String, vararg args: Any?) : super(cause, message, args)
36     constructor(code: Int, cause: Throwable) : super(code, cause)
37     constructor(code: Int, message: String) : super(code, message)
38     constructor(code: Int, message: String, cause: Throwable) : super(code, message, cause)
39
40     override fun code(code: Int): BluePrintProcessorException {
41         return this.updateCode(code)
42     }
43
44     override fun domain(domain: String): BluePrintProcessorException {
45         return this.updateDomain(domain)
46     }
47
48     override fun action(action: String): BluePrintProcessorException {
49         return this.updateAction(action)
50     }
51
52     override fun http(type: String): BluePrintProcessorException {
53         return this.updateHttp(type)
54     }
55
56     override fun grpc(type: String): BluePrintProcessorException {
57         return this.updateGrpc(type)
58     }
59
60     override fun convertToHttp(): BluePrintProcessorException {
61         return this.inverseToHttp()
62     }
63
64     override fun convertToGrpc(): BluePrintProcessorException {
65         return this.inverseToHttp()
66     }
67
68     override fun payloadMessage(message: String): BluePrintProcessorException {
69         return this.updatePayloadMessage(message)
70     }
71
72     override fun addErrorPayloadMessage(message: String): BluePrintProcessorException {
73         return this.updateErrorPayloadMessage(message)
74     }
75
76     override fun addSubError(errorMessage: ErrorMessage): BluePrintProcessorException {
77         return this.updateSubError(errorMessage)
78     }
79 }
80
81 class BluePrintRetryException : RuntimeException {
82     constructor(message: String, cause: Throwable) : super(message, cause)
83     constructor(message: String) : super(message)
84     constructor(cause: Throwable) : super(cause)
85     constructor(cause: Throwable, message: String, vararg args: Any?) : super(format(message, *args), cause)
86 }
87
88 /** Extension Functions */
89
90 fun processorException(message: String): BluePrintProcessorException {
91     return BluePrintProcessorException(message)
92 }
93
94 fun processorException(message: String, cause: Throwable): BluePrintProcessorException {
95     return BluePrintProcessorException(message, cause)
96 }
97
98 fun processorException(cause: Throwable, message: String, vararg args: Any?): BluePrintProcessorException {
99     return BluePrintProcessorException(cause, message, args)
100 }
101
102 fun processorException(code: Int, message: String): BluePrintProcessorException {
103     return processorException(message).code(code)
104 }
105
106 fun processorException(code: Int, message: String, cause: Throwable): BluePrintProcessorException {
107     return processorException(message, cause).code(code)
108 }
109
110 fun processorException(code: Int, cause: Throwable, message: String, vararg args: Any?): BluePrintProcessorException {
111     return processorException(cause, message, args).code(code)
112 }
113
114 fun httpProcessorException(type: String, message: String): BluePrintProcessorException {
115     return processorException(message).http(type)
116 }
117
118 fun grpcProcessorException(type: String, message: String): BluePrintProcessorException {
119     return processorException(message).grpc(type)
120 }
121
122 fun httpProcessorException(type: String, domain: String, message: String): BluePrintProcessorException {
123     val bluePrintProcessorException = processorException(message).http(type)
124     return bluePrintProcessorException.addDomainAndErrorMessage(domain, message)
125 }
126
127 fun grpcProcessorException(type: String, domain: String, message: String): BluePrintProcessorException {
128     val bluePrintProcessorException = processorException(message).grpc(type)
129     return bluePrintProcessorException.addDomainAndErrorMessage(domain, message)
130 }
131
132 fun httpProcessorException(type: String, domain: String, message: String, cause: Throwable):
133     BluePrintProcessorException {
134         val bluePrintProcessorException = processorException(message, cause).http(type)
135         return bluePrintProcessorException.addDomainAndErrorMessage(domain, message, ExceptionUtils.getRootCauseMessage(cause))
136     }
137
138 fun grpcProcessorException(type: String, domain: String, message: String, cause: Throwable):
139     BluePrintProcessorException {
140         val bluePrintProcessorException = processorException(message, cause).grpc(type)
141         return bluePrintProcessorException.addDomainAndErrorMessage(domain, message, ExceptionUtils.getRootCauseMessage(cause))
142     }
143
144 fun httpProcessorException(type: String, domain: String, message: String, cause: Throwable, vararg args: Any?):
145     BluePrintProcessorException {
146         val bluePrintProcessorException = processorException(cause, message, args).http(type)
147         return bluePrintProcessorException.addDomainAndErrorMessage(domain, message, ExceptionUtils.getRootCauseMessage(cause))
148     }
149
150 fun grpcProcessorException(type: String, domain: String, message: String, cause: Throwable, vararg args: Any?):
151     BluePrintProcessorException {
152         val bluePrintProcessorException = processorException(cause, message, args).grpc(type)
153         return bluePrintProcessorException.addDomainAndErrorMessage(domain, message, ExceptionUtils.getRootCauseMessage(cause))
154     }
155
156 fun BluePrintProcessorException.updateErrorMessage(domain: String, message: String, cause: String):
157     BluePrintProcessorException {
158         return this.addDomainAndErrorMessage(domain, message, cause).domain(domain)
159             .addErrorPayloadMessage(message)
160             .payloadMessage(message)
161     }
162
163 fun BluePrintProcessorException.updateErrorMessage(domain: String, message: String): BluePrintProcessorException {
164     return this.addDomainAndErrorMessage(domain, message).domain(domain)
165         .addErrorPayloadMessage(message)
166         .payloadMessage(message)
167 }
168
169 private fun BluePrintProcessorException.addDomainAndErrorMessage(
170     domain: String,
171     message: String,
172     cause: String = ""
173 ): BluePrintProcessorException {
174     return this.addSubError(ErrorMessage(domain, message, cause)).domain(domain)
175 }