aboutsummaryrefslogtreecommitdiffstats
path: root/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/BluePrintProcessorException.kt
blob: c818b0a44deaefd77fbde9a60167aa8bc590bb04 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
/*
 * Copyright © 2017-2018 AT&T Intellectual Property.
 * Modifications Copyright © 2018 - 2020 IBM, Bell Canada.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.onap.ccsdk.cds.controllerblueprints.core

import org.apache.commons.lang.exception.ExceptionUtils
import org.onap.ccsdk.cds.error.catalog.core.ErrorCatalogException
import org.onap.ccsdk.cds.error.catalog.core.ErrorCatalogExceptionFluent
import org.onap.ccsdk.cds.error.catalog.core.ErrorMessage

/**
 *
 *
 * @author Brinda Santh
 */
open class BluePrintProcessorException : ErrorCatalogException, ErrorCatalogExceptionFluent<BluePrintProcessorException> {

    constructor(message: String, cause: Throwable) : super(message, cause)
    constructor(message: String) : super(message)
    constructor(cause: Throwable) : super(cause)
    constructor(cause: Throwable, message: String, vararg args: Any?) : super(cause, message, args)
    constructor(code: Int, cause: Throwable) : super(code, cause)
    constructor(code: Int, message: String) : super(code, message)
    constructor(code: Int, message: String, cause: Throwable) : super(code, message, cause)

    override fun code(code: Int): BluePrintProcessorException {
        return this.updateCode(code)
    }

    override fun domain(domain: String): BluePrintProcessorException {
        return this.updateDomain(domain)
    }

    override fun action(action: String): BluePrintProcessorException {
        return this.updateAction(action)
    }

    override fun http(type: String): BluePrintProcessorException {
        return this.updateHttp(type)
    }

    override fun grpc(type: String): BluePrintProcessorException {
        return this.updateGrpc(type)
    }

    override fun convertToHttp(): BluePrintProcessorException {
        return this.inverseToHttp()
    }

    override fun convertToGrpc(): BluePrintProcessorException {
        return this.inverseToHttp()
    }

    override fun payloadMessage(message: String): BluePrintProcessorException {
        return this.updatePayloadMessage(message)
    }

    override fun addErrorPayloadMessage(message: String): BluePrintProcessorException {
        return this.updateErrorPayloadMessage(message)
    }

    override fun addSubError(errorMessage: ErrorMessage): BluePrintProcessorException {
        return this.updateSubError(errorMessage)
    }
}

class BluePrintRetryException : RuntimeException {
    constructor(message: String, cause: Throwable) : super(message, cause)
    constructor(message: String) : super(message)
    constructor(cause: Throwable) : super(cause)
    constructor(cause: Throwable, message: String, vararg args: Any?) : super(format(message, *args), cause)
}

/** Extension Functions */

fun processorException(message: String): BluePrintProcessorException {
    return BluePrintProcessorException(message)
}

fun processorException(message: String, cause: Throwable): BluePrintProcessorException {
    return BluePrintProcessorException(message, cause)
}

fun processorException(cause: Throwable, message: String, vararg args: Any?): BluePrintProcessorException {
    return BluePrintProcessorException(cause, message, args)
}

fun processorException(code: Int, message: String): BluePrintProcessorException {
    return processorException(message).code(code)
}

fun processorException(code: Int, message: String, cause: Throwable): BluePrintProcessorException {
    return processorException(message, cause).code(code)
}

fun processorException(code: Int, cause: Throwable, message: String, vararg args: Any?): BluePrintProcessorException {
    return processorException(cause, message, args).code(code)
}

fun httpProcessorException(type: String, message: String): BluePrintProcessorException {
    return processorException(message).http(type)
}

fun grpcProcessorException(type: String, message: String): BluePrintProcessorException {
    return processorException(message).grpc(type)
}

fun httpProcessorException(type: String, domain: String, message: String): BluePrintProcessorException {
    val bluePrintProcessorException = processorException(message).http(type)
    return bluePrintProcessorException.addDomainAndErrorMessage(domain, message)
}

fun grpcProcessorException(type: String, domain: String, message: String): BluePrintProcessorException {
    val bluePrintProcessorException = processorException(message).grpc(type)
    return bluePrintProcessorException.addDomainAndErrorMessage(domain, message)
}

fun httpProcessorException(type: String, domain: String, message: String, cause: Throwable):
    BluePrintProcessorException {
        val bluePrintProcessorException = processorException(message, cause).http(type)
        return bluePrintProcessorException.addDomainAndErrorMessage(domain, message, ExceptionUtils.getRootCauseMessage(cause))
    }

fun grpcProcessorException(type: String, domain: String, message: String, cause: Throwable):
    BluePrintProcessorException {
        val bluePrintProcessorException = processorException(message, cause).grpc(type)
        return bluePrintProcessorException.addDomainAndErrorMessage(domain, message, ExceptionUtils.getRootCauseMessage(cause))
    }

fun httpProcessorException(type: String, domain: String, message: String, cause: Throwable, vararg args: Any?):
    BluePrintProcessorException {
        val bluePrintProcessorException = processorException(cause, message, args).http(type)
        return bluePrintProcessorException.addDomainAndErrorMessage(domain, message, ExceptionUtils.getRootCauseMessage(cause))
    }

fun grpcProcessorException(type: String, domain: String, message: String, cause: Throwable, vararg args: Any?):
    BluePrintProcessorException {
        val bluePrintProcessorException = processorException(cause, message, args).grpc(type)
        return bluePrintProcessorException.addDomainAndErrorMessage(domain, message, ExceptionUtils.getRootCauseMessage(cause))
    }

fun BluePrintProcessorException.updateErrorMessage(domain: String, message: String, cause: String):
    BluePrintProcessorException {
        return this.addDomainAndErrorMessage(domain, message, cause).domain(domain)
            .addErrorPayloadMessage(message)
            .payloadMessage(message)
    }

fun BluePrintProcessorException.updateErrorMessage(domain: String, message: String): BluePrintProcessorException {
    return this.addDomainAndErrorMessage(domain, message).domain(domain)
        .addErrorPayloadMessage(message)
        .payloadMessage(message)
}

private fun BluePrintProcessorException.addDomainAndErrorMessage(
    domain: String,
    message: String,
    cause: String = ""
): BluePrintProcessorException {
    return this.addSubError(ErrorMessage(domain, message, cause)).domain(domain)
}