Specify "Accept" header in A&AI requests
[policy/models.git] / models-interactions / model-actors / actor.aai / src / main / java / org / onap / policy / controlloop / actor / aai / AaiGetTenantOperation.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 package org.onap.policy.controlloop.actor.aai;
22
23 import java.util.Map;
24 import java.util.concurrent.CompletableFuture;
25 import javax.ws.rs.client.Invocation.Builder;
26 import javax.ws.rs.client.WebTarget;
27 import org.onap.policy.aai.AaiConstants;
28 import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
29 import org.onap.policy.common.endpoints.utils.NetLoggerUtil.EventType;
30 import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
31 import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams;
32 import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpConfig;
33
34 /**
35  * A&AI get-tenant operator.
36  */
37 public class AaiGetTenantOperation extends AaiGetOperation {
38
39     public static final String NAME = "Tenant";
40
41     // property prefixes
42     private static final String KEY_PREFIX = AaiConstants.CONTEXT_PREFIX + NAME + ".";
43
44     /**
45      * Constructs the object.
46      *
47      * @param params operation parameters
48      * @param config configuration for this operation
49      */
50     public AaiGetTenantOperation(ControlLoopOperationParams params, HttpConfig config) {
51         super(params, config);
52     }
53
54     /**
55      * Gets the "context key" for the tenant query response associated with the given
56      * target entity.
57      *
58      * @param targetEntity target entity
59      * @return the "context key" for the response associated with the given target
60      */
61     public static String getKey(String targetEntity) {
62         return (KEY_PREFIX + targetEntity);
63     }
64
65     @Override
66     protected CompletableFuture<OperationOutcome> startOperationAsync(int attempt, OperationOutcome outcome) {
67         final Map<String, Object> headers = makeHeaders();
68
69         StringBuilder str = new StringBuilder(getClient().getBaseUrl());
70
71         String path = getPath();
72         WebTarget web = getClient().getWebTarget().path(path);
73         str.append(path);
74
75         web = addQuery(web, str, "?", "search-node-type", "vserver");
76         web = addQuery(web, str, "&", "filter", "vserver-name:EQUALS:" + getTargetEntity());
77
78         Builder webldr = web.request();
79         addHeaders(webldr, headers);
80
81         String url = str.toString();
82
83         logMessage(EventType.OUT, CommInfrastructure.REST, url, null);
84
85         return handleResponse(outcome, url, callback -> webldr.async().get(callback));
86     }
87 }