2 * Copyright © 2017-2018 AT&T Intellectual Property.
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
17 package org.onap.ccsdk.apps.controllerblueprints.core.utils
\r
19 import com.att.eelf.configuration.EELFLogger
\r
20 import com.att.eelf.configuration.EELFManager
\r
21 import com.fasterxml.jackson.databind.JsonNode
\r
22 import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
\r
23 import reactor.core.publisher.Mono
\r
24 import reactor.core.publisher.toMono
\r
26 object JacksonReactorUtils {
\r
27 private val log: EELFLogger = EELFManager.getInstance().getLogger(this::class.toString())
\r
30 fun getContent(fileName: String): Mono<String> {
\r
31 return JacksonUtils.getContent(fileName).toMono()
\r
35 fun getClassPathFileContent(fileName: String): Mono<String> {
\r
36 return JacksonUtils.getClassPathFileContent(fileName).toMono()
\r
40 fun <T> readValue(content: String, valueType: Class<T>): Mono<T> {
\r
41 return Mono.just(jacksonObjectMapper().readValue(content, valueType))
\r
45 fun jsonNode(content: String): Mono<JsonNode> {
\r
46 return Mono.just(jacksonObjectMapper().readTree(content))
\r
50 fun getJson(any: kotlin.Any, pretty: Boolean = false): Mono<String> {
\r
51 return Mono.just(JacksonUtils.getJson(any, pretty))
\r
55 fun <T> getListFromJson(content: String, valueType: Class<T>): Mono<List<T>> {
\r
56 val objectMapper = jacksonObjectMapper()
\r
57 val javaType = objectMapper.typeFactory.constructCollectionType(List::class.java, valueType)
\r
58 return objectMapper.readValue<List<T>>(content, javaType).toMono()
\r
62 fun <T> readValueFromFile(fileName: String, valueType: Class<T>): Mono<T> {
\r
63 return getContent(fileName)
\r
64 .flatMap { content ->
\r
65 readValue(content, valueType)
\r
70 fun <T> readValueFromClassPathFile(fileName: String, valueType: Class<T>): Mono<T> {
\r
71 return getClassPathFileContent(fileName)
\r
72 .flatMap { content ->
\r
73 readValue(content, valueType)
\r
78 fun jsonNodeFromFile(fileName: String): Mono<JsonNode> {
\r
79 return getContent(fileName)
\r
80 .flatMap { content ->
\r
86 fun jsonNodeFromClassPathFile(fileName: String): Mono<JsonNode> {
\r
87 return getClassPathFileContent(fileName)
\r
88 .flatMap { content ->
\r
94 fun <T> getListFromFile(fileName: String, valueType: Class<T>): Mono<List<T>> {
\r
95 return getContent(fileName)
\r
96 .flatMap { content ->
\r
97 getListFromJson(content, valueType)
\r
102 fun <T> getListFromClassPathFile(fileName: String, valueType: Class<T>): Mono<List<T>> {
\r
103 return getClassPathFileContent(fileName)
\r
104 .flatMap { content ->
\r
105 getListFromJson(content, valueType)
\r