Java 17 Upgrade
[policy/models.git] / models-interactions / model-actors / actorServiceProvider / src / main / java / org / onap / policy / controlloop / actorserviceprovider / impl / HttpActor.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP
4  * ================================================================================
5  * Copyright (C) 2020 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.actorserviceprovider.impl;
23
24 import java.util.Map;
25 import java.util.function.Function;
26 import org.onap.policy.controlloop.actorserviceprovider.Util;
27 import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpActorParams;
28
29 /**
30  * Actor that uses HTTP, where the only additional property that an operator needs is a
31  * URL. The actor's operator parameters are expected to be an
32  * {@link org.onap.policy.controlloop.actorserviceprovider.parameters.HttpParams}.
33  *
34  * @param <P> type of parameters
35  */
36 public class HttpActor<P extends HttpActorParams> extends ActorImpl {
37
38     /**
39      * Class of Actor parameters.
40      */
41     private final Class<P> paramsClass;
42
43     /**
44      * Constructs the object.
45      *
46      * @param name actor's name
47      * @param paramsClass class of parameters
48      */
49     public HttpActor(String name, Class<P> paramsClass) {
50         super(name);
51         this.paramsClass = paramsClass;
52     }
53
54     /**
55      * Translates the parameters to an {@link HttpActorParams} and then creates a function
56      * that will extract operator-specific parameters.
57      */
58     @Override
59     protected Function<String, Map<String, Object>> makeOperatorParameters(Map<String, Object> actorParameters) {
60         String actorName = getName();
61
62         // @formatter:off
63         return Util.translate(actorName, actorParameters, paramsClass)
64                         .doValidation(actorName)
65                         .makeOperationParameters(actorName);
66         // @formatter:on
67     }
68 }