2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2016-2018 Ericsson. All rights reserved.
4 * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
5 * ================================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.apex.service.engine.event.impl.jsonprotocolplugin;
26 import org.onap.policy.apex.service.parameters.eventprotocol.EventProtocolTextCharDelimitedParameters;
30 * Event protocol parameters for JSON as an event protocol.
32 * <p>The parameters for this plugin are:
34 * <li>nameAlias: The field in a JSON event to use as an alias for the event name. This parameter is
36 * <li>versionAlias: The field in a JSON event to use as an alias for the event version. This
37 * parameter is optional.
38 * <li>nameSpaceAlias: The field in a JSON event to use as an alias for the event name space. This
39 * parameter is optional.
40 * <li>sourceAlias: The field in a JSON event to use as an alias for the event source. This
41 * parameter is optional.
42 * <li>targetAlias: The field in a JSON event to use as an alias for the event target. This
43 * parameter is optional.
44 * <li>pojoField: The event is received and sent as a single POJO using the event field
45 * definition in this field name in the schema, there must be one and only one field in the
46 * event definition, the event has a single parameter whose type is the Pojo. This parameter is optional.
49 * @author Liam Fallon (liam.fallon@ericsson.com)
54 public class JsonEventProtocolParameters extends EventProtocolTextCharDelimitedParameters {
55 /** The label of this event protocol. */
56 public static final String JSON_EVENT_PROTOCOL_LABEL = "JSON";
58 // Constants for text block delimiters
59 private static final char JSON_TEXT_BLOCK_START_DELIMITER = '{';
60 private static final char JSON_TEXT_BLOCK_END_DELIMITER = '}';
62 // Aliases for Apex event header fields
64 private String nameAlias = null;
65 private String versionAlias = null;
66 private String nameSpaceAlias = null;
67 private String sourceAlias = null;
68 private String targetAlias = null;
71 // Flag indicating POJO decoding and encoding and parameter indicating the name of the Pojo field
72 private String pojoField = null;
75 * Constructor to create a JSON event protocol parameter instance and register the instance with the parameter
78 public JsonEventProtocolParameters() {
79 this(JSON_EVENT_PROTOCOL_LABEL);
83 * Constructor to create an event protocol parameters instance with the name of a sub class of this class.
84 * @param eventProtocolLabel the name of the event protocol for this plugin
86 public JsonEventProtocolParameters(final String eventProtocolLabel) {
89 // Set the event protocol properties for the JSON event protocol
90 this.setLabel(eventProtocolLabel);
92 // Set the starting and ending delimiters for text blocks of JSON events
93 this.setStartChar(JSON_TEXT_BLOCK_START_DELIMITER);
94 this.setEndChar(JSON_TEXT_BLOCK_END_DELIMITER);
96 // Set the event protocol plugin class
97 this.setEventProtocolPluginClass(Apex2JsonEventConverter.class.getName());
104 public String getName() {
105 return this.getLabel();