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;
25 import java.util.Optional;
26 import javax.ws.rs.client.ClientBuilder;
27 import javax.ws.rs.core.Response;
28 import org.onap.aaiclient.client.CacheControlFeature;
29 import org.onap.aaiclient.client.FlushCache;
30 import org.onap.logging.filter.base.ONAPComponentsList;
31 import org.onap.so.client.AddCacheHeaders;
32 import org.onap.so.client.CacheFactory;
33 import org.onap.so.client.ResponseExceptionMapper;
34 import org.onap.so.client.RestClientSSL;
35 import org.onap.so.client.RestProperties;
36 import org.onap.so.client.policy.CommonObjectMapperProvider;
38 public abstract class GraphInventoryRestClient extends RestClientSSL {
40 protected static final GraphInventoryCommonObjectMapperProvider standardProvider =
41 new GraphInventoryCommonObjectMapperProvider();
43 protected final GraphInventoryPatchConverter patchConverter = new GraphInventoryPatchConverter();
45 protected GraphInventoryRestClient(RestProperties props, URI uri) {
46 super(props, Optional.of(uri));
50 protected ClientBuilder enableCaching(ClientBuilder builder) {
51 builder.register(new AddCacheHeaders(props.getCacheProperties()));
52 builder.register(new FlushCache(props.getCacheProperties()));
53 CacheControlFeature cacheControlFeature = new CacheControlFeature();
54 cacheControlFeature.setCacheResponseInputStream(true);
55 cacheControlFeature.setExpiryPolicyFactory(new CacheFactory(props.getCacheProperties()));
56 builder.property("org.onap.aaiclient.client.CacheControlFeature.name",
57 props.getCacheProperties().getCacheName());
59 builder.register(cacheControlFeature);
65 public abstract ONAPComponentsList getTargetEntity();
68 protected abstract void initializeHeaderMap(Map<String, String> headerMap);
71 protected abstract Optional<ResponseExceptionMapper> addResponseExceptionMapper();
74 protected CommonObjectMapperProvider getCommonObjectMapperProvider() {
75 return standardProvider;
79 public Response patch(Object obj) {
80 return super.patch(convertToPatchFormat(obj));
84 public <T> T patch(Object obj, Class<T> resultClass) {
85 return super.patch(convertToPatchFormat(obj), resultClass);
88 protected GraphInventoryPatchConverter getPatchConverter() {
89 return this.patchConverter;
92 protected String convertToPatchFormat(Object obj) {
93 return getPatchConverter().convertPatchFormat(obj);