68d5f8a5646b38ad7234de586419ce8bbea09ac4
[policy/apex-pdp.git] / services / services-engine / src / main / java / org / onap / policy / apex / service / parameters / eventprotocol / EventProtocolParameters.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2016-2018 Ericsson. All rights reserved.
4  *  Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
5  * ================================================================================
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * SPDX-License-Identifier: Apache-2.0
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.policy.apex.service.parameters.eventprotocol;
23
24 import org.onap.policy.common.parameters.GroupValidationResult;
25 import org.onap.policy.common.parameters.ParameterGroup;
26 import org.onap.policy.common.parameters.ParameterRuntimeException;
27 import org.onap.policy.common.parameters.ValidationStatus;
28
29 /**
30  * A default event protocol parameter class that may be specialized by event protocol plugins that require plugin
31  * specific parameters.
32  *
33  * <p>The following parameters are defined:
34  * <ol>
35  * <li>label: The label of the event protocol technology.
36  * <li>eventProducerPluginClass: The name of the plugin class that will be used by Apex to produce and emit output
37  * events for this carrier technology
38  * </ol>
39  *
40  * @author Liam Fallon (liam.fallon@ericsson.com)
41  */
42 public abstract class EventProtocolParameters implements ParameterGroup {
43     // The event protocol label
44     private String label = null;
45
46     // Event protocol converter plugin class for this event protocol
47     private String eventProtocolPluginClass;
48
49     /**
50      * Constructor to create an event protocol parameters instance with the name of a sub class of this class and
51      * register the instance with the parameter service.
52      */
53     protected EventProtocolParameters() {
54         super();
55     }
56
57     /**
58      * Gets the label of the event protocol.
59      *
60      * @return the label of the event protocol
61      */
62     public String getLabel() {
63         return label;
64     }
65
66     /**
67      * Sets the label of the event protocol.
68      *
69      * @param label the label of the event protocol
70      */
71     public void setLabel(final String label) {
72         this.label = label.replaceAll("\\s+", "");
73     }
74
75     /**
76      * Gets the event event protocol plugin class.
77      *
78      * @return the event event protocol plugin class
79      */
80     public String getEventProtocolPluginClass() {
81         return eventProtocolPluginClass;
82     }
83
84     /**
85      * Sets the event event protocol plugin class.
86      *
87      * @param eventProtocolPluginClass the event event protocol plugin class
88      */
89     public void setEventProtocolPluginClass(final String eventProtocolPluginClass) {
90         this.eventProtocolPluginClass = eventProtocolPluginClass.replaceAll("\\s+", "");
91     }
92
93     /**
94      * {@inheritDoc}.
95      */
96     @Override
97     public String toString() {
98         return "CarrierTechnologyParameters [label=" + label + ", EventProtocolPluginClass=" + eventProtocolPluginClass
99                         + "]";
100     }
101
102     /**
103      * {@inheritDoc}.
104      */
105     @Override
106     public GroupValidationResult validate() {
107         final GroupValidationResult result = new GroupValidationResult(this);
108
109         if (label == null || label.length() == 0) {
110             result.setResult("label", ValidationStatus.INVALID, "event protocol label not specified or is blank");
111         }
112
113         if (eventProtocolPluginClass == null || eventProtocolPluginClass.length() == 0) {
114             result.setResult("eventProtocolPluginClass", ValidationStatus.INVALID,
115                             "event protocol eventProtocolPluginClass not specified or is blank");
116         }
117
118         return result;
119     }
120
121     @Override
122     public String getName() {
123         return this.getLabel();
124     }
125
126     @Override
127     public void setName(final String name) {
128         throw new ParameterRuntimeException("the name/label of this event protocol is always \"" + getLabel() + "\"");
129     }
130 }