2 * Copyright © 2018-2019 AT&T Intellectual Property.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package org.onap.ccsdk.cds.blueprintsprocessor.functions.message.prioritization.topology
19 import org.apache.kafka.common.serialization.Deserializer
20 import org.apache.kafka.common.serialization.Serde
21 import org.apache.kafka.common.serialization.Serializer
22 import org.onap.ccsdk.cds.blueprintsprocessor.functions.message.prioritization.db.MessagePrioritization
23 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException
24 import org.onap.ccsdk.cds.controllerblueprints.core.asJsonString
25 import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
26 import java.nio.charset.Charset
28 open class MessagePrioritizationSerde : Serde<MessagePrioritization> {
30 override fun configure(configs: MutableMap<String, *>?, isKey: Boolean) {
33 override fun close() {
36 override fun deserializer(): Deserializer<MessagePrioritization> {
37 return object : Deserializer<MessagePrioritization> {
38 override fun deserialize(topic: String, data: ByteArray): MessagePrioritization {
39 return JacksonUtils.readValue(String(data), MessagePrioritization::class.java)
40 ?: throw BluePrintProcessorException("failed to convert")
43 override fun configure(configs: MutableMap<String, *>?, isKey: Boolean) {
46 override fun close() {
51 override fun serializer(): Serializer<MessagePrioritization> {
52 return object : Serializer<MessagePrioritization> {
53 override fun configure(configs: MutableMap<String, *>?, isKey: Boolean) {
56 override fun serialize(topic: String?, data: MessagePrioritization): ByteArray {
57 return data.asJsonString().toByteArray(Charset.defaultCharset())
60 override fun close() {