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