c752020b9811aebd554440dfabd12667931afed8
[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
26 import org.onap.policy.common.parameters.GroupValidationResult;
27 import org.onap.policy.common.parameters.ParameterGroup;
28 import org.onap.policy.common.parameters.ValidationStatus;
29 import org.onap.policy.distribution.forwarding.parameters.PolicyForwarderParameters;
30
31 /**
32  * Class to hold all the plugin handler parameters.
33  *
34  * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com)
35  */
36 public class PluginHandlerParameters implements ParameterGroup {
37
38     private static final String PLUGIN_HANDLER = "_PluginHandler";
39
40     private String name;
41     private Map<String, PolicyDecoderParameters> policyDecoders;
42     private Map<String, PolicyForwarderParameters> policyForwarders;
43
44     /**
45      * Constructor for instantiating PluginHandlerParameters.
46      *
47      * @param policyDecoders the map of policy decoders
48      * @param policyForwarders the map of policy forwarders
49      */
50     public PluginHandlerParameters(final Map<String, PolicyDecoderParameters> policyDecoders,
51             final Map<String, PolicyForwarderParameters> policyForwarders) {
52         this.policyDecoders = policyDecoders;
53         this.policyForwarders = policyForwarders;
54     }
55
56     /**
57      * Return the policyDecoders of this PluginHandlerParameters instance.
58      *
59      * @return the policyDecoders
60      */
61     public Map<String, PolicyDecoderParameters> getPolicyDecoders() {
62         return policyDecoders;
63     }
64
65     /**
66      * Return the policyForwarders of this PluginHandlerParameters instance.
67      *
68      * @return the policyForwarders
69      */
70     public Map<String, PolicyForwarderParameters> getPolicyForwarders() {
71         return policyForwarders;
72     }
73
74     @Override
75     public String getName() {
76         return name + PLUGIN_HANDLER;
77     }
78
79     /**
80      * Validate the plugin handler parameters.
81      *
82      */
83     @Override
84     public GroupValidationResult validate() {
85         final GroupValidationResult validationResult = new GroupValidationResult(this);
86         if (policyDecoders == null || policyDecoders.size() == 0) {
87             validationResult.setResult("policyDecoders", ValidationStatus.INVALID,
88                     "must have at least one policy decoder");
89         } else {
90             for (final Entry<String, PolicyDecoderParameters> nestedGroupEntry : policyDecoders.entrySet()) {
91                 validationResult.setResult("policyDecoders", nestedGroupEntry.getKey(),
92                         nestedGroupEntry.getValue().validate());
93             }
94         }
95         if (policyForwarders == null || policyForwarders.size() == 0) {
96             validationResult.setResult("policyForwarders", ValidationStatus.INVALID,
97                     "must have at least one policy forwarder");
98         } else {
99             for (final Entry<String, PolicyForwarderParameters> nestedGroupEntry : policyForwarders.entrySet()) {
100                 validationResult.setResult("policyForwarders", nestedGroupEntry.getKey(),
101                         nestedGroupEntry.getValue().validate());
102             }
103         }
104         return validationResult;
105     }
106
107     /**
108      * Set the name of this group.
109      *
110      * @param name the name to set.
111      */
112     public void setName(final String name) {
113         this.name = name;
114     }
115 }