bd0ad900311d703da339e891684bb0449b9b13b7
[policy/distribution.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2018 Ericsson. All rights reserved.
4  * ================================================================================
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.distribution.reception.parameters;
22
23 import java.util.Map;
24 import java.util.Map.Entry;
25 import org.onap.policy.common.parameters.GroupValidationResult;
26 import org.onap.policy.common.parameters.ParameterGroup;
27 import org.onap.policy.common.parameters.ValidationStatus;
28 import org.onap.policy.distribution.forwarding.parameters.PolicyForwarderParameters;
29
30 /**
31  * Class to hold all the plugin handler parameters.
32  *
33  * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com)
34  */
35 public class PluginHandlerParameters implements ParameterGroup {
36
37     private static final String PLUGIN_HANDLER = "_PluginHandler";
38
39     private String name;
40     private Map<String, PolicyDecoderParameters> policyDecoders;
41     private Map<String, PolicyForwarderParameters> policyForwarders;
42
43     /**
44      * Constructor for instantiating PluginHandlerParameters.
45      *
46      * @param policyDecoders the map of policy decoders
47      * @param policyForwarders the map of policy forwarders
48      */
49     public PluginHandlerParameters(final Map<String, PolicyDecoderParameters> policyDecoders,
50             final Map<String, PolicyForwarderParameters> policyForwarders) {
51         this.policyDecoders = policyDecoders;
52         this.policyForwarders = policyForwarders;
53     }
54
55     /**
56      * Return the policyDecoders of this PluginHandlerParameters instance.
57      *
58      * @return the policyDecoders
59      */
60     public Map<String, PolicyDecoderParameters> getPolicyDecoders() {
61         return policyDecoders;
62     }
63
64     /**
65      * Return the policyForwarders of this PluginHandlerParameters instance.
66      *
67      * @return the policyForwarders
68      */
69     public Map<String, PolicyForwarderParameters> getPolicyForwarders() {
70         return policyForwarders;
71     }
72
73     @Override
74     public String getName() {
75         return name + PLUGIN_HANDLER;
76     }
77
78     /**
79      * Validate the plugin handler parameters.
80      *
81      */
82     @Override
83     public GroupValidationResult validate() {
84         final GroupValidationResult validationResult = new GroupValidationResult(this);
85         if (policyDecoders == null || policyDecoders.size() == 0) {
86             validationResult.setResult("policyDecoders", ValidationStatus.INVALID,
87                     "must have at least one policy decoder");
88         } else {
89             for (final Entry<String, PolicyDecoderParameters> nestedGroupEntry : policyDecoders.entrySet()) {
90                 validationResult.setResult("policyDecoders", nestedGroupEntry.getKey(),
91                         nestedGroupEntry.getValue().validate());
92             }
93         }
94         if (policyForwarders == null || policyForwarders.size() == 0) {
95             validationResult.setResult("policyForwarders", ValidationStatus.INVALID,
96                     "must have at least one policy forwarder");
97         } else {
98             for (final Entry<String, PolicyForwarderParameters> nestedGroupEntry : policyForwarders.entrySet()) {
99                 validationResult.setResult("policyForwarders", nestedGroupEntry.getKey(),
100                         nestedGroupEntry.getValue().validate());
101             }
102         }
103         return validationResult;
104     }
105
106     /**
107      * Set the name of this group.
108      *
109      * @param name the name to set.
110      */
111     @Override
112     public void setName(final String name) {
113         this.name = name;
114     }
115 }