Standalone TCA with EELF Logger
[dcaegen2/analytics/tca-gen2.git] / dcae-analytics / dcae-analytics-model / src / main / java / org / onap / dcae / analytics / model / util / json / AnalyticsModelJsonConversion.java
1 /*
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
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
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=========================================================
17  *
18  */
19
20 package org.onap.dcae.analytics.model.util.json;
21
22 import com.fasterxml.jackson.core.type.TypeReference;
23 import com.fasterxml.jackson.databind.ObjectMapper;
24
25 import java.util.List;
26 import java.util.Optional;
27 import java.util.function.Function;
28
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;
32
33 /**
34  * @author Rajiv Singla
35  */
36 public abstract class AnalyticsModelJsonConversion {
37
38     public static final ObjectMapper ANALYTICS_MODEL_OBJECT_MAPPER = new BaseObjectMapperSupplier() {
39         @Override
40         public void registerCustomModules(final ObjectMapper objectMapper) {
41             // do nothing
42         }
43     }.get();
44
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>>() {
48     };
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>>() {
52             };
53     // Type reference to convert single event listener
54     private static final TypeReference<EventListener> EVENT_LISTENER_TYPE_REF = new TypeReference<EventListener>() {
55     };
56
57
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);
62
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);
67
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);
73
74     private AnalyticsModelJsonConversion() {
75         // private constructor
76     }
77 }