bab76b59b347e5639036c15df52ded18ae54dd52
[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.carriertechnology;
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  * The default carrier technology parameter class that may be specialized by carrier technology plugins that require
30  * plugin specific parameters.
31  * 
32  * <p>The following parameters are defined: <ol> <li>label: The label of the carrier technology.
33  * <li>eventProducerPluginClass: The name of the plugin class that will be used by Apex to produce and emit output
34  * events for this carrier technology <li>eventConsumerPluginClass: The name of the plugin class that will be used by
35  * Apex to receive and process input events from this carrier technology carrier technology </ol>
36  *
37  * @author Liam Fallon (liam.fallon@ericsson.com)
38  */
39 public abstract class CarrierTechnologyParameters implements ParameterGroup {
40
41     // The carrier technology label
42     private String label = null;
43
44     // Producer and Consumer plugin classes for the event producer and consumer for this carrier
45     // technology
46     private String eventProducerPluginClass = null;
47     private String eventConsumerPluginClass = null;
48
49     /**
50      * Constructor to create a carrier technology parameters instance with the name of a sub class of this class and
51      * register the instance with the parameter service.
52      */
53     public CarrierTechnologyParameters() {
54         super();
55     }
56
57     /**
58      * Gets the label of the carrier technology.
59      *
60      * @return the label of the carrier technology
61      */
62     public String getLabel() {
63         return label;
64     }
65
66     /**
67      * Sets the label of the carrier technology.
68      *
69      * @param label the label of the carrier technology
70      */
71     public void setLabel(final String label) {
72         if (label != null) {
73             this.label = label.replaceAll("\\s+", "");
74         } else {
75             this.label = null;
76         }
77     }
78
79     /**
80      * Gets the event producer plugin class.
81      *
82      * @return the event producer plugin class
83      */
84     public String getEventProducerPluginClass() {
85         return eventProducerPluginClass;
86     }
87
88     /**
89      * Sets the event producer plugin class.
90      *
91      * @param eventProducerPluginClass the new event producer plugin class
92      */
93     public void setEventProducerPluginClass(final String eventProducerPluginClass) {
94         if (eventProducerPluginClass != null) {
95             this.eventProducerPluginClass = eventProducerPluginClass.replaceAll("\\s+", "");
96         } else {
97             this.eventProducerPluginClass = null;
98         }
99     }
100
101     /**
102      * Gets the event consumer plugin class.
103      *
104      * @return the event consumer plugin class
105      */
106     public String getEventConsumerPluginClass() {
107         return eventConsumerPluginClass;
108     }
109
110     /**
111      * Sets the event consumer plugin class.
112      *
113      * @param eventConsumerPluginClass the new event consumer plugin class
114      */
115     public void setEventConsumerPluginClass(final String eventConsumerPluginClass) {
116         if (eventConsumerPluginClass != null) {
117             this.eventConsumerPluginClass = eventConsumerPluginClass.replaceAll("\\s+", "");
118         } else {
119             this.eventConsumerPluginClass = null;
120         }
121     }
122
123     /*
124      * (non-Javadoc)
125      * 
126      * @see java.lang.Object#toString()
127      */
128     @Override
129     public String toString() {
130         return "CarrierTechnologyParameters [label=" + label + ", eventProducerPluginClass=" + eventProducerPluginClass
131                         + ", eventConsumerPluginClass=" + eventConsumerPluginClass + "]";
132     }
133
134     /*
135      * (non-Javadoc)
136      *
137      * @see org.onap.policy.apex.service.parameters.ApexParameterValidator#validate()
138      */
139     @Override
140     public GroupValidationResult validate() {
141         final GroupValidationResult result = new GroupValidationResult(this);
142
143         if (label == null || label.length() == 0) {
144             result.setResult("label", ValidationStatus.INVALID, "carrier technology label not specified or is blank");
145         }
146
147         if (eventProducerPluginClass == null || eventProducerPluginClass.length() == 0) {
148             result.setResult("eventProducerPluginClass", ValidationStatus.INVALID,
149                             "carrier technology eventProducerPluginClass not specified or is blank");
150         }
151
152         if (eventConsumerPluginClass == null || eventConsumerPluginClass.length() == 0) {
153             result.setResult("eventConsumerPluginClass", ValidationStatus.INVALID,
154                             "carrier technology eventConsumerPluginClass not specified or is blank");
155         }
156
157         return result;
158     }
159
160     @Override
161     public String getName() {
162         return this.getLabel();
163     }
164
165     @Override
166     public void setName(final String name) {
167         throw new ParameterRuntimeException(
168                         "the name/label of this carrier technology is always \"" + getLabel() + "\"");
169     }
170
171 }