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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.apex.service.engine.event.impl.jsonprotocolplugin;
23 import org.onap.policy.apex.service.parameters.eventprotocol.EventProtocolTextCharDelimitedParameters;
27 * Event protocol parameters for JSON as an event protocol.
29 * <p>The parameters for this plugin are:
31 * <li>nameAlias: The field in a JSON event to use as an alias for the event name. This parameter is
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.
46 * @author Liam Fallon (liam.fallon@ericsson.com)
49 public class JsonEventProtocolParameters extends EventProtocolTextCharDelimitedParameters {
50 /** The label of this event protocol. */
51 public static final String JSON_EVENT_PROTOCOL_LABEL = "JSON";
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 = '}';
57 // Aliases for Apex event header fields
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;
66 // Flag indicating POJO decoding and encoding and parameter indicating the name of the Pojo field
67 private String pojoField = null;
70 * Constructor to create a JSON event protocol parameter instance and register the instance with the parameter
73 public JsonEventProtocolParameters() {
74 this(JSON_EVENT_PROTOCOL_LABEL);
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
81 public JsonEventProtocolParameters(final String eventProtocolLabel) {
84 // Set the event protocol properties for the JSON event protocol
85 this.setLabel(eventProtocolLabel);
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);
91 // Set the event protocol plugin class
92 this.setEventProtocolPluginClass(Apex2JsonEventConverter.class.getName());
98 * @see org.onap.policy.common.parameters.ParameterGroup#getName()
101 public String getName() {
102 return this.getLabel();
106 * Gets the name alias.
108 * @return the name alias
110 public String getNameAlias() {
115 * Gets the version alias.
117 * @return the version alias
119 public String getVersionAlias() {
124 * Gets the name space alias.
126 * @return the name space alias
128 public String getNameSpaceAlias() {
129 return nameSpaceAlias;
133 * Gets the source alias.
135 * @return the source alias
137 public String getSourceAlias() {
142 * Gets the target alias.
144 * @return the target alias
146 public String getTargetAlias() {
151 * Return the name of the POJO field to use for POJO decoding and encoding.
153 * @return the name of the POJO field
155 public String getPojoField() {
160 * Sets the name alias.
162 * @param nameAlias the new name alias
164 public void setNameAlias(String nameAlias) {
165 this.nameAlias = nameAlias;
169 * Sets the version alias.
171 * @param versionAlias the new version alias
173 public void setVersionAlias(String versionAlias) {
174 this.versionAlias = versionAlias;
178 * Sets the name space alias.
180 * @param nameSpaceAlias the new name space alias
182 public void setNameSpaceAlias(String nameSpaceAlias) {
183 this.nameSpaceAlias = nameSpaceAlias;
187 * Sets the source alias.
189 * @param sourceAlias the new source alias
191 public void setSourceAlias(String sourceAlias) {
192 this.sourceAlias = sourceAlias;
196 * Sets the target alias.
198 * @param targetAlias the new target alias
200 public void setTargetAlias(String targetAlias) {
201 this.targetAlias = targetAlias;
205 * Sets the POJO field that name for POJO decoding and encoding.
207 * @param pojoField The name of the POJO field to use on the event
209 public void setPojoField(final String pojoField) {
210 this.pojoField = pojoField;