6e66a18e947c175f192682d8a25ccf23656654e4
[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.apex.model.basicmodel.service.AbstractParameters;
24 import org.onap.policy.apex.service.parameters.ApexParameterValidator;
25
26 /**
27  * A default event protocol parameter class that may be specialized by event protocol plugins that
28  * require plugin specific parameters.
29  *
30  * <p>
31  * The following parameters are defined:
32  * <ol>
33  * <li>label: The label of the event protocol technology.
34  * <li>eventProducerPluginClass: The name of the plugin class that will be used by Apex to produce
35  * and emit output events for this carrier technology
36  * </ol>
37  *
38  * @author Liam Fallon (liam.fallon@ericsson.com)
39  */
40 public abstract class EventProtocolParameters extends AbstractParameters implements ApexParameterValidator {
41     // The event protocol label
42     private String label = null;
43
44     // Event protocol converter plugin class for this event protocol
45     private String eventProtocolPluginClass;
46
47     /**
48      * Constructor to create an event protocol parameters instance with the name of a sub class of
49      * this class and register the instance with the parameter service.
50      *
51      * @param parameterClassName the class name of a sub class of this class
52      */
53     public EventProtocolParameters(final String parameterClassName) {
54         super(parameterClassName);
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      * (non-Javadoc)
95      *
96      * @see org.onap.policy.apex.model.basicmodel.service.AbstractParameters#toString()
97      */
98     @Override
99     public String toString() {
100         return "CarrierTechnologyParameters [label=" + label + ", EventProtocolPluginClass=" + eventProtocolPluginClass
101                 + "]";
102     }
103
104     /*
105      * (non-Javadoc)
106      *
107      * @see org.onap.policy.apex.service.parameters.ApexParameterValidator#validate()
108      */
109     @Override
110     public String validate() {
111         final StringBuilder errorMessageBuilder = new StringBuilder();
112
113         if (label == null || label.length() == 0) {
114             errorMessageBuilder.append("  event protocol label not specified or is blank\n");
115         }
116
117         if (eventProtocolPluginClass == null || eventProtocolPluginClass.length() == 0) {
118             errorMessageBuilder.append("  event protocol eventProtocolPluginClass not specified or is blank\n");
119         }
120
121         return errorMessageBuilder.toString();
122     }
123 }