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.bpmn.common.baseclient.BaseClient;
26 import org.onap.so.bpmn.core.UrnPropertiesReader;
27 import org.onap.so.client.exception.BadResponseException;
28 import org.onap.so.client.oof.beans.OofProperties;
29 import org.onap.so.client.oof.beans.OofRequest;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32 import org.springframework.beans.factory.annotation.Autowired;
33 import org.springframework.core.ParameterizedTypeReference;
34 import org.springframework.http.HttpHeaders;
35 import org.springframework.http.MediaType;
36 import org.springframework.stereotype.Component;
38 import com.fasterxml.jackson.core.JsonProcessingException;
39 import java.util.LinkedHashMap;
42 public class OofClient {
44 private static final Logger logger = LoggerFactory.getLogger(OofClient.class);
45 public static final String X_MINOR_VERSION = "X-MinorVersion";
46 public static final String X_PATCH_VERSION = "X-PatchVersion";
47 public static final String X_LATEST_VERSION = "X-LatestVersion";
50 private OofProperties oofProperties;
53 private OofValidator validator;
57 * Makes a rest call to oof to perform homing and licensing for a
60 * @param homingRequest
62 * @throws JsonProcessingException
65 public void postDemands(OofRequest homingRequest) throws BadResponseException, JsonProcessingException{
66 logger.trace("Started oof Client Post Demands");
67 String url = oofProperties.getHost() + oofProperties.getUri();
68 logger.debug("Post demands url: " + url);
69 logger.debug("Post demands payload: " + homingRequest.toJsonString());
71 HttpHeaders header = new HttpHeaders();
72 header.setContentType(MediaType.APPLICATION_JSON);
73 header.set(HttpHeaders.AUTHORIZATION, oofProperties.getHeaders().get("auth"));
74 header.set(X_PATCH_VERSION, oofProperties.getHeaders().get("patchVersion"));
75 header.set(X_MINOR_VERSION, oofProperties.getHeaders().get("minorVersion"));
76 header.set(X_LATEST_VERSION, oofProperties.getHeaders().get("latestVersion"));
77 BaseClient<String, LinkedHashMap<?, ?>> baseClient = new BaseClient<>();
79 baseClient.setTargetUrl(url);
80 baseClient.setHttpHeader(header);
82 LinkedHashMap<?, ?> response = baseClient.post(homingRequest.toJsonString(), new ParameterizedTypeReference<LinkedHashMap<? ,?>>() {});
83 validator.validateDemandsResponse(response);
84 logger.trace("Completed OOF Client Post Demands");