aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/main/java/org/onap/policy/apex/plugins/event/protocol/yaml/YamlEventProtocolParameters.java
blob: e5539cd0419d9f100aba0c20451745721464d1c0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*-
 * ============LICENSE_START=======================================================
 *  Copyright (C) 2016-2018 Ericsson. All rights reserved.
 *  Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * SPDX-License-Identifier: Apache-2.0
 * ============LICENSE_END=========================================================
 */

package org.onap.policy.apex.plugins.event.protocol.yaml;

import lombok.Getter;
import lombok.Setter;
import org.onap.policy.apex.service.parameters.eventprotocol.EventProtocolTextTokenDelimitedParameters;

/**
 * Event protocol parameters for YAML as an event protocol.
 *
 * <p>The parameters for this plugin are:
 * <ol>
 * <li>nameAlias: The field in a YAML event to use as an alias for the event name. This parameter is
 * optional.
 * <li>versionAlias: The field in a YAML event to use as an alias for the event version. This
 * parameter is optional.
 * <li>nameSpaceAlias: The field in a YAML event to use as an alias for the event name space. This
 * parameter is optional.
 * <li>sourceAlias: The field in a YAML event to use as an alias for the event source. This
 * parameter is optional.
 * <li>targetAlias: The field in a YAML event to use as an alias for the event target. This
 * parameter is optional.
 * <li>yamlFieldName: The name of the field in the APEX event that will contain the unmarshaled YAML object. The
 * parameter is optional and defaults to the value "yaml_field".
 * </ol>
 *
 * @author Liam Fallon (liam.fallon@ericsson.com)
 */
@Getter
@Setter
public class YamlEventProtocolParameters extends EventProtocolTextTokenDelimitedParameters {
    /** The label of this event protocol. */
    public static final String YAML_EVENT_PROTOCOL_LABEL = "YAML";

    // Constants for text block delimiters
    private static final String YAML_START_TEXT_DELIMITER_TOKEN = "---";
    private static final String YAML_END_TEXT_DELIMITER_TOKEN = "...";

    // Default parameter values
    private static final String DEFAULT_YAML_FIELD_NAME = "yaml_field";

    // Aliases for Apex event header fields
    // @formatter:off
    private String nameAlias      = null;
    private String versionAlias   = null;
    private String nameSpaceAlias = null;
    private String sourceAlias    = null;
    private String targetAlias    = null;
    private String yamlFieldName  = DEFAULT_YAML_FIELD_NAME;
    // @formatter:on

    /**
     * Constructor to create a YAML event protocol parameter instance and register the instance with
     * the parameter service.
     */
    public YamlEventProtocolParameters() {
        this(YAML_EVENT_PROTOCOL_LABEL);
    }

    /**
     * Constructor to create an event protocol parameters instance with the name of a sub class of
     * this class.
     *
     * @param eventProtocolLabel the name of the event protocol for this plugin
     */
    public YamlEventProtocolParameters(final String eventProtocolLabel) {
        super();

        // Set the event protocol properties for the YAML event protocol
        this.setLabel(eventProtocolLabel);

        // Set the delimiter token for text blocks of YAML events
        this.setStartDelimiterToken(YAML_START_TEXT_DELIMITER_TOKEN);
        this.setEndDelimiterToken(YAML_END_TEXT_DELIMITER_TOKEN);

        // Set the event protocol plugin class
        this.setEventProtocolPluginClass(Apex2YamlEventConverter.class.getName());
    }
}