Fix return building on policy get
[policy/models.git] / models-interactions / model-actors / actorServiceProvider / src / main / java / org / onap / policy / controlloop / actorserviceprovider / parameters / TopicPairActorParams.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.parameters;
22
23 import java.util.Map;
24 import lombok.Builder;
25 import lombok.Data;
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.NotBlank;
30 import org.onap.policy.common.parameters.annotations.NotNull;
31
32 /**
33  * Parameters used by Actors whose Operators use a pair of Topics, one to publish requests
34  * and the other to receive responses.
35  */
36 @NotNull
37 @NotBlank
38 @Data
39 @Builder
40 public class TopicPairActorParams {
41
42     /**
43      * This contains the default parameters that are used when an operation doesn't
44      * specify them. Note: each operation to be used must still have an entry in
45      * {@link #operation}, even if it's empty. Otherwise, the given operation will not be
46      * started.
47      */
48     private TopicPairParams defaults;
49
50     /**
51      * Maps an operation name to its individual parameters.
52      */
53     private Map<String, Map<String, Object>> operation;
54
55
56     /**
57      * Validates the parameters.
58      *
59      * @param name name of the object containing these parameters
60      * @return "this"
61      * @throws IllegalArgumentException if the parameters are invalid
62      */
63     public TopicPairActorParams doValidation(String name) {
64         ValidationResult result = validate(name);
65         if (!result.isValid()) {
66             throw new ParameterValidationRuntimeException("invalid parameters", result);
67         }
68
69         return this;
70     }
71
72     /**
73      * Validates the parameters.
74      *
75      * @param resultName name of the result
76      *
77      * @return the validation result
78      */
79     public ValidationResult validate(String resultName) {
80         BeanValidationResult result = new BeanValidator().validateTop(resultName, this);
81
82         if (defaults != null) {
83             result.addResult(defaults.validate("defaults"));
84         }
85
86         // @formatter:off
87         result.validateMap("operation", operation,
88             (result2, entry) -> result2.validateNotNull(entry.getKey(), entry.getValue()));
89         // @formatter:on
90
91         return result;
92     }
93 }