Java 17 Upgrade
[policy/models.git] / models-interactions / model-actors / actor.so / src / main / java / org / onap / policy / controlloop / actor / so / ModifyNssi.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP
4  * ================================================================================
5  * Copyright (C) 2020 Wipro Limited.
6  * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
7  * Modifications Copyright (C) 2023 Nordix Foundation.
8  * ================================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * ============LICENSE_END=========================================================
21  */
22
23 package org.onap.policy.controlloop.actor.so;
24
25 import jakarta.ws.rs.client.Entity;
26 import jakarta.ws.rs.core.MediaType;
27 import java.util.List;
28 import java.util.Map;
29 import java.util.concurrent.CompletableFuture;
30 import org.onap.policy.common.endpoints.event.comm.Topic;
31 import org.onap.policy.common.endpoints.utils.NetLoggerUtil;
32 import org.onap.policy.common.utils.coder.CoderException;
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.HttpPollingConfig;
37 import org.onap.policy.so.SoRequest3gpp;
38
39 public class ModifyNssi extends SoOperation {
40     public static final String NAME = "Modify NSSI";
41
42     private static final List<String> PROPERTY_NAMES = List.of(
43             OperationProperties.EVENT_PAYLOAD);
44
45     /**
46      * Constructs the object.
47      *
48      * @param params        operation parameters
49      * @param config        configuration for this operation
50      */
51     public ModifyNssi(ControlLoopOperationParams params, HttpPollingConfig config) {
52         super(params, config, PROPERTY_NAMES);
53     }
54
55     @Override
56     protected CompletableFuture<OperationOutcome> startOperationAsync(int attempt, OperationOutcome outcome) {
57
58         SoRequest3gpp soRequest = makeRequest();
59
60         String path = getPath();
61         String url = getClient().getBaseUrl() + path;
62
63         String strRequest = prettyPrint(soRequest);
64         logMessage(NetLoggerUtil.EventType.OUT, Topic.CommInfrastructure.REST, url, strRequest);
65
66         Entity<String> entity = Entity.entity(strRequest, MediaType.APPLICATION_JSON);
67         Map<String, Object> headers = createSimpleHeaders();
68
69         return handleResponse(outcome, url, callback -> getClient().put(callback, path, entity, headers));
70     }
71
72     protected SoRequest3gpp makeRequest() {
73
74         String payload = getRequiredProperty(OperationProperties.EVENT_PAYLOAD, "event payload");
75         try {
76             return getCoder().convert(payload, SoRequest3gpp.class);
77         } catch (CoderException e) {
78             throw new IllegalArgumentException("invalid payload value: " + payload, e);
79         }
80     }
81 }