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