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());
99 public String getName() {
100 return this.getLabel();
104 * Gets the name alias.
106 * @return the name alias
108 public String getNameAlias() {
113 * Gets the version alias.
115 * @return the version alias
117 public String getVersionAlias() {
122 * Gets the name space alias.
124 * @return the name space alias
126 public String getNameSpaceAlias() {
127 return nameSpaceAlias;
131 * Gets the source alias.
133 * @return the source alias
135 public String getSourceAlias() {
140 * Gets the target alias.
142 * @return the target alias
144 public String getTargetAlias() {
149 * Return the name of the POJO field to use for POJO decoding and encoding.
151 * @return the name of the POJO field
153 public String getPojoField() {
158 * Sets the name alias.
160 * @param nameAlias the new name alias
162 public void setNameAlias(String nameAlias) {
163 this.nameAlias = nameAlias;
167 * Sets the version alias.
169 * @param versionAlias the new version alias
171 public void setVersionAlias(String versionAlias) {
172 this.versionAlias = versionAlias;
176 * Sets the name space alias.
178 * @param nameSpaceAlias the new name space alias
180 public void setNameSpaceAlias(String nameSpaceAlias) {
181 this.nameSpaceAlias = nameSpaceAlias;
185 * Sets the source alias.
187 * @param sourceAlias the new source alias
189 public void setSourceAlias(String sourceAlias) {
190 this.sourceAlias = sourceAlias;
194 * Sets the target alias.
196 * @param targetAlias the new target alias
198 public void setTargetAlias(String targetAlias) {
199 this.targetAlias = targetAlias;
203 * Sets the POJO field that name for POJO decoding and encoding.
205 * @param pojoField The name of the POJO field to use on the event
207 public void setPojoField(final String pojoField) {
208 this.pojoField = pojoField;