2 * ================================================================================
3 * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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 * ============LICENSE_END=========================================================
20 package org.onap.dcae.analytics.model.util.json;
22 import com.fasterxml.jackson.core.type.TypeReference;
23 import com.fasterxml.jackson.databind.ObjectMapper;
25 import java.util.List;
26 import java.util.Optional;
27 import java.util.function.Function;
29 import org.onap.dcae.analytics.model.cef.EventListener;
30 import org.onap.dcae.analytics.model.configbindingservice.ConsulConfigBindingServiceQueryResponse;
31 import org.onap.dcae.analytics.model.util.function.JsonToJavaObjectBiFunction;
34 * @author Rajiv Singla
36 public abstract class AnalyticsModelJsonConversion {
38 public static final ObjectMapper ANALYTICS_MODEL_OBJECT_MAPPER = new BaseObjectMapperSupplier() {
40 public void registerCustomModules(final ObjectMapper objectMapper) {
45 // Type reference to convert a list or array of Config Service Binding
46 private static final TypeReference<List<ConsulConfigBindingServiceQueryResponse>>
47 CONFIG_BINDING_SERVICE_LIST_TYPE_REF = new TypeReference<List<ConsulConfigBindingServiceQueryResponse>>() {
49 // Type reference to convert a list or array of event listener list
50 private static final TypeReference<List<EventListener>> EVENT_LISTENER_LIST_TYPE_REF =
51 new TypeReference<List<EventListener>>() {
53 // Type reference to convert single event listener
54 private static final TypeReference<EventListener> EVENT_LISTENER_TYPE_REF = new TypeReference<EventListener>() {
58 // Event Listener Json Conversion Function
59 public static final Function<String, Optional<EventListener>> EVENT_LISTENER_JSON_FUNCTION =
60 new JsonToJavaObjectBiFunction<EventListener>(ANALYTICS_MODEL_OBJECT_MAPPER)
61 .curry(EVENT_LISTENER_TYPE_REF);
63 // Event Listener List Json Conversion Function
64 public static final Function<String, Optional<List<EventListener>>> EVENT_LISTENER_LIST_JSON_FUNCTION =
65 new JsonToJavaObjectBiFunction<List<EventListener>>(ANALYTICS_MODEL_OBJECT_MAPPER)
66 .curry(EVENT_LISTENER_LIST_TYPE_REF);
68 // Consul Config Binding Service Query Json Conversion Function
69 public static final Function<String, Optional<List<ConsulConfigBindingServiceQueryResponse>>>
70 CONFIG_BINDING_SERVICE_LIST_JSON_FUNCTION = new
71 JsonToJavaObjectBiFunction<List<ConsulConfigBindingServiceQueryResponse>>(ANALYTICS_MODEL_OBJECT_MAPPER)
72 .curry(CONFIG_BINDING_SERVICE_LIST_TYPE_REF);
74 private AnalyticsModelJsonConversion() {
75 // private constructor