Java 17 Upgrade
[policy/models.git] / models-interactions / model-actors / actor.aai / src / main / java / org / onap / policy / controlloop / actor / aai / AaiGetPnfOperation.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.net.URLEncoder;
27 import java.nio.charset.StandardCharsets;
28 import java.util.Map;
29 import java.util.concurrent.CompletableFuture;
30 import org.onap.policy.aai.AaiConstants;
31 import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
32 import org.onap.policy.common.endpoints.utils.NetLoggerUtil.EventType;
33 import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
34 import org.onap.policy.controlloop.actorserviceprovider.OperationProperties;
35 import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams;
36 import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpConfig;
37
38 /**
39  * A&AI get-pnf operator.
40  */
41 public class AaiGetPnfOperation extends AaiGetOperation {
42     private static final String URI_SEP = "/";
43
44     public static final String NAME = "Pnf";
45
46     // property prefixes
47     private static final String KEY_PREFIX = AaiConstants.CONTEXT_PREFIX + NAME + ".";
48
49     /**
50      * Constructs the object.
51      *
52      * @param params operation parameters
53      * @param config configuration for this operation
54      */
55     public AaiGetPnfOperation(ControlLoopOperationParams params, HttpConfig config) {
56         super(params, config);
57     }
58
59     /**
60      * Gets the "context key" for the PNF query response associated with the given
61      * target entity.
62      *
63      * @param targetEntity target entity
64      * @return the "context key" for the response associated with the given target
65      */
66     public static String getKey(String targetEntity) {
67         return (KEY_PREFIX + targetEntity);
68     }
69
70     @Override
71     protected CompletableFuture<OperationOutcome> startOperationAsync(int attempt, OperationOutcome outcome) {
72         Map<String, Object> headers = makeHeaders();
73
74         var str = new StringBuilder(getClient().getBaseUrl());
75
76         String target = getRequiredProperty(OperationProperties.AAI_TARGET_ENTITY, "target entity");
77         String path = getPath() + URI_SEP + URLEncoder.encode(target, StandardCharsets.UTF_8);
78         WebTarget web = getClient().getWebTarget().path(path);
79         str.append(path);
80
81         web = addQuery(web, str, "?", "depth", "0");
82
83         Builder webldr = web.request();
84         addHeaders(webldr, headers);
85
86         var url = str.toString();
87
88         logMessage(EventType.OUT, CommInfrastructure.REST, url, null);
89
90         return handleResponse(outcome, url, callback -> webldr.async().get(callback));
91     }
92 }