e5539cd0419d9f100aba0c20451745721464d1c0
[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.plugins.event.protocol.yaml;
23
24 import lombok.Getter;
25 import lombok.Setter;
26 import org.onap.policy.apex.service.parameters.eventprotocol.EventProtocolTextTokenDelimitedParameters;
27
28 /**
29  * Event protocol parameters for YAML as an event protocol.
30  *
31  * <p>The parameters for this plugin are:
32  * <ol>
33  * <li>nameAlias: The field in a YAML event to use as an alias for the event name. This parameter is
34  * optional.
35  * <li>versionAlias: The field in a YAML event to use as an alias for the event version. This
36  * parameter is optional.
37  * <li>nameSpaceAlias: The field in a YAML event to use as an alias for the event name space. This
38  * parameter is optional.
39  * <li>sourceAlias: The field in a YAML event to use as an alias for the event source. This
40  * parameter is optional.
41  * <li>targetAlias: The field in a YAML event to use as an alias for the event target. This
42  * parameter is optional.
43  * <li>yamlFieldName: The name of the field in the APEX event that will contain the unmarshaled YAML object. The
44  * parameter is optional and defaults to the value "yaml_field".
45  * </ol>
46  *
47  * @author Liam Fallon (liam.fallon@ericsson.com)
48  */
49 @Getter
50 @Setter
51 public class YamlEventProtocolParameters extends EventProtocolTextTokenDelimitedParameters {
52     /** The label of this event protocol. */
53     public static final String YAML_EVENT_PROTOCOL_LABEL = "YAML";
54
55     // Constants for text block delimiters
56     private static final String YAML_START_TEXT_DELIMITER_TOKEN = "---";
57     private static final String YAML_END_TEXT_DELIMITER_TOKEN = "...";
58
59     // Default parameter values
60     private static final String DEFAULT_YAML_FIELD_NAME = "yaml_field";
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     private String yamlFieldName  = DEFAULT_YAML_FIELD_NAME;
70     // @formatter:on
71
72     /**
73      * Constructor to create a YAML event protocol parameter instance and register the instance with
74      * the parameter service.
75      */
76     public YamlEventProtocolParameters() {
77         this(YAML_EVENT_PROTOCOL_LABEL);
78     }
79
80     /**
81      * Constructor to create an event protocol parameters instance with the name of a sub class of
82      * this class.
83      *
84      * @param eventProtocolLabel the name of the event protocol for this plugin
85      */
86     public YamlEventProtocolParameters(final String eventProtocolLabel) {
87         super();
88
89         // Set the event protocol properties for the YAML event protocol
90         this.setLabel(eventProtocolLabel);
91
92         // Set the delimiter token for text blocks of YAML events
93         this.setStartDelimiterToken(YAML_START_TEXT_DELIMITER_TOKEN);
94         this.setEndDelimiterToken(YAML_END_TEXT_DELIMITER_TOKEN);
95
96         // Set the event protocol plugin class
97         this.setEventProtocolPluginClass(Apex2YamlEventConverter.class.getName());
98     }
99 }