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