2 * ============LICENSE_START=======================================================
3 * DCAEGEN2-SERVICES-SDK
4 * ================================================================================
5 * Copyright (C) 2018-2019 NOKIA 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=========================================================
20 package org.onap.dcaegen2.services.sdk.rest.services.aai.client.impl;
22 import io.vavr.collection.HashMap;
24 import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpMethod;
25 import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpRequest;
26 import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.ImmutableHttpRequest;
27 import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.RequestBody;
28 import org.onap.dcaegen2.services.sdk.rest.services.aai.client.model.ClientModel;
29 import org.onap.dcaegen2.services.sdk.rest.services.aai.client.model.JsonBodyBuilder;
30 import org.onap.dcaegen2.services.sdk.rest.services.model.logging.RequestDiagnosticContext;
32 public final class AaiRequests {
34 private AaiRequests(){}
36 public static HttpRequest createAaiPatchRequest(String url,
37 RequestDiagnosticContext context,
38 Map<String, String> customHeaders,
39 JsonBodyBuilder jsonBodyBuilder,
40 ClientModel clientModel) {
42 return buildAaiRequestWithBody(url, context, customHeaders,
43 jsonBodyBuilder, clientModel, HttpMethod.PATCH);
46 public static HttpRequest createAaiPutRequest(String url,
47 RequestDiagnosticContext context,
48 Map<String, String> customHeaders,
49 JsonBodyBuilder jsonBodyBuilder,
50 ClientModel clientModel) {
52 return buildAaiRequestWithBody(url, context, customHeaders,
53 jsonBodyBuilder, clientModel, HttpMethod.PUT);
56 private static HttpRequest buildAaiRequestWithBody(String url,
57 RequestDiagnosticContext context,
58 Map<String, String> customHeaders,
59 JsonBodyBuilder jsonBodyBuilder,
60 ClientModel clientModel,
63 String jsonBody = jsonBodyBuilder.createJsonBody(clientModel);
65 return ImmutableHttpRequest.builder()
67 .customHeaders(HashMap.ofAll(customHeaders))
68 .diagnosticContext(context)
69 .body(RequestBody.fromString(jsonBody))
74 public static HttpRequest createAaiGetRequest(String url,
75 RequestDiagnosticContext context,
76 Map<String, String> customHeaders) {
77 return ImmutableHttpRequest.builder()
78 .method(HttpMethod.GET)
80 .customHeaders(HashMap.ofAll(customHeaders))
81 .diagnosticContext(context)