8e44ec59bfa5605ab8031190700f5ba3ddc154e6
[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.engine.event.impl.jsonprotocolplugin;
22
23 import org.onap.policy.apex.service.parameters.eventprotocol.EventProtocolTextCharDelimitedParameters;
24
25 /**
26  * Event protocol parameters for JSON as an event protocol.
27  *
28  * <p>The parameters for this plugin are:
29  * <ol>
30  * <li>nameAlias: The field in a JSON event to use as an alias for the event name. This parameter is
31  * optional.
32  * <li>versionAlias: The field in a JSON event to use as an alias for the event version. This
33  * parameter is optional.
34  * <li>nameSpaceAlias: The field in a JSON event to use as an alias for the event name space. This
35  * parameter is optional.
36  * <li>sourceAlias: The field in a JSON event to use as an alias for the event source. This
37  * parameter is optional.
38  * <li>targetAlias: The field in a JSON event to use as an alias for the event target. This
39  * parameter is optional.
40  * </ol>
41  * 
42  * @author Liam Fallon (liam.fallon@ericsson.com)
43  */
44 public class JsonEventProtocolParameters extends EventProtocolTextCharDelimitedParameters {
45     /** The label of this event protocol. */
46     public static final String JSON_EVENT_PROTOCOL_LABEL = "JSON";
47
48     // Constants for text block delimiters
49     private static final char JSON_TEXT_BLOCK_START_DELIMITER = '{';
50     private static final char JSON_TEXT_BLOCK_END_DELIMITER = '}';
51
52     // Aliases for Apex event header fields
53     // @formatter:off
54     private String nameAlias      = null;
55     private String versionAlias   = null;
56     private String nameSpaceAlias = null;
57     private String sourceAlias    = null;
58     private String targetAlias    = null;
59     // @formatter:on
60
61     /**
62      * Constructor to create a JSON event protocol parameter instance and register the instance with
63      * the parameter service.
64      */
65     public JsonEventProtocolParameters() {
66         this(JsonEventProtocolParameters.class.getCanonicalName(), JSON_EVENT_PROTOCOL_LABEL);
67     }
68
69     /**
70      * Constructor to create an event protocol parameters instance with the name of a sub class of
71      * this class.
72      *
73      * @param parameterClassName the class name of a sub class of this class
74      * @param eventProtocolLabel the name of the event protocol for this plugin
75      */
76     public JsonEventProtocolParameters(final String parameterClassName, final String eventProtocolLabel) {
77         super(parameterClassName);
78
79         // Set the event protocol properties for the JSON event protocol
80         this.setLabel(eventProtocolLabel);
81
82         // Set the starting and ending delimiters for text blocks of JSON events
83         this.setStartChar(JSON_TEXT_BLOCK_START_DELIMITER);
84         this.setEndChar(JSON_TEXT_BLOCK_END_DELIMITER);
85
86         // Set the event protocol plugin class
87         this.setEventProtocolPluginClass(Apex2JsonEventConverter.class.getCanonicalName());
88     }
89
90     /* (non-Javadoc)
91      * @see org.onap.policy.common.parameters.ParameterGroup#getName()
92      */
93     @Override
94     public String getName() {
95         return this.getLabel();
96     }
97
98     /**
99      * Gets the name alias.
100      *
101      * @return the name alias
102      */
103     public String getNameAlias() {
104         return nameAlias;
105     }
106
107     /**
108      * Gets the version alias.
109      *
110      * @return the version alias
111      */
112     public String getVersionAlias() {
113         return versionAlias;
114     }
115
116     /**
117      * Gets the name space alias.
118      *
119      * @return the name space alias
120      */
121     public String getNameSpaceAlias() {
122         return nameSpaceAlias;
123     }
124
125     /**
126      * Gets the source alias.
127      *
128      * @return the source alias
129      */
130     public String getSourceAlias() {
131         return sourceAlias;
132     }
133
134     /**
135      * Gets the target alias.
136      *
137      * @return the target alias
138      */
139     public String getTargetAlias() {
140         return targetAlias;
141     }
142     
143     /**
144      * Sets the name alias.
145      *
146      * @param nameAlias the new name alias
147      */
148     public void setNameAlias(String nameAlias) {
149         this.nameAlias = nameAlias;
150     }
151
152     /**
153      * Sets the version alias.
154      *
155      * @param versionAlias the new version alias
156      */
157     public void setVersionAlias(String versionAlias) {
158         this.versionAlias = versionAlias;
159     }
160
161     /**
162      * Sets the name space alias.
163      *
164      * @param nameSpaceAlias the new name space alias
165      */
166     public void setNameSpaceAlias(String nameSpaceAlias) {
167         this.nameSpaceAlias = nameSpaceAlias;
168     }
169
170     /**
171      * Sets the source alias.
172      *
173      * @param sourceAlias the new source alias
174      */
175     public void setSourceAlias(String sourceAlias) {
176         this.sourceAlias = sourceAlias;
177     }
178
179     /**
180      * Sets the target alias.
181      *
182      * @param targetAlias the new target alias
183      */
184     public void setTargetAlias(String targetAlias) {
185         this.targetAlias = targetAlias;
186     }
187 }