2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.aaiclient.client.graphinventory;
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;
40 public abstract class GraphInventoryRestClient extends RestClientSSL {
42 protected static final GraphInventoryCommonObjectMapperProvider standardProvider =
43 new GraphInventoryCommonObjectMapperProvider();
45 protected final GraphInventoryPatchConverter patchConverter = new GraphInventoryPatchConverter();
47 protected GraphInventoryRestClient(RestProperties props, URI uri) {
48 super(props, Optional.of(uri));
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());
61 builder.register(cacheControlFeature);
67 public abstract ONAPComponentsList getTargetEntity();
70 protected abstract void initializeHeaderMap(MultivaluedMap<String, Pair<String, String>> headerMap);
73 protected abstract Optional<ResponseExceptionMapper> addResponseExceptionMapper();
76 protected CommonObjectMapperProvider getCommonObjectMapperProvider() {
77 return standardProvider;
81 public Response patch(Object obj) {
82 return super.patch(convertToPatchFormat(obj));
86 public <T> T patch(Object obj, Class<T> resultClass) {
87 return super.patch(convertToPatchFormat(obj), resultClass);
90 protected GraphInventoryPatchConverter getPatchConverter() {
91 return this.patchConverter;
94 protected String convertToPatchFormat(Object obj) {
95 return getPatchConverter().convertPatchFormat(obj);