b3a264481b02a166d18d3394d76b3310e84b96ee
[policy/apex-pdp.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2016-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.apex.service.parameters.eventprotocol;
22
23 import org.onap.policy.common.parameters.GroupValidationResult;
24 import org.onap.policy.common.parameters.ParameterGroup;
25 import org.onap.policy.common.parameters.ParameterRuntimeException;
26 import org.onap.policy.common.parameters.ValidationStatus;
27
28 /**
29  * A default event protocol parameter class that may be specialized by event protocol plugins that require plugin
30  * specific parameters.
31  *
32  * <p>The following parameters are defined:
33  * <ol>
34  * <li>label: The label of the event protocol technology.
35  * <li>eventProducerPluginClass: The name of the plugin class that will be used by Apex to produce and emit output
36  * events for this carrier technology
37  * </ol>
38  *
39  * @author Liam Fallon (liam.fallon@ericsson.com)
40  */
41 public abstract class EventProtocolParameters implements ParameterGroup {
42     // The event protocol label
43     private String label = null;
44
45     // Event protocol converter plugin class for this event protocol
46     private String eventProtocolPluginClass;
47
48     /**
49      * Constructor to create an event protocol parameters instance with the name of a sub class of this class and
50      * register the instance with the parameter service.
51      */
52     public EventProtocolParameters() {
53         super();
54     }
55
56     /**
57      * Gets the label of the event protocol.
58      *
59      * @return the label of the event protocol
60      */
61     public String getLabel() {
62         return label;
63     }
64
65     /**
66      * Sets the label of the event protocol.
67      *
68      * @param label the label of the event protocol
69      */
70     public void setLabel(final String label) {
71         this.label = label.replaceAll("\\s+", "");
72     }
73
74     /**
75      * Gets the event event protocol plugin class.
76      *
77      * @return the event event protocol plugin class
78      */
79     public String getEventProtocolPluginClass() {
80         return eventProtocolPluginClass;
81     }
82
83     /**
84      * Sets the event event protocol plugin class.
85      *
86      * @param eventProtocolPluginClass the event event protocol plugin class
87      */
88     public void setEventProtocolPluginClass(final String eventProtocolPluginClass) {
89         this.eventProtocolPluginClass = eventProtocolPluginClass.replaceAll("\\s+", "");
90     }
91
92     /**
93      * {@inheritDoc}.
94      */
95     @Override
96     public String toString() {
97         return "CarrierTechnologyParameters [label=" + label + ", EventProtocolPluginClass=" + eventProtocolPluginClass
98                         + "]";
99     }
100
101     /**
102      * {@inheritDoc}.
103      */
104     @Override
105     public GroupValidationResult validate() {
106         final GroupValidationResult result = new GroupValidationResult(this);
107
108         if (label == null || label.length() == 0) {
109             result.setResult("label", ValidationStatus.INVALID, "event protocol label not specified or is blank");
110         }
111
112         if (eventProtocolPluginClass == null || eventProtocolPluginClass.length() == 0) {
113             result.setResult("eventProtocolPluginClass", ValidationStatus.INVALID,
114                             "event protocol eventProtocolPluginClass not specified or is blank");
115         }
116
117         return result;
118     }
119
120     @Override
121     public String getName() {
122         return this.getLabel();
123     }
124
125     @Override
126     public void setName(final String name) {
127         throw new ParameterRuntimeException("the name/label of this event protocol is always \"" + getLabel() + "\"");
128     }
129 }