5a90f847db2d715d6c02b8b2c4035cbe33d705f2
[policy/apex-pdp.git] / services / services-engine / src / main / java / org / onap / policy / apex / service / parameters / carriertechnology / CarrierTechnologyParameters.java
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      * {@inheritDoc}.
125      */
126     @Override
127     public String toString() {
128         return "CarrierTechnologyParameters [label=" + label + ", eventProducerPluginClass=" + eventProducerPluginClass
129                         + ", eventConsumerPluginClass=" + eventConsumerPluginClass + "]";
130     }
131
132     /**
133      * {@inheritDoc}.
134      */
135     @Override
136     public GroupValidationResult validate() {
137         final GroupValidationResult result = new GroupValidationResult(this);
138
139         if (label == null || label.length() == 0) {
140             result.setResult("label", ValidationStatus.INVALID, "carrier technology label not specified or is blank");
141         }
142
143         if (eventProducerPluginClass == null || eventProducerPluginClass.length() == 0) {
144             result.setResult("eventProducerPluginClass", ValidationStatus.INVALID,
145                             "carrier technology eventProducerPluginClass not specified or is blank");
146         }
147
148         if (eventConsumerPluginClass == null || eventConsumerPluginClass.length() == 0) {
149             result.setResult("eventConsumerPluginClass", ValidationStatus.INVALID,
150                             "carrier technology eventConsumerPluginClass not specified or is blank");
151         }
152
153         return result;
154     }
155
156     @Override
157     public String getName() {
158         return this.getLabel();
159     }
160
161     @Override
162     public void setName(final String name) {
163         throw new ParameterRuntimeException(
164                         "the name/label of this carrier technology is always \"" + getLabel() + "\"");
165     }
166
167 }