2 * Copyright © 2017-2018 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.apps.controllerblueprints.core.utils
19 import com.att.eelf.configuration.EELFLogger
20 import com.att.eelf.configuration.EELFManager
21 import com.fasterxml.jackson.databind.JsonNode
22 import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
23 import reactor.core.publisher.Mono
24 import reactor.core.publisher.toMono
26 @Deprecated("Reactor will be replaced by coroutines by default")
27 object JacksonReactorUtils {
28 private val log: EELFLogger = EELFManager.getInstance().getLogger(this::class.toString())
31 fun getContent(fileName: String): Mono<String> {
32 return JacksonUtils.getContent(fileName).toMono()
36 fun getClassPathFileContent(fileName: String): Mono<String> {
37 return JacksonUtils.getClassPathFileContent(fileName).toMono()
41 fun <T> readValue(content: String, valueType: Class<T>): Mono<T> {
42 return Mono.just(jacksonObjectMapper().readValue(content, valueType))
46 fun jsonNode(content: String): Mono<JsonNode> {
47 return Mono.just(jacksonObjectMapper().readTree(content))
51 fun getJson(any: kotlin.Any, pretty: Boolean = false): Mono<String> {
52 return Mono.just(JacksonUtils.getJson(any, pretty))
56 fun <T> getListFromJson(content: String, valueType: Class<T>): Mono<List<T>> {
57 val objectMapper = jacksonObjectMapper()
58 val javaType = objectMapper.typeFactory.constructCollectionType(List::class.java, valueType)
59 return objectMapper.readValue<List<T>>(content, javaType).toMono()
63 fun <T> readValueFromFile(fileName: String, valueType: Class<T>): Mono<T> {
64 return getContent(fileName)
66 readValue(content, valueType)
71 fun <T> readValueFromClassPathFile(fileName: String, valueType: Class<T>): Mono<T> {
72 return getClassPathFileContent(fileName)
74 readValue(content, valueType)
79 fun jsonNodeFromFile(fileName: String): Mono<JsonNode> {
80 return getContent(fileName)
87 fun jsonNodeFromClassPathFile(fileName: String): Mono<JsonNode> {
88 return getClassPathFileContent(fileName)
95 fun <T> getListFromFile(fileName: String, valueType: Class<T>): Mono<List<T>> {
96 return getContent(fileName)
98 getListFromJson(content, valueType)
103 fun <T> getListFromClassPathFile(fileName: String, valueType: Class<T>): Mono<List<T>> {
104 return getClassPathFileContent(fileName)
105 .flatMap { content ->
106 getListFromJson(content, valueType)