2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2020 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.policy.controlloop.actor.aai;
23 import java.util.List;
25 import java.util.Map.Entry;
26 import javax.ws.rs.client.Invocation.Builder;
27 import javax.ws.rs.client.WebTarget;
28 import org.onap.policy.common.utils.coder.StandardCoderObject;
29 import org.onap.policy.controlloop.actorserviceprovider.OperationProperties;
30 import org.onap.policy.controlloop.actorserviceprovider.impl.HttpOperation;
31 import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams;
32 import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpConfig;
35 * Superclass of A&AI operators that use "get" to perform their request and store their
36 * response within the context as a {@link StandardCoderObject}. The property name under
37 * which they are stored is ${actor}.${operation}.${targetEntity}.
39 public class AaiGetOperation extends HttpOperation<StandardCoderObject> {
40 public static final int DEFAULT_RETRY = 3;
42 private static final List<String> PROPERTY_NAMES = List.of(OperationProperties.AAI_TARGET_ENTITY);
45 * Constructs the object.
47 * @param params operation parameters
48 * @param config configuration for this operation
50 public AaiGetOperation(ControlLoopOperationParams params, HttpConfig config) {
51 super(params, config, StandardCoderObject.class, PROPERTY_NAMES);
55 public void generateSubRequestId(int attempt) {
56 setSubRequestId(String.valueOf(attempt));
60 * Adds a query parameter to a web target.
62 * @param web target to which the parameter should be added
63 * @param str the separator and parameter are appended here, for logging purposes
64 * @param separator separator to be added to "str"; that's its only use
65 * @param name parameter name
66 * @param value parameter value
69 protected WebTarget addQuery(WebTarget web, StringBuilder str, String separator, String name, String value) {
70 str.append(separator);
75 return web.queryParam(name, value);
79 * Adds headers to the web builder.
81 * @param webldr builder to which the headers should be added
82 * @param headers headers to be added
84 protected void addHeaders(Builder webldr, Map<String, Object> headers) {
85 for (Entry<String, Object> header : headers.entrySet()) {
86 webldr.header(header.getKey(), header.getValue());
91 protected Map<String, Object> makeHeaders() {
92 return AaiUtil.makeHeaders(params);
96 * Provides a default retry value, if none specified.
99 protected int getRetry(Integer retry) {
100 return (retry == null ? DEFAULT_RETRY : retry);