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