48e20e30904c38af777cc5d1b1255376814667ab
[policy/models.git] / models-interactions / model-actors / actor.so / src / main / java / org / onap / policy / controlloop / actor / so / ModifyCll.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP
4  * ================================================================================
5  * Copyright (C) 2022 CTC, Inc. and others. 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.so;
22
23 import java.util.List;
24 import java.util.Map;
25 import java.util.concurrent.CompletableFuture;
26 import javax.ws.rs.client.Entity;
27 import javax.ws.rs.core.MediaType;
28 import org.onap.policy.common.endpoints.event.comm.Topic;
29 import org.onap.policy.common.endpoints.utils.NetLoggerUtil;
30 import org.onap.policy.common.utils.coder.CoderException;
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.HttpPollingConfig;
35 import org.onap.policy.so.SoRequestCll;
36
37 public class ModifyCll extends SoOperation {
38     public static final String NAME = "ModifyCloudLeasedLine";
39
40     private static final List<String> PROPERTY_NAMES = List.of(
41             OperationProperties.EVENT_PAYLOAD);
42
43     /**
44      * Constructs the object.
45      *
46      * @param params        operation parameters
47      * @param config        configuration for this operation
48      */
49     public ModifyCll(ControlLoopOperationParams params, HttpPollingConfig config) {
50         super(params, config, PROPERTY_NAMES);
51     }
52
53     @Override
54     protected CompletableFuture<OperationOutcome> startOperationAsync(int attempt, OperationOutcome outcome) {
55
56         SoRequestCll soRequest = makeRequest();
57
58         String path = getPath();
59         String url = getClient().getBaseUrl() + path;
60
61         String strRequest = prettyPrint(soRequest);
62         logMessage(NetLoggerUtil.EventType.OUT, Topic.CommInfrastructure.REST, url, strRequest);
63
64         Entity<String> entity = Entity.entity(strRequest, MediaType.APPLICATION_JSON);
65         Map<String, Object> headers = createSimpleHeaders();
66
67         return handleResponse(outcome, url, callback -> getClient().put(callback, path, entity, headers));
68     }
69
70     protected SoRequestCll makeRequest() {
71
72         String payload = getRequiredProperty(OperationProperties.EVENT_PAYLOAD, "event payload");
73         try {
74             return getCoder().convert(payload, SoRequestCll.class);
75         } catch (CoderException e) {
76             throw new IllegalArgumentException("invalid payload value: " + payload, e);
77         }
78     }
79 }