2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
6 * Modifications Copyright (C) 2023 Nordix Foundation.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.controlloop.actor.aai;
24 import jakarta.ws.rs.client.Invocation.Builder;
25 import jakarta.ws.rs.client.WebTarget;
26 import java.util.List;
28 import java.util.Map.Entry;
29 import org.onap.policy.common.utils.coder.StandardCoderObject;
30 import org.onap.policy.controlloop.actorserviceprovider.OperationProperties;
31 import org.onap.policy.controlloop.actorserviceprovider.impl.HttpOperation;
32 import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams;
33 import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpConfig;
36 * Superclass of A&AI operators that use "get" to perform their request and store their
37 * response within the context as a {@link StandardCoderObject}. The property name under
38 * which they are stored is ${actor}.${operation}.${targetEntity}.
40 public class AaiGetOperation extends HttpOperation<StandardCoderObject> {
41 public static final int DEFAULT_RETRY = 3;
43 private static final List<String> PROPERTY_NAMES = List.of(OperationProperties.AAI_TARGET_ENTITY);
46 * Constructs the object.
48 * @param params operation parameters
49 * @param config configuration for this operation
51 public AaiGetOperation(ControlLoopOperationParams params, HttpConfig config) {
52 super(params, config, StandardCoderObject.class, PROPERTY_NAMES);
56 public void generateSubRequestId(int attempt) {
57 setSubRequestId(String.valueOf(attempt));
61 * Adds a query parameter to a web target.
63 * @param web target to which the parameter should be added
64 * @param str the separator and parameter are appended here, for logging purposes
65 * @param separator separator to be added to "str"; that's its only use
66 * @param name parameter name
67 * @param value parameter value
70 protected WebTarget addQuery(WebTarget web, StringBuilder str, String separator, String name, String value) {
71 str.append(separator);
76 return web.queryParam(name, value);
80 * Adds headers to the web builder.
82 * @param webldr builder to which the headers should be added
83 * @param headers headers to be added
85 protected void addHeaders(Builder webldr, Map<String, Object> headers) {
86 for (Entry<String, Object> header : headers.entrySet()) {
87 webldr.header(header.getKey(), header.getValue());
92 protected Map<String, Object> makeHeaders() {
93 return AaiUtil.makeHeaders(params);
97 * Provides a default retry value, if none specified.
100 protected int getRetry(Integer retry) {
101 return (retry == null ? DEFAULT_RETRY : retry);