2  * ============LICENSE_START=======================================================
 
   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
 
  11  *      http://www.apache.org/licenses/LICENSE-2.0
 
  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=========================================================
 
  21 package org.onap.policy.controlloop.actorserviceprovider.parameters;
 
  24 import java.util.function.Function;
 
  26 import org.onap.policy.common.parameters.BeanValidationResult;
 
  27 import org.onap.policy.common.parameters.BeanValidator;
 
  28 import org.onap.policy.common.parameters.ValidationResult;
 
  29 import org.onap.policy.common.parameters.annotations.Min;
 
  30 import org.onap.policy.common.parameters.annotations.NotBlank;
 
  31 import org.onap.policy.common.parameters.annotations.NotNull;
 
  32 import org.onap.policy.controlloop.actorserviceprovider.Util;
 
  35  * Parameters used by Actors that connect to a server via HTTP. This contains the
 
  36  * parameters that are common to all of the operations. Only the path changes for each
 
  37  * operation, thus it includes a mapping from operation name to path.
 
  42 public class HttpActorParams {
 
  45      * Name of the HttpClient, as found in the HttpClientFactory.
 
  47     private String clientName;
 
  50      * Amount of time, in seconds to wait for the HTTP request to complete, where zero
 
  51      * indicates that it should wait forever. The default is zero.
 
  54     private long timeoutSec = 0;
 
  57      * Maps the operation name to its URI path.
 
  59     private Map<String, String> path;
 
  62      * Extracts a specific operation's parameters from "this".
 
  64      * @param name name of the item containing "this"
 
  65      * @return a function to extract an operation's parameters from "this". Note: the
 
  66      *         returned function is not thread-safe
 
  68     public Function<String, Map<String, Object>> makeOperationParameters(String name) {
 
  69         HttpParams subparams = HttpParams.builder().clientName(getClientName()).timeoutSec(getTimeoutSec()).build();
 
  72             String subpath = path.get(operation);
 
  73             if (subpath == null) {
 
  77             subparams.setPath(subpath);
 
  78             return Util.translateToMap(name + "." + operation, subparams);
 
  83      * Validates the parameters.
 
  85      * @param name name of the object containing these parameters
 
  87      * @throws IllegalArgumentException if the parameters are invalid
 
  89     public HttpActorParams doValidation(String name) {
 
  90         ValidationResult result = validate(name);
 
  91         if (!result.isValid()) {
 
  92             throw new ParameterValidationRuntimeException("invalid parameters", result);
 
  99      * Validates the parameters.
 
 101      * @param resultName name of the result
 
 103      * @return the validation result
 
 105     public ValidationResult validate(String resultName) {
 
 106         BeanValidationResult result = new BeanValidator().validateTop(resultName, this);
 
 108         result.validateMap("path", path, (result2, entry) -> result2.validateNotNull(entry.getKey(), entry.getValue()));