2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 Intel Corp. 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.oof;
24 import org.camunda.bpm.engine.delegate.BpmnError;
25 import org.onap.so.client.BaseClient;
26 import org.onap.so.client.exception.BadResponseException;
27 import org.onap.so.client.oof.beans.OofProperties;
28 import org.onap.so.client.oof.beans.OofRequest;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
31 import org.springframework.beans.factory.annotation.Autowired;
32 import org.springframework.core.ParameterizedTypeReference;
33 import org.springframework.http.HttpHeaders;
34 import org.springframework.http.MediaType;
35 import org.springframework.stereotype.Component;
36 import com.fasterxml.jackson.core.JsonProcessingException;
37 import java.util.LinkedHashMap;
40 public class OofClient {
42 private static final Logger logger = LoggerFactory.getLogger(OofClient.class);
43 public static final String X_MINOR_VERSION = "X-MinorVersion";
44 public static final String X_PATCH_VERSION = "X-PatchVersion";
45 public static final String X_LATEST_VERSION = "X-LatestVersion";
48 private OofProperties oofProperties;
51 private OofValidator validator;
55 * Makes a rest call to oof to perform homing and licensing for a list of demands
57 * @param homingRequest
59 * @throws JsonProcessingException
62 public void postDemands(OofRequest homingRequest) throws BadResponseException, JsonProcessingException {
63 logger.trace("Started oof Client Post Demands");
64 String url = oofProperties.getHost() + oofProperties.getUri();
65 logger.debug("Post demands url: " + url);
66 logger.debug("Post demands payload: " + homingRequest.toJsonString());
68 HttpHeaders header = new HttpHeaders();
69 header.setContentType(MediaType.APPLICATION_JSON);
70 header.set(HttpHeaders.AUTHORIZATION, oofProperties.getHeaders().get("auth"));
71 header.set(X_PATCH_VERSION, oofProperties.getHeaders().get("patchVersion"));
72 header.set(X_MINOR_VERSION, oofProperties.getHeaders().get("minorVersion"));
73 header.set(X_LATEST_VERSION, oofProperties.getHeaders().get("latestVersion"));
74 BaseClient<String, LinkedHashMap<?, ?>> baseClient = new BaseClient<>();
76 baseClient.setTargetUrl(url);
77 baseClient.setHttpHeader(header);
79 LinkedHashMap<?, ?> response =
80 baseClient.post(homingRequest.toJsonString(), new ParameterizedTypeReference<LinkedHashMap<?, ?>>() {});
81 validator.validateDemandsResponse(response);
82 logger.trace("Completed OOF Client Post Demands");