2c1d6bc4202b7fe536068bfb1b747a2d1abbd259
[so.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.aaiclient.client.graphinventory;
22
23 import java.net.URI;
24 import java.util.Optional;
25 import javax.ws.rs.client.ClientBuilder;
26 import javax.ws.rs.core.MultivaluedMap;
27 import javax.ws.rs.core.Response;
28 import org.javatuples.Pair;
29 import org.onap.aaiclient.client.CacheControlFeature;
30 import org.onap.aaiclient.client.FlushCache;
31 import org.onap.logging.filter.base.ONAPComponentsList;
32 import org.onap.so.client.AddCacheHeaders;
33 import org.onap.so.client.CacheFactory;
34 import org.onap.so.client.ResponseExceptionMapper;
35 import org.onap.so.client.RestClientSSL;
36 import org.onap.so.client.RestProperties;
37 import org.onap.so.client.CommonObjectMapperProvider;
38 import org.onap.so.objects.audit.AAIObjectAudit;
39
40 public abstract class GraphInventoryRestClient extends RestClientSSL {
41
42     protected static final GraphInventoryCommonObjectMapperProvider standardProvider =
43             new GraphInventoryCommonObjectMapperProvider();
44
45     protected final GraphInventoryPatchConverter patchConverter = new GraphInventoryPatchConverter();
46
47     protected GraphInventoryRestClient(RestProperties props, URI uri) {
48         super(props, Optional.of(uri));
49     }
50
51
52     protected ClientBuilder enableCaching(ClientBuilder builder) {
53         builder.register(new AddCacheHeaders(props.getCacheProperties()));
54         builder.register(new FlushCache(props.getCacheProperties()));
55         CacheControlFeature cacheControlFeature = new CacheControlFeature();
56         cacheControlFeature.setCacheResponseInputStream(true);
57         cacheControlFeature.setExpiryPolicyFactory(new CacheFactory(props.getCacheProperties()));
58         builder.property("org.onap.aaiclient.client.CacheControlFeature.name",
59                 props.getCacheProperties().getCacheName());
60
61         builder.register(cacheControlFeature);
62
63         return builder;
64     }
65
66     @Override
67     public abstract ONAPComponentsList getTargetEntity();
68
69     @Override
70     protected abstract void initializeHeaderMap(MultivaluedMap<String, Pair<String, String>> headerMap);
71
72     @Override
73     protected abstract Optional<ResponseExceptionMapper> addResponseExceptionMapper();
74
75     @Override
76     protected CommonObjectMapperProvider getCommonObjectMapperProvider() {
77         return standardProvider;
78     }
79
80     @Override
81     public Response patch(Object obj) {
82         return super.patch(convertToPatchFormat(obj));
83     }
84
85     @Override
86     public <T> T patch(Object obj, Class<T> resultClass) {
87         return super.patch(convertToPatchFormat(obj), resultClass);
88     }
89
90     protected GraphInventoryPatchConverter getPatchConverter() {
91         return this.patchConverter;
92     }
93
94     protected String convertToPatchFormat(Object obj) {
95         return getPatchConverter().convertPatchFormat(obj);
96     }
97
98 }