51e9b6d4036f70fa9cd0b5119bfa726b37bcbb5b
[policy/apex-pdp.git] /
1 /*-
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
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
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.
17  *
18  * SPDX-License-Identifier: Apache-2.0
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.policy.apex.service.engine.event.impl.jsonprotocolplugin;
23
24 import lombok.Getter;
25 import lombok.Setter;
26 import org.onap.policy.apex.service.parameters.eventprotocol.EventProtocolTextCharDelimitedParameters;
27
28 // @formatter:off
29 /**
30  * Event protocol parameters for JSON as an event protocol.
31  *
32  * <p>The parameters for this plugin are:
33  * <ol>
34  * <li>nameAlias: The field in a JSON event to use as an alias for the event name. This parameter is
35  * optional.
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.
47  * </ol>
48  *
49  * @author Liam Fallon (liam.fallon@ericsson.com)
50  */
51 //@formatter:on
52 @Getter
53 @Setter
54 public class JsonEventProtocolParameters extends EventProtocolTextCharDelimitedParameters {
55     /** The label of this event protocol. */
56     public static final String JSON_EVENT_PROTOCOL_LABEL = "JSON";
57
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 = '}';
61
62     // Aliases for Apex event header fields
63     // @formatter:off
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;
69     // @formatter:on
70
71     // Flag indicating POJO decoding and encoding and parameter indicating the name of the Pojo field
72     private String pojoField = null;
73
74     /**
75      * Constructor to create a JSON event protocol parameter instance and register the instance with the parameter
76      * service.
77      */
78     public JsonEventProtocolParameters() {
79         this(JSON_EVENT_PROTOCOL_LABEL);
80     }
81
82     /**
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
85      */
86     public JsonEventProtocolParameters(final String eventProtocolLabel) {
87         super();
88
89         // Set the event protocol properties for the JSON event protocol
90         this.setLabel(eventProtocolLabel);
91
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);
95
96         // Set the event protocol plugin class
97         this.setEventProtocolPluginClass(Apex2JsonEventConverter.class.getName());
98     }
99
100     /**
101      * {@inheritDoc}.
102      */
103     @Override
104     public String getName() {
105         return this.getLabel();
106     }
107 }