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