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.so.client.db.request;
23 import java.io.IOException;
26 import org.onap.so.db.request.beans.InfraActiveRequests;
27 import org.springframework.beans.factory.annotation.Value;
28 import org.springframework.http.HttpRequest;
29 import org.springframework.http.client.ClientHttpRequestExecution;
30 import org.springframework.http.client.ClientHttpRequestInterceptor;
31 import org.springframework.http.client.ClientHttpResponse;
32 import org.springframework.stereotype.Component;
33 import org.springframework.web.client.RestTemplate;
35 import uk.co.blackpepper.bowman.Client;
36 import uk.co.blackpepper.bowman.ClientFactory;
37 import uk.co.blackpepper.bowman.Configuration;
38 import uk.co.blackpepper.bowman.RestTemplateConfigurer;
40 @Component("RequestDbClient")
41 public class RequestsDbClient {
43 private Client<InfraActiveRequests> infraActiveRequestClient;
45 @Value("${mso.adapters.db.spring.endpoint}")
46 private String endpoint;
48 @Value("${mso.db.auth}")
49 private String msoAdaptersAuth;
51 public RequestsDbClient() {
52 ClientFactory clientFactory = Configuration.builder().setRestTemplateConfigurer(new RestTemplateConfigurer() {
54 public void configure(RestTemplate restTemplate) {
56 restTemplate.getInterceptors().add(new ClientHttpRequestInterceptor() {
58 public ClientHttpResponse intercept(HttpRequest request, byte[] body,
59 ClientHttpRequestExecution execution) throws IOException {
61 request.getHeaders().add("Authorization", msoAdaptersAuth);
62 return execution.execute(request, body);
66 }).build().buildClientFactory();
67 infraActiveRequestClient = clientFactory.create(InfraActiveRequests.class);
71 public InfraActiveRequests getInfraActiveRequestbyRequestId(String requestId) {
72 return this.getSingleInfraActiveRequests(this.getUri(endpoint + "/infraActiveRequests/" + requestId));
75 protected InfraActiveRequests getSingleInfraActiveRequests(URI uri) {
76 return infraActiveRequestClient.get(uri);
79 public void updateInfraActiveRequests(InfraActiveRequests request) {
80 infraActiveRequestClient.put(request);
83 protected URI getUri(String uri) {
84 return URI.create(uri);