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