0c10df706c1aedd6d0a642a23354279d405b8cc6
[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      * @param parameterClassName the class name of a sub class of this class
59      */
60     public CarrierTechnologyParameters() {
61         super();
62     }
63
64     /**
65      * Gets the label of the carrier technology.
66      *
67      * @return the label of the carrier technology
68      */
69     public String getLabel() {
70         return label;
71     }
72
73     /**
74      * Sets the label of the carrier technology.
75      *
76      * @param label the label of the carrier technology
77      */
78     public void setLabel(final String label) {
79         if (label != null) {
80             this.label = label.replaceAll("\\s+", "");
81         } else {
82             this.label = null;
83         }
84     }
85
86     /**
87      * Gets the event producer plugin class.
88      *
89      * @return the event producer plugin class
90      */
91     public String getEventProducerPluginClass() {
92         return eventProducerPluginClass;
93     }
94
95     /**
96      * Sets the event producer plugin class.
97      *
98      * @param eventProducerPluginClass the new event producer plugin class
99      */
100     public void setEventProducerPluginClass(final String eventProducerPluginClass) {
101         if (eventProducerPluginClass != null) {
102             this.eventProducerPluginClass = eventProducerPluginClass.replaceAll("\\s+", "");
103         } else {
104             this.eventProducerPluginClass = null;
105         }
106     }
107
108     /**
109      * Gets the event consumer plugin class.
110      *
111      * @return the event consumer plugin class
112      */
113     public String getEventConsumerPluginClass() {
114         return eventConsumerPluginClass;
115     }
116
117     /**
118      * Sets the event consumer plugin class.
119      *
120      * @param eventConsumerPluginClass the new event consumer plugin class
121      */
122     public void setEventConsumerPluginClass(final String eventConsumerPluginClass) {
123         if (eventConsumerPluginClass != null) {
124             this.eventConsumerPluginClass = eventConsumerPluginClass.replaceAll("\\s+", "");
125         } else {
126             this.eventConsumerPluginClass = null;
127         }
128     }
129
130     /*
131      * (non-Javadoc)
132      * 
133      * @see java.lang.Object#toString()
134      */
135     @Override
136     public String toString() {
137         return "CarrierTechnologyParameters [label=" + label + ", eventProducerPluginClass=" + eventProducerPluginClass
138                         + ", eventConsumerPluginClass=" + eventConsumerPluginClass + "]";
139     }
140
141     /*
142      * (non-Javadoc)
143      *
144      * @see org.onap.policy.apex.service.parameters.ApexParameterValidator#validate()
145      */
146     @Override
147     public GroupValidationResult validate() {
148         final GroupValidationResult result = new GroupValidationResult(this);
149
150         if (label == null || label.length() == 0) {
151             result.setResult("label", ValidationStatus.INVALID, "carrier technology label not specified or is blank");
152         }
153
154         if (eventProducerPluginClass == null || eventProducerPluginClass.length() == 0) {
155             result.setResult("eventProducerPluginClass", ValidationStatus.INVALID,
156                             "carrier technology eventProducerPluginClass not specified or is blank");
157         }
158
159         if (eventConsumerPluginClass == null || eventConsumerPluginClass.length() == 0) {
160             result.setResult("eventConsumerPluginClass", ValidationStatus.INVALID,
161                             "carrier technology eventConsumerPluginClass not specified or is blank");
162         }
163
164         return result;
165     }
166     
167     @Override
168     public String getName() {
169         return this.getLabel();
170     }
171
172     @Override
173     public void setName(final String name) {
174         throw new ParameterRuntimeException("the name/label of this carrier technology is always \"" + getLabel() + "\"");
175     }
176
177 }