Support 7.2.1 VES in TCAGEN2
[dcaegen2/analytics/tca-gen2.git] / dcae-analytics / dcae-analytics-tca-model / src / main / java / org / onap / dcae / analytics / tca / model / util / json / TcaModelJsonConversion.java
1 /*
2  * ===========LICENSE_START========================================================
3  * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
4  * Copyright (c) 2022 Wipro Limited Intellectual Property. All rights reserved.
5  * ================================================================================
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  * ============LICENSE_END=========================================================
18  *
19  */
20
21 package org.onap.dcae.analytics.tca.model.util.json;
22
23 import com.fasterxml.jackson.core.type.TypeReference;
24 import com.fasterxml.jackson.databind.ObjectMapper;
25
26 import java.util.Optional;
27 import java.util.function.Function;
28 import java.util.List;
29
30 import org.onap.dcae.analytics.model.util.function.JsonToJavaObjectBiFunction;
31 import org.onap.dcae.analytics.tca.model.facade.TcaAlert;
32 import org.onap.dcae.analytics.tca.model.policy.TcaPolicy;
33
34 /**
35  * @author Rajiv Singla
36  */
37 public abstract class TcaModelJsonConversion {
38
39
40     public static final ObjectMapper TCA_OBJECT_MAPPER = new TcaObjectMapperSupplier().get();
41
42     // Type reference to convert tca policy string to tca policy object
43     private static final TypeReference<List<TcaPolicy>> TCA_POLICY_TYPE_REF = new TypeReference<List<TcaPolicy>>() {
44     };
45
46     // Type reference to convert tca alert string to tca alert
47     private static final TypeReference<TcaAlert> TCA_ALERT_TYPE_REF = new TypeReference<TcaAlert>() {
48     };
49
50     // Tca Policy JSON conversion function
51     public static final Function<String, Optional<List<TcaPolicy>>> TCA_POLICY_JSON_FUNCTION = new
52             JsonToJavaObjectBiFunction<List<TcaPolicy>>(TCA_OBJECT_MAPPER).curry(TCA_POLICY_TYPE_REF);
53
54     // Tca Alert JSON conversion function
55     public static final Function<String, Optional<TcaAlert>> TCA_ALERT_JSON_FUNCTION = new
56             JsonToJavaObjectBiFunction<TcaAlert>(TCA_OBJECT_MAPPER).curry(TCA_ALERT_TYPE_REF);
57
58     private TcaModelJsonConversion() {
59         // private constructor
60     }
61
62 }